def test_on_one_row(self): test_argument = np.array([[1382.0, 390167.0]]) with pytest.raises(ValueError) as exc_info: split_into_training_and_testing_sets(test_argument) expected_error_msg = "Argument data_array must have at least 2 rows," " it actually has just 1" assert exc_info.match(expected_error_msg)
def test_on_one_row(): test_argument = np.array([[1382.0, 390167.0]]) # Store information about raised ValueError in exc_info with pytest.raises(ValueError) as exc_info: split_into_training_and_testing_sets(test_argument) expected_error_msg = "Argument data_array must have at least 2 rows, it actually has just 1" # Check if the raised ValueError contains the correct message assert exc_info.match(expected_error_msg)
def test_valueerror_on_one_dimensional_argument_message(): example_argument = np.array([2081, 314942, 1059, 186606, 1148, 206186]) # exception_info stores ValueError with pytest.raises(ValueError) as exception_info: split_into_training_and_testing_sets(example_argument) assert exception_info.match( "Argument data_array must be two dimensional. Got 1 dimensional array instead!" )
def test_on_six_rows(self): example_argument = np.array([[2081.0, 314942.0], [1059.0, 186606.0], [1148.0, 206186.0], [1506.0, 248419.0], [1210.0, 214114.0], [1697.0, 277794.0]]) expected_training_array_num_rows = 4 expected_testing_array_num_rows = 2 actual = split_into_training_and_testing_sets(example_argument) assert actual[0].shape[0] == expected_training_array_num_rows, \ "The actual number of rows in the training array is not {}".format(expected_training_array_num_rows) assert actual[1].shape[0] == expected_testing_array_num_rows, \ "The actual number of rows in the testing array is not {}".format(expected_testing_array_num_rows)
def test_on_six_rows(self): test_argument = np.array([ [2081.0, 314942.0], [1059.0, 186606.0], [1148.0, 206186.0], [1506.0, 248419.0], [1210.0, 214114.0], [1697.0, 277794.0], ]) expected_length_training_set = 4 expected_length_testing_set = 2 actual = split_into_training_and_testing_sets(test_argument) assert actual[0].shape[0] == expected_length_training_set, \ "The actual number of rows in the training array is not 4" assert actual[1].shape[0] == expected_length_testing_set, \ "The actual number of rows in the testing array is not 2"
def test_valueerror_on_one_dimensional_argument(): example_argument = np.array([2081, 314942, 1059, 186606, 1148, 206186]) with pytest.raises(ValueError): split_into_training_and_testing_sets(example_argument)
def test_on_one_dimensional_array(self): test_argument = np.array([1382.0, 390167.0]) with pytest.raises(ValueError) as exc_info: split_into_training_and_testing_sets(test_argument) expected_error_msg = "Argument data_array must be two dimensional. Got 1 dimensional array instead!" assert exc_info.match(expected_error_msg)