|
126 | 126 | "not coll or map expansion"))) |
127 | 127 |
|
128 | 128 | (deftest approx=-test |
129 | | - (testing "Default tolerance (1e-6)" |
130 | | - (is (t/approx= 1.0 1.0)) |
131 | | - (is (t/approx= 1.0 1.000001)) |
132 | | - (is (not (t/approx= 1.0 1.00001))) |
133 | | - (is (t/approx= 0.0 0.0)) |
134 | | - (is (t/approx= -1.0 -1.0)) |
135 | | - (is (t/approx= 1000000.0 1000000.0000009))) |
136 | | - |
137 | | - (testing "Custom tolerance" |
138 | | - (is (t/approx= 1.0 1.001 :tolerance 1e-2)) |
139 | | - (is (not (t/approx= 1.0 1.01 :tolerance 1e-2))) |
140 | | - (is (t/approx= 1.0 1.01 :tolerance 1e-1))) |
141 | | - |
142 | | - #?(:clj |
143 | | - (testing "Infinity cases" |
144 | | - (is (t/approx= Double/POSITIVE_INFINITY Double/POSITIVE_INFINITY)) |
145 | | - (is (t/approx= Double/NEGATIVE_INFINITY Double/NEGATIVE_INFINITY)) |
146 | | - (is (not (t/approx= Double/POSITIVE_INFINITY Double/NEGATIVE_INFINITY))) |
147 | | - (is (not (t/approx= Double/POSITIVE_INFINITY 1000.0))) |
148 | | - (is (not (t/approx= 1000.0 Double/POSITIVE_INFINITY))) |
149 | | - (is (not (t/approx= Double/NEGATIVE_INFINITY 1000.0))) |
150 | | - (is (not (t/approx= 1000.0 Double/NEGATIVE_INFINITY))) |
151 | | - (is (not (t/approx= Double/POSITIVE_INFINITY Double/NEGATIVE_INFINITY :tolerance 1e10))))) |
152 | | - |
153 | | - #?(:clj |
154 | | - (testing "NaN cases without nan-equal? flag" |
155 | | - (is (not (t/approx= Double/NaN Double/NaN))) |
156 | | - (is (not (t/approx= Double/NaN 1.0))) |
157 | | - (is (not (t/approx= 1.0 Double/NaN))) |
158 | | - (is (not (t/approx= Double/NaN Double/POSITIVE_INFINITY))) |
159 | | - (is (not (t/approx= Double/POSITIVE_INFINITY Double/NaN))))) |
160 | | - |
161 | | - #?(:clj |
162 | | - (testing "NaN cases with nan-equal? true" |
163 | | - (is (t/approx= Double/NaN Double/NaN :nan-equal? true)) |
164 | | - (is (not (t/approx= Double/NaN 1.0 :nan-equal? true))) |
165 | | - (is (not (t/approx= 1.0 Double/NaN :nan-equal? true))) |
166 | | - (is (not (t/approx= Double/NaN Double/POSITIVE_INFINITY :nan-equal? true)))))) |
| 129 | + ;; Testing private approx= function via #' |
| 130 | + (let [approx= @#'t/approx=] |
| 131 | + (testing "Default tolerance (1e-6)" |
| 132 | + (is (approx= 1.0 1.0)) |
| 133 | + (is (approx= 1.0 1.000001)) |
| 134 | + (is (not (approx= 1.0 1.00001))) |
| 135 | + (is (approx= 0.0 0.0)) |
| 136 | + (is (approx= -1.0 -1.0)) |
| 137 | + (is (approx= 1000000.0 1000000.0000009))) |
| 138 | + |
| 139 | + (testing "Custom tolerance" |
| 140 | + (is (approx= 1.0 1.001 :tolerance 1e-2)) |
| 141 | + (is (not (approx= 1.0 1.01 :tolerance 1e-2))) |
| 142 | + (is (approx= 1.0 1.01 :tolerance 1e-1))) |
| 143 | + |
| 144 | + #?(:clj |
| 145 | + (testing "Infinity cases" |
| 146 | + (is (approx= Double/POSITIVE_INFINITY Double/POSITIVE_INFINITY)) |
| 147 | + (is (approx= Double/NEGATIVE_INFINITY Double/NEGATIVE_INFINITY)) |
| 148 | + (is (not (approx= Double/POSITIVE_INFINITY Double/NEGATIVE_INFINITY))) |
| 149 | + (is (not (approx= Double/POSITIVE_INFINITY 1000.0))) |
| 150 | + (is (not (approx= 1000.0 Double/POSITIVE_INFINITY))) |
| 151 | + (is (not (approx= Double/NEGATIVE_INFINITY 1000.0))) |
| 152 | + (is (not (approx= 1000.0 Double/NEGATIVE_INFINITY))) |
| 153 | + (is (not (approx= Double/POSITIVE_INFINITY Double/NEGATIVE_INFINITY :tolerance 1e10))))) |
| 154 | + |
| 155 | + #?(:clj |
| 156 | + (testing "NaN cases without nan-equal? flag" |
| 157 | + (is (not (approx= Double/NaN Double/NaN))) |
| 158 | + (is (not (approx= Double/NaN 1.0))) |
| 159 | + (is (not (approx= 1.0 Double/NaN))) |
| 160 | + (is (not (approx= Double/NaN Double/POSITIVE_INFINITY))) |
| 161 | + (is (not (approx= Double/POSITIVE_INFINITY Double/NaN))))) |
| 162 | + |
| 163 | + #?(:clj |
| 164 | + (testing "NaN cases with nan-equal? true" |
| 165 | + (is (approx= Double/NaN Double/NaN :nan-equal? true)) |
| 166 | + (is (not (approx= Double/NaN 1.0 :nan-equal? true))) |
| 167 | + (is (not (approx= 1.0 Double/NaN :nan-equal? true))) |
| 168 | + (is (not (approx= Double/NaN Double/POSITIVE_INFINITY :nan-equal? true))))))) |
167 | 169 |
|
168 | 170 | (deftest is-valid-test |
169 | 171 | (t/is-valid int? 1)) |
|
0 commit comments