def test_intersection(self): test_set = Set([1, 2, 3, 4, 5]) other_set = Set([1, 2, 3, 7]) unions = test_set.intersection(other_set) assert unions.contains(1) assert unions.contains(2) assert unions.contains(3)
def test_difference(self): test_set = Set([1, 2, 3, 4, 5]) other_set = Set([1, 2, 3, 7]) unions = test_set.difference(other_set) assert unions.contains(4) == True assert unions.contains(5) == True assert unions.contains(9) == False
def test_difference(self): a = Set([6, 7, 8, 9]) b = Set([8, 9, 0, 1]) a_or_b = a.difference(b) print("a or b", a_or_b) assert a_or_b.__contains__(6) == True assert a_or_b.__contains__(7) == True assert a_or_b.__contains__(8) == False assert a_or_b.__contains__(9) == False b.remove(8) a_or_b = a.difference(b) assert a_or_b.__contains__(8) == True a.add(None) a.add(3.1) print("a", a, "b", b, "both", a_or_b) b.add(3.0) print(a, b) a.add('f') b.add('f') a_or_b = a.difference(b) assert a_or_b.__contains__('f') == False assert a_or_b.__contains__(3.0) == False assert a_or_b.__contains__(3.1) == True assert a_or_b.__contains__(None) == True
def test_intersection(self): a = Set([6, 7, 8, 9]) b = Set([8, 9, 0, 1]) both_a_and_b = a.intersection(b) assert both_a_and_b.__contains__(6) is False assert both_a_and_b.__contains__(8) is True assert both_a_and_b.__contains__(9) is True assert both_a_and_b.__contains__(1) is False a.add('f') b.add('f') b.add(0.5) both_a_and_b = a.intersection(b) assert both_a_and_b.__contains__('f') is True assert both_a_and_b.__contains__(0.5) is False b.remove(8) both_a_and_b = a.intersection(b) assert both_a_and_b.__contains__(8) is False
def test_init(self): s = Set() assert s.count == 0 s_two = Set(['R', 'I', 'N']) assert s_two.count == 3 s_two = Set(['R', 'I', 'N', 'N', 'I']) assert s_two.count == 3
def test_is_subset(self): test_set = Set([1, 2, 3, 4, 5]) other_set = Set([1, 2, 3]) next_set = Set([7, 8]) assert test_set.is_subset(other_set) == True assert other_set.is_subset(test_set) == False assert next_set.is_subset(test_set) == False
def test_difference(self): set_test_1 = Set(['a', 'b', 'c']) set_test_2 = Set(['c', 'd', 'e']) assert set_test_1.difference(set_test_2).length() == 2 set_test_3 = Set(['a', 'b', 'c', 'd']) set_test_4 = Set(['a', 'b', 'c', 'd']) assert set_test_3.difference(set_test_4).length() == 0
def test_is_subset(self): test_set = Set(['Apple','Banana','Cactus','Durian']) subset = Set(['Apple', 'Banana']) assert test_set.is_subset(subset) == True subset.add('Z') assert subset.is_subset(test_set) == False
def __init__(self, initial_state_str): if len(initial_state_str) != 81: raise InvalidPuzzleInitStringException( 'Supplied Puzzle init string is not 81 characters long and is thus invalid' ) self._puzzle = [] self._boxes = [Set(SetType.BOX) for i in range(9)] self._rows = [Set(SetType.ROW) for i in range(9)] self._columns = [Set(SetType.COLUMN) for i in range(9)] self._empty_squares = set() self._errors_visible = True for index, value in enumerate(initial_state_str): row = int(index / 9) if row >= len(self._puzzle): self._puzzle.append([]) column = index % 9 square = Square(value) self._puzzle[row].append(square) square._set_puzzle(self) self._box_for(row, column).add_square(square) self._rows[row].add_square(square) self._columns[column].add_square(square) if square.is_empty(): self._empty_squares.add(square) if not self.is_valid(): raise InvalidPuzzleInitStringException( 'Supplied Puzzle init string has conflicts and is invalid: \n' + str(self))
def test_is_subset(self): st = Set([6, 9, 4, 2, 0, 'X', 'MJ', 'Santa Cruz']) other = Set([6, 4, 18, 21, 'X', 'Nintendo', 'Sony']) sub = Set([4, 2, 0, 'MJ']) assert st.is_subset(other) is False assert st.is_subset(sub) is True assert st.is_subset(st) is True
def test_set(): test_set = Set() test_set.add(1) test_set.add(2) test_set.add(3) assert test_set.contains(1) == True assert test_set.contains(4) == False assert test_set.length() == 3 test_set.remove(2) test_set.remove(3) assert test_set.contains(2) == False assert test_set.length() == 1 test_set.add(2) test_set.add(3) set_two = Set() set_two.add(2) set_two.add(6) set_two.add(7) set_two.add(1) set_two.add(0) set_two.add(3) assert set_two.intersect(test_set).contains(1) == True assert set_two.intersect(test_set).contains(7) == False assert test_set.is_subset(set_two) == True
def test_union(self): s = Set(['Sunny', 'Ouyang']) new_s = Set(['Stephen', 'Ouyeezy']) assert s.size() == 2 # assert s.set.items() == [('Ouyang', None), ('Sunny', None)] s = s.union(new_s) assert s.size() == 4
def test_intersect(self): s = Set(['Sunny', 'Ouyang']) assert s.size() == 2 new_s = Set(['Stephen', 'Ouyang']) s = s.intersect(new_s) assert s.size() == 1 assert s.set.items() == [('Ouyang', None)]
def test_intersection(self): # Typical test, should just have two elements test1 = Set([1, 2, 3, 4, 5]) test2 = Set([4, 5, 6, 7, 8]) result = test1.intersection(test2) assert result.contents() == [4, 5] assert test1.contents() == [1, 2, 3, 4, 5] # If same, just in case test1 = Set([1, 2, 3, 4, 5]) test2 = Set([1, 2, 3, 4, 5]) result = test1.intersection(test2) assert result.contents() == [1, 2, 3, 4, 5] # If none match test1 = Set([1, 2, 3, 4, 5]) test2 = Set([6, 7, 8, 9, 10]) result = test1.intersection(test2) assert result.contents() == [] # If both empty test1 = Set([]) test2 = Set([]) result = test1.intersection(test2) test1 = Set(['A', 'B', 'C', 'E']) test2 = Set(['A', 'B', 'C', 'D']) result = test1.intersection(test2) assert result.contains('A') is True assert result.contains('B') is True assert result.contains('C') is True assert result.contains('D') is False assert result.contains('E') is False
def test_difference(self): test_set_one = Set(['Apple','Banana','Cactus','Durian']) test_set_two = Set(['Apple','F','Cactus','H']) difference = test_set_one.difference(test_set_two) assert difference.size == 2 assert difference.contains('Banana') == True assert difference.contains('Durian') == True
def test_init(self): s1 = Set([], 20) assert s1.max_size == 20 assert s1.size == 0 s2 = Set(['cat', 'dog', 'fish']) assert s2.size == 3 assert s2.max_size == 19 # defaults to 3x starting items + 10
def test_difference_all_unique_elements(self): '''Test the Set.difference method.''' set_one = Set(self.one_two_three) set_two = Set(self.four_five_six) set_three = set_one.difference(set_two) assert set_three.size == 3 assert set_three.collection.keys() == self.one_two_three
def test_intersect(self): set_test_1 = Set(['a', 'b', 'c']) set_test_2 = Set(['c', 'd', 'e']) assert set_test_1.intersection(set_test_2).length() == 1 set_test_3 = Set(['a', 'b', 'c', 'd']) set_test_4 = Set(['e', 'f', 'g', 'h']) assert set_test_3.intersection(set_test_4).length() == 0
def test_difference(self): Instruct_Set = Set(["Adam", "Eliel", "Alan", "Mike", "Mitchell"]) DS1_Instruct_Set = Set(["Alan", "Mike"]) diffSet = DS1_Instruct_Set.difference(Instruct_Set) assert diffSet.contains(["Adam", "Eliel", "Mitchell"]) is True assert diffSet.contains(["Alan"]) is False assert diffSet.contains(["Mike"]) is False
def test_intersection(self): CS3_Set = Set(["James", "Tony", "Chris", "Sky", "Matthew"]) DS1_Set = Set(["James", "Matthew", "Tassos", "Sam", "Don"]) interSet = CS3_Set.intersection(DS1_Set) assert interSet.contains(["James", "Matthew"]) is True assert interSet.contains("Tony") is False assert interSet.contains("Sam") is False
def test_intersection_all_unique_elements(self): '''Test the Set.intersection method.''' set_one = Set(self.one_two_three) set_two = Set(self.four_five_six) set_three = set_one.intersection(set_two) assert set_three.size == 0 set_four = set_two.intersection(set_one) assert set_four.size == 0
def test_difference(self): set1 = Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) set2 = Set([11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1]) set3 = set1.diferrence(set2) assert set3.size == 10 assert set3.contains(11) is True assert set3.contains(15) is True assert set3.contains(100) is False
def test_intersection(self): set_a = Set([1, 3, 5, 7]) set_b = Set([2, 3, 4, 6, 7]) set_c = set_a.intersection_op(set_b) assert set_c.contains(1) == False assert set_c.contains(7) == True assert set_c.contains(3) == True assert set_c.contains(4) == False
def test_init(self): CS3_Set = Set(["James", "Tony", "Chris", "Sky", "Matthew"]) DS1_Set = Set(["James", "Matthew", "Tassos", "Sam", "Don"]) assert CS3_Set.contains("Tony") is True assert CS3_Set.contains("Jeff") is False assert DS1_Set.contains("Don") is True assert DS1_Set.contains("Sky") is False assert CS3_Set.size is 5
def test_init(self): s = Set() assert s.length() == 0 assert s.all_items() == [] sVal = Set([3, 4, 5]) assert sVal.length() == 3 assert sVal.all_items() == [3, 4, 5]
def test_union_one_empty_one_with_items(self): '''Test the Set.union method.''' set_one = Set() set_two = Set(self.one_two_three) set_three = set_one.union(set_two) assert set_three.size == 3 for element in self.one_two_three: assert set_three.contains(element) is True
def test_is_subset(self): test_set = Set(['A', 'B', 'C', 'D', 'E']) subset = Set(['B', 'C']) assert test_set.is_subset(subset) == True subset = Set([1, 2, 3]) assert test_set.is_subset(subset) == False subset = Set(['D', 'E']) assert test_set.is_subset(subset) == True
def test_remove(self): list = [1, 2, 3, 4, 5] set = Set(list) set.remove(2) set.remove(4) assert set == Set([1,3,5]) assert set.size == 3
def test_intersection(self): set1 = Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) set2 = Set([11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1]) set3 = set1.intersection(set2) assert set3.size == 1 assert set3.contains(1) is True assert set3.contains(15) is False assert set3.contains(100) is False
def test_intersection(self): test_set_one = Set(['Apple','Banana','Cactus','Durian']) test_set_two = Set(['Apple','Eggs','Cactus','F']) intersection_set = test_set_one.intersection(test_set_two) assert intersection_set.size == 2 assert intersection_set.contains('Apple') == True assert intersection_set.contains('Cactus') == True assert intersection_set.contains('F') == False
def __init__(self, name='Problem-Set', **kwargs): Set.__init__(self, name=name, **kwargs) return
def __init__(self, name, problems, measures): self.problems = problems self.measures = measures Set.__init__(self, name) return