summaryrefslogtreecommitdiff
path: root/test/res/test.lisp
blob: 713ee2a065b3128345941c2cc65e8195029e55e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(import :test)

(test.test "Identity equality" (seq
    ((test.assert-eq false false))
    ((test.assert-eq true true))))

(test.test "Not behaves correctly" (seq
    ((test.assert-eq (not false) true))
    ((test.assert-eq (not true) false))))

(test.test "And behaves correctly" (seq
    ((test.assert-eq (& true true) true))
    ((test.assert-eq (& true false) false))
    ((test.assert-eq (& false true) false))
    ((test.assert-eq (& false false) false))))

(test.test "Or behaves correctly" (seq
    ((test.assert-eq (| true true) true))
    ((test.assert-eq (| true false) true))
    ((test.assert-eq (| false true) true))
    ((test.assert-eq (| false false) false))))

(test.test "Hashes" (seq
    (def funnyhash (hash.new :test1 1 :test2 2))
    ((test.assert-eq
        (hash.merge funnyhash (hash.new :test1 2))
        (hash.new :test1 2 :test2 2)))
    ((test.assert-eq funnyhash (hash.new :test1 1 :test2 2)))
    ((test.assert-eq (hash.get funnyhash :test1) 1))
    ((test.assert-eq (hash.get funnyhash :tesst3) nil))
    ))

(test.test "Hex literals" (seq
    ((test.assert-eqd 0x0 0 0.0001))
    ((test.assert-eqd 0xFF 255 0.0001))
    ((test.assert-eqd 0xFFFFFFFF 4294967295 0.0001))
    ))

(test.test "List joining" (seq
    ((test.assert-eq
        (list.new 1 2 3 4)
        (list.join [list.new 1 2] [list.new 3 4])
        ))
    ))

(test.test "List slicing" (seq
    ((test.assert-eq
        (list.slice [list.new 1 2 3 4] 2 4)
        (list.new 3 4)
        ))
    ))

(test.test "List length"
    ((test.assert-eq [list.length (list.new 1 2 3 4)] 4))
    )

(test.test "List mapping"
    ((test.assert-eq
        [list.map (list.new 1 2 3 4) (lambda (x) (+ 1 x))]
        [list.new 2 3 4 5]))
    )