Commit 8c31b715 authored by Thomas Purcell's avatar Thomas Purcell
Browse files

Update Classification tests to check exceptions

parent 82910ba8
......@@ -206,7 +206,7 @@ void LPWrapper::copy_data(const int cls, const std::vector<double*> val_ptrs, co
{
throw std::logic_error("Size of the val_ptrs vector is larger than _n_dim");
}
if(val_ptrs.size() > _n_dim)
if(test_val_ptrs.size() > _n_dim)
{
throw std::logic_error("Size of the test_val_ptrs vector is larger than _n_dim");
}
......
......@@ -110,6 +110,11 @@ void SVMWrapper::setup_x_space()
void SVMWrapper::copy_data(const std::vector<int> inds, const int task)
{
if((task < 0) || (task >= node_value_arrs::TASK_SZ_TRAIN.size()))
{
throw std::logic_error("The requested task is invalid.");
}
if(inds.size() > _n_dim)
{
throw std::logic_error("Size of the inds vector is larger than _n_dim");
......
......@@ -136,6 +136,33 @@ namespace
TEST_F(LPWrapperTests, WithTestData)
{
EXPECT_THROW(
LPWrapper lp(
_samp_per_class,
_task_num,
_n_class,
_n_dim,
_n_samp + 1,
_tol,
_samp_per_class_test,
_n_samp_test
),
std::logic_error
);
EXPECT_THROW(
LPWrapper lp(
_samp_per_class,
_task_num,
_n_class,
_n_dim,
_n_samp,
_tol,
_samp_per_class_test,
_n_samp_test + 1
),
std::logic_error
);
LPWrapper lp(
_samp_per_class,
_task_num,
......@@ -160,10 +187,30 @@ namespace
EXPECT_EQ(lp.n_samp_test(), _n_samp_test);
EXPECT_EQ(lp.n_overlap(), 0);
EXPECT_EQ(lp.n_overlap_test(), 0);
EXPECT_THROW(lp.copy_data(0, {0, 1, 2}), std::logic_error);
val_ptrs = {_phi[0].value_ptr(), _phi[1].value_ptr(), _phi[1].value_ptr()};
EXPECT_THROW(lp.set_n_overlap(val_ptrs, test_val_ptrs, _error.data(), _test_error.data()), std::logic_error);
val_ptrs = {_phi[0].value_ptr(), _phi[1].value_ptr()};
test_val_ptrs = {_phi[0].test_value_ptr(), _phi[1].test_value_ptr(), _phi[1].test_value_ptr()};
EXPECT_THROW(lp.set_n_overlap(val_ptrs, test_val_ptrs, _error.data(), _test_error.data()), std::logic_error);
}
TEST_F(LPWrapperTests, WithoutTestData)
{
EXPECT_THROW(
LPWrapper lp(
_samp_per_class,
_task_num,
_n_class,
_n_dim,
_n_samp + 1,
_tol
),
std::logic_error
);
LPWrapper lp(
_samp_per_class,
......@@ -187,11 +234,19 @@ namespace
EXPECT_EQ(lp.n_samp_test(), 0);
EXPECT_EQ(lp.n_overlap(), 0);
EXPECT_EQ(lp.n_overlap_test(), 0);
EXPECT_THROW(lp.copy_data(0, {0, 1, 2}), std::logic_error);
val_ptrs = {_phi[0].value_ptr(), _phi[1].value_ptr(), _phi[1].value_ptr()};
EXPECT_THROW(lp.set_n_overlap(val_ptrs, test_val_ptrs, _error.data(), _test_error.data()), std::logic_error);
val_ptrs = {_phi[0].value_ptr(), _phi[1].value_ptr()};
test_val_ptrs = {_phi[0].test_value_ptr(), _phi[1].test_value_ptr(), _phi[1].test_value_ptr()};
EXPECT_THROW(lp.set_n_overlap(val_ptrs, test_val_ptrs, _error.data(), _test_error.data()), std::logic_error);
}
TEST_F(LPWrapperTests, CopyTest)
{
LPWrapper lp(
_samp_per_class,
_task_num,
......
......@@ -62,5 +62,22 @@ namespace
prop_sorted_d_mat::access_sample_sorted_d_matrix(2)[0] = 1.5;
EXPECT_EQ(prop_sorted_d_mat::access_sample_sorted_d_matrix(2, 0, 0)[0], 1.5);
prop_sorted_d_mat::finalize_sorted_d_matrix_arr();
EXPECT_THROW(
prop_sorted_d_mat::initialize_sorted_d_matrix_arr(1, _n_task, _n_class + 1, _n_samples_per_class),
std::logic_error
);
EXPECT_THROW(
prop_sorted_d_mat::initialize_sorted_d_matrix_arr(1, _n_task + 1, _n_class, _n_samples_per_class),
std::logic_error
);
_n_samples_per_class.push_back(1);
EXPECT_THROW(
prop_sorted_d_mat::initialize_sorted_d_matrix_arr(1, _n_task, _n_class, _n_samples_per_class),
std::logic_error
);
}
}
......@@ -168,6 +168,15 @@ namespace
EXPECT_EQ(svm.n_dim(), _n_dim);
EXPECT_EQ(svm.n_samp(), _n_samp);
EXPECT_EQ(svm.n_misclassified(), 0);
EXPECT_THROW(svm.copy_data({0,1,2}, 0), std::logic_error);
EXPECT_THROW(svm.copy_data({0,1}, 3), std::logic_error);
val_ptrs = {_phi[0].value_ptr(), _phi[1].value_ptr(), _phi[1].value_ptr()};
EXPECT_THROW(svm.copy_data(val_ptrs), std::logic_error);
test_val_ptrs = {_phi[0].test_value_ptr(), _phi[1].test_value_ptr(), _phi[1].test_value_ptr()};
EXPECT_THROW(svm.predict(20, test_val_ptrs), std::logic_error);
}
TEST_F(SVMWrapperTests, CTest)
......@@ -210,5 +219,14 @@ namespace
EXPECT_EQ(svm.n_dim(), _n_dim);
EXPECT_EQ(svm.n_samp(), _n_samp);
EXPECT_EQ(svm.n_misclassified(), 0);
EXPECT_THROW(svm.copy_data({0,1,2}, 0), std::logic_error);
EXPECT_THROW(svm.copy_data({0,1}, 3), std::logic_error);
val_ptrs = {_phi[0].value_ptr(), _phi[1].value_ptr(), _phi[1].value_ptr()};
EXPECT_THROW(svm.copy_data(val_ptrs), std::logic_error);
test_val_ptrs = {_phi[0].test_value_ptr(), _phi[1].test_value_ptr(), _phi[1].test_value_ptr()};
EXPECT_THROW(svm.predict(20, test_val_ptrs), std::logic_error);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment