def test_multimap_remove(self): temp = util.MultiMap({'a': 1, 'b': 2, 'c': 1}) temp['c'].add(2) temp['c'].remove(1) temp_inv = temp.inverse() self.assertIn(2, temp_inv) self.assertCountEqual(temp_inv[2], set(['b', 'c'])) self.assertIn(1, temp_inv) self.assertCountEqual(temp_inv[1], set(['a']))
def test_multimap_add(self): temp = util.MultiMap({'a': 1, 'b': 2, 'c': 1}) temp['a'].add(3) temp_inv = temp.inverse() self.assertIn(3, temp_inv) self.assertCountEqual(temp_inv[3], set(['a'])) temp['a'].add(2) temp_inv = temp.inverse() self.assertIn(2, temp_inv) self.assertCountEqual(temp_inv[2], set(['a', 'b']))
def test_multimap_setitem(self): # test key addition and handling of duplicate values temp = util.MultiMap({'a': 1, 'b': 2}) temp['c'] = 1 temp_inv = temp.inverse() self.assertIn(1, temp_inv) self.assertCountEqual(temp_inv[1], set(['a', 'c'])) temp['b'] = 3 temp_inv = temp.inverse() self.assertNotIn(2, temp_inv)
def test_multimap_delitem(self): # test item deletion temp = util.MultiMap({'a': 1, 'b': 2}) del temp['b'] temp_inv = temp.inverse() self.assertNotIn(2, temp_inv)
def test_multimap_inverse(self): # test inverse map temp = util.MultiMap({'a': 1, 'b': 2}) temp_inv = temp.inverse() self.assertIn(1, temp_inv) self.assertEqual(temp_inv[2], set(['b']))