Example #1
0
 def test_insert_check_iterator(self):
     treap = Treap()
     treap.insert("a", 1, 2)
     treap.insert("d", 3, 4)
     treap.insert("b", 2, 10)
     treap.insert("c", 2, 1)
     return self.assertEqual(list(iter(treap)), ["a", "b", "c", "d"])
Example #2
0
 def test_set_check_iterator(self):
     treap = Treap()
     treap[2.0] = "a"
     treap[10.9] = 3.3
     treap[2.5] = 100
     treap[8.9] = True
     return self.assertEqual(list(iter(treap)), [2.0, 2.5, 8.9, 10.9])
Example #3
0
 def test_update_value(self):
     treap = Treap()
     treap["1"] = "a"
     treap["2"] = "b"
     treap["3"] = "c"
     treap["2"] = "updated"
     return self.assertEqual(treap["2"], "updated")
Example #4
0
    def test_delete_no_key_in_treap(self):
        treap = Treap()
        treap[202] = "a"
        treap[303] = "b"

        with self.assertRaises(KeyError) as context:
            del treap[0]
        self.assertTrue(check_error_message(context, get_message_about_key_absence(0)))
Example #5
0
    def test_get_no_key_in_treap(self):
        treap = Treap()
        treap[-100] = 100
        treap[100] = -100

        with self.assertRaises(KeyError) as context:
            treap[101]

        self.assertTrue(check_error_message(context, get_message_about_key_absence(101)))
Example #6
0
 def test_insert_and_delete(self):
     treap = Treap()
     treap[100] = "a"
     del treap[100]
     treap[150] = "b"
     treap[-10] = "c"
     del treap[150]
     treap[200] = "d"
     del treap[-10]
     del treap[200]
     return self.assertEqual(len(treap), 0)
Example #7
0
 def test_set_check_get(self):
     treap = Treap()
     treap[100] = "a"
     treap[150] = "b"
     treap[-10] = "c"
     return self.assertEqual(treap[150], "b")
Example #8
0
 def test_contains_no_key_in_treap(self):
     treap = Treap()
     treap[100] = "a"
     treap[30] = "b"
     treap[20] = "c"
     return self.assertNotIn(-1, treap)
Example #9
0
 def test_contains(self):
     treap = Treap()
     treap[100] = "a"
     treap[150] = "b"
     treap[-10] = "c"
     return self.assertIn(-10, treap)
Example #10
0
def get_big_treap():
    treap = Treap()
    keys = set([random.randint(0, 1000) for _ in range(500)])
    for key in keys:
        treap[key] = f"{key}"
    return treap, keys
Example #11
0
 def test_reversed_iterator(self):
     self.assertEqual(list(reversed(Treap())), [])
Example #12
0
 def test_iterator(self):
     self.assertEqual(list(iter(Treap())), [])
Example #13
0
    def test_get(self):
        treap = Treap()
        with self.assertRaises(KeyError) as context:
            treap[100]

        self.assertTrue(check_error_message(context, TREAP_IS_EMPTY_ERROR_MESSAGE))
Example #14
0
 def test_insert(self):
     treap = Treap()
     treap[100] = "100"
     return self.assertTrue(100 in treap)
Example #15
0
 def test_length(self):
     return self.assertEqual(len(Treap()), 0)
Example #16
0
 def test_delete(self):
     treap = Treap()
     treap["b"] = 1
     treap["a"] = 404
     del treap["b"]
     return self.assertNotIn("b", treap)