Skip to content

Commit

Permalink
Added hash tests for ion and solution.
Browse files Browse the repository at this point in the history
  • Loading branch information
lewispurigenbio committed Dec 4, 2016
1 parent 0b9c5bc commit 7afb988
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ionize/Ion/BaseIon.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __str__(self):

def __hash__(self):
"""Return the hash value for the object."""
return hash(json.dumps(self._state))
return hash(self.serialize())

def __eq__(self, other):
"""Test equality between two ions."""
Expand Down
15 changes: 15 additions & 0 deletions ionize/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ def test_equality(self):
sol = Solution([hcl], [0.1])
self.assertEqual(hcl, hcl2)

def test_hash(self):
for ion in self.database.keys():
ion1 = self.database[ion]
ion2 = self.database[ion]
ion1.context({'pH': 8, 'ionic_strength': 0.1, 'temperature': 28})
ion2.context({'pH': 9, 'ionic_strength': 0.05, 'temperature': 23})
self.assertTrue(hash(ion1)==hash(ion2),
"Ions from database aren't identitcal.",
)

def test_serialize(self):
for ion_name in self.database.keys():
ion = self.database.load(ion_name)
Expand Down Expand Up @@ -365,6 +375,11 @@ def test_moderate(self):
self.assertFalse(sol.moderate(), 'Unbuffered acid evaluated as safe.')
self.assertTrue(sol.titrate('tris', 8).moderate(), 'Tris buffer evaluated as unsafe.')

def test_hash(self):
sol1 = Solution('chloride', 0.001)
sol2 = Solution('chloride', 0.001)
self.assertEqual(hash(sol1), hash(sol2))

class TestNucleicAcid(unittest.TestCase):

def test_mobility(self):
Expand Down

0 comments on commit 7afb988

Please sign in to comment.