You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2016/03/01 04:03:28 UTC

[20/22] lucy-clownfish git commit: Add test for the Py binding of Hash.

Add test for the Py binding of Hash.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/9d058f4b
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/9d058f4b
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/9d058f4b

Branch: refs/heads/master
Commit: 9d058f4b324dabf4f2cdd2ea88f40c9aabe2d622
Parents: 8b41f26
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Feb 10 18:45:50 2016 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Feb 24 15:41:13 2016 -0800

----------------------------------------------------------------------
 runtime/python/test/test_hash.py | 102 ++++++++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/9d058f4b/runtime/python/test/test_hash.py
----------------------------------------------------------------------
diff --git a/runtime/python/test/test_hash.py b/runtime/python/test/test_hash.py
new file mode 100644
index 0000000..5bfd034
--- /dev/null
+++ b/runtime/python/test/test_hash.py
@@ -0,0 +1,102 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+import inspect
+import clownfish
+
+class TestHash(unittest.TestCase):
+
+    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 testDelete(self):
+        h = clownfish.Hash()
+        h.store("foo", "bar")
+        got = h.delete("foo")
+        self.assertEqual(h.get_size(), 0)
+        self.assertEqual(got, "bar")
+
+    def testClear(self):
+        h = clownfish.Hash()
+        h.store("foo", 1)
+        h.clear()
+        self.assertEqual(h.get_size(), 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"))
+
+    def testKeys(self):
+        h = clownfish.Hash()
+        h.store("a", 1)
+        h.store("b", 1)
+        keys = sorted(h.keys())
+        self.assertEqual(keys, ["a", "b"])
+
+    def testValues(self):
+        h = clownfish.Hash()
+        h.store("foo", "a")
+        h.store("bar", "b")
+        got = sorted(h.values())
+        self.assertEqual(got, ["a", "b"])
+
+    def testGetCapacity(self):
+        h = clownfish.Hash(capacity=1)
+        self.assertGreater(h.get_capacity(), 0)
+
+    def testGetSize(self):
+        h = clownfish.Hash()
+        self.assertEqual(h.get_size(), 0)
+        h.store("meep", "moop")
+        self.assertEqual(h.get_size(), 1)
+
+    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 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())
+
+if __name__ == '__main__':
+    unittest.main()
+