MCPcopy Create free account
hub / github.com/PyVRP/PyVRP / test_hash

Function test_hash

tests/test_Solution.py:757–775  ·  view source on GitHub ↗

Tests that solutions that compare the same have the same hash.

(ok_small)

Source from the content-addressed store, hash-verified

755
756
757def 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
778def test_solution_can_be_pickled(ok_small):

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected