def test_del_error(self): """ Test that remove raise KeyError """ with self.assertRaises(KeyError): self.bst.remove(3) size = 10 seq = utils.random_seq(size) utils.list_to_bst(seq, self.bst) with self.assertRaises(KeyError): self.bst.remove(-1) with self.assertRaises(KeyError): self.bst.remove(size + 1) self.assertTrue(utils.is_bst(self.bst.root))
def test_del_error(self): """ Test that remove raise KeyError """ with self.assertRaises(KeyError): self.bst.remove(3) seq = [1, 5, 2, 4, 3, 0, 9, 7, 8, 6] utils.list_to_bst(seq, self.bst) with self.assertRaises(KeyError): self.bst.remove(-1) with self.assertRaises(KeyError): self.bst.remove(len(seq)+1) self.assertTrue(utils.is_bst(self.bst.root))
def test_del(self): """ Test that remove maintain correct structure in tree """ seq = [1, 5, 2, 4, 3, 0, 9, 7, 8, 6] utils.list_to_bst(seq, self.bst) remove_seq = [5, 0, 2, 3, 4, 1, 6, 7, 8, 9] for k in remove_seq: v = seq.index(k) self.assertEqual(v, self.bst.remove(k)) with self.assertRaises(KeyError): self.bst.get(k) self.assertTrue(utils.is_bst(self.bst.root))
def test_del(self): """ Test that remove maintain correct structure in tree """ size = 10 seq = utils.random_seq(size) utils.list_to_bst(seq, self.bst) r_seq = utils.random_seq_from_list(seq) for k in r_seq: v = seq.index(k) self.assertEqual(v, self.bst.remove(k)) self.assertTrue(utils.is_bst(self.bst.root)) print('k: {}, v: {}'.format(k, v))
def test_insert(self): """ Test that insert creates binary search tree """ size = 100 seq = utils.random_seq(size) utils.list_to_bst(seq, self.bst) self.assertTrue(utils.is_bst(self.bst.root))
def test_insert(self): """ Test that insert creates binary search tree """ seq = [3, 8, 5, 6, 1, 0, 2, 4, 9, 7] utils.list_to_bst(seq, self.bst) self.assertTrue(utils.is_bst(self.bst.root))