from brik64 import mc, eva


def test_seq_pipeline():
    p = eva.seq(
        lambda pair: mc.add8(pair[0], pair[1]),
        lambda s: mc.mod8(s, 10),
    )
    assert p((7, 8)) == 5  # add8(7,8)=15 -> mod8(15,10)=5


def test_par_composition():
    dual = eva.par(mc.add8, mc.xor8)
    result = dual((10, 5), (0b1100, 0b1010))
    assert result == (15, 0b0110)


def test_cond_branching():
    transform = eva.cond(
        lambda x: x % 2 == 0,
        lambda x: x * 2,
        lambda x: x // 2,
    )
    assert transform(4) == 8
    assert transform(5) == 2


def test_pipeline_chain():
    result = eva.pipeline(5, [lambda x: x + 1, lambda x: x * 2, lambda x: x - 3])
    assert result == 9
