def test_set(self):
     treemap = TreeMap()
     treemap.set('A', 3)
     assert treemap.size == 1
     assert treemap.get('A') == 3
     treemap.set('A', 3)
     assert treemap.size == 1
Beispiel #2
0
 def test_contains(self):
     ht = TreeMap()
     ht.set('I', 1)
     ht.set('V', 5)
     ht.set('X', 10)
     assert ht.contains('I') is True
     assert ht.contains('V') is True
     assert ht.contains('X') is True
     assert ht.contains('A') is False
Beispiel #3
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
Beispiel #4
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
Beispiel #5
0
 def test_set(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.set(3, 5)
     assert tm.size == 3
     self.assertCountEqual(tm.items(), [(1, 2), (2, 3), (3, 5)])
Beispiel #6
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
Beispiel #7
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
Beispiel #8
0
 def test_items(self):
     ht = TreeMap()
     assert ht.items() == []
     ht.set('I', 1)
     assert ht.items() == [('I', 1)]
     ht.set('V', 5)
     self.assertCountEqual(ht.items(), [('I', 1), ('V', 5)])
     ht.set('X', 10)
     self.assertCountEqual(ht.items(), [('I', 1), ('V', 5), ('X', 10)])
Beispiel #9
0
 def test_values(self):
     ht = TreeMap()
     assert ht.values() == []
     ht.set('I', 1)
     assert ht.values() == [1]
     ht.set('V', 5)
     self.assertCountEqual(ht.values(), [1, 5])  # Ignore item order
     ht.set('X', 10)
     self.assertCountEqual(ht.values(), [1, 5, 10])  # Ignore item order
Beispiel #10
0
 def test_keys(self):
     ht = TreeMap()
     assert ht.keys() == []
     ht.set('I', 1)
     assert ht.keys() == ['I']
     ht.set('V', 5)
     self.assertCountEqual(ht.keys(), ['I', 'V'])  # Ignore item order
     ht.set('X', 10)
     self.assertCountEqual(ht.keys(), ['I', 'V', 'X'])  # Ignore item order
Beispiel #11
0
 def test_size(self):
     ht = TreeMap()
     assert ht.size == 0
     ht.set('I', 1)
     assert ht.size == 1
     ht.set('V', 5)
     assert ht.size == 2
     ht.set('X', 10)
     assert ht.size == 3
Beispiel #12
0
 def test_size(self):
     tree = TreeMap()
     assert tree.size == 0
     tree.set('B')
     assert tree.size == 1
     tree.set('A')
     assert tree.size == 2
     tree.set('C')
     assert tree.size == 3
Beispiel #13
0
 def test_set(self):
     tree = TreeMap()
     tree.set(2, 'B')
     assert tree.contains(2)
     assert tree.get(2) == 'B'
     tree.set(1, 'A')
     assert tree.contains(1)
     assert tree.get(1) == 'A'
     tree.set(3, 'C')
     assert tree.contains(3)
     assert tree.get(3) == 'C'
Beispiel #14
0
 def test_resize(self):
     ht = TreeMap(2)  # Set init_size to 2
     assert ht.size == 0
     assert len(ht.buckets) == 2
     assert ht.load_factor() == 0
     ht.set('I', 1)
     assert ht.size == 1
     assert len(ht.buckets) == 2
     assert ht.load_factor() == 0.5
     ht.set('V', 5)  # Should trigger resize
     assert ht.size == 2
     assert len(ht.buckets) == 4
     assert ht.load_factor() == 0.5
     ht.set('X', 10)
     assert ht.size == 3
     assert len(ht.buckets) == 4
     assert ht.load_factor() == 0.75
     ht.set('L', 50)  # Should trigger resize
     assert ht.size == 4
     assert len(ht.buckets) == 8
     assert ht.load_factor() == 0.5
Beispiel #15
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
Beispiel #16
0
    def test_set(self):

        treepMap = TreeMap()

        assert treepMap.set('Medi', 123) == False
 def test_contains(self):
     treemap = TreeMap()
     treemap.set('A', 3)
     assert treemap.contains('A')
     assert treemap.contains('B') is False