コード例 #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")