summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-07-01 20:07:38 +0100
committerubq323 <ubq323@ubq323.website>2024-07-01 20:07:38 +0100
commit4571c3cb409808942ecbe353b1ffa6794cabc557 (patch)
tree3deb90f066dd48f4d9b769b80593d5d77a479bcb
parent61ff477d139e8a93b635993cd8b8725a2957ce1b (diff)
add map test
-rw-r--r--tests/map.bth15
-rw-r--r--tests/map.out2
2 files changed, 17 insertions, 0 deletions
diff --git a/tests/map.bth b/tests/map.bth
new file mode 100644
index 0000000..aa9f45e
--- /dev/null
+++ b/tests/map.bth
@@ -0,0 +1,15 @@
+(set map' (fn (f ix in out)
+ (if (< ix (len in))
+ (let (elem (in ix)
+ felem (f elem)
+ newix (+ 1 ix))
+ (set (out ix) felem)
+ (map' f newix in out))
+ out)))
+(set map (fn (f in) (map' f 0 in (arr))))
+
+(let (a [1 2 3 4 5 6 7 8 9]
+ f1 (fn (x) (* 10 x))
+ f2 (fn (x) (* x x)))
+ (say (map f1 a))
+ (say (map f2 a)))
diff --git a/tests/map.out b/tests/map.out
new file mode 100644
index 0000000..41f7fac
--- /dev/null
+++ b/tests/map.out
@@ -0,0 +1,2 @@
+[ 10 20 30 40 50 60 70 80 90 ]
+[ 1 4 9 16 25 36 49 64 81 ]