summaryrefslogtreecommitdiff
path: root/tests/gobang.go
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2025-02-14 10:29:25 -0300
committerEuAndreh <eu@euandre.org>2025-02-14 10:29:25 -0300
commit1cecd293f5d3e536cd89a21c00f44118b2426b3c (patch)
tree08c2e7553b5b9e382b6303e7ca9b8b7b63a03bed /tests/gobang.go
parentsrc/gobang.go: Add PanicIf() companion to Must() (diff)
downloadgobang-1cecd293f5d3e536cd89a21c00f44118b2426b3c.tar.gz
gobang-1cecd293f5d3e536cd89a21c00f44118b2426b3c.tar.xz
src/gobang.go: Add simplistic implementation of Map() and Filter()
Diffstat (limited to 'tests/gobang.go')
-rw-r--r--tests/gobang.go93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/gobang.go b/tests/gobang.go
index 32f6d99..56e3978 100644
--- a/tests/gobang.go
+++ b/tests/gobang.go
@@ -15,6 +15,96 @@ import (
+func test_MapIndexed() {
+ TestStart("MapIndexed()")
+
+ Testing("empty array", func() {
+ noop := func(s string, i int) string {
+ return s
+ }
+
+ arr := []string{}
+ TAssertEqual(MapIndexed(noop, arr), arr)
+ })
+
+ Testing("replace content with index", func() {
+ index := func(s string, i int) int {
+ return i
+ }
+
+ TAssertEqual(
+ MapIndexed(index, []string{"a", "b", "c"}),
+ []int{0, 1, 2},
+ )
+ })
+
+ Testing("a computed value", func() {
+ fn := func(x int, i int) int {
+ return x + i
+ }
+
+ TAssertEqual(
+ MapIndexed(fn, []int{1, 2, 3, 4, 5}),
+ []int{1, 3, 5, 7, 9},
+ )
+ })
+}
+
+func test_Map() {
+ TestStart("Map()")
+
+ Testing("empty array", func() {
+ noop := func(s string) string {
+ return s
+ }
+
+ arr := []string{}
+ TAssertEqual(Map(noop, arr), arr)
+ })
+
+ Testing("a derived value", func() {
+ appendBang := func(s string) string {
+ return s + "!"
+ }
+
+ TAssertEqual(
+ Map(appendBang, []string{"a", "b", "c"}),
+ []string{"a!", "b!", "c!"},
+ )
+ })
+}
+
+func test_Filter() {
+ TestStart("Filter()")
+
+ fn := func(i int) bool {
+ return i < 10
+ }
+
+
+ Testing("empty array", func() {
+ arr := []int{}
+ TAssertEqual(Filter(fn, arr), arr)
+ })
+
+ Testing("filters everything", func() {
+ arr := []int{10, 11, 12, 13, 14, 15}
+ TAssertEqual(Filter(fn, arr), []int{})
+ })
+
+ Testing("filters nothing", func() {
+ arr := []int{1, 2, 3, 4, 5}
+ TAssertEqual(Filter(fn, arr), arr)
+ })
+
+ Testing("filters some", func() {
+ TAssertEqual(
+ Filter(fn, []int{8, 9, 10, 11, 12, 0, 13}),
+ []int{8, 9, 0},
+ )
+ })
+}
+
func test_PanicIf() {
TestStart("PanicIf()")
@@ -1354,6 +1444,9 @@ func test_setHostname() {
func MainTest() {
Init()
+ test_MapIndexed()
+ test_Map()
+ test_Filter()
test_PanicIf()
test_Must()
test_Clamp()