aboutsummaryrefslogtreecommitdiff
path: root/tests/functional/list-api/pds.go
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-12-27 04:55:33 -0300
committerEuAndreh <eu@euandre.org>2024-12-27 04:55:33 -0300
commit2764d269764e5c34c0d94ea58a5544692762560d (patch)
treeb90c4bf1b9905566c00f9a7436c2cc79f1c8d843 /tests/functional/list-api/pds.go
parentAdd Makefile and move files to structured folders (diff)
downloadpds-2764d269764e5c34c0d94ea58a5544692762560d.tar.gz
pds-2764d269764e5c34c0d94ea58a5544692762560d.tar.xz
tests/pds.go: Move benchmarks and examples to separate test files
Diffstat (limited to 'tests/functional/list-api/pds.go')
-rw-r--r--tests/functional/list-api/pds.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/functional/list-api/pds.go b/tests/functional/list-api/pds.go
new file mode 100644
index 0000000..c4290c8
--- /dev/null
+++ b/tests/functional/list-api/pds.go
@@ -0,0 +1,61 @@
+package pds
+
+import (
+ g "gobang"
+)
+
+
+
+func MainTest() {
+ g.Testing("NewList() - API usage", func() {
+ l := NewList[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("NewList().Iterator() - API usage", func() {
+ l := NewList[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",
+ })
+ })
+}