diff options
author | EuAndreh <eu@euandre.org> | 2025-01-22 07:44:09 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2025-01-22 07:51:07 -0300 |
commit | 342945dc4ff166517fb89e38f28e027e3b71f8c8 (patch) | |
tree | fb63c8bf13121c3a98b0eb73551ff548a566b8cf /tests/functional/vector-api/pds.go | |
parent | tests/pds.go: Init removal of "testing" usage (diff) | |
download | pds-342945dc4ff166517fb89e38f28e027e3b71f8c8.tar.gz pds-342945dc4ff166517fb89e38f28e027e3b71f8c8.tar.xz |
s/List/Vector/g
Diffstat (limited to 'tests/functional/vector-api/pds.go')
-rw-r--r-- | tests/functional/vector-api/pds.go | 61 |
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", + }) + }) +} |