~subsetpark/ec

ref: 6651eadf644e6f2b004cfa39e16ba36636e00c38 ec/test/arity-checks.janet -rw-r--r-- 971 bytes
6651eadf — Zach Smith Move out arity checks 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
(import /src/calc)

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

(use testament)
(use /test-support)

(deftest get-arity
  (is (= 2 (calc/get-arity (quote-wrap o/add)))
      "A quoted operation's arity is the operation's arity")
  (is (= 3 (calc/get-arity (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
      ```)
  (is (= 2 (calc/get-arity (quote-wrap o/add 2 o/add)))
      "Interposed numbers will reduce the arity of a quotation")
  (is (= 0 (calc/get-arity (:new calc/Int 2)))
      "A number's arity is 0")
  (is (= 0 (calc/get-arity (quote-wrap 2)))
      "A quoted number's arity is 0")
  (is (= 0 (calc/get-arity (quote-wrap 2 2 2 2)))
      "A quoted sequence of numbers is 0")
  (is (= 0 (calc/get-arity (quote-wrap 2 2 o/add)))
      "A quoted operation is 0 if the quote enough values to fulfill it"))

(run-tests!)