1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
@pytest.mark.task0_2 @given(small_floats) def test_sigmoid(a: float) -> None: """Check properties of the sigmoid function, specifically * It is always between 0.0 and 1.0. * one minus sigmoid is the same as sigmoid of the negative * It crosses 0 at 0.5 * It is strictly increasing. """ assert sigmoid(a) >= 0.0 assert sigmoid(a) <= 1.0 assert_close(1 - sigmoid(a), sigmoid(-a)) assert_close(sigmoid(0), 0.5) assert sigmoid(a + 1.0) >= sigmoid(a)
@pytest.mark.task0_2 @given(small_floats, small_floats, small_floats) def test_transitive(a: float, b: float, c: float) -> None: "Test the transitive property of less-than (a < b and b < c implies a < c)" if lt(a, b) and lt(b, c): assert lt(a, c) elif lt(a, c) and lt(c, b): assert lt(a, b) elif lt(b, c) and lt(c, a): assert lt(b, a)
@pytest.mark.task0_2 @given(small_floats, small_floats) def test_symmetric(a:float, b:float) -> None: """ 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 mul(a, b) == mul(b, a)
@pytest.mark.task0_2 @given(small_floats, small_floats, small_floats) def test_distribute(x: float, y: float, z: float) -> None: """ Write a test that ensures that your operators distribute, i.e. :math:`z \times (x + y) = z \times x + z \times y` """ assert_close(mul(z, add(x, y)), add(mul(z, x), mul(z, y)))
@pytest.mark.task0_2 @given(small_floats, small_floats)
def test_other(a:float, b:float) -> None: """ Write a test that ensures some other property holds for your functions. """ assert mul(a, b) == mul(b, a)
|