-
Notifications
You must be signed in to change notification settings - Fork 37
Add tests for >=
#865
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
Add tests for >=
#865
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| (ns clojure.core-test.gt-eq | ||
| (:require [clojure.test :as t :refer [are deftest is testing]] | ||
| [clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists] :as p])) | ||
|
|
||
| (when-var-exists >= | ||
| (deftest test->= | ||
| (testing "arity 1" | ||
| (are [x] (= true (>= x)) | ||
| ;; Doesn't matter what the argument is, `>=` return `true` for | ||
| ;; one argument. | ||
| 1 | ||
| 0 | ||
| -1 | ||
| ;; Doesn't check whether the argument is a number | ||
| "abc" | ||
| :foo | ||
| nil)) | ||
|
|
||
| (testing "arity 2" | ||
| (are [expected x y] (= expected (>= x y)) | ||
| false 0 1 | ||
| false -1 0 | ||
| false 0N 1N | ||
| false -1N 0N | ||
| false 0.0 1.0 | ||
| false -1.0 0.0 | ||
| false 0.0M 1.0M | ||
| false -1.0M 0.0M | ||
| false ##-Inf -1 | ||
| false 1 ##Inf | ||
| false 1 ##NaN ; Anything compared with ##NaN is false | ||
| false ##NaN 1 | ||
|
|
||
| true 1 0 | ||
| true 0 -1 | ||
| true 1N 0N | ||
| true 0N -1N | ||
| true 1.0 0.0 | ||
| true 0.0 -1.0 | ||
| true 1.0M 0.0M | ||
| true 0.0M -1.0M | ||
| true -1 ##-Inf | ||
| true ##Inf 1 | ||
|
|
||
| true 0 0 | ||
| true 1 1 | ||
| true -1 -1 | ||
| true ##Inf ##Inf | ||
| true ##-Inf ##-Inf | ||
| false ##NaN ##NaN ; ##NaN is never equal, even to itself | ||
|
Comment on lines
+45
to
+50
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation is weird here
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
|
|
||
| ;; Mixing numeric types should't matter | ||
| true 1.0 0 | ||
| true 0 -1.0 | ||
| true 1.0M 0N | ||
| true 0.0M -1N) | ||
|
|
||
| #?(:cljs nil | ||
| :default | ||
| (testing "Rationals" | ||
| (are [expected x y] (= expected (>= x y)) | ||
| true 1/2 1/16 | ||
| true -1/16 -1/2 | ||
| true 0.5 1/16 | ||
| true -1/16 -0.5 | ||
| false 1/16 1/2 | ||
| false 1/16 0.5 | ||
| false -1/2 -1/16 | ||
| false -0.5 -1/16 | ||
| true 1/2 1/2 | ||
| true 1/3 1/3 | ||
| true -1/2 -1/2 | ||
| true -1/3 -1/3)))) | ||
|
|
||
| (testing "arity 3 and more" | ||
| (are [expected x y z] (= expected (>= x y z)) | ||
| true 2 1 0 | ||
| true 0 -1 -2 | ||
| true 1 0 -1 | ||
| true 1 1 1 | ||
| false 2 0 1 | ||
| false 0 2 1 | ||
| false -1 -2 0 | ||
| false -1 0 -2 | ||
| true 1 0 0 | ||
| true 1 1 0 | ||
| false 0 0 1 | ||
| false 0 1 1 | ||
| true ##Inf 0 ##-Inf | ||
| false ##-Inf 0 ##Inf) | ||
| (is (= true (apply >= (reverse (range 10))))) | ||
| (is (= true (apply >= 10 (reverse (range 10))))) | ||
| (is (= false (apply >= -1 (reverse (range 10))))) | ||
| (is (= true (apply >= (repeat 5 1))))) | ||
|
|
||
| (testing "negative tests" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we'll want to scale back on these negative tests, since they're technically undefined behavior in Clojure. The docs string for Interestingly, the doc string also says
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah "returns
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll switch the tests to check for non-nil and
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also removed all negative tests for anything other than numbers and |
||
| ;; `<=` only compares numbers, except in ClojureScript (really | ||
| ;; JavaScript under the hood) where comparisons are just a bit | ||
| ;; of a mess. | ||
| #?@(:cljs | ||
| [(is (= true (>= 1 nil))) | ||
| (is (= false (>= nil 1))) | ||
| (is (= true (>= 2 1 nil))) | ||
| (is (= false (>= nil 2 1)))] | ||
| :cljr | ||
| [(is (p/thrown? (>= 1 nil))) | ||
| (is (p/thrown? (>= nil 1))) | ||
| (is (p/thrown? (>= 2 1 nil))) | ||
| (is (p/thrown? (>= nil 2 1)))] | ||
| :lpy | ||
| [(is (p/thrown? (>= 1 nil))) | ||
| (is (p/thrown? (>= nil 1))) | ||
| (is (p/thrown? (>= 2 1 nil))) | ||
| (is (p/thrown? (>= nil 2 1)))] | ||
| :default | ||
| [(is (p/thrown? (>= 1 nil))) | ||
| (is (p/thrown? (>= nil 1))) | ||
| (is (p/thrown? (>= 2 1 nil))) | ||
| (is (p/thrown? (>= nil 2 1)))])))) | ||
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.
nitpick, I think
test>=is more clear since to me this looks like we're testing some function/macro->=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.
The template has a standard format: "test-" appended with function name. I'm going to leave this as is unless you have a lot of heartburn, just for consistency with every other test.