2014-05-16 18:58:57 +02:00
|
|
|
(defn test-shadow-addition []
|
|
|
|
"NATIVE: test shadow addition"
|
2015-08-17 09:07:32 +02:00
|
|
|
(let [x +]
|
2014-08-26 11:38:52 +02:00
|
|
|
(assert (try
|
|
|
|
(x)
|
2015-08-09 08:41:11 +02:00
|
|
|
(except [TypeError] True)
|
2015-08-09 06:04:02 +02:00
|
|
|
(else (raise AssertionError))))
|
2014-05-16 18:58:57 +02:00
|
|
|
(assert (= (x 1 2 3 4) 10))
|
2014-08-26 11:38:52 +02:00
|
|
|
(assert (= (x 1 2 3 4 5) 15))
|
|
|
|
; with strings
|
|
|
|
(assert (= (x "a" "b" "c")
|
|
|
|
"abc"))
|
|
|
|
; with lists
|
|
|
|
(assert (= (x ["a"] ["b"] ["c"])
|
|
|
|
["a" "b" "c"]))))
|
2014-05-16 18:58:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
(defn test-shadow-subtraction []
|
|
|
|
"NATIVE: test shadow subtraction"
|
2015-08-17 09:07:32 +02:00
|
|
|
(let [x -]
|
2014-05-16 18:58:57 +02:00
|
|
|
(assert (try
|
|
|
|
(x)
|
2015-08-09 08:41:11 +02:00
|
|
|
(except [TypeError] True)
|
2015-08-09 06:04:02 +02:00
|
|
|
(else (raise AssertionError))))
|
2014-05-16 18:58:57 +02:00
|
|
|
(assert (= (x 1) -1))
|
|
|
|
(assert (= (x 2 1) 1))
|
|
|
|
(assert (= (x 2 1 1) 0))))
|
|
|
|
|
|
|
|
|
|
|
|
(defn test-shadow-multiplication []
|
|
|
|
"NATIVE: test shadow multiplication"
|
2015-08-17 09:07:32 +02:00
|
|
|
(let [x *]
|
2014-05-16 18:58:57 +02:00
|
|
|
(assert (= (x) 1))
|
|
|
|
(assert (= (x 3) 3))
|
|
|
|
(assert (= (x 3 3) 9))))
|
|
|
|
|
|
|
|
|
|
|
|
(defn test-shadow-division []
|
|
|
|
"NATIVE: test shadow division"
|
2015-08-17 09:07:32 +02:00
|
|
|
(let [x /]
|
2014-05-16 18:58:57 +02:00
|
|
|
(assert (try
|
|
|
|
(x)
|
2015-08-09 08:41:11 +02:00
|
|
|
(except [TypeError] True)
|
2015-08-09 06:04:02 +02:00
|
|
|
(else (raise AssertionError))))
|
2014-05-16 18:58:57 +02:00
|
|
|
(assert (= (x 1) 1))
|
|
|
|
(assert (= (x 8 2) 4))
|
|
|
|
(assert (= (x 8 2 2) 2))
|
|
|
|
(assert (= (x 8 2 2 2) 1))))
|
2015-03-12 05:11:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
(defn test-shadow-compare []
|
|
|
|
"NATIVE: test shadow compare"
|
2017-02-04 00:43:00 +01:00
|
|
|
|
2015-03-12 05:11:22 +01:00
|
|
|
(for [x [< <= = != >= >]]
|
|
|
|
(assert (try
|
|
|
|
(x)
|
2015-08-09 08:41:11 +02:00
|
|
|
(except [TypeError] True)
|
2015-08-09 06:04:02 +02:00
|
|
|
(else (raise AssertionError))))
|
2015-03-12 05:11:22 +01:00
|
|
|
(assert (try
|
|
|
|
(x 1)
|
2015-08-09 08:41:11 +02:00
|
|
|
(except [TypeError] True)
|
2015-08-09 06:04:02 +02:00
|
|
|
(else (raise AssertionError)))))
|
2017-02-04 00:43:00 +01:00
|
|
|
|
2015-03-12 05:11:22 +01:00
|
|
|
(for [(, x y) [[< >=]
|
|
|
|
[<= >]
|
|
|
|
[= !=]]]
|
|
|
|
(for [args [[1 2]
|
|
|
|
[2 1]
|
|
|
|
[1 1]
|
|
|
|
[2 2]]]
|
|
|
|
(assert (= (apply x args) (not (apply y args))))))
|
2017-02-04 00:43:00 +01:00
|
|
|
|
2015-08-17 09:07:32 +02:00
|
|
|
(let [s-lt <
|
|
|
|
s-gt >
|
|
|
|
s-le <=
|
|
|
|
s-ge >=
|
|
|
|
s-eq =
|
|
|
|
s-ne !=]
|
2015-03-12 05:11:22 +01:00
|
|
|
(assert (apply s-lt [1 2 3]))
|
|
|
|
(assert (not (apply s-lt [3 2 1])))
|
|
|
|
(assert (apply s-gt [3 2 1]))
|
|
|
|
(assert (not (apply s-gt [1 2 3])))
|
|
|
|
(assert (apply s-le [1 1 2 2 3 3]))
|
|
|
|
(assert (not (apply s-le [1 1 2 2 1 1])))
|
|
|
|
(assert (apply s-ge [3 3 2 2 1 1]))
|
|
|
|
(assert (not (apply s-ge [3 3 2 2 3 3])))
|
|
|
|
(assert (apply s-eq [1 1 1 1 1]))
|
|
|
|
(assert (not (apply s-eq [1 1 2 1 1])))
|
|
|
|
(assert (apply s-ne [1 2 3 4 5]))
|
2017-02-04 00:43:00 +01:00
|
|
|
(assert (not (apply s-ne [1 1 2 3 4]))))
|
|
|
|
|
|
|
|
; Make sure chained comparisons use `and`, not `&`.
|
|
|
|
; https://github.com/hylang/hy/issues/1191
|
|
|
|
(defclass C [object] [
|
|
|
|
__init__ (fn [self x]
|
|
|
|
(setv self.x x))
|
|
|
|
__lt__ (fn [self other]
|
|
|
|
self.x)])
|
|
|
|
(assert (= (< (C "a") (C "b") (C "c")) "b"))
|
|
|
|
(setv f <)
|
|
|
|
(assert (= (f (C "a") (C "b") (C "c")) "b")))
|