1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-17 16:47:22 +03:00
mal/tests/lib/equality.mal
Nicolas Boulenguez 83665b4fda lib/: add tests, fix detected problems, improve implementations
equality.mal:
- fix typos
- let and2 and or2 always return booleans
- when looping in sequences, compare lengths only once
- empty? instead of an equality test
- when looping on a keys, do not check if a contains the current key
- change the `cond` logic: when a is a sequence and b a map, return
  false instead of delegating to scalar-equal?.
- add tests

memoize.mal:
- make explicit that the function name must be kept
- fix typo in tests

protocols.mal:
- document
- add a function mapping an object to its type
- add default types for remaining built-in MAL values
- let defprotocol return the new protocol instead of last method
- set the right profile for abstract methods, improving error messages
- replace incomplete example with lots of tests

pprint:
- escape parenthesis in expected test results

[kanaka]
- explain in lib/README.md how to run tests/lib/*.
- rename folds to reducers and composition to threading
- move fib and sumdown from lib/ to tests/
2019-05-18 01:52:13 +02:00

62 lines
910 B
Plaintext

(def! orig= =)
;; Testing equality.mal does not fix built-in equality.
(load-file "../lib/equality.mal")
;=>nil
;; Testing and2
(and2)
;=>true
(and2 true)
;=>true
(and2 false)
;=>false
(and2 nil)
;=>false
(and2 1)
;=>true
(and2 1 2)
;=>true
(and2 nil (nth () 1))
;=>false
;; Testing or2
(or2)
;=>false
(or2 true)
;=>true
(or2 false)
;=>false
(or2 nil)
;=>false
(or2 1)
;=>true
(or2 1 (nth () 1))
;=>true
(or2 1 2)
;=>true
(or2 false nil)
;=>false
;; Breaking equality.
(def! = (fn* [a b] (and2 (orig= a b) (cond (list? a) (list? b) (vector? a) (vector? b) true true))))
(= [] ())
;=>false
;; Testing that equality.mal detects the problem.
(load-file "../lib/equality.mal")
;/equality.mal: Replaced = with pure mal implementation
;=>nil
;; Testing fixed equality.
(= [] ())
;=>true
(= [:a :b] (list :a :b))
;=>true
(= [:a :b] [:a :b :c])
;=>false
(= {:a 1} {:a 1})
;=>true
(= {:a 1} {:a 1 :b 2})
;=>false