def test_on_perfect_fit(self):
     test_argument = np.array([[1.0, 3.0], [2.0, 5.0], [3.0, 7.0]])
     expected = 1.0
     actual = model_test(test_argument, 2.0, 1.0)
     message = "model_test({0}) should return {1}, but it actually returned {2}".format(
         test_argument, expected, actual)
     assert actual == pytest.approx(expected), message
Esempio n. 2
0
def test_on_perfect_fit():
    # Assign to a NumPy array containing a linear testing set
    test_argument = np.array([[1.0, 3.0], [2.0, 5.0], [3.0, 7.0]])
    # Fill in with the expected value of r^2 in the case of perfect fit
    expected = 1.0
    # Fill in with the slope and intercept of the model
    actual = model_test(test_argument, slope=2.0, intercept=1.0)
    # Complete the assert statement
    assert actual == pytest.approx(expected), "Expected: {0}, Actual: {1}".format(expected, actual)
def test_on_circular_data(self):
    theta = pi / 4.0
    # Assign to a NumPy array holding the circular testing data
    test_argument = np.array([[1.0, 0.0], [cos(theta), sin(theta)], [0.0, 1.0],
                              [cos(3 * theta), sin(3 * theta)], [-1.0, 0.0],
                              [cos(5 * theta), sin(5 * theta)], [0.0, -1.0],
                              [cos(7 * theta), sin(7 * theta)]])
    # Fill in with the slope and intercept of the straight line
    actual = model_test(test_argument, slope=0.0, intercept=0.0)
    # Complete the assert statement
    assert actual == pytest.approx(0.0)
 def test_on_circular_data(self):
     theta = pi / 4.0
     test_argument = np.array([[0.0, 1.0], [cos(theta),
                                            sin(theta)], [1.0, 0.0],
                               [cos(3 * theta),
                                sin(3 * theta)], [0.0, -1.0],
                               [cos(5 * theta),
                                sin(5 * theta)], [-1.0, 0.0],
                               [cos(7 * theta),
                                sin(7 * theta)]])
     actual = model_test(test_argument, 0.0, 0.0)
     assert actual == pytest.approx(0.0)
Esempio n. 5
0
 def test_on_one_dimensional_array(self):
     test_argument = np.array([1.0, 2.0, 3.0, 4.0])
     with pytest.raises(ValueError) as exc_info:
         model_test(test_argument, 1.0, 1.0)
     expected_error_msg = "Argument testing_set must be two dimensional. Got 1 dimensional array instead!"
     assert exc_info.match(expected_error_msg)