Esempio n. 1
0
 def test_length(self):
     ht = TreeMap()
     assert ht.length() == 0
     ht.set('I', 1)
     assert ht.length() == 1
     ht.set('V', 5)
     assert ht.length() == 2
     ht.set('X', 10)
     assert ht.length() == 3
Esempio n. 2
0
 def test_set_twice_and_get(self):
     ht = TreeMap()
     ht.set('I', 1)
     ht.set('V', 4)
     ht.set('X', 9)
     assert ht.length() == 3
     assert ht.size == 3
     ht.set('V', 5)  # Update value
     ht.set('X', 10)  # Update value
     assert ht.get('I') == 1
     assert ht.get('V') == 5
     assert ht.get('X') == 10
     assert ht.length() == 3  # Check length is not overcounting
     assert ht.size == 3  # Check size is not overcounting
Esempio n. 3
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
Esempio n. 4
0
 def test_set_and_get(self):
     ht = TreeMap()
     ht.set('I', 1)
     ht.set('V', 5)
     ht.set('X', 10)
     assert ht.get('I') == 1
     assert ht.get('V') == 5
     assert ht.get('X') == 10
     assert ht.length() == 3
     assert ht.size == 3
     with self.assertRaises(KeyError):
         ht.get('A')  # Key does not exist
Esempio n. 5
0
 def test_init(self):
     ht = TreeMap(4)
     assert len(ht.buckets) == 4
     assert ht.length() == 0
     assert ht.size == 0