-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_only.py
More file actions
41 lines (35 loc) · 1.49 KB
/
test_only.py
File metadata and controls
41 lines (35 loc) · 1.49 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
38
39
40
41
from arrayutilities import Arr
import unittest
class TestArr(unittest.TestCase):
def test_only_with_existing_keys(self):
array = {'a': 1, 'b': 2, 'c': 3}
keys = ['a', 'c']
expected = {'a': 1, 'c': 3}
result = Arr.only(array, keys)
self.assertEqual(result, expected, "Should return a dictionary with only the specified keys")
def test_only_with_nonexistent_keys(self):
array = {'a': 1, 'b': 2, 'c': 3}
keys = ['x', 'y', 'z']
expected = {}
result = Arr.only(array, keys)
self.assertEqual(result, expected, "Should return an empty dictionary if none of the keys exist in the array")
def test_only_with_empty_keys(self):
array = {'a': 1, 'b': 2, 'c': 3}
keys = []
expected = {}
result = Arr.only(array, keys)
self.assertEqual(result, expected, "Should return an empty dictionary if no keys are provided")
def test_only_with_empty_array(self):
array = {}
keys = ['a', 'b', 'c']
expected = {}
result = Arr.only(array, keys)
self.assertEqual(result, expected, "Should return an empty dictionary if the array is empty")
def test_only_with_mixed_keys(self):
array = {'a': 1, 'b': 2, 'c': 3}
keys = ['a', 'x', 'c']
expected = {'a': 1, 'c': 3}
result = Arr.only(array, keys)
self.assertEqual(result, expected, "Should return a dictionary with only the existing keys")
if __name__ == '__main__':
unittest.main()