def test_add(self): hs = HashSet([1, 3, 5, 7]) # size 4 assert hs.contains(23) == False hs.add(23) #size 5 assert hs.contains(23) == True hs.add(2) #size 6 assert hs.size == 6
def test_init_with_list(self): data = [8, 5, 1] hs = HashSet(data) assert hs.size == 3 assert hs.contains(8) == True assert hs.contains(5) == True assert hs.contains(1) == True
def test_contains(self): elements = [2, 4, 6, 8] hs = HashSet(elements) assert hs.contains(2) is True assert hs.contains(4) is True assert hs.contains(8) is True assert hs.contains(20) is False
def test_contains(self): new_set = HashSet(['This', 'is', 'my', 'set']) assert new_set.contains('This') == True assert new_set.contains('my') == True assert new_set.contains('set') == True assert new_set.contains('Willowwww') == False assert new_set.contains('your') == False
def test_remove(self): elements = ["hola", "adios", "test", "test", "annie"] hs = HashSet(elements) assert hs.contains("annie") == True hs.remove("annie") assert hs.contains("annie") == False with self.assertRaises(ValueError): hs.remove("pamis") # Element does not exist
def test_add(self): elements = ["hola", "adios", "test", "test"] hs = HashSet(elements) hs.add("annie") assert hs.size == 4 assert hs.contains("annie") == True hs.add("hola") assert hs.size == 4 assert hs.contains("hola") == True
def test_add_and_contains(self): hs = HashSet() hs.add('I') hs.add('V') hs.add('X') assert hs.contains('I') is True assert hs.contains('V') is True assert hs.contains('X') is True assert hs.size == 3
def test_contains(self): hs = HashSet() hs.add('I') hs.add('V') hs.add('X') assert hs.contains('I') is True assert hs.contains('V') is True assert hs.contains('X') is True assert hs.contains('A') is False
def test_contains(self): hs = HashSet() hs.add(0) hs.add(1) hs.add('zero') hs.add('one') assert hs.contains(0) is True assert hs.contains('zero') is True assert hs.contains('0') is False assert hs.contains(2) is False
def test_remove(self): new_set = HashSet(['red', 'brown', 'gray']) assert new_set.__length__() == 3 new_set.remove('brown') assert new_set.__length__() == 2 assert new_set.contains('brown') == False assert new_set.contains('red') == True assert new_set.contains('gray') == True new_set.remove('gray') assert new_set.__length__() == 1 assert new_set.contains('red') == True assert new_set.contains('gray') == False
def test_contains(self): """Check to see if the contains method works as intended.""" hashset = HashSet() hashset.add('Hello') hashset.add('are') hashset.add('you') hashset.add('a') hashset.add('hashset') assert hashset.contains('Hello') is True assert hashset.contains('no') is False assert hashset.contains('you') is True assert hashset.contains('are') is True
def test_add_twice_and_contains(self): hs = HashSet() hs.add('I') hs.add('V') hs.add('X') assert hs.size == 3 hs.add('V') # Update value hs.add('X') # Update value assert hs.contains('I') is True assert hs.contains('V') is True assert hs.contains('X') is True assert hs.size == 3 # Check size is not overcounting
def test_add(self): new_set = HashSet() assert new_set.__length__() == 0 new_set.add('red') new_set.add('brown') new_set.add('gray') assert new_set.__length__() == 3 assert new_set.contains('red') == True assert new_set.contains('brown') == True assert new_set.contains('purple') == False new_set.add('orange') new_set.add('purple') assert new_set.__length__() == 5 assert new_set.contains('purple') == True
def test_union(self): data_a = ['A', 'B', 'C'] hs_a = HashSet(data_a) data_b = ['D', 'E', 'F'] hs_b = HashSet(data_b) union_hs = hs_a.union(hs_b) assert union_hs.contains('A') == True assert union_hs.contains('B') == True assert union_hs.contains('C') == True assert union_hs.contains('D') == True assert union_hs.contains('E') == True assert union_hs.contains('F') == True assert hs_a.contains('D') == False assert hs_a.contains('E') == False assert hs_a.contains('F') == False
def test_remove(self): hs = HashSet() hs.add('A') hs.add('B') hs.add('C') hs.remove('A') assert hs.contains('A') == False assert hs.size == 2 hs.remove('C') assert hs.contains('C') == False assert hs.size == 1 hs.remove('B') assert hs.contains('B') == False assert hs.size == 0 with self.assertRaises(ValueError): hs.remove('D') # Key never existed hs.remove('A') # Key no longer exists
def test_add_and_remove(self): elements = [1, 2, 3] hs = HashSet(elements) hs.add(4) hs.add(5) hs.add(6) hs.add(7) assert hs.contains(2) is True assert hs.contains(4) is True assert hs.contains(5) is True assert hs.contains(6) is True assert hs.contains(7) is True assert hs.contains(21) is False hs.remove(7) assert hs.contains(7) is False hs.remove(6) assert hs.contains(6) is False hs.remove(5) assert hs.contains(5) is False hs.remove(4) assert hs.contains(4) is False assert hs.size() == 3
def test_add_remove(self): set = HashSet() set.add('A') assert len(set) == 1 assert set.contains('A') is True set.add('B') assert len(set) == 2 assert set.contains('B') is True set.add('C') assert len(set) == 3 assert set.contains('C') is True set.remove('B') assert len(set) == 2 assert set.contains('B') is False set.remove('A') assert len(set) == 1 assert set.contains('A') is False set.remove('C') assert len(set) == 0 assert set.contains('C') is False with self.assertRaises(ValueError): set.remove('C')
def d_test_contains(self): hs = HashSet(["A", "B", "XYZ", "4"]) assert hs.contains("B") == True assert hs.contains("XYZ4") == False assert hs.contains("") == False
def test_init(self): set = HashSet(['A', 'B', 'C']) assert len(set) == 3 assert set.contains('A') is True assert set.contains('B') is True assert set.contains('C') is True
def test_contains(self): hs = HashSet() assert hs.contains('') == False hs = HashSet('A', 'B', 'C') assert hs.contains('A') == True