def test_id(x): """ Write a test that ensures some other property holds for your functions. """ assert operators.id(x) == x assert_close(x, operators.neg(operators.neg(x))) if x != 0: assert_close(x, operators.inv(operators.inv(x)))
def test_inv(x): """ Write a test that ensures some other property holds for your functions. """ if x != 0: assert_close(operators.mul(x, operators.inv(x)), 1) assert_close(operators.add(x, operators.neg(x)), 0)
def test_same_as_python(x, y): "Check that the main operators all return the same value of the python version" assert_close(mul(x, y), x * y) assert_close(add(x, y), x + y) assert_close(neg(x), -x) assert_close(max(x, y), x if x > y else y) if x != 0.0: assert_close(inv(x), 1.0 / x)
def inv(a): return operators.inv(a + 3.5)
def inv(a): "Invert after adding" return operators.inv(a + 3.5)