-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_dot.py
More file actions
37 lines (30 loc) · 1.5 KB
/
test_dot.py
File metadata and controls
37 lines (30 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import unittest
from arrayutilities import Arr
class TestArr(unittest.TestCase):
def test_empty_dict(self):
result = Arr.dot({})
self.assertEqual(result, {}, "Should return an empty dictionary when the input is empty")
def test_flat_dict(self):
test_dict = {'a': 1, 'b': 2}
result = Arr.dot(test_dict)
self.assertEqual(result, {'a': 1, 'b': 2}, "Should handle flat dictionaries without modification")
def test_nested_dict(self):
test_dict = {'a': {'b': 2, 'c': 3}}
result = Arr.dot(test_dict)
self.assertEqual(result, {'a.b': 2, 'a.c': 3}, "Should correctly flatten a nested dictionary")
def test_deeply_nested_dict(self):
test_dict = {'a': {'b': {'c': {'d': 4}}}}
result = Arr.dot(test_dict)
self.assertEqual(result, {'a.b.c.d': 4}, "Should correctly flatten a deeply nested dictionary")
def test_multiple_nested_levels(self):
test_dict = {'a': 1, 'b': {'c': 2, 'd': {'e': 3}}}
result = Arr.dot(test_dict)
expected = {'a': 1, 'b.c': 2, 'b.d.e': 3}
self.assertEqual(result, expected, "Should handle dictionaries with multiple nested levels and flatten them correctly")
def test_with_initial_prepend(self):
test_dict = {'a': 1}
result = Arr.dot(test_dict, 'init.')
self.assertEqual(result, {'init.a': 1}, "Should correctly prepend a given string to the keys")
# This allows the test to be run from the command line
if __name__ == '__main__':
unittest.main()