diff options
| author | Andrey Orst <andreyorst@gmail.com> | 2020-10-21 20:34:39 +0300 |
|---|---|---|
| committer | Andrey Orst <andreyorst@gmail.com> | 2020-10-21 20:34:39 +0300 |
| commit | 58c188560c2935d500852ebb03f00f832c61cc72 (patch) | |
| tree | 6e783535473649b7d44c7eb80b603e0a06dca826 /core_test.fnl | |
| parent | 46f472901768d53ad62f9313a977c5ff006a041c (diff) | |
added more macros, and functions to the `core` modules
Diffstat (limited to 'core_test.fnl')
| -rw-r--r-- | core_test.fnl | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/core_test.fnl b/core_test.fnl new file mode 100644 index 0000000..eb58a44 --- /dev/null +++ b/core_test.fnl @@ -0,0 +1,43 @@ +(import-macros {: fn*} :macros.fn) + +(local {: seq + : mapv + : mapkv + : reduce + : reduce-kv + : conj + : cons + : consj + : first + : rest + : eq? + : identity + : comp + : every?} (require :core)) + +;; Test equality function should be done first and with a lot of care, +;; because we rely on deep comparison in other tests. + +(assert (eq? 1 1)) +(assert (not (eq? 1 2))) +(assert (eq? 1 1 1 1 1)) +(assert (eq? "1" "1" "1" "1" "1")) +(assert (eq? [1 2] [1 2])) +(assert (not (eq? [1] [1 2]))) +(assert (not (eq? [1 2] [1]))) +(assert (eq? [1 [2]] [1 [2]] [1 [2]])) +(assert (eq? [1 [2]] [1 [2]] [1 [2]])) +(assert (not (eq? [1 [2]] [1 [2]] [1 [2 [3]]]))) + +(fn* range + ([upper] (range 0 upper 1)) + ([lower upper] (range lower upper 1)) + ([lower upper step] + (let [res []] + (for [i lower (- upper step) step] + (table.insert res i)) + res))) + +(assert (eq? (range 10) [0 1 2 3 4 5 6 7 8 9])) +(assert (eq? (range -5 5) [-5 -4 -3 -2 -1 0 1 2 3 4])) +;; (assert (eq? (range 0 1 0.2) [0 0.2 0.4 0.6 0.8])) ;; TODO: fails, unsure why. |