Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
 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")
Ejemplo n.º 3
0
    def test_delete_all(self):
        t = LinearProbingHashTable()
        ls = gen_rand_list_of_distinct_ascii_and_numbers()
        for elem in ls:
            t.put(elem, elem)

        self.assertEqual(t.size, len(ls))

        for key in ls:
            self.assertEqual(t.delete(key), key)

        self.assertEqual(t.size, 0)
Ejemplo n.º 4
0
    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))
Ejemplo n.º 5
0
    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))
Ejemplo n.º 6
0
 def test_show(self):
     t = LinearProbingHashTable()
     ls = sample(range(3), 3)
     for elem in ls:
         t.put(elem, choice(string.ascii_letters))
     print()
     t.show()
Ejemplo n.º 7
0
    def test_delete_some(self):
        t = LinearProbingHashTable()
        ls = [(1, 3), (5, "two"), (2.72, 10), ("one", 3.14), (1, "seven")]

        for k, v in ls:
            t.put(k, v)

        self.assertEqual(t.size, 4)
        self.assertEqual(t.delete(1), "seven")
        self.assertEqual(t.delete(2.72), 10)
        self.assertEqual(t.size, 2)
Ejemplo n.º 8
0
 def test_get_no_key_found(self):
     t = LinearProbingHashTable()
     t.put("three", 3)
     t["four"] = 4
     self.assertIsNone(t.get("five"))
Ejemplo n.º 9
0
 def test_delete_empty_table(self):
     t = LinearProbingHashTable()
     self.assertIsNone(t.delete(3))
Ejemplo n.º 10
0
 def test_delete_key_not_present(self):
     t = LinearProbingHashTable()
     t.put(-10, "testing deletion when key not in the table")
     self.assertIsNone(t.delete(7))
Ejemplo n.º 11
0
 def test_get_with_syntactic_sugar(self):
     t = LinearProbingHashTable()
     t.put(5, 12)
     self.assertEqual(t[5], 12)
Ejemplo n.º 12
0
 def test_delete_non_hashable_type(self):
     t = LinearProbingHashTable()
     self.assertRaises(TypeError, t.delete, [])
     self.assertRaises(TypeError, t.delete, {})
Ejemplo n.º 13
0
 def test_get_key_None(self):
     t = LinearProbingHashTable()
     self.assertRaises(TypeError, t.get, None)
Ejemplo n.º 14
0
 def test_create_set_initial_capacity(self):
     t = LinearProbingHashTable(9)
     self.assertEqual(t.capacity, 9)
     self.assertEqual(t.size, 0)
Ejemplo n.º 15
0
 def test_put_non_hashable_type(self):
     t = LinearProbingHashTable()
     self.assertRaises(TypeError, t.put, [], 12)
     self.assertRaises(TypeError, t.put, {}, None)
Ejemplo n.º 16
0
 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)
Ejemplo n.º 17
0
 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))
Ejemplo n.º 18
0
 def test_create_capacity_int(self):
     t = LinearProbingHashTable()
     self.assertEqual(t.size, 0)
Ejemplo n.º 19
0
 def test_delete_key_None(self):
     t = LinearProbingHashTable()
     self.assertRaises(TypeError, t.delete, None)
Ejemplo n.º 20
0
 def test_get_non_hashable_type(self):
     t = LinearProbingHashTable()
     t.put(23, 31)
     t.put(11, 13)
     self.assertRaises(TypeError, t.get, [])
     self.assertRaises(TypeError, t.get, {})
Ejemplo n.º 21
0
 def test_get_empty_table(self):
     t = LinearProbingHashTable()
     self.assertIsNone(t.get(3))