~subsetpark/ec

6651eadf644e6f2b004cfa39e16ba36636e00c38 — Zach Smith 9 months ago 44a6ba6
Move out arity checks
2 files changed, 28 insertions(+), 20 deletions(-)

A test/arity-checks.janet
M test/calc.janet
A test/arity-checks.janet => test/arity-checks.janet +28 -0
@@ 0,0 1,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!)

M test/calc.janet => test/calc.janet +0 -20
@@ 118,24 118,4 @@
        (calc/push s a/wrap-stack))
      "Wrapping a stack requires homogeneous data"))

(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!)