summaryrefslogtreecommitdiff
path: root/tests/dict_utils_test.py
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2021-07-08 19:44:27 -0700
committerScott Gasch <[email protected]>2021-07-08 19:44:27 -0700
commit3bc4daf1edc121cd633429187392227f2fa61885 (patch)
tree0663cf35f562c7023c914454c85050d502ad9f3c /tests/dict_utils_test.py
parent5fd30ef12c100cbb936aa0fdb515b67cff4064db (diff)
Lots of changes.
Diffstat (limited to 'tests/dict_utils_test.py')
-rwxr-xr-xtests/dict_utils_test.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/dict_utils_test.py b/tests/dict_utils_test.py
new file mode 100755
index 0000000..1bdbb9b
--- /dev/null
+++ b/tests/dict_utils_test.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python3
+
+import unittest
+
+import dict_utils as du
+
+
+class TestDictUtils(unittest.TestCase):
+
+ def test_init_or_inc(self):
+ d = {}
+ du.init_or_inc(d, 'a')
+ du.init_or_inc(d, 'b')
+ du.init_or_inc(d, 'a')
+ du.init_or_inc(d, 'b')
+ du.init_or_inc(d, 'c')
+ du.init_or_inc(d, 'c')
+ du.init_or_inc(d, 'd')
+ du.init_or_inc(d, 'e')
+ du.init_or_inc(d, 'a')
+ du.init_or_inc(d, 'b')
+ e = {
+ 'a': 3, 'b': 3, 'c': 2, 'd': 1, 'e': 1
+ }
+ self.assertEqual(d, e)
+
+ def test_shard_coalesce(self):
+ d = {
+ 'a': 3, 'b': 3, 'c': 2, 'd': 1, 'e': 1
+ }
+ shards = du.shard(d, 2)
+ merged = du.coalesce(shards)
+ self.assertEqual(d, merged)
+
+ def test_item_with_max_value(self):
+ d = {
+ 'a': 4, 'b': 3, 'c': 2, 'd': 1, 'e': 1
+ }
+ self.assertEqual('a', du.item_with_max_value(d)[0])
+ self.assertEqual(4, du.item_with_max_value(d)[1])
+ self.assertEqual('a', du.key_with_max_value(d))
+ self.assertEqual(4, du.max_value(d))
+
+ def test_item_with_min_value(self):
+ d = {
+ 'a': 4, 'b': 3, 'c': 2, 'd': 1, 'e': 0
+ }
+ self.assertEqual('e', du.item_with_min_value(d)[0])
+ self.assertEqual(0, du.item_with_min_value(d)[1])
+ self.assertEqual('e', du.key_with_min_value(d))
+ self.assertEqual(0, du.min_value(d))
+
+ def test_min_max_key(self):
+ d = {
+ 'a': 4, 'b': 3, 'c': 2, 'd': 1, 'e': 0
+ }
+ self.assertEqual('a', du.min_key(d))
+ self.assertEqual('e', du.max_key(d))
+
+
+if __name__ == '__main__':
+ unittest.main()