~subsetpark/ec

ref: big ec/test/regressions.janet -rw-r--r-- 1.6 KiB
3f9b6ebe — Zach Smith Support bigints (note: this does not work on account of floats being coerced to big ints) 8 months ago
                                                                                
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
65
66
67
68
69
70
71
72
(import /src/calc)
(import /src/parser)
(import /src/print)
(import /src/eval)
(import /src/env)

(import /src/operations :prefix "o/")
(import /src/adverbs :prefix "a/")

(use testament)
(use /test-support)

(deftest regression1
  # [1] 1 + 1 +
  (def s (env/new-env))
  (let [in (parser/parse "[1] 1 + 1 +")]
    (eval/eval-and-push s (in 0))
    (vec= [1] (calc/peek s))
    (eval/eval-and-push s (in 1))
    (vec= 1 (calc/peek s))
    (eval/eval-and-push s (in 2))
    (vec= [2] (calc/peek s))
    (eval/eval-and-push s (in 3))
    (vec= 1 (calc/peek s))
    (eval/eval-and-push s (in 4)))

  (def res (calc/pop s))
  (vec= [3] res))

(deftest regression2
  # [4 5] 6 +  8 +
  (def s (env/new-env))
  (let [in (parser/parse "[4 5] 6 + 8 +")]
    (eval-all s in))

  (def res (calc/pop s))
  (vec= [18 19] res))

(deftest regression3
  # [2 3 4] 1 -
  (def s (env/new-env))
  (let [in (parser/parse "[2 3 4] 1 -")]
    (eval-all s in))

  (def res (calc/pop s))
  (vec= [1 2 3] res))

(deftest regression4
  # ([[1] [2] [3]])> !
  #could not find method :- for 0, or :r- for nil
  (def s (env/new-env))
  (let [in (parser/parse "[[1][2]] i")]
    (eval-all s in))
  (while ((complement empty?) (s :data))
    (def inner-q (calc/pop s))
    (is (= [1] (calc/get-shape inner-q)))))

(deftest regression5
  # .[.[2].[4]] [.[2 1] fill] /
  (def s (env/new-env))
  (let [in (parser/parse "[[2][4]] ([2 1] fill) each")]
    (eval-all s in))
  # Distribute `[2 1] fill`:
  # Push [2]
  # Push [2 1] fill
  # => [[2][2]]
  # Push [4]
  # Push [2 1] fill
  # => [[4 4]]
  (is (= "[[2] [2]] [[4] [4]]" (print/p (s :data)))))
# I think this is right but I don't fully understand it.
(run-tests!)