From 342945dc4ff166517fb89e38f28e027e3b71f8c8 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Wed, 22 Jan 2025 07:44:09 -0300 Subject: s/List/Vector/g --- tests/functional/vector-api/pds.go | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/functional/vector-api/pds.go (limited to 'tests/functional/vector-api/pds.go') 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", + }) + }) +} -- cgit v1.2.3