def test_put_same_key_multiple_times(self): t = LinearProbingHashTable() t.put(3, "three") t.put(5, 6) t.put(3, 3) t.put(3, "three") self.assertEqual(t.size, 2) self.assertEqual(t.get(3), "three")
def test_get_all(self): t = LinearProbingHashTable() ls = gen_rand_list_of_distinct_ascii_and_numbers() for elem in ls: t.put(elem, 13) for elem in reversed(ls): self.assertEqual(t.get(elem), 13)
def test_put_n_distinct_keys_equal_values(self): t = LinearProbingHashTable() n = randint(2, 1000) population = sample(range(n), n) for elem in population: t.put(elem, elem) self.assertEqual(t.size, n) for elem in population: self.assertIsNotNone(t.get(elem))
def test_put_n_distinct_keys_all_values_different(self): """Testing that the same elements inserted multiple times in the same order, but always with different values associated with them.""" t = LinearProbingHashTable() ls = gen_rand_list_of_distinct_ascii_and_numbers() n = len(ls) for val, key in enumerate(ls): t.put(key, val) self.assertEqual(t.size, n) for elem in ls: self.assertIsNotNone(t.get(elem))
def test_put_key_not_None_value_not_None(self): t = LinearProbingHashTable() t.put(5, 19) self.assertTrue(t.size, 1) self.assertEqual(t.get(5), 19)
def test_put_key_not_None_value_None(self): t = LinearProbingHashTable() t.put(3, None) self.assertTrue(t.size, 1) self.assertIsNone(t.get(3))
def test_get_no_key_found(self): t = LinearProbingHashTable() t.put("three", 3) t["four"] = 4 self.assertIsNone(t.get("five"))
def test_get_empty_table(self): t = LinearProbingHashTable() self.assertIsNone(t.get(3))