def test_orderedbidict_iter(ob_cls, init_items): """:meth:`bidict.OrderedBidictBase.__iter__` should yield all the keys in an ordered bidict in the order they were inserted. """ some_bidict = ob_cls(init_items) key_iters = (some_bidict, iterkeys(some_bidict), (KEY(pair) for pair in init_items)) assert all(i == j == k for (i, j, k) in izip(*key_iters))
def test_orderedbidict_reversed(ob_cls, init_items): """:meth:`bidict.OrderedBidictBase.__reversed__` should yield all the keys in an ordered bidict in the reverse-order they were inserted. """ some_bidict = ob_cls(init_items) key_seqs = (some_bidict, list(iterkeys(some_bidict)), [KEY(pair) for pair in init_items]) key_seqs_rev = (reversed(i) for i in key_seqs) assert all(i == j == k for (i, j, k) in izip(*key_seqs_rev))
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
def test_orderedbidict_reversed(bi_cls, init_items): """:meth:`bidict.OrderedBidictBase.__reversed__` should yield all the keys in an ordered bidict in the reverse-order they were inserted. """ some_bidict = bi_cls(init_items) assert all(i == j == k for ( i, j, k) in zip(reversed(some_bidict), reversed(list(iterkeys(some_bidict))), reversed(list(KEY(pair) for pair in init_items))))
def test_bidict_iter(bi_cls, init_items): """:meth:`bidict.BidictBase.__iter__` should yield all the keys in a bidict.""" some_bidict = bi_cls(init_items) assert set(some_bidict) == set(iterkeys(some_bidict)) == set( KEY(pair) for pair in init_items)
def test_orderedbidict_reversed(bi_cls, init_items): """Ensure :meth:`bidict.OrderedBidictBase.__reversed__` works correctly.""" some_bidict = bi_cls(init_items) assert all(i == j for (i, j) in izip(reversed(some_bidict), list(iterkeys(some_bidict))[::-1]))
def test_orderedbidict_iter(bi_cls, init_items): """Ensure :meth:`bidict.OrderedBidictBase.__iter__` works correctly.""" some_bidict = bi_cls(init_items) assert all(i == j for (i, j) in izip(some_bidict, iterkeys(some_bidict)))
def test_bidict_iter(bi_cls, init_items): """Ensure :meth:`bidict.BidictBase.__iter__` works correctly.""" some_bidict = bi_cls(init_items) assert set(some_bidict) == set(iterkeys(some_bidict))