from brik64 import mc


def test_add8_saturates():
    assert mc.add8(200, 100) == 255
    assert mc.add8(10, 20) == 30


def test_sub8_saturates():
    assert mc.sub8(5, 10) == 0
    assert mc.sub8(20, 5) == 15


def test_div8_safe():
    assert mc.div8(17, 5) == (3, 2)
    assert mc.div8(10, 0) == (0, 0)


def test_clamp():
    assert mc.clamp(300, 0, 255) == 255
    assert mc.clamp(-5, 0, 100) == 0
    assert mc.clamp(50, 0, 100) == 50


def test_mod8_safe():
    assert mc.mod8(17, 5) == 2
    assert mc.mod8(10, 0) == 0
