def test_symmetric(x, y): """ Write a test that ensures that :func:`minitorch.operators.mul` is symmetric, i.e. gives the same value regardless of the order of its input. """ assert operators.mul(x, y) == operators.mul(y, x) assert operators.add(x, y) == operators.add(y, x)
def test_distribute(x, y, z): r""" Write a test that ensures that your operators distribute, i.e. :math:`z \times (x + y) = z \times x + z \times y` """ assert_close(operators.mul(z, operators.add(x, y)), operators.add(operators.mul(x, z), operators.mul(y, z)))
def test_associate(x, y, z): """ Write a test that ensures some other property holds for your functions. """ assert_close(operators.mul(operators.mul(x, y), z), operators.mul(x, operators.mul(y, z))) assert_close(operators.add(operators.add(x, y), z), operators.add(x, operators.add(y, z)))
def test_distribute(x, y, z): r""" Write a test that ensures that your operators distribute, i.e. :math:`z \times (x + y) = z \times x + z \times y` """ r1 = operators.mul(z, operators.add(x, y)) r2 = operators.add(operators.mul(z, x), operators.mul(z, y)) assert_close(r1, r2)
def test_distribute(x, y, z): r""" Write a test that ensures that your operators distribute, i.e. :math:`z \times (x + y) = z \times x + z \times y` """ # TODO: Implement for Task 0.2. assert_close(operators.mul(z, operators.add(x, y)), operators.add(operators.mul(z, x), operators.mul(z, y)))
def test_distribute(x, y, z): """ Write a test that ensures that your operators distribute, i.e. :math:`z \times (x + y) = z \times x + z \times y` """ #None assert_close(operators.add((operators.mul(z, y)), operators.mul(z, x)), (z * x) + (z * y)) assert_close(operators.mul(z, operators.add(x, y)), z * (x + y))
def test_distribute(): r""" A test that ensures that your operators distribute, i.e. :math:`z \times (x + y) = z \times x + z \times y` """ a = list(range(-500, 501)) b = list(range(-500, 501)) c = list(range(-500, 501)) for i, j, z in zip(a, b, c): assert operators.mul(z, operators.add(i, j)) == operators.add( operators.mul(z, i), operators.mul(z, j))
def test_property(ls1, ls2): """ Write a test that ensures that the sum of `ls1` plus the sum of `ls2` is the same as the sum of each element of `ls1` plus each element of `ls2`. """ assert_close(operators.add(operators.sum(ls1), operators.sum(ls2)), operators.sum(operators.zipWith(operators.add)(ls1, ls2)))
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_property(ls1, ls2): """ Write a test that ensures that the sum of `ls1` plus the sum of `ls2` is the same as the sum of each element of `ls1` plus each element of `ls2`. """ indiv_sum = operators.add(operators.sum(ls1), operators.sum(ls2)) total_sum = operators.sum(operators.addLists(ls1, ls2)) assert_close(indiv_sum, total_sum)
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_property(ls1, ls2): """ Write a test that ensures that the sum of `ls1` plus the sum of `ls2` is the same as the sum of each element of `ls1` plus each element of `ls2`. """ # TODO: Implement for Task 0.3. sum = operators.add(operators.sum(ls1), operators.sum(ls2)) elem_sum = operators.sum(operators.addLists(ls1, ls2)) assert_close(sum, elem_sum)
def test_distribute(x, y, z): assert_close(op.mul(z, op.add(x, y)), op.add(op.mul(z, x), op.mul(z, y)))
def test_symmetric(x, y): assert op.mul(x, y) == op.mul(y, x) assert op.add(x, y) == op.add(y, x) assert op.max(x, y) == op.max(y, x) assert op.eq(x, y) == op.eq(y, x)
def test_other(x): """ Difference of identical numbers is 0 """ assert_close(operators.add(x, operators.neg(x)), 0.)
def test_distribute(a, b, c): r""" Write a test that ensures that your operators distribute, i.e. :math:`z \times (x + y) = z \times x + z \times y` """ assert operators.mul(a, operators.add(b, c)) == operators.add(operators.mul(a, b), operators.mul(a, c))
def test_distribute(x, y, z): assert_close(operators.mul(x, operators.add(y, z)), operators.add(operators.mul(x, y), operators.mul(x, z)))
def test_property(ls1, ls2): assert_close(op.add(op.sum(ls1), op.sum(ls2)), op.sum([op.add(x, y) for x, y in zip(ls1, ls2)]))
def test_other(x, y): """ Write a test that ensures some other property holds for your functions. """ # TODO: Implement for Task 0.2. assert operators.add(x, y) == operators.add(y, x)
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_associative(x, y, z): """ Write a test that ensures some other property holds for your functions. """ assert operators.add(x, operators.add(y, z)) == operators.add( operators.add(x, y), z)
def test_property(ls1, ls2): assert_close(operators.add(math.fsum(ls1), math.fsum(ls2)), math.fsum(operators.addLists(ls1, ls2)))
def test_other(a, b): """ Write a test that ensures some other property holds for your functions. """ assert_close(operators.add(a, b), operators.add(b, a))