Exemplo n.º 1
0
    def test_add_by_key_to_empty(self):
        """Test adding a single item to empty bimap by key."""
        bimap = BiMap()
        bimap.add_key(1, "first")

        self.assertEqual({1: "first"}, bimap.get_key_to_value())
        self.assertEqual(1, len(bimap))
        self.assertEqual("first", bimap.get_key(1))
        self.assertEqual(1, bimap.get_value("first"))
Exemplo n.º 2
0
    def test_add_to_nonempty(self):
        """Test adding a single item to nonempty bimap."""
        bimap = BiMap({1: "first", 2: "second"})
        bimap.add_key(3, "third")
        bimap.add_value("fourth", 4)

        self.assertEqual(4, len(bimap))
        self.assertEqual("second", bimap.get_key(2))
        self.assertEqual("fourth", bimap.get_key(4))
        self.assertEqual(3, bimap.get_value("third"))