def testWildDict2(self): Trace("testWildDict1","TestEventPubSub") # Create and test dictionary wd = WildDict() kvs = [("a","A1"), ("a","A2"), ("b","B1"), ("b","B2"), (None,"N1"), (None,"N2")] for (k,v) in kvs: wd.insert(k,v) self.assertEqual(list(wd.iterateAll()), kvs) self.assertEqual(wd.count(), 6) # Now test iterateWild functions self.assertEqual(list(wd.iterateWild(None)), kvs) self.assertEqual(list(wd.iterateWild("a")), [("a","A1"), ("a","A2"), (None,"N1"), (None,"N2")]) self.assertEqual(list(wd.iterateWild("b")), [("b","B1"), ("b","B2"), (None,"N1"), (None,"N2")]) self.assertEqual(list(wd.iterateWild("c")), [(None,"N1"), (None,"N2")]) return
def testWildDict1(self): Trace("testWildDict1","TestEventPubSub") wd = WildDict() # Basic insertion tests self.assertEqual(wd.find("a"), []) self.assertEqual(wd.find("b"), []) wd.insert("a","A1") wd.insert(None,"N1") self.assertEqual(wd.find("a"), ["A1","N1"]) self.assertEqual(wd.find("b"), ["N1"]) wd.insert("a","A2") wd.insert("b","B1") wd.insert("b","B2") wd.insert(None,"N2") self.assertEqual(wd.find("a"), ["A1","A2","N1","N2"]) self.assertEqual(wd.find("b"), ["B1","B2","N1","N2"]) # Scan contents kvs = [("a","A1"), ("a","A2"), ("b","B1"), ("b","B2"), (None,"N1"), (None,"N2")] self.assertEqual(list(wd.iterateAll()), kvs) self.assertEqual(wd.count(), 6) # Basic removal tests b1 = wd.remove("b","B1") self.assertEqual(b1, ["B1"]) self.assertEqual(wd.find("b"), ["B2","N1","N2"]) b2 = wd.remove("b","B2") self.assertEqual(b2, ["B2"]) self.assertEqual(wd.find("b"), ["N1","N2"]) n2 = wd.remove(None,"N2") self.assertEqual(n2, ["N2"]) self.assertEqual(wd.find("a"), ["A1","A2","N1"]) self.assertEqual(wd.find("b"), ["N1"]) n1 = wd.remove(None,"N1") self.assertEqual(n1, ["N1"]) self.assertEqual(wd.find("a"), ["A1","A2"]) self.assertEqual(wd.find("b"), []) # Multiple-value insertion tests wd.insert("c","C") wd.insert(None,"N") wd.insert("c","C") wd.insert(None,"N") self.assertEqual(wd.find("c"), ["C","C","N","N"]) # Multiple-value removal tests el = wd.remove("c","C1") self.assertEqual(el, []) self.assertEqual(wd.find("c"), ["C","C","N","N"]) cc = wd.remove("c","C") self.assertEqual(cc, ["C","C"]) self.assertEqual(wd.find("c"), ["N","N"]) el = wd.remove("c","C") self.assertEqual(el, []) self.assertEqual(wd.find("c"), ["N","N"]) el = wd.remove(None,"C") self.assertEqual(el, []) self.assertEqual(wd.find("c"), ["N","N"]) nn = wd.remove(None,"N") self.assertEqual(nn, ["N","N"]) self.assertEqual(wd.find("c"), []) el = wd.remove(None,"N") self.assertEqual(el, []) self.assertEqual(wd.find("a"), ["A1","A2"]) self.assertEqual(wd.find("b"), []) self.assertEqual(wd.find("c"), []) return