예제 #1
0
 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")
예제 #2
0
 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"))
예제 #3
0
 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)
예제 #4
0
 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())
예제 #5
0
 def testGetSize(self):
     h = clownfish.Hash()
     self.assertEqual(h.get_size(), 0)
     h.store("meep", "moop")
     self.assertEqual(h.get_size(), 1)
예제 #6
0
 def testGetCapacity(self):
     h = clownfish.Hash(capacity=1)
     self.assertGreater(h.get_capacity(), 0)
예제 #7
0
 def testValues(self):
     h = clownfish.Hash()
     h.store("foo", "a")
     h.store("bar", "b")
     got = sorted(h.values())
     self.assertEqual(got, ["a", "b"])
예제 #8
0
 def testKeys(self):
     h = clownfish.Hash()
     h.store("a", 1)
     h.store("b", 1)
     keys = sorted(h.keys())
     self.assertEqual(keys, ["a", "b"])
예제 #9
0
 def testClear(self):
     h = clownfish.Hash()
     h.store("foo", 1)
     h.clear()
     self.assertEqual(h.get_size(), 0)
예제 #10
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")