Ejemplo n.º 1
0
 def test_delete(self):
     tree = TreeMap([(2, 'B'), (1, 'A'), (3, 'C')])
     tree.delete(2)
     assert not tree.contains(2)
     assert tree.contains(1)
     assert tree.contains(3)
     tree.delete(1)
     assert not tree.contains(1)
     assert tree.contains(3)
     tree.delete(3)
     assert tree.is_empty()
     assert not tree.contains(3)
Ejemplo n.º 2
0
 def test_delete(self):
     ht = TreeMap()
     ht.set('I', 1)
     ht.set('V', 5)
     ht.set('X', 10)
     assert ht.length() == 3
     assert ht.size == 3
     ht.delete('I')
     ht.delete('X')
     assert ht.length() == 1
     assert ht.size == 1
     with self.assertRaises(KeyError):
         ht.delete('X')  # Key no longer exists
     with self.assertRaises(KeyError):
         ht.delete('A')  # Key does not exist
Ejemplo n.º 3
0
 def test_delete(self):
     tm = TreeMap()
     assert tm.size == 0
     tm.set(1, 2)
     assert tm.size == 1
     tm.set(2, 3)
     assert tm.size == 2
     tm.set(3, 4)
     assert tm.size == 3
     self.assertCountEqual(tm.items(), [(1, 2), (2, 3), (3, 4)])
     tm.delete(3)
     assert tm.size == 2
     self.assertCountEqual(tm.items(), [(1, 2), (2, 3)])
     tm.delete(2)
     assert tm.size == 1
     tm.delete(1)
     assert tm.size == 0