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/benchmarks/list-append/main.go | 1 - tests/benchmarks/list-append/pds.go | 23 --- tests/benchmarks/list-builder-append/main.go | 1 - tests/benchmarks/list-builder-append/pds.go | 23 --- tests/benchmarks/list-builder-prepend/main.go | 1 - tests/benchmarks/list-builder-prepend/pds.go | 23 --- tests/benchmarks/list-builder-set/main.go | 1 - tests/benchmarks/list-builder-set/pds.go | 27 ---- tests/benchmarks/list-iterator-backward/main.go | 1 - tests/benchmarks/list-iterator-backward/pds.go | 29 ---- tests/benchmarks/list-iterator-forward/main.go | 1 - tests/benchmarks/list-iterator-forward/pds.go | 29 ---- tests/benchmarks/list-prepend/main.go | 1 - tests/benchmarks/list-prepend/pds.go | 23 --- tests/benchmarks/list-set/main.go | 1 - tests/benchmarks/list-set/pds.go | 27 ---- tests/benchmarks/vector-append/main.go | 1 + tests/benchmarks/vector-append/pds.go | 23 +++ tests/benchmarks/vector-builder-append/main.go | 1 + tests/benchmarks/vector-builder-append/pds.go | 23 +++ tests/benchmarks/vector-builder-prepend/main.go | 1 + tests/benchmarks/vector-builder-prepend/pds.go | 23 +++ tests/benchmarks/vector-builder-set/main.go | 1 + tests/benchmarks/vector-builder-set/pds.go | 27 ++++ tests/benchmarks/vector-iterator-backward/main.go | 1 + tests/benchmarks/vector-iterator-backward/pds.go | 29 ++++ tests/benchmarks/vector-iterator-forward/main.go | 1 + tests/benchmarks/vector-iterator-forward/pds.go | 29 ++++ tests/benchmarks/vector-prepend/main.go | 1 + tests/benchmarks/vector-prepend/pds.go | 23 +++ tests/benchmarks/vector-set/main.go | 1 + tests/benchmarks/vector-set/pds.go | 27 ++++ tests/functional/list-api/main.go | 1 - tests/functional/list-api/pds.go | 61 -------- tests/functional/list-builder-api/main.go | 1 - tests/functional/list-builder-api/pds.go | 53 ------- tests/functional/vector-api/main.go | 1 + tests/functional/vector-api/pds.go | 61 ++++++++ tests/functional/vector-builder-api/main.go | 1 + tests/functional/vector-builder-api/pds.go | 53 +++++++ tests/pds.go | 172 +++++++++++----------- 41 files changed, 414 insertions(+), 414 deletions(-) delete mode 120000 tests/benchmarks/list-append/main.go delete mode 100644 tests/benchmarks/list-append/pds.go delete mode 120000 tests/benchmarks/list-builder-append/main.go delete mode 100644 tests/benchmarks/list-builder-append/pds.go delete mode 120000 tests/benchmarks/list-builder-prepend/main.go delete mode 100644 tests/benchmarks/list-builder-prepend/pds.go delete mode 120000 tests/benchmarks/list-builder-set/main.go delete mode 100644 tests/benchmarks/list-builder-set/pds.go delete mode 120000 tests/benchmarks/list-iterator-backward/main.go delete mode 100644 tests/benchmarks/list-iterator-backward/pds.go delete mode 120000 tests/benchmarks/list-iterator-forward/main.go delete mode 100644 tests/benchmarks/list-iterator-forward/pds.go delete mode 120000 tests/benchmarks/list-prepend/main.go delete mode 100644 tests/benchmarks/list-prepend/pds.go delete mode 120000 tests/benchmarks/list-set/main.go delete mode 100644 tests/benchmarks/list-set/pds.go create mode 120000 tests/benchmarks/vector-append/main.go create mode 100644 tests/benchmarks/vector-append/pds.go create mode 120000 tests/benchmarks/vector-builder-append/main.go create mode 100644 tests/benchmarks/vector-builder-append/pds.go create mode 120000 tests/benchmarks/vector-builder-prepend/main.go create mode 100644 tests/benchmarks/vector-builder-prepend/pds.go create mode 120000 tests/benchmarks/vector-builder-set/main.go create mode 100644 tests/benchmarks/vector-builder-set/pds.go create mode 120000 tests/benchmarks/vector-iterator-backward/main.go create mode 100644 tests/benchmarks/vector-iterator-backward/pds.go create mode 120000 tests/benchmarks/vector-iterator-forward/main.go create mode 100644 tests/benchmarks/vector-iterator-forward/pds.go create mode 120000 tests/benchmarks/vector-prepend/main.go create mode 100644 tests/benchmarks/vector-prepend/pds.go create mode 120000 tests/benchmarks/vector-set/main.go create mode 100644 tests/benchmarks/vector-set/pds.go delete mode 120000 tests/functional/list-api/main.go delete mode 100644 tests/functional/list-api/pds.go delete mode 120000 tests/functional/list-builder-api/main.go delete mode 100644 tests/functional/list-builder-api/pds.go create mode 120000 tests/functional/vector-api/main.go create mode 100644 tests/functional/vector-api/pds.go create mode 120000 tests/functional/vector-builder-api/main.go create mode 100644 tests/functional/vector-builder-api/pds.go (limited to 'tests') diff --git a/tests/benchmarks/list-append/main.go b/tests/benchmarks/list-append/main.go deleted file mode 120000 index f67563d..0000000 --- a/tests/benchmarks/list-append/main.go +++ /dev/null @@ -1 +0,0 @@ -../../main.go \ No newline at end of file diff --git a/tests/benchmarks/list-append/pds.go b/tests/benchmarks/list-append/pds.go deleted file mode 100644 index a9b7690..0000000 --- a/tests/benchmarks/list-append/pds.go +++ /dev/null @@ -1,23 +0,0 @@ -package pds - -import ( - "flag" -) - - - -var nFlag = flag.Int( - "n", - 1_000, - "The number of iterations to execute", -) - -func MainTest() { - flag.Parse() - n := *nFlag - - l := NewList[int]() - for i := 0; i < n; i++ { - l = l.Append(i) - } -} diff --git a/tests/benchmarks/list-builder-append/main.go b/tests/benchmarks/list-builder-append/main.go deleted file mode 120000 index f67563d..0000000 --- a/tests/benchmarks/list-builder-append/main.go +++ /dev/null @@ -1 +0,0 @@ -../../main.go \ No newline at end of file diff --git a/tests/benchmarks/list-builder-append/pds.go b/tests/benchmarks/list-builder-append/pds.go deleted file mode 100644 index 3357ee6..0000000 --- a/tests/benchmarks/list-builder-append/pds.go +++ /dev/null @@ -1,23 +0,0 @@ -package pds - -import ( - "flag" -) - - - -var nFlag = flag.Int( - "n", - 1_000, - "The number of iterations to execute", -) - -func MainTest() { - flag.Parse() - n := *nFlag - - builder := NewListBuilder[int]() - for i := 0; i < n; i++ { - builder.Append(i) - } -} diff --git a/tests/benchmarks/list-builder-prepend/main.go b/tests/benchmarks/list-builder-prepend/main.go deleted file mode 120000 index f67563d..0000000 --- a/tests/benchmarks/list-builder-prepend/main.go +++ /dev/null @@ -1 +0,0 @@ -../../main.go \ No newline at end of file diff --git a/tests/benchmarks/list-builder-prepend/pds.go b/tests/benchmarks/list-builder-prepend/pds.go deleted file mode 100644 index 572b6b6..0000000 --- a/tests/benchmarks/list-builder-prepend/pds.go +++ /dev/null @@ -1,23 +0,0 @@ -package pds - -import ( - "flag" -) - - - -var nFlag = flag.Int( - "n", - 1_000, - "The number of iterations to execute", -) - -func MainTest() { - flag.Parse() - n := *nFlag - - builder := NewListBuilder[int]() - for i := 0; i < n; i++ { - builder.Prepend(i) - } -} diff --git a/tests/benchmarks/list-builder-set/main.go b/tests/benchmarks/list-builder-set/main.go deleted file mode 120000 index f67563d..0000000 --- a/tests/benchmarks/list-builder-set/main.go +++ /dev/null @@ -1 +0,0 @@ -../../main.go \ No newline at end of file diff --git a/tests/benchmarks/list-builder-set/pds.go b/tests/benchmarks/list-builder-set/pds.go deleted file mode 100644 index 4080e22..0000000 --- a/tests/benchmarks/list-builder-set/pds.go +++ /dev/null @@ -1,27 +0,0 @@ -package pds - -import ( - "flag" -) - - - -var nFlag = flag.Int( - "n", - 1_000, - "The number of iterations to execute", -) - -func MainTest() { - flag.Parse() - n := *nFlag - - builder := NewListBuilder[int]() - for i := 0; i < n; i++ { - builder.Append(i) - } - - for i := 0; i < n; i++ { - builder.Set(i, i * 10) - } -} diff --git a/tests/benchmarks/list-iterator-backward/main.go b/tests/benchmarks/list-iterator-backward/main.go deleted file mode 120000 index f67563d..0000000 --- a/tests/benchmarks/list-iterator-backward/main.go +++ /dev/null @@ -1 +0,0 @@ -../../main.go \ No newline at end of file diff --git a/tests/benchmarks/list-iterator-backward/pds.go b/tests/benchmarks/list-iterator-backward/pds.go deleted file mode 100644 index 6ca51e4..0000000 --- a/tests/benchmarks/list-iterator-backward/pds.go +++ /dev/null @@ -1,29 +0,0 @@ -package pds - -import ( - "flag" -) - - - -var nFlag = flag.Int( - "n", - 1_000, - "The number of iterations to execute", -) - -func MainTest() { - flag.Parse() - n := *nFlag - - l := NewList[int]() - for i := 0; i < n; i++ { - l = l.Append(i) - } - - itr := l.Iterator() - itr.Last() - for i := 0; i < n; i++ { - itr.Prev() - } -} diff --git a/tests/benchmarks/list-iterator-forward/main.go b/tests/benchmarks/list-iterator-forward/main.go deleted file mode 120000 index f67563d..0000000 --- a/tests/benchmarks/list-iterator-forward/main.go +++ /dev/null @@ -1 +0,0 @@ -../../main.go \ No newline at end of file diff --git a/tests/benchmarks/list-iterator-forward/pds.go b/tests/benchmarks/list-iterator-forward/pds.go deleted file mode 100644 index 6831dad..0000000 --- a/tests/benchmarks/list-iterator-forward/pds.go +++ /dev/null @@ -1,29 +0,0 @@ -package pds - -import ( - "flag" -) - - - -var nFlag = flag.Int( - "n", - 1_000, - "The number of iterations to execute", -) - -func MainTest() { - flag.Parse() - n := *nFlag - - l := NewList[int]() - for i := 0; i < n; i++ { - l = l.Append(i) - } - - itr := l.Iterator() - itr.First() - for i := 0; i < n; i++ { - itr.Next() - } -} diff --git a/tests/benchmarks/list-prepend/main.go b/tests/benchmarks/list-prepend/main.go deleted file mode 120000 index f67563d..0000000 --- a/tests/benchmarks/list-prepend/main.go +++ /dev/null @@ -1 +0,0 @@ -../../main.go \ No newline at end of file diff --git a/tests/benchmarks/list-prepend/pds.go b/tests/benchmarks/list-prepend/pds.go deleted file mode 100644 index 918ff72..0000000 --- a/tests/benchmarks/list-prepend/pds.go +++ /dev/null @@ -1,23 +0,0 @@ -package pds - -import ( - "flag" -) - - - -var nFlag = flag.Int( - "n", - 1_000, - "The number of iterations to execute", -) - -func MainTest() { - flag.Parse() - n := *nFlag - - l := NewList[int]() - for i := 0; i < n; i++ { - l = l.Prepend(i) - } -} diff --git a/tests/benchmarks/list-set/main.go b/tests/benchmarks/list-set/main.go deleted file mode 120000 index f67563d..0000000 --- a/tests/benchmarks/list-set/main.go +++ /dev/null @@ -1 +0,0 @@ -../../main.go \ No newline at end of file diff --git a/tests/benchmarks/list-set/pds.go b/tests/benchmarks/list-set/pds.go deleted file mode 100644 index e2d3709..0000000 --- a/tests/benchmarks/list-set/pds.go +++ /dev/null @@ -1,27 +0,0 @@ -package pds - -import ( - "flag" -) - - - -var nFlag = flag.Int( - "n", - 1_000, - "The number of iterations to execute", -) - -func MainTest() { - flag.Parse() - n := *nFlag - - l := NewList[int]() - for i := 0; i < n; i++ { - l = l.Append(i) - } - - for i := 0; i < n; i++ { - l = l.Set(i, i * 10) - } -} diff --git a/tests/benchmarks/vector-append/main.go b/tests/benchmarks/vector-append/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/benchmarks/vector-append/main.go @@ -0,0 +1 @@ +../../main.go \ No newline at end of file diff --git a/tests/benchmarks/vector-append/pds.go b/tests/benchmarks/vector-append/pds.go new file mode 100644 index 0000000..58368b3 --- /dev/null +++ b/tests/benchmarks/vector-append/pds.go @@ -0,0 +1,23 @@ +package pds + +import ( + "flag" +) + + + +var nFlag = flag.Int( + "n", + 1_000, + "The number of iterations to execute", +) + +func MainTest() { + flag.Parse() + n := *nFlag + + l := NewVector[int]() + for i := 0; i < n; i++ { + l = l.Append(i) + } +} diff --git a/tests/benchmarks/vector-builder-append/main.go b/tests/benchmarks/vector-builder-append/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/benchmarks/vector-builder-append/main.go @@ -0,0 +1 @@ +../../main.go \ No newline at end of file diff --git a/tests/benchmarks/vector-builder-append/pds.go b/tests/benchmarks/vector-builder-append/pds.go new file mode 100644 index 0000000..ab5cdec --- /dev/null +++ b/tests/benchmarks/vector-builder-append/pds.go @@ -0,0 +1,23 @@ +package pds + +import ( + "flag" +) + + + +var nFlag = flag.Int( + "n", + 1_000, + "The number of iterations to execute", +) + +func MainTest() { + flag.Parse() + n := *nFlag + + builder := NewVectorBuilder[int]() + for i := 0; i < n; i++ { + builder.Append(i) + } +} diff --git a/tests/benchmarks/vector-builder-prepend/main.go b/tests/benchmarks/vector-builder-prepend/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/benchmarks/vector-builder-prepend/main.go @@ -0,0 +1 @@ +../../main.go \ No newline at end of file diff --git a/tests/benchmarks/vector-builder-prepend/pds.go b/tests/benchmarks/vector-builder-prepend/pds.go new file mode 100644 index 0000000..9d1d669 --- /dev/null +++ b/tests/benchmarks/vector-builder-prepend/pds.go @@ -0,0 +1,23 @@ +package pds + +import ( + "flag" +) + + + +var nFlag = flag.Int( + "n", + 1_000, + "The number of iterations to execute", +) + +func MainTest() { + flag.Parse() + n := *nFlag + + builder := NewVectorBuilder[int]() + for i := 0; i < n; i++ { + builder.Prepend(i) + } +} diff --git a/tests/benchmarks/vector-builder-set/main.go b/tests/benchmarks/vector-builder-set/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/benchmarks/vector-builder-set/main.go @@ -0,0 +1 @@ +../../main.go \ No newline at end of file diff --git a/tests/benchmarks/vector-builder-set/pds.go b/tests/benchmarks/vector-builder-set/pds.go new file mode 100644 index 0000000..c4d5b2b --- /dev/null +++ b/tests/benchmarks/vector-builder-set/pds.go @@ -0,0 +1,27 @@ +package pds + +import ( + "flag" +) + + + +var nFlag = flag.Int( + "n", + 1_000, + "The number of iterations to execute", +) + +func MainTest() { + flag.Parse() + n := *nFlag + + builder := NewVectorBuilder[int]() + for i := 0; i < n; i++ { + builder.Append(i) + } + + for i := 0; i < n; i++ { + builder.Set(i, i * 10) + } +} diff --git a/tests/benchmarks/vector-iterator-backward/main.go b/tests/benchmarks/vector-iterator-backward/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/benchmarks/vector-iterator-backward/main.go @@ -0,0 +1 @@ +../../main.go \ No newline at end of file diff --git a/tests/benchmarks/vector-iterator-backward/pds.go b/tests/benchmarks/vector-iterator-backward/pds.go new file mode 100644 index 0000000..a03e138 --- /dev/null +++ b/tests/benchmarks/vector-iterator-backward/pds.go @@ -0,0 +1,29 @@ +package pds + +import ( + "flag" +) + + + +var nFlag = flag.Int( + "n", + 1_000, + "The number of iterations to execute", +) + +func MainTest() { + flag.Parse() + n := *nFlag + + l := NewVector[int]() + for i := 0; i < n; i++ { + l = l.Append(i) + } + + itr := l.Iterator() + itr.Last() + for i := 0; i < n; i++ { + itr.Prev() + } +} diff --git a/tests/benchmarks/vector-iterator-forward/main.go b/tests/benchmarks/vector-iterator-forward/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/benchmarks/vector-iterator-forward/main.go @@ -0,0 +1 @@ +../../main.go \ No newline at end of file diff --git a/tests/benchmarks/vector-iterator-forward/pds.go b/tests/benchmarks/vector-iterator-forward/pds.go new file mode 100644 index 0000000..298fd4e --- /dev/null +++ b/tests/benchmarks/vector-iterator-forward/pds.go @@ -0,0 +1,29 @@ +package pds + +import ( + "flag" +) + + + +var nFlag = flag.Int( + "n", + 1_000, + "The number of iterations to execute", +) + +func MainTest() { + flag.Parse() + n := *nFlag + + l := NewVector[int]() + for i := 0; i < n; i++ { + l = l.Append(i) + } + + itr := l.Iterator() + itr.First() + for i := 0; i < n; i++ { + itr.Next() + } +} diff --git a/tests/benchmarks/vector-prepend/main.go b/tests/benchmarks/vector-prepend/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/benchmarks/vector-prepend/main.go @@ -0,0 +1 @@ +../../main.go \ No newline at end of file diff --git a/tests/benchmarks/vector-prepend/pds.go b/tests/benchmarks/vector-prepend/pds.go new file mode 100644 index 0000000..4f82cea --- /dev/null +++ b/tests/benchmarks/vector-prepend/pds.go @@ -0,0 +1,23 @@ +package pds + +import ( + "flag" +) + + + +var nFlag = flag.Int( + "n", + 1_000, + "The number of iterations to execute", +) + +func MainTest() { + flag.Parse() + n := *nFlag + + l := NewVector[int]() + for i := 0; i < n; i++ { + l = l.Prepend(i) + } +} diff --git a/tests/benchmarks/vector-set/main.go b/tests/benchmarks/vector-set/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/benchmarks/vector-set/main.go @@ -0,0 +1 @@ +../../main.go \ No newline at end of file diff --git a/tests/benchmarks/vector-set/pds.go b/tests/benchmarks/vector-set/pds.go new file mode 100644 index 0000000..ce0ee55 --- /dev/null +++ b/tests/benchmarks/vector-set/pds.go @@ -0,0 +1,27 @@ +package pds + +import ( + "flag" +) + + + +var nFlag = flag.Int( + "n", + 1_000, + "The number of iterations to execute", +) + +func MainTest() { + flag.Parse() + n := *nFlag + + l := NewVector[int]() + for i := 0; i < n; i++ { + l = l.Append(i) + } + + for i := 0; i < n; i++ { + l = l.Set(i, i * 10) + } +} diff --git a/tests/functional/list-api/main.go b/tests/functional/list-api/main.go deleted file mode 120000 index f67563d..0000000 --- a/tests/functional/list-api/main.go +++ /dev/null @@ -1 +0,0 @@ -../../main.go \ No newline at end of file diff --git a/tests/functional/list-api/pds.go b/tests/functional/list-api/pds.go deleted file mode 100644 index c4290c8..0000000 --- a/tests/functional/list-api/pds.go +++ /dev/null @@ -1,61 +0,0 @@ -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", - }) - }) -} diff --git a/tests/functional/list-builder-api/main.go b/tests/functional/list-builder-api/main.go deleted file mode 120000 index f67563d..0000000 --- a/tests/functional/list-builder-api/main.go +++ /dev/null @@ -1 +0,0 @@ -../../main.go \ No newline at end of file diff --git a/tests/functional/list-builder-api/pds.go b/tests/functional/list-builder-api/pds.go deleted file mode 100644 index c7b632c..0000000 --- a/tests/functional/list-builder-api/pds.go +++ /dev/null @@ -1,53 +0,0 @@ -package pds - -import ( - g "gobang" -) - - - -func MainTest() { - g.Testing("API usage", func() { - b1 := NewListBuilder[string]() - b1.Append("foo") - b1.Append("bar") - b1.Append("baz") - - l1 := b1.List() - g.TAssertEqual(l1.Get(0), "foo") - g.TAssertEqual(l1.Get(1), "bar") - g.TAssertEqual(l1.Get(2), "baz") - - - b2 := NewListBuilder[string]() - b2.Prepend("foo") - b2.Prepend("bar") - b2.Prepend("baz") - - l2 := b2.List() - g.TAssertEqual(l2.Get(0), "baz") - g.TAssertEqual(l2.Get(1), "bar") - g.TAssertEqual(l2.Get(2), "foo") - - - b3 := NewListBuilder[string]() - b3.Append("foo") - b3.Append("bar") - b3.Set(1, "___") - l3 := b3.List() - g.TAssertEqual(l3.Get(0), "foo") - g.TAssertEqual(l3.Get(1), "___") - - - b4 := NewListBuilder[string]() - b4.Append("foo") - b4.Append("bar") - b4.Append("baz") - b4.Slice(1, 3) - - l4 := b4.List() - g.TAssertEqual(l4.Len(), 2) - g.TAssertEqual(l4.Get(0), "bar") - g.TAssertEqual(l4.Get(1), "baz") - }) -} diff --git a/tests/functional/vector-api/main.go b/tests/functional/vector-api/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/functional/vector-api/main.go @@ -0,0 +1 @@ +../../main.go \ No newline at end of file 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", + }) + }) +} diff --git a/tests/functional/vector-builder-api/main.go b/tests/functional/vector-builder-api/main.go new file mode 120000 index 0000000..f67563d --- /dev/null +++ b/tests/functional/vector-builder-api/main.go @@ -0,0 +1 @@ +../../main.go \ No newline at end of file diff --git a/tests/functional/vector-builder-api/pds.go b/tests/functional/vector-builder-api/pds.go new file mode 100644 index 0000000..6dd8c2f --- /dev/null +++ b/tests/functional/vector-builder-api/pds.go @@ -0,0 +1,53 @@ +package pds + +import ( + g "gobang" +) + + + +func MainTest() { + g.Testing("API usage", func() { + b1 := NewVectorBuilder[string]() + b1.Append("foo") + b1.Append("bar") + b1.Append("baz") + + l1 := b1.Vector() + g.TAssertEqual(l1.Get(0), "foo") + g.TAssertEqual(l1.Get(1), "bar") + g.TAssertEqual(l1.Get(2), "baz") + + + b2 := NewVectorBuilder[string]() + b2.Prepend("foo") + b2.Prepend("bar") + b2.Prepend("baz") + + l2 := b2.Vector() + g.TAssertEqual(l2.Get(0), "baz") + g.TAssertEqual(l2.Get(1), "bar") + g.TAssertEqual(l2.Get(2), "foo") + + + b3 := NewVectorBuilder[string]() + b3.Append("foo") + b3.Append("bar") + b3.Set(1, "___") + l3 := b3.Vector() + g.TAssertEqual(l3.Get(0), "foo") + g.TAssertEqual(l3.Get(1), "___") + + + b4 := NewVectorBuilder[string]() + b4.Append("foo") + b4.Append("bar") + b4.Append("baz") + b4.Slice(1, 3) + + l4 := b4.Vector() + g.TAssertEqual(l4.Len(), 2) + g.TAssertEqual(l4.Get(0), "bar") + g.TAssertEqual(l4.Get(1), "baz") + }) +} diff --git a/tests/pds.go b/tests/pds.go index 049edae..33ef400 100644 --- a/tests/pds.go +++ b/tests/pds.go @@ -15,50 +15,50 @@ import ( -func test_NewList() { - g.TestStart("NewList[]()") +func test_NewVector() { + g.TestStart("NewVector[]()") - g.Testing("a brand new list starts empty", func() { - g.TAssertEqual(NewList[int]().Len(), 0) + g.Testing("a brand new vector starts empty", func() { + g.TAssertEqual(NewVector[int]().Len(), 0) }) } -func TestList(t *testing.T) { +func TestVector(t *testing.T) { t.Run("Shallow", func(t *testing.T) { - list := NewList[string]() - list = list.Append("foo") - if v := list.Get(0); v != "foo" { + vector := NewVector[string]() + vector = vector.Append("foo") + if v := vector.Get(0); v != "foo" { t.Fatalf("unexpected value: %v", v) } - other := list.Append("bar") + other := vector.Append("bar") if v := other.Get(0); v != "foo" { t.Fatalf("unexpected value: %v", v) } else if v := other.Get(1); v != "bar" { t.Fatalf("unexpected value: %v", v) } - if v := list.Len(); v != 1 { + if v := vector.Len(); v != 1 { t.Fatalf("unexpected value: %v", v) } }) t.Run("Deep", func(t *testing.T) { - list := NewList[int]() + vector := NewVector[int]() var array []int const n = 1000 // FIXME: 100000 was too slow for i := 0; i < n; i++ { - list = list.Append(i) + vector = vector.Append(i) array = append(array, i) } - if got, exp := len(array), list.Len(); got != exp { - t.Fatalf("List.Len()=%d, exp %d", got, exp) + if got, exp := len(array), vector.Len(); got != exp { + t.Fatalf("Vector.Len()=%d, exp %d", got, exp) } for j := range array { - if got, exp := list.Get(j), array[j]; got != exp { + if got, exp := vector.Get(j), array[j]; got != exp { t.Fatalf( - "%d. List.Get(%d)=%d, exp %d", + "%d. Vector.Get(%d)=%d, exp %d", len(array), j, got, @@ -69,18 +69,18 @@ func TestList(t *testing.T) { }) t.Run("Set", func(t *testing.T) { - list := NewList[string]() - list = list.Append("foo") - list = list.Append("bar") + vector := NewVector[string]() + vector = vector.Append("foo") + vector = vector.Append("bar") - if v := list.Get(0); v != "foo" { + if v := vector.Get(0); v != "foo" { t.Fatalf("unexpected value: %v", v) } - list = list.Set(0, "baz") - if v := list.Get(0); v != "baz" { + vector = vector.Set(0, "baz") + if v := vector.Get(0); v != "baz" { t.Fatalf("unexpected value: %v", v) - } else if v := list.Get(1); v != "bar" { + } else if v := vector.Get(1); v != "bar" { t.Fatalf("unexpected value: %v", v) } }) @@ -89,11 +89,11 @@ func TestList(t *testing.T) { var r string func() { defer func() { r = recover().(string) }() - l := NewList[string]() + l := NewVector[string]() l = l.Append("foo") l.Get(-1) }() - if r != `immutable.List.Get: index -1 out of bounds` { + if r != `immutable.Vector.Get: index -1 out of bounds` { t.Fatalf("unexpected panic: %q", r) } }) @@ -102,11 +102,11 @@ func TestList(t *testing.T) { var r string func() { defer func() { r = recover().(string) }() - l := NewList[string]() + l := NewVector[string]() l = l.Append("foo") l.Get(1) }() - if r != `immutable.List.Get: index 1 out of bounds` { + if r != `immutable.Vector.Get: index 1 out of bounds` { t.Fatalf("unexpected panic: %q", r) } }) @@ -115,11 +115,11 @@ func TestList(t *testing.T) { var r string func() { defer func() { r = recover().(string) }() - l := NewList[string]() + l := NewVector[string]() l = l.Append("foo") l.Set(1, "bar") }() - if r != `immutable.List.Set: index 1 out of bounds` { + if r != `immutable.Vector.Set: index 1 out of bounds` { t.Fatalf("unexpected panic: %q", r) } }) @@ -128,11 +128,11 @@ func TestList(t *testing.T) { var r string func() { defer func() { r = recover().(string) }() - l := NewList[string]() + l := NewVector[string]() l = l.Append("foo") l.Slice(2, 3) }() - if r != `immutable.List.Slice: start index 2 out of bounds` { + if r != `immutable.Vector.Slice: start index 2 out of bounds` { t.Fatalf("unexpected panic: %q", r) } }) @@ -141,11 +141,11 @@ func TestList(t *testing.T) { var r string func() { defer func() { r = recover().(string) }() - l := NewList[string]() + l := NewVector[string]() l = l.Append("foo") l.Slice(1, 3) }() - if r != `immutable.List.Slice: end index 3 out of bounds` { + if r != `immutable.Vector.Slice: end index 3 out of bounds` { t.Fatalf("unexpected panic: %q", r) } }) @@ -154,25 +154,25 @@ func TestList(t *testing.T) { var r string func() { defer func() { r = recover().(string) }() - l := NewList[string]() + l := NewVector[string]() l = l.Append("foo") l = l.Append("bar") l.Slice(2, 1) }() - if r != `immutable.List.Slice: invalid slice index: [2:1]` { + if r != `immutable.Vector.Slice: invalid slice index: [2:1]` { t.Fatalf("unexpected panic: %q", r) } }) t.Run("SliceBeginning", func(t *testing.T) { - l := NewList[string]() + l := NewVector[string]() l = l.Append("foo") l = l.Append("bar") l = l.Slice(1, 2) if got, exp := l.Len(), 1; got != exp { - t.Fatalf("List.Len()=%d, exp %d", got, exp) + t.Fatalf("Vector.Len()=%d, exp %d", got, exp) } else if got, exp := l.Get(0), "bar"; got != exp { - t.Fatalf("List.Get(0)=%v, exp %v", got, exp) + t.Fatalf("Vector.Get(0)=%v, exp %v", got, exp) } }) @@ -180,35 +180,35 @@ func TestList(t *testing.T) { var r string func() { defer func() { r = recover().(string) }() - l := NewList[string]() + l := NewVector[string]() l = l.Append("foo") l.Iterator().Seek(-1) }() - if r != `immutable.ListIterator.Seek: index -1 out of bounds` { + if r != `immutable.VectorIterator.Seek: index -1 out of bounds` { t.Fatalf("unexpected panic: %q", r) } }) t.Run("TestSliceFreesReferences", func(t *testing.T) { - // Test that the leaf node in a sliced list contains zero'ed + // Test that the leaf node in a sliced vector contains zero'ed // entries at the correct positions. To do this we directly - // access the internal tree structure of the list. - l := NewList[*int]() + // access the internal tree structure of the vector. + l := NewVector[*int]() var ints [5]int for i := 0; i < 5; i++ { l = l.Append(&ints[i]) } sl := l.Slice(2, 4) - var findLeaf func(listNode[*int]) *listLeafNode[*int] - findLeaf = func(n listNode[*int]) *listLeafNode[*int] { + var findLeaf func(vectorNode[*int]) *vectorLeafNode[*int] + findLeaf = func(n vectorNode[*int]) *vectorLeafNode[*int] { switch n := n.(type) { - case *listBranchNode[*int]: + case *vectorBranchNode[*int]: if n.children[0] == nil { t.Fatal("Failed to find leaf node due to nil child") } return findLeaf(n.children[0]) - case *listLeafNode[*int]: + case *vectorLeafNode[*int]: return n default: panic("Unexpected case") @@ -220,7 +220,7 @@ func TestList(t *testing.T) { t.Errorf("Expected occupied to be 1100, was %032b", leaf.occupied) } - for i := 0; i < listNodeSize; i++ { + for i := 0; i < vectorNodeSize; i++ { if 2 <= i && i < 4 { if leaf.children[i] != &ints[i] { t.Errorf("Position %v does not contain the right pointer?", i) @@ -232,12 +232,12 @@ func TestList(t *testing.T) { }) t.Run("AppendImmutable", func(t *testing.T) { - outer_l := NewList[int]() + outer_l := NewVector[int]() for N := 0; N < 1_000; N++ { l1 := outer_l.Append(0) outer_l.Append(1) if actual := l1.Get(N); actual != 0 { - t.Fatalf("Append mutates list with %d elements. Got %d instead of 0", N, actual) + t.Fatalf("Append mutates vector with %d elements. Got %d instead of 0", N, actual) } outer_l = outer_l.Append(0) @@ -246,7 +246,7 @@ func TestList(t *testing.T) { RunRandom(t, "Random", func(t *testing.T, rand *rand.Rand) { const n = 100 // FIXME: 100000 was too slow - l := newTList() + l := newTVector() for i := 0; i < n; i++ { rnd := rand.Intn(70) switch { @@ -269,29 +269,29 @@ func TestList(t *testing.T) { }) } -// TList represents a list that operates on a standard Go slice & immutable -// list. -type tList struct { - im, prev *List[int] - builder *ListBuilder[int] +// TVector represents a vector that operates on a standard Go slice & immutable +// vector. +type tVector struct { + im, prev *Vector[int] + builder *VectorBuilder[int] std []int } -// newTList returns a new instance of tList. -func newTList() *tList { - return &tList{ - im: NewList[int](), - builder: NewListBuilder[int](), +// newTVector returns a new instance of tVector. +func newTVector() *tVector { + return &tVector{ + im: NewVector[int](), + builder: NewVectorBuilder[int](), } } -// Len returns the size of the list. -func (l *tList) Len() int { +// Len returns the size of the vector. +func (l *tVector) Len() int { return len(l.std) } // ChooseIndex returns a randomly chosen, valid index from the standard slice. -func (l *tList) ChooseIndex(rand *rand.Rand) int { +func (l *tVector) ChooseIndex(rand *rand.Rand) int { if len(l.std) == 0 { return -1 } @@ -299,7 +299,7 @@ func (l *tList) ChooseIndex(rand *rand.Rand) int { } // ChooseSliceIndices returns randomly chosen, valid indices for slicing. -func (l *tList) ChooseSliceIndices(rand *rand.Rand) (start, end int) { +func (l *tVector) ChooseSliceIndices(rand *rand.Rand) (start, end int) { if len(l.std) == 0 { return 0, 0 } @@ -308,40 +308,40 @@ func (l *tList) ChooseSliceIndices(rand *rand.Rand) (start, end int) { return start, end } -// Append adds v to the end of slice and List. -func (l *tList) Append(v int) { +// Append adds v to the end of slice and Vector. +func (l *tVector) Append(v int) { l.prev = l.im l.im = l.im.Append(v) l.builder.Append(v) l.std = append(l.std, v) } -// Prepend adds v to the beginning of the slice and List. -func (l *tList) Prepend(v int) { +// Prepend adds v to the beginning of the slice and Vector. +func (l *tVector) Prepend(v int) { l.prev = l.im l.im = l.im.Prepend(v) l.builder.Prepend(v) l.std = append([]int{v}, l.std...) } -// Set updates the value at index i to v in the slice and List. -func (l *tList) Set(i, v int) { +// Set updates the value at index i to v in the slice and Vector. +func (l *tVector) Set(i, v int) { l.prev = l.im l.im = l.im.Set(i, v) l.builder.Set(i, v) l.std[i] = v } -// Slice contracts the slice and List to the range of start/end indices. -func (l *tList) Slice(start, end int) { +// Slice contracts the slice and Vector to the range of start/end indices. +func (l *tVector) Slice(start, end int) { l.prev = l.im l.im = l.im.Slice(start, end) l.builder.Slice(start, end) l.std = l.std[start:end] } -// Validate returns an error if the slice and List are different. -func (l *tList) Validate() error { +// Validate returns an error if the slice and Vector are different. +func (l *tVector) Validate() error { if got, exp := l.im.Len(), len(l.std); got != exp { return fmt.Errorf("Len()=%v, expected %d", got, exp) } else if got, exp := l.builder.Len(), len(l.std); got != exp { @@ -352,7 +352,7 @@ func (l *tList) Validate() error { if got, exp := l.im.Get(i), l.std[i]; got != exp { return fmt.Errorf("Get(%d)=%v, expected %v", i, got, exp) } else if got, exp := l.builder.Get(i), l.std[i]; got != exp { - return fmt.Errorf("Builder.List/Get(%d)=%v, expected %v", i, got, exp) + return fmt.Errorf("Builder.Vector/Get(%d)=%v, expected %v", i, got, exp) } } @@ -370,37 +370,37 @@ func (l *tList) Validate() error { return nil } -func (l *tList) validateForwardIterator(typ string, itr *ListIterator[int]) error { +func (l *tVector) validateForwardIterator(typ string, itr *VectorIterator[int]) error { for i := range l.std { if j, v := itr.Next(); i != j || l.std[i] != v { - return fmt.Errorf("ListIterator.Next()=<%v,%v>, expected <%v,%v> [%s]", j, v, i, l.std[i], typ) + return fmt.Errorf("VectorIterator.Next()=<%v,%v>, expected <%v,%v> [%s]", j, v, i, l.std[i], typ) } done := i == len(l.std)-1 if v := itr.Done(); v != done { - return fmt.Errorf("ListIterator.Done()=%v, expected %v [%s]", v, done, typ) + return fmt.Errorf("VectorIterator.Done()=%v, expected %v [%s]", v, done, typ) } } if i, v := itr.Next(); i != -1 || v != 0 { - return fmt.Errorf("ListIterator.Next()=<%v,%v>, expected DONE [%s]", i, v, typ) + return fmt.Errorf("VectorIterator.Next()=<%v,%v>, expected DONE [%s]", i, v, typ) } return nil } -func (l *tList) validateBackwardIterator(typ string, itr *ListIterator[int]) error { +func (l *tVector) validateBackwardIterator(typ string, itr *VectorIterator[int]) error { itr.Last() for i := len(l.std) - 1; i >= 0; i-- { if j, v := itr.Prev(); i != j || l.std[i] != v { - return fmt.Errorf("ListIterator.Prev()=<%v,%v>, expected <%v,%v> [%s]", j, v, i, l.std[i], typ) + return fmt.Errorf("VectorIterator.Prev()=<%v,%v>, expected <%v,%v> [%s]", j, v, i, l.std[i], typ) } done := i == 0 if v := itr.Done(); v != done { - return fmt.Errorf("ListIterator.Done()=%v, expected %v [%s]", v, done, typ) + return fmt.Errorf("VectorIterator.Done()=%v, expected %v [%s]", v, done, typ) } } if i, v := itr.Prev(); i != -1 || v != 0 { - return fmt.Errorf("ListIterator.Prev()=<%v,%v>, expected DONE [%s]", i, v, typ) + return fmt.Errorf("VectorIterator.Prev()=<%v,%v>, expected DONE [%s]", i, v, typ) } return nil } @@ -2030,10 +2030,10 @@ func TestSortedSetBuilder(t *testing.T) { func MainTest() { - test_NewList() + test_NewVector() tests := []testing.InternalTest{ - { "TestList", TestList }, + { "TestVector", TestVector }, { "TestInternal_mapNode_Overwrite", TestInternal_mapNode_Overwrite }, { "TestInternal_mapArrayNode", TestInternal_mapArrayNode }, { "TestInternal_mapValueNode", TestInternal_mapValueNode }, -- cgit v1.2.3