Tests that solutions that compare the same have the same hash.
(ok_small)
| 755 | |
| 756 | |
| 757 | def test_hash(ok_small): |
| 758 | """ |
| 759 | Tests that solutions that compare the same have the same hash. |
| 760 | """ |
| 761 | rng = RandomNumberGenerator(seed=2) |
| 762 | |
| 763 | sol1 = Solution.make_random(ok_small, rng) |
| 764 | sol2 = Solution.make_random(ok_small, rng) |
| 765 | |
| 766 | # Two random solutions. They're not the same, so the hashes should not be |
| 767 | # the same either (unless there's a collision, which is not the case here). |
| 768 | assert_(sol1 != sol2) |
| 769 | assert_(hash(sol1) != hash(sol2)) |
| 770 | |
| 771 | sol3 = deepcopy(sol2) # is a direct copy |
| 772 | |
| 773 | # These two are the same solution, so their hashes should be the same too. |
| 774 | assert_equal(sol2, sol3) |
| 775 | assert_equal(hash(sol2), hash(sol3)) |
| 776 | |
| 777 | |
| 778 | def test_solution_can_be_pickled(ok_small): |
nothing calls this directly
no test coverage detected