def xor_buffers(left, right): """Xor two bytes-like objects, repeating the shorter as needed""" return bytes(xor_pairs(repeating_zip(left, right)))
def test_symmetrical(self, pairs): pairs = [pair for pair in pairs] flipped = [pair[::-1] for pair in pairs] assert list(bf.xor_pairs(pairs)) == list(bf.xor_pairs(flipped))
def test_empty(self): assert list(bf.xor_pairs([])) == []
def test_self_xor_yields_zero(self, ints): length = len(ints) pairs = [(el, el) for el in ints] result = list(bf.xor_pairs(pairs)) should_be = [0] * length assert result == should_be
def test_length_preserved(self, pairs): list_ = list(pairs) assert len(list_) == len(list(bf.xor_pairs(list_)))
def test_known_values(self): pairs = [(1, 1), (7, 0), (3, 1), (512, 1), (-1, 3), (-7, 6)] result = list(bf.xor_pairs(pairs)) assert result == [0, 7, 2, 513, -4, -1]
def test_not_pairs(self): with pytest.raises(TypeError): list(bf.xor_pairs(iter([1, 2, 3])))
def test_not_xorable(self): with pytest.raises(TypeError): list(bf.xor_pairs([(1, "bla"), (2, "blo"), (3, "bli")]))