~subsetpark/ec

ref: 4457018244c48dcde004539d1d7b2e5a86af294f ec/test/regressions.janet -rw-r--r-- 1.6 KiB
44570182 — Zach Smith Add ec#1 regression 11 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
(import /src/calc)
(import /src/parser)
(import /src/print)

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

(use testament)
(use /test-support)

(deftest regression1
  # [1] 1 + 1 +
  (def s (:new calc/Stack))
  (let [in (parser/parse ".[1] 1 + 1 +")]
    (calc/push s (in 0))
    (vec= [1] (calc/peek s))
    (calc/push s (in 1))
    (vec= 1 (calc/peek s))
    (calc/push s (in 2))
    (vec= [2] (calc/peek s))
    (calc/push s (in 3))
    (vec= 1 (calc/peek s))
    (calc/push s (in 4)))

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

(deftest regression2
  # [4 5] 6 +  8 +
  (def s (:new calc/Stack))
  (let [in (parser/parse ".[4 5] 6 + 8 +")]
    (push-all s in))

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

(deftest regression3
  # [2 3 4] 1 -
  (def s (:new calc/Stack))
  (let [in (parser/parse ".[2 3 4] 1 -")]
    (push-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 (:new calc/Stack))
  (let [in (parser/parse ".[.[1].[2]] !")]
    (push-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 (:new calc/Stack))
  (let [in (parser/parse ".[.[2].[4]] [.[2 1] fill] /")]
    (push-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!)