def test_uniqueness(self): s = SingleLinkedSet() for _ in range(100): # as we didn't do random.seed, this test is easy to reproduce. s.add(random.randint(0, 5)) # as list does not have any public methods to inspect it's size, # we will use `get_n_th_node`. self.assertRaises(InvalidPositionError, s._container.get_n_th_node, 7)
def test_main_features(self): s = SingleLinkedSet() self.assertFalse(s.contains(1)) s = SingleLinkedSet([1, 1, 1, 1, 1]) self.assertTrue(s.contains(1)) self.assertFalse(s.contains(2)) s = SingleLinkedSet() s.add(2) self.assertTrue(s.contains(2)) self.assertFalse(s.contains(1)) s.add(1) self.assertTrue(s.contains(1)) self.assertTrue(s.contains(2))