Last active
July 15, 2022 01:42
-
-
Save camsaul/a9f7d3f2c53536f15fae9718caa50e4e to your computer and use it in GitHub Desktop.
≈ example tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(deftest custom-unify-methods | |
(is (≈ {[String java.time.temporal.Temporal] | |
(fn [_next-method expected actual] | |
(let [actual-str (u.date/format actual)] | |
(when-not (= expected actual-str) | |
(list 'not= expected (symbol "#t") actual-str))))} | |
"2022-07-14" | |
#t "2022-07-14")) | |
(is (≈ {[String String] | |
(fn [_next-method ^String expected ^String actual] | |
(println "(.compareToIgnoreCase expected actual):" (.compareToIgnoreCase expected actual)) ; NOCOMMIT | |
(when-not (zero? (.compareToIgnoreCase expected actual)) | |
(list 'not (list 'zero? (list '.compareToIgnoreCase expected actual)))))} | |
"AbC" | |
"abc"))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(deftest custom-unify-methods-failing | |
(is (≈ {[String java.time.temporal.Temporal] | |
(fn [_next-method expected actual] | |
(let [actual-str (u.date/format actual)] | |
(when-not (= expected actual-str) | |
(list 'not= expected (symbol "#t") actual-str))))} | |
"2022-07-14" | |
#t "2022-07-16")) | |
(is (≈ {[String String] | |
(fn [_next-method ^String expected ^String actual] | |
(println "(.compareToIgnoreCase expected actual):" (.compareToIgnoreCase expected actual)) ; NOCOMMIT | |
(when-not (zero? (.compareToIgnoreCase expected actual)) | |
(list 'not (list 'zero? (list '.compareToIgnoreCase expected actual)))))} | |
"AbC" | |
"abcd"))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fail in custom-unify-methods-failing | |
expected: "2022-07-14" | |
actual: #t "2022-07-16" | |
diff: - (not= "2022-07-14" #t "2022-07-16") | |
+ nil | |
Fail in custom-unify-methods-failing | |
expected: "AbC" | |
actual: "abcd" | |
diff: - (not (zero? (.compareToIgnoreCase "AbC" "abcd"))) | |
+ nil | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Optional debugging output. | |
(≈ "2022-07-14" #t "2022-07-14") | |
=> (≈ java.lang.String java.time.LocalDate) | |
=> (≈ :default) | |
=> nil | |
(≈ {:a "AbC"} {:a "abc", :b 100}) | |
=> (≈ clojure.lang.PersistentArrayMap clojure.lang.PersistentArrayMap) | |
=> (≈ clojure.lang.IPersistentMap clojure.lang.IPersistentMap) | |
(≈ "AbC" "abc") | |
=> (≈ java.lang.String java.lang.String) | |
=> (≈ :default) | |
=> (not= "AbC" "abc") | |
=> {:a (not= "AbC" "abc")} | |
FAIL in (custom-unify-methods) (unify_test.clj:47) | |
expected: {:a "AbC"} | |
actual: {:a "abc", :b 100} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(unify 100 100) | |
(unify 100 100) | |
=> (unify java.lang.Long java.lang.Long) | |
=> (unify :default) | |
=> nil | |
nil | |
metabase.test-runner.assert-exprs.unify> (unify #"cans" "toucans") | |
(unify #"cans" "toucans") | |
=> (unify java.util.regex.Pattern java.lang.String) | |
=> (unify java.util.regex.Pattern java.lang.String) | |
=> nil | |
nil | |
metabase.test-runner.assert-exprs.unify> (unify int? 100) | |
(unify #function[clojure.core/int?] 100) | |
=> (unify clojure.core$int_QMARK_ java.lang.Long) | |
=> (unify clojure.lang.AFunction java.lang.Object) | |
=> nil | |
nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(deftest passing-tests | |
(testing "basic equality" | |
(is (≈ 100 100))) | |
(testing "predicate function" | |
(is (≈ int? 100))) | |
(testing "regexes" | |
(is (≈ #"cans$" "cans"))) | |
(testing "classes" | |
(is (≈ String | |
"toucans"))) | |
(testing "sequences" | |
(is (≈ [:a int?] | |
[:a 100]))) | |
(testing "maps" | |
(is (≈ {:a int? | |
:b {:c [int? String] | |
:d #"cans$"}} | |
{:a 100 | |
:b {:c [2 "cans"] | |
:d "toucans"}})) | |
(testing "extra keys in actual" | |
(is (≈ {:a 100} | |
{:a 100, :b 200}))))) | |
(deftest failing-tests | |
(testing "basic equality" | |
(is (≈ 100 200))) | |
(testing "predicate function") | |
(testing "regexes" | |
(is (≈ #"cans$" "can"))) | |
(testing "classes" | |
(is (≈ String | |
1000))) | |
(testing "sequences" | |
(testing "second element is different" | |
(is (≈ [:a int?] | |
[:a 100.0]))) | |
(testing "actual has more elements than expected" | |
(is (≈ [] | |
[:a]))) | |
(testing "expected has more elements than actual" | |
(is (≈ [int?] | |
[])))) | |
(testing "maps" | |
(testing ":a and [:b :c] are invalid; :d is ok" | |
(is (≈ {:a int? | |
:b {:c [int? String] | |
:d #"cans$"}} | |
{:a 100.0 | |
:b {:c [2.0 :cans] | |
:d "toucans"}}))) | |
(testing "missing key [:b :c] in actual" | |
(is (≈ {:a int? | |
:b {:c [int? String] | |
:d #"cans$"}} | |
{:a 100 | |
:b {:d "toucans"}}))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fail in failing-tests | |
basic equality | |
expected: 100 | |
actual: 200 | |
diff: - (not= 100 200) | |
+ nil | |
Fail in failing-tests | |
regexes | |
expected: #"cans$" | |
actual: "can" | |
diff: - (not (re-find #"cans$" "can")) | |
+ nil | |
Fail in failing-tests | |
classes | |
expected: java.lang.String | |
actual: 1000 | |
diff: - (not (instance? java.lang.String 1000)) | |
+ nil | |
Fail in failing-tests | |
sequences second element is different | |
expected: [:a #function[clojure.core/int?]] | |
actual: [:a 100.0] | |
diff: - [nil (not (#function[clojure.core/int?] 100.0))] | |
+ nil | |
Fail in failing-tests | |
sequences actual has more elements than expected | |
expected: [] | |
actual: [:a] | |
diff: - [(not= nil :a)] | |
+ nil | |
Fail in failing-tests | |
sequences expected has more elements than actual | |
expected: [#function[clojure.core/int?]] | |
actual: [] | |
diff: - [(not= #function[clojure.core/int?] nil)] | |
+ nil | |
Fail in failing-tests | |
maps :a and [:b :c] are invalid; :d is ok | |
expected: {:a #function[clojure.core/int?], :b {:c [#function[clojure.core/int?] java.lang.String], :d #"cans$"}} | |
actual: {:a 100.0, :b {:c [2.0 :cans], :d "toucans"}} | |
diff: - {:a (not (#function[clojure.core/int?] 100.0)), | |
:b {:c [(not (#function[clojure.core/int?] 2.0)) (not (instance? java.lang.String :cans))]}} | |
+ nil | |
Fail in failing-tests | |
maps missing key in actual | |
expected: {:a #function[clojure.core/int?], :b {:c [#function[clojure.core/int?] java.lang.String], :d #"cans$"}} | |
actual: {:a 100, :b {:d "toucans"}} | |
diff: - {:b {:c (not= [#function[clojure.core/int?] java.lang.String] nil #_"key is not present.")}} | |
+ nil | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment