-
Notifications
You must be signed in to change notification settings - Fork 27
Redo num
#831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Redo num
#831
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d4067bf
Num take 0
E-A-Griffin 0b1aeb9
Syntastix
E-A-Griffin 3f0d530
nil is always the odd one out
E-A-Griffin 36c066c
kill dead code
E-A-Griffin 66e3882
oop
E-A-Griffin b69c305
cljr does do something!
E-A-Griffin 4e1d103
cljr time
E-A-Griffin fb6d895
NaN of that
E-A-Griffin 35c84ac
Fix bb
E-A-Griffin abd227f
underscores!!
E-A-Griffin 658230f
Add :bb case
E-A-Griffin 2bd9447
NaN again
E-A-Griffin c411ed8
Indentation, all around the nation
E-A-Griffin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,140 @@ | ||
| (ns clojure.core-test.num | ||
| (:require [clojure.test :as t :refer [deftest is]] | ||
| [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists]])) | ||
| (:require [clojure.test :as t :refer [are deftest is testing]] | ||
| [clojure.core-test.portability | ||
| #?(:cljs :refer-macros :default :refer) [when-var-exists]])) | ||
|
|
||
| (defn f []) | ||
|
|
||
| #?(:bb | ||
| nil | ||
|
|
||
| :clj | ||
| (do | ||
| (definterface IChecker | ||
| (isLong [^long l]) | ||
| (isLong [^Object l]) | ||
|
|
||
| (isDouble [^double d]) | ||
| (isDouble [^Object d])) | ||
|
|
||
| (deftype Checker [] | ||
| IChecker | ||
| (isLong [_this ^long _l] true) | ||
| (isLong [_this ^Object _l] false) | ||
| (isDouble [_this ^double _d] true) | ||
| (isDouble [_this ^Object _d] false)))) | ||
|
|
||
| (when-var-exists num | ||
| (deftest test-num | ||
| #?@(:cljs [] | ||
| :clj | ||
| ;; The compiler should pass `x` as a primitive to `num`. | ||
| [(let [x 1.0] | ||
| (is (instance? java.lang.Double (num x)))) | ||
| (let [x 1] | ||
| (is (instance? java.lang.Long (num x)))) | ||
| ;; `BigInt` and `BigDecimal` are always boxed and `num` just returns them as-is. | ||
| (is (instance? clojure.lang.BigInt (num 1N))) | ||
| (is (instance? java.math.BigDecimal (num 1.0M)))] | ||
| :cljr | ||
| ;; The compiler should pass `x` as a primitive to `num`. | ||
| [(let [x 1.0] | ||
| (is (instance? System.Double (num x)))) | ||
| (let [x 1] | ||
| (is (instance? System.Int64 (num x)))) | ||
| ;; `BigInt` and `BigDecimal` are always boxed and `num` just returns them as-is. | ||
| (is (instance? clojure.lang.BigInt (num 1N))) | ||
| (is (instance? clojure.lang.BigDecimal (num 1.0M)))] | ||
| :default (is false "TODO test num")))) | ||
| (testing "positive cases" | ||
| #?@(:bb | ||
| [(is (NaN? (num ##NaN))) | ||
| (are [n] (and (= n (num n)) | ||
| (= (type n) (type (num n)))) | ||
| 0 | ||
| 0.1 | ||
| 1/2 | ||
| 1N | ||
| 1.0M | ||
| (short 1) | ||
| (byte 1) | ||
| (int 1) | ||
| (long 1) | ||
| (float 1.0) | ||
| (double 1.0) | ||
| nil | ||
| ##Inf)] | ||
|
|
||
| :cljs | ||
| [] | ||
|
|
||
| :clj | ||
| [(testing "longs" | ||
| (let [l (long 1) | ||
| L (num l) | ||
| checker (Checker.)] | ||
| (is (.isLong checker l)) | ||
| (is (false? (.isLong checker L))))) | ||
| (testing "doubles" | ||
| (let [d (double 1.0) | ||
| D (num d) | ||
| checker (Checker.)] | ||
| (is (.isDouble checker d)) | ||
| (is (false? (.isDouble checker D))))) | ||
| ;; `BigInt` and `BigDecimal` are always boxed and `num` just returns them as-is. | ||
| (is (instance? clojure.lang.BigInt (num 1N))) | ||
| (is (instance? java.math.BigDecimal (num 1.0M)))] | ||
|
|
||
| :cljr [(is (NaN? (num ##NaN))) | ||
| (is (= (byte 1) (num (byte 1)))) | ||
| (is (= System.UInt64 (type (num (byte 1))))) | ||
| (are [n] (and (= n (num n)) | ||
| (= (type (num n)) System.Int64)) | ||
| (short 1) | ||
| (int 1)) | ||
| (are [n] (and (= n (num n)) | ||
| (= (type n) (type (num n)))) | ||
| 0 | ||
| 0.1 | ||
| 1/2 | ||
| 1N | ||
| 1.0M | ||
| (long 1) | ||
| (float 1.0) | ||
| (double 1.0) | ||
| nil | ||
| ##Inf)] | ||
|
|
||
| ;; By default assume that other platforms are no-ops for numeric inputs | ||
| :default [(is (NaN? (num ##NaN))) | ||
| (are [n] (and (= n (num n)) | ||
| (= (type n) (type (num n)))) | ||
| 0 | ||
| 0.1 | ||
| 1/2 | ||
| 1N | ||
| 1.0M | ||
| (short 1) | ||
| (byte 1) | ||
| (int 1) | ||
| (long 1) | ||
| (float 1.0) | ||
| (double 1.0) | ||
| nil | ||
| ##Inf)]) | ||
| (testing "exceptions thrown" | ||
| ;; [[num]] is *almost* a true no-op in `cljr`, equivalent to [[identity]], | ||
| ;; except that it will upcast to System.Int64/System.UInt64 | ||
| #?@(:cljs | ||
| [] | ||
|
|
||
| :cljr | ||
| [(are [x] (and (= x (num x)) | ||
| (= (type x) (type (num x)))) | ||
| f | ||
| {} | ||
| #{} | ||
| [] | ||
| '() | ||
| \1 | ||
| \a | ||
| "" | ||
| "1" | ||
| 'a | ||
| #"") | ||
| (is (fn? (num (fn []))))] | ||
|
|
||
| :default | ||
| [(are [x] (thrown? Exception (num x)) | ||
| (fn []) | ||
| f | ||
| {} | ||
| #{} | ||
| [] | ||
| '() | ||
| \1 | ||
| \a | ||
| "" | ||
| "1" | ||
| 'a | ||
| #"")]))))) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added these changes to make
cljrdevelopment easier for myself