Finished
11class CustomSet:
22 def __init__(self, elements=[]):
3 pass
4
3 # Edge Case: Avoid mutable default argument trap
4 if elements is None:
5 elements = []
6 self.elements = []
7 for element in elements:
8 self.add(element)
9
510 def isempty(self):
6 pass
7
11 return len(self.elements) == 0
12
813 def __contains__(self, element):
9 pass
10
14 return element in self.elements
15
1116 def issubset(self, other):
12 pass
13
17 # Edge Case: Handle when other is not a CustomSet
18 if not isinstance(other, CustomSet):
19 return NotImplemented
20 # Edge Case: Empty set is subset of any set
21 if self.isempty():
22 return True
23 # Check if all elements in self are in other
24 for element in self.elements:
25 if element not in other:
26 return False
27 return True
28
1429 def isdisjoint(self, other):
15 pass
16
30 # Edge Case: Handle when other is not a CustomSet
31 if not isinstance(other, CustomSet):
32 return NotImplemented
33 # Edge Case: Empty sets are disjoint
34 if self.isempty() or other.isempty():
35 return True
36 # Check if there are no common elements
37 for element in self.elements:
38 if element in other:
39 return False
40 return True
41
1742 def __eq__(self, other):
18 pass
19
43 # Edge Case: Handle when other is not a CustomSet
44 if not isinstance(other, CustomSet):
45 return NotImplemented
46 # Edge Case: Both empty sets are equal
47 if self.isempty() and other.isempty():
48 return True
49 # Edge Case: Different sizes means not equal
50 if len(self.elements) != len(other.elements):
51 return False
52 # Check if all elements match (order doesn't matter)
53 for element in self.elements:
54 if element not in other:
55 return False
56 return True
57
2058 def add(self, element):
21 pass
22
59 if element not in self.elements:
60 self.elements.append(element)
61
2362 def intersection(self, other):
24 pass
25
63 # Edge Case: Handle when other is not a CustomSet
64 if not isinstance(other, CustomSet):
65 return NotImplemented
66 # Edge Case: Intersection with empty set is empty
67 if self.isempty() or other.isempty():
68 return CustomSet()
69 # Create new set with common elements
70 result_elements = []
71 for element in self.elements:
72 if element in other:
73 result_elements.append(element)
74 return CustomSet(result_elements)
75
2676 def __sub__(self, other):
27 pass
28
77 # Edge Case: Handle when other is not a CustomSet
78 if not isinstance(other, CustomSet):
79 return NotImplemented
80 # Edge Case: Subtracting from empty set results in empty set
81 if self.isempty():
82 return CustomSet()
83 # Edge Case: Subtracting empty set leaves original set
84 if other.isempty():
85 return CustomSet(self.elements)
86 # Create new set with elements in self but not in other
87 result_elements = []
88 for element in self.elements:
89 if element not in other:
90 result_elements.append(element)
91 return CustomSet(result_elements)
92
2993 def __add__(self, other):
30 pass
94 # Edge Case: Handle when other is not a CustomSet
95 if not isinstance(other, CustomSet):
96 return NotImplemented
97 # Edge Case: Union with empty set is the other set
98 if self.isempty():
99 return CustomSet(other.elements)
100 if other.isempty():
101 return CustomSet(self.elements)
102 # Create new set with all unique elements from both sets
103 result_elements = list(self.elements)
104 for element in other.elements:
105 if element not in result_elements:
106 result_elements.append(element)
107 return CustomSet(result_elements)
108
109# Handled Edge Cases: Mutable default argument trap, non-CustomSet operands, empty sets in all operations, subset relationships, equality with different orders, disjoint sets, set differences, unions
Test NameStatus
test_add_to_empty_set
Pass
test_add_to_non_empty_set
Pass
test_adding_an_existing_element_does_not_change_the_set
Pass
test_difference_of_a_non_empty_set_and_an_empty_set_is_the_non_empty_set
Pass
test_difference_of_empty_set_and_non_empty_set_is_an_empty_set
Pass
test_difference_of_two_empty_sets_is_an_empty_set
Pass
test_difference_of_two_non_empty_sets_is_a_set_of_elements_that_are_only_in_the_first_set
Pass
test_difference_removes_all_duplicates_in_the_first_set
Pass
test_empty_set_is_a_subset_of_another_empty_set
Pass
test_empty_set_is_a_subset_of_non_empty_set
Pass
test_empty_set_is_disjoint_with_non_empty_set
Pass
test_empty_set_is_not_equal_to_non_empty_set
Pass
test_empty_sets_are_equal
Pass
test_intersection_of_a_non_empty_set_and_an_empty_set_is_an_empty_set
Pass
test_intersection_of_an_empty_set_and_non_empty_set_is_an_empty_set
Pass
test_intersection_of_two_empty_sets_is_an_empty_set
Pass
test_intersection_of_two_sets_with_no_shared_elements_is_an_empty_set
Pass
test_intersection_of_two_sets_with_shared_elements_is_a_set_of_the_shared_elements
Pass
test_non_empty_set_is_disjoint_with_empty_set
Pass
test_non_empty_set_is_not_a_subset_of_empty_set
Pass
test_non_empty_set_is_not_equal_to_empty_set
Pass
test_nothing_is_contained_in_an_empty_set
Pass
test_set_is_a_subset_of_larger_set_with_same_elements
Pass
test_set_is_a_subset_of_set_with_exact_same_elements
Pass
test_set_is_equal_to_a_set_constructed_from_an_array_with_duplicates
Pass
test_set_is_not_a_subset_of_set_that_does_not_contain_its_elements
Pass
test_set_is_not_equal_to_larger_set_with_same_elements
Pass
test_sets_are_disjoint_if_they_share_no_elements
Pass
test_sets_are_not_disjoint_if_they_share_an_element
Pass
test_sets_with_different_elements_are_not_equal
Pass
test_sets_with_elements_are_not_empty
Pass
test_sets_with_no_elements_are_empty
Pass
test_sets_with_the_same_elements_are_equal
Pass
test_the_empty_set_is_disjoint_with_itself
Pass
test_union_of_a_non_empty_set_and_empty_set_is_the_non_empty_set
Pass
test_union_of_an_empty_set_and_non_empty_set_is_the_non_empty_set
Pass
test_union_of_empty_sets_is_an_empty_set
Pass
test_union_of_non_empty_sets_contains_all_unique_elements
Pass
test_when_the_element_is_in_the_set
Pass
test_when_the_element_is_not_in_the_set
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.