| 616 | assert 1 != approx({"a": 0}) |
| 617 | |
| 618 | def test_numpy_array(self): |
| 619 | np = pytest.importorskip("numpy") |
| 620 | |
| 621 | actual = np.array([1 + 1e-7, 2 + 1e-8]) |
| 622 | expected = np.array([1, 2]) |
| 623 | |
| 624 | # Return false if any element is outside the tolerance. |
| 625 | assert actual == approx(expected, rel=5e-7, abs=0) |
| 626 | assert actual != approx(expected, rel=5e-8, abs=0) |
| 627 | assert approx(expected, rel=5e-7, abs=0) == expected |
| 628 | assert approx(expected, rel=5e-8, abs=0) != actual |
| 629 | |
| 630 | # Should be able to compare lists with numpy arrays. |
| 631 | assert list(actual) == approx(expected, rel=5e-7, abs=0) |
| 632 | assert list(actual) != approx(expected, rel=5e-8, abs=0) |
| 633 | assert actual == approx(list(expected), rel=5e-7, abs=0) |
| 634 | assert actual != approx(list(expected), rel=5e-8, abs=0) |
| 635 | |
| 636 | def test_numpy_tolerance_args(self): |
| 637 | """ |