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
def test_initialization(self): empty = TreeMap() self.assertEqual([], list(empty.keys())) non_empty = TreeMap({5: "a", 4: "b", 3: "c"}) self.assertSequenceEqual([3, 4, 5], list(non_empty.keys()))
def test_clear(self): tm = TreeMap({"key": "Value"}) tm.clear() self.assertSequenceEqual([], list(tm.keys()))
def test_remove_item(self): tm = TreeMap({"c": "C", "b": "B", "a": "A"}) del tm["b"] self.assertSequenceEqual(["a", "c"], list(tm.keys()))
def test_add_item(self): tm = TreeMap() tm["b"] = "B" tm["a"] = "A" self.assertSequenceEqual(["a", "b"], list(tm.keys()))
def test_keys(self): tree = TreeMap([(2, 'B'), (1, 'A'), (3, 'C')]) assert tree.keys() == [1,2,3] tree = TreeMap([('B', 2), ('A', 1), ('C', 3)]) assert tree.keys() == ['A', 'B', 'C']