def test_bijectivity(bi_cls, init_items): """b[k] == v <==> b.inv[v] == k""" some_bidict = bi_cls(init_items) ordered = isinstance(some_bidict, OrderedBidictBase) collection = list if ordered else set keys = collection(iterkeys(some_bidict)) vals = collection(itervalues(some_bidict)) fwd_by_keys = collection(some_bidict[k] for k in iterkeys(some_bidict)) inv_by_vals = collection(some_bidict.inv[v] for v in itervalues(some_bidict)) assert keys == inv_by_vals assert vals == fwd_by_keys inv = some_bidict.inv inv_keys = collection(iterkeys(inv)) inv_vals = collection(itervalues(inv)) inv_fwd_by_keys = collection(inv[k] for k in iterkeys(inv)) inv_inv_by_vals = collection(inv.inv[v] for v in itervalues(inv)) assert inv_keys == inv_inv_by_vals assert inv_vals == inv_fwd_by_keys
def test_bijectivity(bi_cls, init_items): """*b[k] == v <==> b.inv[v] == k*""" some_bidict = bi_cls(init_items) ordered = getattr(bi_cls, '__reversed__', None) canon = list if ordered else set keys = canon(iterkeys(some_bidict)) vals = canon(itervalues(some_bidict)) fwd_by_keys = canon(some_bidict[k] for k in iterkeys(some_bidict)) inv_by_vals = canon(some_bidict.inv[v] for v in itervalues(some_bidict)) assert keys == inv_by_vals assert vals == fwd_by_keys inv = some_bidict.inv inv_keys = canon(iterkeys(inv)) inv_vals = canon(itervalues(inv)) inv_fwd_by_keys = canon(inv[k] for k in iterkeys(inv)) inv_inv_by_vals = canon(inv.inv[v] for v in itervalues(inv)) assert inv_keys == inv_inv_by_vals assert inv_vals == inv_fwd_by_keys