diff options
author | nitincodery | 2025-01-31 23:36:34 +0530 |
---|---|---|
committer | nitincodery | 2025-01-31 23:36:34 +0530 |
commit | 72b58af387946428b0d6b3a12da3eb38adaa882a (patch) | |
tree | 40b40b14ed13c2f8a626d8791cce7abb54974e4c | |
parent | 49c6d561b08746d65a45690fee5516376459c901 (diff) |
ADD: Print tests and results to stdout
5 files changed, 79 insertions, 63 deletions
diff --git a/languages/c/clojure/lambda-core/deps.edn b/languages/c/clojure/lambda-core/deps.edn index 6cb68b3..7c90c0d 100644 --- a/languages/c/clojure/lambda-core/deps.edn +++ b/languages/c/clojure/lambda-core/deps.edn @@ -1,6 +1,6 @@ {:paths ["src"] :deps {org.clojure/clojure {:mvn/version "1.10.0"}} :aliases - {:test - {:extra-paths ["test"] - :main-opts ["-m" "test-runner"]}}} + {:test {:extra-paths ["test"] + :main-opts ["-m" "test-runner"]}}} + diff --git a/languages/c/clojure/lambda-core/test/booleans_test.clj b/languages/c/clojure/lambda-core/test/booleans_test.clj index 8a75125..6c4dc63 100644 --- a/languages/c/clojure/lambda-core/test/booleans_test.clj +++ b/languages/c/clojure/lambda-core/test/booleans_test.clj @@ -1,67 +1,68 @@ (ns booleans-test (:require [booleans :refer :all] - [clojure.test :refer :all])) + [clojure.test :refer :all] + [print-macro :refer [is-print]])) (deftest λ-booleans (testing "true" - (is (= (toBoolean T) true))) + (is-print (= (toBoolean T) true))) (testing "false" - (is (= (toBoolean F) false))) + (is-print (= (toBoolean F) false))) (testing "If" - (is (= (toBoolean (((If T) T) F)) true)) - (is (= (toBoolean (((If F) T) F)) false))) + (is-print (= (toBoolean (((If T) T) F)) true)) + (is-print (= (toBoolean (((If F) T) F)) false))) (testing "And" - (is (= (toBoolean ((And T) T)) true)) - (is (= (toBoolean ((And T) F)) false)) - (is (= (toBoolean ((And F) T)) false)) - (is (= (toBoolean ((And F) F)) false)) - (is (= (toBoolean ((And T) ((And T) T))) true)) - (is (= (toBoolean ((And T) ((And F) T))) false))) + (is-print (= (toBoolean ((And T) T)) true)) + (is-print (= (toBoolean ((And T) F)) false)) + (is-print (= (toBoolean ((And F) T)) false)) + (is-print (= (toBoolean ((And F) F)) false)) + (is-print (= (toBoolean ((And T) ((And T) T))) true)) + (is-print (= (toBoolean ((And T) ((And F) T))) false))) (testing "Or" - (is (= (toBoolean ((Or T) T)) true)) - (is (= (toBoolean ((Or T) F)) true)) - (is (= (toBoolean ((Or F) T)) true)) - (is (= (toBoolean ((Or F) F)) false)) - (is (= (toBoolean ((Or F) ((Or F) F))) false)) - (is (= (toBoolean ((Or F) ((Or T) F))) true))) + (is-print (= (toBoolean ((Or T) T)) true)) + (is-print (= (toBoolean ((Or T) F)) true)) + (is-print (= (toBoolean ((Or F) T)) true)) + (is-print (= (toBoolean ((Or F) F)) false)) + (is-print (= (toBoolean ((Or F) ((Or F) F))) false)) + (is-print (= (toBoolean ((Or F) ((Or T) F))) true))) (testing "Not" - (is (= (toBoolean (Not T)) false)) - (is (= (toBoolean (Not F)) true)) - (is (= (toBoolean (Not (Not T))) true)) - (is (= (toBoolean (Not (Not F))) false))) + (is-print (= (toBoolean (Not T)) false)) + (is-print (= (toBoolean (Not F)) true)) + (is-print (= (toBoolean (Not (Not T))) true)) + (is-print (= (toBoolean (Not (Not F))) false))) (testing "Xor" - (is (= (toBoolean ((Xor T) T)) false)) - (is (= (toBoolean ((Xor T) F)) true)) - (is (= (toBoolean ((Xor F) T)) true)) - (is (= (toBoolean ((Xor F) F)) false))) + (is-print (= (toBoolean ((Xor T) T)) false)) + (is-print (= (toBoolean ((Xor T) F)) true)) + (is-print (= (toBoolean ((Xor F) T)) true)) + (is-print (= (toBoolean ((Xor F) F)) false))) (testing "Expressions" ;T AND T AND F OR T - (is (= (toBoolean ((And T) ((And T) ((Or F) T)))) + (is-print (= (toBoolean ((And T) ((And T) ((Or F) T)))) true)) ;T AND F AND F OR T AND T - (is (= (toBoolean ((And T) ((And F) ((Or F) ((And T) T))))) + (is-print (= (toBoolean ((And T) ((And F) ((Or F) ((And T) T))))) false)) ;T OR (F AND F OR T AND T) - (is (= (toBoolean ((Or T) ((And F) ((Or F) ((And T) T))))) + (is-print (= (toBoolean ((Or T) ((And F) ((Or F) ((And T) T))))) true)) ;F OR (F AND F OR F AND T) - (is (= (toBoolean ((Or F) ((And F) ((Or F) ((And F) T))))) + (is-print (= (toBoolean ((Or F) ((And F) ((Or F) ((And F) T))))) false)) ;F OR F AND F OR T AND T - (is (= (toBoolean ((And ((Or F) F)) ((And T) ((Or F) T)))) + (is-print (= (toBoolean ((And ((Or F) F)) ((And T) ((Or F) T)))) false)) ;T OR F AND F OR T AND T - (is (= (toBoolean ((And ((Or T) F)) ((And T) ((Or F) T)))) + (is-print (= (toBoolean ((And ((Or T) F)) ((And T) ((Or F) T)))) true)))) diff --git a/languages/c/clojure/lambda-core/test/combinators_test.clj b/languages/c/clojure/lambda-core/test/combinators_test.clj index 586946d..ba32fd2 100644 --- a/languages/c/clojure/lambda-core/test/combinators_test.clj +++ b/languages/c/clojure/lambda-core/test/combinators_test.clj @@ -3,7 +3,8 @@ [combinators :refer :all] [booleans :refer :all] [numerals :refer :all] - [clojure.test :refer :all])) + [clojure.test :refer :all] + [print-macro :refer [is-print]])) (def factorial-gen ;; Church encoding of functions, such as 'λ', does not @@ -31,9 +32,9 @@ (deftest Y-Combinator (testing "Y-factorial" - (is (= (toInt (Y-factorial (fromInt 9) one)) 362880)))) + (is-print (= (toInt (Y-factorial (fromInt 9) one)) 362880)))) (deftest Z-Combinator (testing "Z-factorial" - (is (= (toInt (Z-factorial (fromInt 9) one)) 362880)))) + (is-print (= (toInt (Z-factorial (fromInt 9) one)) 362880)))) diff --git a/languages/c/clojure/lambda-core/test/numerals_test.clj b/languages/c/clojure/lambda-core/test/numerals_test.clj index 44458dc..e7e5526 100644 --- a/languages/c/clojure/lambda-core/test/numerals_test.clj +++ b/languages/c/clojure/lambda-core/test/numerals_test.clj @@ -1,65 +1,66 @@ (ns numerals-test (:require [numerals :refer :all] - [clojure.test :refer :all])) - + [clojure.test :refer :all] + [print-macro :refer [is-print]])) + (deftest λ-numbers (testing "zero" - (is (= (toInt zero) 0))) + (is-print (= (toInt zero) 0))) (testing "one" - (is (= (toInt (succ zero)) 1)) - (is (= (toInt one)) 1)) + (is-print (= (toInt (succ zero)) 1)) + (is-print (= (toInt one) 1))) (testing "two" - (is (= (toInt (succ (succ zero))) 2)) - (is (= (toInt two)) 2)) + (is-print (= (toInt (succ (succ zero))) 2)) + (is-print (= (toInt two) 2))) (testing "three" - (is (= (toInt (succ (succ (succ zero)))) 3))) + (is-print (= (toInt (succ (succ (succ zero)))) 3))) (testing "predecessor" - (is (= (toInt (pred one)) 0)) - (is (= (toInt (pred two)) 1)) - (is (= (toInt (pred (succ (succ (succ zero))))) 2)) - (is (= (toInt (pred (fromInt 10))) 9)))) + (is-print (= (toInt (pred one)) 0)) + (is-print (= (toInt (pred two)) 1)) + (is-print (= (toInt (pred (succ (succ (succ zero))))) 2)) + (is-print (= (toInt (pred (fromInt 10))) 9)))) (deftest λ-numerical-operations (testing "addition" - (is (= + (is-print (= (toInt ((plus (fromInt 7)) (fromInt 5))) 12)) - (is (= + (is-print (= (toInt ((plus (fromInt 7)) ((plus (fromInt 6)) (fromInt 2)))) 15))) (testing "subtraction" - (is (= + (is-print (= (toInt ((minus (fromInt 7)) (fromInt 5))) 2)) - (is (= + (is-print (= (toInt ((minus (fromInt 7)) ((minus (fromInt 6)) (fromInt 2)))) 3))) (testing "multiplication" - (is (= + (is-print (= (toInt ((mult (fromInt 2)) (fromInt 3))) 6)) - (is (= + (is-print (= (toInt ((mult (fromInt 2)) ((mult (fromInt 5)) (fromInt 3)))) 30))) (testing "exponentiation" - (is (= + (is-print (= (toInt ((exp (fromInt 2)) (fromInt 3))) 8)) - (is (= + (is-print (= (toInt ((exp (fromInt 2)) ((exp (fromInt 2)) (fromInt 3)))) 256)))) (deftest λ-numeral-expressions (testing "numeral expressions" ; 3 * (2 + 5) - 2^3 - (is (= + (is-print (= (toInt ((minus ((mult (fromInt 3)) ((plus (fromInt 2)) (fromInt 5)))) ((exp (fromInt 2)) (fromInt 3)))) @@ -67,9 +68,9 @@ (deftest λ-toStr (testing "toStr" - (is (= (toStr zero) "λf.λn.(n)")) - (is (= (toStr one) "λf.λn.(f(n))")) - (is (= (toStr two) "λf.λn.(f(f(n)))")) - (is (= (toStr (succ (succ (succ zero)))) "λf.λn.(f(f(f(n))))")) - (is (= (toStr (fromInt 5)) "λf.λn.(f(f(f(f(f(n))))))")))) + (is-print (= (toStr zero) "λf.λn.(n)")) + (is-print (= (toStr one) "λf.λn.(f(n))")) + (is-print (= (toStr two) "λf.λn.(f(f(n)))")) + (is-print (= (toStr (succ (succ (succ zero)))) "λf.λn.(f(f(f(n))))")) + (is-print (= (toStr (fromInt 5)) "λf.λn.(f(f(f(f(f(n))))))")))) diff --git a/languages/c/clojure/lambda-core/test/print_macro.clj b/languages/c/clojure/lambda-core/test/print_macro.clj new file mode 100644 index 0000000..5fc4de6 --- /dev/null +++ b/languages/c/clojure/lambda-core/test/print_macro.clj @@ -0,0 +1,13 @@ +(ns print-macro + (:require [clojure.test :as t])) + +(defmacro is-print + ([form] + `(let [form-args# (rest '~form) + first-arg# (first form-args#) + second-arg# (second form-args#)] + (println (format "%s = %s => %s" + t/*testing-contexts* + (pr-str first-arg#) + (pr-str second-arg#))) + (t/is ~form)))) |