| 415 | assert 0.1 + 0.2 == approx(0.3) |
| 416 | |
| 417 | def test_default_tolerances(self): |
| 418 | # This tests the defaults as they are currently set. If you change the |
| 419 | # defaults, this test will fail but you should feel free to change it. |
| 420 | # None of the other tests (except the doctests) should be affected by |
| 421 | # the choice of defaults. |
| 422 | examples = [ |
| 423 | # Relative tolerance used. |
| 424 | (eq, 1e100 + 1e94, 1e100), |
| 425 | (ne, 1e100 + 2e94, 1e100), |
| 426 | (eq, 1e0 + 1e-6, 1e0), |
| 427 | (ne, 1e0 + 2e-6, 1e0), |
| 428 | # Absolute tolerance used. |
| 429 | (eq, 1e-100, +1e-106), |
| 430 | (eq, 1e-100, +2e-106), |
| 431 | (eq, 1e-100, 0), |
| 432 | ] |
| 433 | for op, a, x in examples: |
| 434 | assert op(a, approx(x)) |
| 435 | |
| 436 | def test_custom_tolerances(self): |
| 437 | assert 1e8 + 1e0 == approx(1e8, rel=5e-8, abs=5e0) |