def test_difference(self): set_one = HashSet(["A", "B", "C"]) set_two = HashSet(["C", "D", "E"]) set_three = set_one.difference(set_two) assert set_three.size == 4
def test_union(self): set_one = HashSet(["A", "B", "C"]) set_two = HashSet(["C", "D", "E"]) set_three = set_one.union(set_two) assert set_three.size == 5
def test_contains(self): elements = ['P', 'C', 'X', 'U'] set = HashSet(elements) assert set.contains('P') is True assert set.contains('C') is True assert set.contains('U') is True assert set.contains('D') is False assert set.contains('J') is False
def test_contains(self): elements = ['K', 'Q', 'J', 'O'] set = HashSet(elements) assert set.contains('K') is True assert set.contains('J') is True assert set.contains('Q') is True assert set.contains('C') is False assert set.contains('W') is False
def test_intersection(self): set_one = HashSet(["A", "B", "C"]) set_two = HashSet(["C", "D", "E"]) set_three = set_one.intersection(set_two) assert set_three.contains("C") == True assert set_three.size == 1
def test_add(self): set = HashSet() set.add('After the darkness') assert set.size == 1 # added one element set.add('Dertogada') assert set.size == 2 # added a second element set.add('Ramatohara') assert set.size == 3 # added a thrid element set.add('Ramatohara') assert set.size == 3 # element already exist, no size change
def test_is_subset(self): set_one = HashSet(["A", "B", "C"]) set_two = HashSet(["C", "D", "E"]) assert set_one.is_subset(set_two) == False assert set_one.is_subset(HashSet(["A", "B", "C"])) == True assert set_one.is_subset(HashSet(["A", "B", "C", "D"])) == True
def test_add(self): elements = ['J', 'K'] set = HashSet(elements) set.add('P') set.add('E') with self.assertRaises(KeyError): set.add('K') # Element already exists with self.assertRaises(KeyError): set.add('E') # Element already exists assert set.size is 4 assert set.contains('P') is True assert set.contains('E') is True
def test_remove(self): # Double check set = HashSet(['Talent code', 'Outliers', 'Talking to strangers']) assert set.size == 3 #started with 3 elements set.remove('Talent code') assert set.size == 2 #one element is removed set.remove('Outliers') assert set.size == 1 #second element removed set.remove('Talking to strangers') assert set.size == 0 #third element removed
def test_is_subset(self): elements = ['A', 'G', 'R'] elements2 = ['G', 'D', 'R', 'P', 'A', 'W'] elements3 = ['I', 'O', 'S', 'K', 'M', 'Z'] set1 = HashSet(elements) set2 = HashSet(elements2) set3 = HashSet(elements3) assert set1.is_subset(set2) is True assert set1.is_subset(set3) is False assert set2.is_subset(set3) is False
def test_is_subset(self): elements = ['Y', 'C', 'D'] elements2 = ['C', 'G', 'U', 'D', 'T', 'Y'] elements3 = ['P', 'H', 'Y', 'D', 'E', 'F'] set = HashSet(elements) set2 = HashSet(elements2) set3 = HashSet(elements3) assert set.is_subset(set2) is True assert set.is_subset(set3) is False assert set2.is_subset(set3) is False
def test_difference(self): elements = ['4', '7', '8', '9', '0'] elements2 = ['4', '5', '6', '10', '8', '9'] elements3 = ['1', '3', '5', '7', '0'] set = HashSet(elements) set2 = HashSet(elements2) set3 = HashSet(elements3) self.assertCountEqual(set.difference(set2).hash.values(), ['7', '0']) # Ignore item order self.assertCountEqual( set.difference(set3).hash.values(), ['4', '8', '9']) # Ignore item order
def test_difference(self): elements = ['5', '6', '8', '10', '1'] elements2 = ['1', '5', '6', '7', '2', '9'] elements3 = ['2', '4', '6', '9', '10'] set1 = HashSet(elements) set2 = HashSet(elements2) set3 = HashSet(elements3) self.assertCountEqual( set1.difference(set2).hash.values(), ['8', '10']) # Item order does not matter self.assertCountEqual( set1.difference(set3).hash.values(), ['5', '8', '1']) # Item order does not matter
def test_intersection(self): elements = ['2', 'A', 'B', 'C'] elements2 = ['0', 'A', 'C', 'E', 'X', '2'] elements3 = ['B', 'J', 'L', 'K', 'C', '2'] set1 = HashSet(elements) set2 = HashSet(elements2) set3 = HashSet(elements3) self.assertCountEqual( set1.intersection(set2).hash.values(), ['A', 'C', '2']) # Item order does not matter self.assertCountEqual( set1.intersection(set3).hash.values(), ['B', 'C', '2']) # Item order does not matter
def test_intersection(self): elements = ['0', 'B', 'C', 'K'] elements2 = ['0', 'D', 'E', 'C', 'Y', 'K'] elements3 = ['B', 'D', 'P', 'K', 'G', '9'] set = HashSet(elements) set2 = HashSet(elements2) set3 = HashSet(elements3) self.assertCountEqual( set.intersection(set2).hash.values(), ['0', 'C', 'K']) # Ignore item order self.assertCountEqual( set.intersection(set3).hash.values(), ['B', 'K']) # Ignore item order
def test_union(self): elements = ['A', 'C', 'D', 'F'] elements2 = ['A', 'B', 'D', 'F', 'G', 'H'] elements3 = ['C', 'Y', 'T', 'A'] set = HashSet(elements) set2 = HashSet(elements2) set3 = HashSet(elements3) self.assertCountEqual( set.union(set2).hash.values(), ['A', 'B', 'C', 'D', 'F', 'G', 'H']) # Ignore item order self.assertCountEqual( set.union(set3).hash.values(), ['A', 'C', 'D', 'F', 'T', 'Y']) # Ignore item order
def test_union(self): elements = ['W', 'X', 'Y', 'Z'] elements2 = ['A', 'B', 'D', 'E', 'G', 'I'] elements3 = ['C', 'V', 'M', 'N'] set1 = HashSet(elements) set2 = HashSet(elements2) set3 = HashSet(elements3) self.assertCountEqual( set1.union(set2).hash.values(), ['A', 'B', 'D', 'E', 'G', 'I', 'W', 'X', 'Y', 'Z' ]) # Item order does not matter self.assertCountEqual( set1.union(set3).hash.values(), ['C', 'M', 'N', 'V', 'W', 'X', 'Y', 'Z' ]) # Item order does not matter
def test_contains(self): h = HashSet() h.add("Mondale") assert h.contains("Mondale") == True assert h.contains("Alfred") == False
def test_init(self): elements = ['A', 'B', 'C'] set = HashSet(elements) assert set.size is 3
def test_remove(self): elements = ['U', '8', 'Q', 'D'] set = HashSet(elements) with self.assertRaises(KeyError): set.remove('K') # Element doesn't exist with self.assertRaises(KeyError): set.remove('0') # Element doesn't exist set.remove('U') set.remove('Q') assert set.contains('U') is False assert set.contains('Q') is False with self.assertRaises(KeyError): set.remove('Q') # Element doesn't exist anymore
def test_init(self): set = HashSet() assert set.size == 0
def test_contains(self): set = HashSet(['Master of the Game', 'After the darkness']) assert set.contains('Master of the Game') == True assert set.contains('After the darkness') == True assert set.contains('Dertogada') == False
def test_size(self): elements = ['A', 'B', 'C', 'D', 'E'] set = HashSet(elements) assert set.size is 5
def test_difference(self): # two sets with one common element set = HashSet( ['Talent code', 'Outliers', 'Talking to strangers', 'Idea man']) other_set = HashSet( ['Beloved', 'Nightingale', 'Mistress of the game', 'Idea man']) assert set.difference(other_set).size == 3 # two sets with no common ele set = HashSet( ['Talent code', 'Outliers', 'Talking to strangers', 'Capital']) other_set = HashSet( ['Beloved', 'Nightingale', 'Mistress of the game', 'Idea man']) assert set.difference(other_set).size == 4 # two sets with the same element set = HashSet( ['Talent code', 'Outliers', 'Talking to strangers', 'Capital']) other_set = HashSet( ['Talent code', 'Outliers', 'Talking to strangers', 'Capital']) assert set.difference(other_set).size == 0
def test_init(self): data = ["Mondale", "is", "great"] h = HashSet(data) assert h.size == 3
def test_remove(self): elements = ['Z', 'I', 'Q', '4', 'S'] set = HashSet(elements) with self.assertRaises(KeyError): set.remove('A') # Element doesn not exist with self.assertRaises(KeyError): set.remove('X') # Element does not exist set.remove('Z') set.remove('4') assert set.contains('Z') is False assert set.contains('4') is False with self.assertRaises(KeyError): set.remove('Z') # Element does not exist anymore
def test_init(self): elements = ['1', '2', '3'] set = HashSet(elements) assert set.size is 3
def test_add(self): h = HashSet() assert h.size == 0 h.add("Mondale") assert h.size == 1
def test_remove(self): h = HashSet() h.add("Egg") h.add("Tuna") h.remove("Egg") assert h.size == 1
def test_is_subset(self): # two sets with one common element set = HashSet( ['Talent code', 'Outliers', 'Talking to strangers', 'Idea man']) other_set = HashSet( ['Beloved', 'Nightingale', 'Mistress of the game', 'Idea man']) assert set.is_subset( other_set) is False #all the ele in set are not in other_set # therefore expecting false # two sets with no common ele set = HashSet( ['Talent code', 'Outliers', 'Talking to strangers', 'Capital']) other_set = HashSet( ['Beloved', 'Nightingale', 'Mistress of the game', 'Idea man']) assert set.is_subset(other_set) is False # two sets with the same element set = HashSet( ['Talent code', 'Outliers', 'Talking to strangers', 'Capital']) other_set = HashSet( ['Talent code', 'Outliers', 'Talking to strangers', 'Capital']) assert set.is_subset(other_set) is True