aboutsummaryrefslogtreecommitdiff
path: root/tests/functional/vector-api/pds.go
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functional/vector-api/pds.go')
-rw-r--r--tests/functional/vector-api/pds.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/functional/vector-api/pds.go b/tests/functional/vector-api/pds.go
new file mode 100644
index 0000000..aa37949
--- /dev/null
+++ b/tests/functional/vector-api/pds.go
@@ -0,0 +1,61 @@
+package pds
+
+import (
+ g "gobang"
+)
+
+
+
+func MainTest() {
+ g.Testing("NewVector() - API usage", func() {
+ l := NewVector[string]().Append("foo").Append("bar").Append("baz")
+ g.TAssertEqual(l.Get(0), "foo")
+ g.TAssertEqual(l.Get(1), "bar")
+ g.TAssertEqual(l.Get(2), "baz")
+
+ l = l.Prepend("a").Prepend("b").Prepend("c")
+ g.TAssertEqual(l.Get(0), "c")
+ g.TAssertEqual(l.Get(1), "b")
+ g.TAssertEqual(l.Get(2), "a")
+
+ l = l.Set(0, "_")
+ g.TAssertEqual(l.Get(0), "_")
+
+ l = l.Slice(1, 3)
+ g.TAssertEqual(l.Get(0), "b")
+ g.TAssertEqual(l.Get(1), "a")
+ g.TAssertEqual(l.Len(), 2)
+ })
+
+ g.Testing("NewVector().Iterator() - API usage", func() {
+ l := NewVector[string]()
+ l = l.Append("foo")
+ l = l.Append("bar")
+ l = l.Append("baz")
+
+ indexes := []int{}
+ values := []string{}
+ itr := l.Iterator()
+ for !itr.Done() {
+ i, v := itr.Next()
+ indexes = append(indexes, i)
+ values = append(values, v)
+ }
+ itr.Last()
+ for !itr.Done() {
+ i, v := itr.Prev()
+ indexes = append(indexes, i)
+ values = append(values, v)
+ }
+
+ g.TAssertEqual(indexes, []int{0, 1, 2, 2, 1, 0})
+ g.TAssertEqual(values, []string{
+ "foo",
+ "bar",
+ "baz",
+ "baz",
+ "bar",
+ "foo",
+ })
+ })
+}