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_other(x, y): """ Write a test that ensures some other property holds for your functions. """ r1 = operators.mul(operators.neg(x), y) r2 = operators.mul(operators.mul(-1.0, y), operators.mul(1.0, x)) assert_close(r1, r2)
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 test_other(): """ Write a test that ensures some other property holds for your functions. """ a = 10.0 assert operators.neg(a) == -10.0 assert operators.mul(a, -1) == -1 * a
def test_add_and_mul(x, y): assert_close(operators.mul(x, y), x * y) assert_close(operators.add(x, y), x + y) assert_close(operators.neg(x), -x)
def test_other(x): """ Difference of identical numbers is 0 """ assert_close(operators.add(x, operators.neg(x)), 0.)
def test_other(x): """ Write a test that ensures some other property holds for your functions. """ assert operators.neg(x) == operators.mul(-1, x)
def test_other(a): """ Write a test that ensures some other property holds for your functions. """ assert a == operators.neg(operators.neg(a)) assert_close(operators.sigmoid(-a), 1 - operators.sigmoid(a))