|
1 |
| -# Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. |
| 1 | +# Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. |
2 | 2 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
3 | 3 | #
|
4 | 4 | # The Universal Permissive License (UPL), Version 1.0
|
@@ -229,6 +229,58 @@ def test_compare(self):
|
229 | 229 | self.assertTrue(i > f)
|
230 | 230 | self.assertTrue(i >= f)
|
231 | 231 |
|
| 232 | + def test_compare_infinite(self): |
| 233 | + nan = float('nan') |
| 234 | + inf = float('inf') |
| 235 | + ninf = float('-inf') |
| 236 | + positives = [0.0, 1.0, 1, 1125899906842624, 1 << 100] |
| 237 | + negatives = [-x for x in positives] |
| 238 | + for num in [nan, inf, ninf, *positives, *negatives]: |
| 239 | + self.assertFalse(nan == num) |
| 240 | + self.assertTrue(nan != num) |
| 241 | + self.assertFalse(nan < num) |
| 242 | + self.assertFalse(nan <= num) |
| 243 | + self.assertFalse(nan > num) |
| 244 | + self.assertFalse(nan >= num) |
| 245 | + self.assertFalse(num == nan) |
| 246 | + self.assertTrue(num != nan) |
| 247 | + self.assertFalse(num < nan) |
| 248 | + self.assertFalse(num <= nan) |
| 249 | + self.assertFalse(num > nan) |
| 250 | + self.assertFalse(num >= nan) |
| 251 | + |
| 252 | + self.assertTrue(inf == inf) |
| 253 | + self.assertFalse(inf != inf) |
| 254 | + for num in [ninf, *positives, *negatives]: |
| 255 | + self.assertFalse(inf == num) |
| 256 | + self.assertFalse(num == inf) |
| 257 | + self.assertTrue(inf != num) |
| 258 | + self.assertTrue(num != inf) |
| 259 | + self.assertTrue(inf > num) |
| 260 | + self.assertTrue(inf >= num) |
| 261 | + self.assertFalse(inf < num) |
| 262 | + self.assertFalse(inf <= num) |
| 263 | + self.assertFalse(num > inf) |
| 264 | + self.assertFalse(num >= inf) |
| 265 | + self.assertTrue(num < inf) |
| 266 | + self.assertTrue(num <= inf) |
| 267 | + |
| 268 | + self.assertTrue(ninf == ninf) |
| 269 | + self.assertFalse(ninf != ninf) |
| 270 | + for num in [*positives, *negatives]: |
| 271 | + self.assertFalse(ninf == num) |
| 272 | + self.assertFalse(num == ninf) |
| 273 | + self.assertTrue(ninf != num) |
| 274 | + self.assertTrue(num != ninf) |
| 275 | + self.assertFalse(ninf > num) |
| 276 | + self.assertFalse(ninf >= num) |
| 277 | + self.assertTrue(ninf < num) |
| 278 | + self.assertTrue(ninf <= num) |
| 279 | + self.assertTrue(num > ninf) |
| 280 | + self.assertTrue(num >= ninf) |
| 281 | + self.assertFalse(num < ninf) |
| 282 | + self.assertFalse(num <= ninf) |
| 283 | + |
232 | 284 |
|
233 | 285 | fromHex = float.fromhex
|
234 | 286 |
|
|
0 commit comments