X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/jvm/clojure/lang/Numbers.java
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ public Number remainder(Number x, Number y){
}

public boolean equiv(Number x, Number y){
return toBigDecimal(x).equals(toBigDecimal(y));
return toBigDecimal(x).compareTo(toBigDecimal(y)) == 0;
}

public boolean lt(Number x, Number y){
Expand Down
66 changes: 58 additions & 8 deletions test/clojure/test_clojure/numbers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,60 @@
clojure.template))


; TODO:
; ==
; and more...

; TODO: more tests are needed

(deftest equality
(are [x y] (== x y)
42 42
42 42.0
42 42N
42 42M
42 42.0M
42 42.00M
42.0 42
42.0 42.0
42.0 42N
42.0 42M
42.0 42.0M
42.0 42.00M
42N 42
42N 42.0
42N 42N
42N 42M
42N 42.0M
42N 42.00M
42M 42
42M 42.0
42M 42N
42M 42M
42M 42.0M
42M 42.00M
42.0M 42
42.0M 42.0
42.0M 42N
42.0M 42M
42.0M 42.0M
42.0M 42.00M

1.23 1.23
1.23 1.23M
1.23M 1.23
1.23M 1.23M )

(are [x y] (not (== x y))
12 12.1
1.23 123
34 3.4
1.23 1.234
123N 345N
123 345N
123N 345
12.34M 456N
12.34M 4.56
12.34 4.56M
12 4.56M
12M 4.56
12.34M 1.234M ))

;; *** Types ***

Expand Down Expand Up @@ -103,7 +153,7 @@
[byte [-1 0 1 Byte/MAX_VALUE :error :error :error :error :error]]
[unchecked-byte [-1 0 1 Byte/MAX_VALUE -1 -1 -1 -1 -1]]
[short [-1 0 1 Byte/MAX_VALUE Short/MAX_VALUE :error :error :error :error]]
[unchecked-short [-1 0 1 Byte/MAX_VALUE Short/MAX_VALUE -1 -1 -1 -1]]
[unchecked-short [-1 0 1 Byte/MAX_VALUE Short/MAX_VALUE -1 -1 -1 -1]]
[int [-1 0 1 Byte/MAX_VALUE Short/MAX_VALUE Integer/MAX_VALUE :error :error :error]]
[unchecked-int [-1 0 1 Byte/MAX_VALUE Short/MAX_VALUE Integer/MAX_VALUE -1 Integer/MAX_VALUE Integer/MAX_VALUE]]
[long [-1 0 1 Byte/MAX_VALUE Short/MAX_VALUE Integer/MAX_VALUE Long/MAX_VALUE :error :error]]
Expand Down Expand Up @@ -303,7 +353,7 @@
; divide by zero
(is (thrown? ArithmeticException (rem 9 0)))
(is (thrown? ArithmeticException (rem 0 0)))

(are [x y] (= x y)
(rem 4 2) 0
(rem 3 2) 1
Expand Down Expand Up @@ -334,7 +384,7 @@
(rem 2 -5) 2
(rem -2 5) -2
(rem -2 -5) -2

; num = 0, div != 0
(rem 0 3) 0
(rem 0 -3) 0
Expand All @@ -350,7 +400,7 @@
; divide by zero
(is (thrown? ArithmeticException (quot 9 0)))
(is (thrown? ArithmeticException (quot 0 0)))

(are [x y] (= x y)
(quot 4 2) 2
(quot 3 2) 1
Expand Down
X Tutup