Skip to content

Commit 2a28726

Browse files
committed
feat(tests): adding Rosetta Code solutions
1 parent 74f8efb commit 2a28726

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(let point (fun (x y)
2+
(fun (&x &y) ())))
3+
4+
(let point1 (point 3 5))
5+
(let point2 (point 2.7 -3.8))
6+
7+
(assert
8+
(and
9+
(!= point1.x point2.x)
10+
(!= point1.y point2.y))
11+
"point1 and point2 are different")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(let addN (fun (n)
2+
(fun (x &n)
3+
(+ x n))))
4+
5+
(let add2 (addN 2))
6+
(assert (= "Closure" (type add2)) "add2 is a closure")
7+
(assert (= 7 (add2 5)) "add2 5 is 7")
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
($ if2 (conds bothConditionsAreTrue firstConditionIsTrue secondConditionIsTrue noConditionIsTrue) {
2+
(mut result1 (head conds))
3+
(mut result2 (@ conds 1))
4+
(if (and result1 result2)
5+
bothConditionsAreTrue
6+
(if result1
7+
firstConditionIsTrue
8+
(if result2
9+
secondConditionIsTrue
10+
noConditionIsTrue)))})
11+
12+
(if2 (true true)
13+
(assert true "if2 true true")
14+
(assert false "if2 true false")
15+
(assert false "if2 false true")
16+
(assert false "if2 false false"))
17+
18+
(if2 (true false)
19+
(assert false "if2 true true")
20+
(assert true "if2 true false")
21+
(assert false "if2 false true")
22+
(assert false "if2 false false"))
23+
24+
(if2 (false true)
25+
(assert false "if2 true true")
26+
(assert false "if2 true false")
27+
(assert true "if2 false true")
28+
(assert false "if2 false false"))
29+
30+
(if2 (false false)
31+
(assert false "if2 true true")
32+
(assert false "if2 true false")
33+
(assert false "if2 false true")
34+
(assert true "if2 false false"))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(assert (= 0 (string:find "abcd" "ab")) "abcd starts with ab")
2+
(assert (= 6 (string:find "hello world" "world")) "world is located at 6")
3+
(assert (= -1 (string:find "abcd" "zn")) "abcd does not contain zn")
4+
(assert (= -1 (string:find "abab" "bb")) "abab does not contain bb")
5+
(assert (= 0 (string:find "abab" "ab")) "abab contains ab")
6+
(assert (= 2 (string:find "abab" "ab" 1)) "starting lookup at index 1, we found ab at position 2")

0 commit comments

Comments
 (0)