~subsetpark/ec

ref: e85c9853e2f2332e47aaa381a543d0f78de5cd4e ec/test/arity-checks.janet -rw-r--r-- 1.1 KiB
e85c9853 — Zach Smith test-arity helper 9 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
(import /src/calc)

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

(use testament)
(use /test-support)

(defn test-arity
  [n elem doc]
  (is (= n (calc/get-arity elem)) doc)
  (let [s (:new calc/Stack)]
    (loop [_ :range [0 n]]
      (calc/push s (:new calc/Int 0)))
    (calc/push s elem)
    (calc/push s a/apply-quotation)))

(deftest get-arity
  (test-arity 2 (quote-wrap o/add)
      "A quoted operation's arity is the operation's arity")
  (test-arity 3 (quote-wrap o/add o/add)
      ```
      A composition of operations' arity is the greatest of the
      individual operations' arities, each adjusted for the out-arity
      of the one prior
      ```)
  (test-arity 2 (quote-wrap o/add 2 o/add)
      "Interposed numbers will reduce the arity of a quotation")
  (test-arity 0 (:new calc/Int 2)
      "A number's arity is 0")
  (test-arity 0 (quote-wrap 2)
      "A quoted number's arity is 0")
  (test-arity 0 (quote-wrap 2 2 2 2)
      "A quoted sequence of numbers is 0")
  (test-arity 0 (quote-wrap 2 2 o/add)
      "A quoted operation is 0 if the quote enough values to fulfill it"))

(run-tests!)