示例#1
0
    def test_delete_withNoneTypeArgumentKey_shouldRaiseValueError(self):
        bst = Treap()

        with self.assertRaises(ValueError):
            bst.delete(None)
        with self.assertRaises(ValueError):
            del bst[None]
示例#2
0
    def test_delete_withKeyNotInTree_shouldNotModifyTree(self):
        bst = Treap()
        for i in range(1, 20):
            bst.put(i, str(i))

        for i in range(20, 30):
            bst.delete(i)

            self.assertEqual(19, len(bst))
            for j in range(1, 20):
                self.assertIn(j, bst)
示例#3
0
    def test_delete_withKeyInTree_shouldDeleteKeyFromTree(self):
        bst = Treap()
        for i in range(1, 20):
            bst.put(i, str(i))

        for i in range(1, 20):
            bst.delete(i)

            self.assertEqual(19 - i, len(bst))
            self.assertNotIn(i, bst)
            for j in range(i + 1, 20):
                self.assertIn(j, bst)