Skip to content

Commit e856773

Browse files
committed
Add remaining tests
1 parent 810be2b commit e856773

File tree

3 files changed

+186
-35
lines changed

3 files changed

+186
-35
lines changed

src/basic_data_handling/list_nodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,11 @@ def convert(self, list: list[Any]) -> tuple[set[Any]]:
790790
"Basic data handling: ListContains": "contains",
791791
"Basic data handling: ListCount": "count",
792792
"Basic data handling: ListExtend": "extend",
793-
"Basic data handling: ListFirst": "first element",
793+
"Basic data handling: ListFirst": "first",
794794
"Basic data handling: ListGetItem": "get item",
795795
"Basic data handling: ListIndex": "index",
796796
"Basic data handling: ListInsert": "insert",
797-
"Basic data handling: ListLast": "last element",
797+
"Basic data handling: ListLast": "last",
798798
"Basic data handling: ListLength": "length",
799799
"Basic data handling: ListMax": "max",
800800
"Basic data handling: ListMin": "min",

tests/test_dict_nodes.py

Lines changed: 79 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
#import pytest
22
from src.basic_data_handling.dict_nodes import (
3+
DictCompare,
4+
DictContainsKey,
35
DictCreate,
6+
DictCreateFromBoolean,
7+
DictCreateFromFloat,
8+
DictCreateFromInt,
9+
DictCreateFromLists,
10+
DictCreateFromString,
11+
DictExcludeKeys,
12+
DictFilterByKeys,
13+
DictFromKeys,
414
DictGet,
5-
DictSet,
6-
DictKeys,
7-
DictValues,
15+
DictGetKeysValues,
16+
DictGetMultiple,
17+
DictInvert,
818
DictItems,
9-
DictContainsKey,
10-
DictFromKeys,
19+
DictKeys,
20+
DictLength,
21+
DictMerge,
1122
DictPop,
1223
DictPopItem,
24+
DictPopRandom,
25+
DictRemove,
26+
DictSet,
1327
DictSetDefault,
1428
DictUpdate,
15-
DictLength,
16-
DictMerge,
17-
DictGetKeysValues,
18-
DictRemove,
19-
DictFilterByKeys,
20-
DictExcludeKeys,
21-
DictGetMultiple,
22-
DictInvert,
23-
DictCreateFromLists,
24-
DictCompare,
29+
DictValues,
2530
)
2631

2732
def test_dict_create():
@@ -47,6 +52,65 @@ def test_dict_set():
4752
# Test with empty dict
4853
assert node.set({}, "key", "value") == ({"key": "value"},)
4954

55+
def test_dict_create_from_boolean():
56+
node = DictCreateFromBoolean()
57+
# Test with dynamic inputs
58+
result = node.create(key_0="key1", value_0=True, key_1="key2", value_1=False)
59+
assert result == ({"key1": True, "key2": False},)
60+
# Test with empty inputs
61+
assert node.create() == ({},)
62+
63+
64+
def test_dict_create_from_float():
65+
node = DictCreateFromFloat()
66+
# Test with dynamic inputs
67+
result = node.create(key_0="key1", value_0=1.5, key_1="key2", value_1=2.5)
68+
assert result == ({"key1": 1.5, "key2": 2.5},)
69+
# Test with empty inputs
70+
assert node.create() == ({},)
71+
72+
73+
def test_dict_create_from_int():
74+
node = DictCreateFromInt()
75+
# Test with dynamic inputs
76+
result = node.create(key_0="key1", value_0=1, key_1="key2", value_1=2)
77+
assert result == ({"key1": 1, "key2": 2},)
78+
# Test with empty inputs
79+
assert node.create() == ({},)
80+
81+
82+
def test_dict_create_from_string():
83+
node = DictCreateFromString()
84+
# Test with dynamic inputs
85+
result = node.create(key_0="key1", value_0="value1", key_1="key2", value_1="value2")
86+
assert result == ({"key1": "value1", "key2": "value2"},)
87+
# Test with empty inputs
88+
assert node.create() == ({},)
89+
90+
91+
def test_dict_pop_random():
92+
node = DictPopRandom()
93+
# Test with non-empty dictionary
94+
my_dict = {"key1": "value1", "key2": "value2"}
95+
result_dict, key, value, success = node.pop_random(my_dict)
96+
97+
# Check that operation was successful
98+
assert success is True
99+
# Check that one item was removed
100+
assert len(result_dict) == len(my_dict) - 1
101+
# Check that removed key is not in result dict
102+
assert key not in result_dict
103+
# Check that the original key-value pair matches
104+
assert my_dict[key] == value
105+
106+
# Test with empty dictionary
107+
empty_result_dict, empty_key, empty_value, empty_success = node.pop_random({})
108+
assert empty_result_dict == {}
109+
assert empty_key == ""
110+
assert empty_value is None
111+
assert empty_success is False
112+
113+
50114

51115
def test_dict_keys():
52116
node = DictKeys()

tests/test_set_nodes.py

Lines changed: 105 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
#import pytest
22
from src.basic_data_handling.set_nodes import (
33
SetAdd,
4-
SetRemove,
4+
SetContains,
5+
SetCreate,
6+
SetCreateFromBoolean,
7+
SetCreateFromFloat,
8+
SetCreateFromInt,
9+
SetCreateFromString,
10+
SetDifference,
511
SetDiscard,
6-
SetPop,
7-
SetUnion,
812
SetIntersection,
9-
SetDifference,
10-
SetSymmetricDifference,
13+
SetIsDisjoint,
1114
SetIsSubset,
1215
SetIsSuperset,
13-
SetIsDisjoint,
14-
SetContains,
1516
SetLength,
16-
SetToList,
17-
SetCreate,
17+
SetPop,
18+
SetPopRandom,
19+
SetRemove,
20+
SetSymmetricDifference,
1821
SetToDataList,
19-
SetCreateFromInt,
20-
SetCreateFromString,
21-
SetCreateFromFloat,
22-
SetCreateFromBoolean
22+
SetToList,
23+
SetUnion,
2324
)
2425

2526
def test_set_create():
@@ -28,53 +29,71 @@ def test_set_create():
2829
assert node.create_set(item_0=1, item_1=2, item_2=3) == ({1, 2, 3},)
2930
assert node.create_set(item_0="a", item_1="b") == ({"a", "b"},)
3031
assert node.create_set() == (set(),) # Empty set with no arguments
32+
# Mixed types
33+
assert node.create_set(item_0=1, item_1="b", item_2=True) == ({1, "b", True},)
3134

3235

3336
def test_set_create_from_int():
3437
node = SetCreateFromInt()
3538
assert node.create_set(item_0=1, item_1=2, item_2=3) == ({1, 2, 3},)
3639
assert node.create_set(item_0=5) == ({5},) # Single item set
3740
assert node.create_set(item_0=1, item_1=1) == ({1},) # Duplicate items become single item
41+
assert node.create_set() == (set(),) # Empty set with no arguments
3842

3943

4044
def test_set_create_from_string():
4145
node = SetCreateFromString()
42-
# Note: Mocking the string function behavior as it's not defined in the file
43-
# This simulates what would happen assuming string() acts like str()
44-
node.create_set = lambda **kwargs: (set([str(value) for value in kwargs.values()]),)
45-
assert node.create_set(item_0="apple", item_1="banana") == ({"apple", "banana"},)
46-
assert node.create_set(item_0="apple", item_1="apple") == ({"apple"},) # Duplicate strings
46+
result = node.create_set(item_0="apple", item_1="banana")
47+
assert isinstance(result[0], set)
48+
assert result[0] == {"apple", "banana"}
49+
50+
# Duplicate strings
51+
result = node.create_set(item_0="apple", item_1="apple")
52+
assert result[0] == {"apple"}
53+
54+
# Empty set
55+
assert node.create_set() == (set(),)
4756

4857

4958
def test_set_create_from_float():
5059
node = SetCreateFromFloat()
5160
assert node.create_set(item_0=1.5, item_1=2.5) == ({1.5, 2.5},)
5261
assert node.create_set(item_0=3.14) == ({3.14},) # Single item set
5362
assert node.create_set(item_0=1.0, item_1=1.0) == ({1.0},) # Duplicate items
63+
assert node.create_set() == (set(),) # Empty set with no arguments
5464

5565

5666
def test_set_create_from_boolean():
5767
node = SetCreateFromBoolean()
5868
assert node.create_set(item_0=True, item_1=False) == ({True, False},)
5969
assert node.create_set(item_0=True, item_1=True) == ({True},) # Duplicate booleans
70+
assert node.create_set() == (set(),) # Empty set with no arguments
71+
# Test conversion from non-boolean values
72+
assert node.create_set(item_0=1, item_1=0) == ({True, False},)
6073

6174

6275
def test_set_add():
6376
node = SetAdd()
6477
assert node.add({1, 2}, 3) == ({1, 2, 3},)
6578
assert node.add({1, 2}, 1) == ({1, 2},) # Adding an existing item
79+
assert node.add(set(), "first") == ({"first"},) # Adding to empty set
80+
assert node.add({1, 2}, "string") == ({1, 2, "string"},) # Adding different type
6681

6782

6883
def test_set_remove():
6984
node = SetRemove()
7085
assert node.remove({1, 2, 3}, 2) == ({1, 3}, True) # Successful removal
7186
assert node.remove({1, 2, 3}, 4) == ({1, 2, 3}, False) # Item not in set
87+
assert node.remove({1}, 1) == (set(), True) # Removing the only element
88+
assert node.remove(set(), 1) == (set(), False) # Removing from empty set
7289

7390

7491
def test_set_discard():
7592
node = SetDiscard()
7693
assert node.discard({1, 2, 3}, 2) == ({1, 3},) # Successful removal
7794
assert node.discard({1, 2, 3}, 4) == ({1, 2, 3},) # No error for missing item
95+
assert node.discard({1}, 1) == (set(),) # Discarding the only element
96+
assert node.discard(set(), 1) == (set(),) # Discarding from empty set
7897

7998

8099
def test_set_pop():
@@ -83,79 +102,147 @@ def test_set_pop():
83102
result_set, removed_item = node.pop(input_set)
84103
assert result_set != input_set # Arbitrary item removed
85104
assert removed_item in input_set # Removed item was part of original set
105+
assert len(result_set) == len(input_set) - 1 # One item was removed
106+
assert removed_item not in result_set # Removed item is not in result set
86107

87108
empty_set = set()
88109
assert node.pop(empty_set) == (set(), None) # Handle empty set
89110

90111

112+
def test_set_pop_random():
113+
node = SetPopRandom()
114+
# Test with single item - must remove that item
115+
single_item_set = {42}
116+
result_set, removed_item = node.pop_random_element(single_item_set)
117+
assert result_set == set() and removed_item == 42
118+
119+
# Test with multiple items - can't predict which one will be popped
120+
# but we can check the result set size and that the popped item was from the original set
121+
original_set = {1, 2, 3, 4}
122+
result_set, removed_item = node.pop_random_element(original_set)
123+
assert len(result_set) == len(original_set) - 1
124+
assert removed_item in original_set
125+
assert removed_item not in result_set
126+
127+
# Test with empty set
128+
empty_set = set()
129+
assert node.pop_random_element(empty_set) == (set(), None)
130+
131+
91132
def test_set_union():
92133
node = SetUnion()
93134
assert node.union({1, 2}, {3, 4}) == ({1, 2, 3, 4},)
94135
assert node.union({1}, {2}, {3}, {4}) == ({1, 2, 3, 4},)
95136
assert node.union({1, 2}, set()) == ({1, 2},) # Union with empty set
137+
assert node.union(set(), set()) == (set(),) # Union of empty sets
138+
assert node.union({1, 2}, {2, 3}) == ({1, 2, 3},) # Overlapping sets
96139

97140

98141
def test_set_intersection():
99142
node = SetIntersection()
100143
assert node.intersection({1, 2, 3}, {2, 3, 4}) == ({2, 3},)
101144
assert node.intersection({1, 2, 3}, {4, 5}) == (set(),) # No common elements
102145
assert node.intersection({1, 2, 3}, {2, 3}, {3, 4}) == ({3},) # Multiple sets
146+
assert node.intersection({1, 2, 3}, {1, 2, 3}) == ({1, 2, 3},) # Identical sets
147+
assert node.intersection(set(), {1, 2, 3}) == (set(),) # Empty set intersection
103148

104149

105150
def test_set_difference():
106151
node = SetDifference()
107152
assert node.difference({1, 2, 3}, {2, 3, 4}) == ({1},)
108153
assert node.difference({1, 2, 3}, {4, 5}) == ({1, 2, 3},) # Nothing to remove
154+
assert node.difference({1, 2, 3}, {1, 2, 3}) == (set(),) # Identical sets
155+
assert node.difference(set(), {1, 2, 3}) == (set(),) # Empty set difference
156+
assert node.difference({1, 2, 3}, set()) == ({1, 2, 3},) # Difference with empty set
109157

110158

111159
def test_set_symmetric_difference():
112160
node = SetSymmetricDifference()
113161
assert node.symmetric_difference({1, 2, 3}, {3, 4, 5}) == ({1, 2, 4, 5},)
114162
assert node.symmetric_difference({1, 2, 3}, {1, 2, 3}) == (set(),) # No unique elements
163+
assert node.symmetric_difference(set(), {1, 2, 3}) == ({1, 2, 3},) # Empty set symmetric difference
164+
assert node.symmetric_difference({1, 2, 3}, set()) == ({1, 2, 3},) # Symmetric difference with empty set
115165

116166

117167
def test_set_is_subset():
118168
node = SetIsSubset()
119169
assert node.is_subset({1, 2}, {1, 2, 3}) == (True,)
120170
assert node.is_subset({1, 4}, {1, 2, 3}) == (False,)
121171
assert node.is_subset(set(), {1, 2, 3}) == (True,) # Empty set is subset of all sets
172+
assert node.is_subset({1, 2}, {1, 2}) == (True,) # Set is subset of itself
173+
assert node.is_subset({1, 2, 3}, {1, 2}) == (False,) # Superset is not a subset
122174

123175

124176
def test_set_is_superset():
125177
node = SetIsSuperset()
126178
assert node.is_superset({1, 2, 3}, {1, 2}) == (True,)
127179
assert node.is_superset({1, 2}, {1, 2, 3}) == (False,)
128180
assert node.is_superset(set(), set()) == (True,) # Empty set is a superset of itself
181+
assert node.is_superset({1, 2}, {1, 2}) == (True,) # Set is superset of itself
182+
assert node.is_superset({1, 2}, set()) == (True,) # Any set is superset of empty set
129183

130184

131185
def test_set_is_disjoint():
132186
node = SetIsDisjoint()
133187
assert node.is_disjoint({1, 2}, {3, 4}) == (True,) # No common elements
134188
assert node.is_disjoint({1, 2}, {2, 3}) == (False,) # Common element
189+
assert node.is_disjoint(set(), {1, 2, 3}) == (True,) # Empty set is disjoint with any set
190+
assert node.is_disjoint({1, 2}, set()) == (True,) # Empty set is disjoint with any set
191+
assert node.is_disjoint(set(), set()) == (True,) # Empty sets are disjoint
135192

136193

137194
def test_set_contains():
138195
node = SetContains()
139196
assert node.contains({1, 2, 3}, 2) == (True,)
140197
assert node.contains({1, 2, 3}, 4) == (False,)
198+
assert node.contains(set(), 1) == (False,) # Empty set contains nothing
199+
assert node.contains({1, "string", True}, "string") == (True,) # Mixed type set
200+
assert node.contains({1, "string", True}, False) == (False,) # Boolean check
141201

142202

143203
def test_set_length():
144204
node = SetLength()
145205
assert node.length({1, 2, 3}) == (3,)
146206
assert node.length(set()) == (0,) # Empty set
207+
assert node.length({1, 1, 1, 1}) == (1,) # Set with duplicate values (only counts unique)
208+
assert node.length({12, "string", True, 3.14}) == (4,) # Mixed types
147209

148210

149211
def test_set_to_list():
150212
node = SetToList()
151213
result = node.convert({1, 2, 3})
152214
assert isinstance(result, tuple)
215+
assert isinstance(result[0], list)
153216
assert sorted(result[0]) == [1, 2, 3] # Validate conversion to list
154217

218+
# Empty set
219+
result = node.convert(set())
220+
assert result[0] == []
221+
222+
# Mixed types
223+
result = node.convert({1, "string", True})
224+
assert set(result[0]) == {1, "string", True} # Can't check order, just content
225+
155226

156227
def test_set_to_data_list():
157228
node = SetToDataList()
158229
result = node.convert({1, 2, 3})
159230
assert isinstance(result, tuple)
160231
assert isinstance(result[0], list)
161232
assert sorted(result[0]) == [1, 2, 3] # Validate conversion to data list
233+
234+
# Empty set
235+
result = node.convert(set())
236+
assert result[0] == []
237+
238+
# Mixed types
239+
result = node.convert({1, "string", True})
240+
assert set(result[0]) == {1, "string", True} # Can't check order, just content
241+
242+
# Empty set
243+
result = node.convert(set())
244+
assert result[0] == []
245+
246+
# Mixed types
247+
result = node.convert({1, "string", True})
248+
assert set(result[0]) == {1, "string", True} # Can't check order, just content

0 commit comments

Comments
 (0)