def testEquals(self): h = clownfish.Hash() other = clownfish.Hash() h.store("a", "foo") other.store("a", "foo") self.assertTrue(h.equals(other)) other.store("b", "bar") self.assertFalse(h.equals(other)) self.assertTrue(h.equals({"a": "foo"}), "equals() true against a Python dict") vec = clownfish.Vector() self.assertFalse(h.equals(vec), "equals() false against conflicting Clownfish type") self.assertFalse(h.equals(1), "equals() false against conflicting Python type")
def testHasKey(self): h = clownfish.Hash() h.store("foo", 1) h.store("nada", None) self.assertTrue(h.has_key("foo")) self.assertFalse(h.has_key("bar")) self.assertTrue(h.has_key("nada"))
def testStoreFetch(self): h = clownfish.Hash() h.store("foo", "bar") h.store("foo", "bar") self.assertEqual(h.fetch("foo"), "bar") h.store("nada", None) self.assertEqual(h.fetch("nada"), None)
def testIterator(self): h = clownfish.Hash() h.store("a", "foo") i = clownfish.HashIterator(h) self.assertTrue(i.next()) self.assertEqual(i.get_key(), "a") self.assertEqual(i.get_value(), "foo") self.assertFalse(i.next())
def testGetSize(self): h = clownfish.Hash() self.assertEqual(h.get_size(), 0) h.store("meep", "moop") self.assertEqual(h.get_size(), 1)
def testGetCapacity(self): h = clownfish.Hash(capacity=1) self.assertGreater(h.get_capacity(), 0)
def testValues(self): h = clownfish.Hash() h.store("foo", "a") h.store("bar", "b") got = sorted(h.values()) self.assertEqual(got, ["a", "b"])
def testKeys(self): h = clownfish.Hash() h.store("a", 1) h.store("b", 1) keys = sorted(h.keys()) self.assertEqual(keys, ["a", "b"])
def testClear(self): h = clownfish.Hash() h.store("foo", 1) h.clear() self.assertEqual(h.get_size(), 0)
def testDelete(self): h = clownfish.Hash() h.store("foo", "bar") got = h.delete("foo") self.assertEqual(h.get_size(), 0) self.assertEqual(got, "bar")