-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_set.py
More file actions
30 lines (26 loc) · 998 Bytes
/
test_set.py
File metadata and controls
30 lines (26 loc) · 998 Bytes
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
from arrayutilities import Arr
import unittest
class TestArr(unittest.TestCase):
def test_set_single_key(self):
test_array = {}
keys = 'a'
value = 1
expected = {'a': 1}
result = Arr.set(test_array, keys, value)
self.assertEqual(result, expected, "Should set a value for a single key")
def test_set_nested_keys(self):
test_array = {}
keys = ['a', 'b', 'c']
value = 1
expected = {'a': {'b': {'c': 1}}}
result = Arr.set(test_array, keys, value)
self.assertEqual(result, expected, "Should set a value for nested keys")
def test_set_existing_nested_keys(self):
test_array = {'a': {'b': {'c': 1}}}
keys = ['a', 'b', 'd']
value = 2
expected = {'a': {'b': {'c': 1, 'd': 2}}}
result = Arr.set(test_array, keys, value)
self.assertEqual(result, expected, "Should set a value for existing nested keys")
if __name__ == '__main__':
unittest.main()