diff options
Diffstat (limited to 'tests/src/test_gensvm_task.c')
| -rw-r--r-- | tests/src/test_gensvm_task.c | 324 |
1 files changed, 324 insertions, 0 deletions
diff --git a/tests/src/test_gensvm_task.c b/tests/src/test_gensvm_task.c index 0dcd825..e3e66da 100644 --- a/tests/src/test_gensvm_task.c +++ b/tests/src/test_gensvm_task.c @@ -34,10 +34,334 @@ char *test_init_free_task() return NULL; } +char *test_task_to_model_linear() +{ + struct GenTask *task = gensvm_init_task(); + struct GenModel *model = gensvm_init_model(); + + // start test code // + task->weight_idx = 2; + task->p = 1.3; + task->kappa = 0.1; + task->lambda = 1.4; + task->epsilon = 5e-3; + task->kerneltype = K_LINEAR; + + gensvm_task_to_model(task, model); + + mu_assert(model->weight_idx = 2, "Incorrect model weight_idx"); + mu_assert(model->p == 1.3, "Incorrect model p"); + mu_assert(model->kappa == 0.1, "Incorrect model kappa"); + mu_assert(model->lambda == 1.4, "Incorrect model lambda"); + mu_assert(model->epsilon == 5e-3, "Incorrect model epsilon"); + mu_assert(model->kerneltype == K_LINEAR, "Incorrect model kerneltype"); + mu_assert(model->kernelparam == NULL, "Incorrect model kernelparam"); + // end test code // + + gensvm_free_model(model); + gensvm_free_task(task); + return NULL; +} + +char *test_task_to_model_rbf() +{ + struct GenTask *task = gensvm_init_task(); + struct GenModel *model = gensvm_init_model(); + + // start test code // + task->weight_idx = 2; + task->p = 1.3; + task->kappa = 0.1; + task->lambda = 1.4; + task->epsilon = 5e-3; + task->kerneltype = K_RBF; + task->kernelparam = Malloc(double, 1); + task->kernelparam[0] = 3.1; + + gensvm_task_to_model(task, model); + + mu_assert(model->weight_idx = 2, "Incorrect model weight_idx"); + mu_assert(model->p == 1.3, "Incorrect model p"); + mu_assert(model->kappa == 0.1, "Incorrect model kappa"); + mu_assert(model->lambda == 1.4, "Incorrect model lambda"); + mu_assert(model->epsilon == 5e-3, "Incorrect model epsilon"); + mu_assert(model->kerneltype == K_RBF, "Incorrect model kerneltype"); + mu_assert(model->kernelparam[0] == 3.1, "Incorrect model kernelparam"); + // end test code // + + gensvm_free_model(model); + gensvm_free_task(task); + return NULL; +} + +char *test_task_to_model_poly() +{ + struct GenTask *task = gensvm_init_task(); + struct GenModel *model = gensvm_init_model(); + + // start test code // + task->weight_idx = 2; + task->p = 1.3; + task->kappa = 0.1; + task->lambda = 1.4; + task->epsilon = 5e-3; + task->kerneltype = K_POLY; + task->kernelparam = Malloc(double, 3); + task->kernelparam[0] = 3.1; + task->kernelparam[1] = 2.1; + task->kernelparam[2] = 1.1; + + gensvm_task_to_model(task, model); + + mu_assert(model->weight_idx = 2, "Incorrect model weight_idx"); + mu_assert(model->p == 1.3, "Incorrect model p"); + mu_assert(model->kappa == 0.1, "Incorrect model kappa"); + mu_assert(model->lambda == 1.4, "Incorrect model lambda"); + mu_assert(model->epsilon == 5e-3, "Incorrect model epsilon"); + mu_assert(model->kerneltype == K_POLY, "Incorrect model kerneltype"); + mu_assert(model->kernelparam[0] == 3.1, "Incorrect model kernelparam"); + mu_assert(model->kernelparam[1] == 2.1, "Incorrect model kernelparam"); + mu_assert(model->kernelparam[2] == 1.1, "Incorrect model kernelparam"); + // end test code // + + gensvm_free_model(model); + gensvm_free_task(task); + return NULL; +} + +char *test_task_to_model_sigmoid() +{ + struct GenTask *task = gensvm_init_task(); + struct GenModel *model = gensvm_init_model(); + + // start test code // + task->weight_idx = 2; + task->p = 1.3; + task->kappa = 0.1; + task->lambda = 1.4; + task->epsilon = 5e-3; + task->kerneltype = K_SIGMOID; + task->kernelparam = Malloc(double, 2); + task->kernelparam[0] = 3.1; + task->kernelparam[1] = 0.1; + + gensvm_task_to_model(task, model); + + mu_assert(model->weight_idx = 2, "Incorrect model weight_idx"); + mu_assert(model->p == 1.3, "Incorrect model p"); + mu_assert(model->kappa == 0.1, "Incorrect model kappa"); + mu_assert(model->lambda == 1.4, "Incorrect model lambda"); + mu_assert(model->epsilon == 5e-3, "Incorrect model epsilon"); + mu_assert(model->kerneltype == K_SIGMOID, "Incorrect model kerneltype"); + mu_assert(model->kernelparam[0] == 3.1, "Incorrect model kernelparam"); + mu_assert(model->kernelparam[1] == 0.1, "Incorrect model kernelparam"); + // end test code // + + gensvm_free_model(model); + gensvm_free_task(task); + return NULL; +} + +char *test_copy_task_linear() +{ + struct GenTask *task = gensvm_init_task(); + struct GenTask *copy = NULL; + struct GenData *train = gensvm_init_data(); + struct GenData *test = gensvm_init_data(); + + // start test code // + task->folds = 7; + task->ID = 13; + task->weight_idx = 2; + task->p = 1.3; + task->kappa = 0.1; + task->lambda = 1.4; + task->epsilon = 5e-3; + task->kerneltype = K_LINEAR; + task->train_data = train; + task->test_data = test; + task->performance = 11.11; + + copy = gensvm_copy_task(task); + + mu_assert(copy->folds == 7, "Incorrect copy folds"); + mu_assert(copy->ID == 13, "Incorrect copy ID"); + mu_assert(copy->weight_idx = 2, "Incorrect copy weight_idx"); + mu_assert(copy->p == 1.3, "Incorrect copy p"); + mu_assert(copy->kappa == 0.1, "Incorrect copy kappa"); + mu_assert(copy->lambda == 1.4, "Incorrect copy lambda"); + mu_assert(copy->epsilon == 5e-3, "Incorrect copy epsilon"); + mu_assert(copy->train_data == train, "Incorrect copy train data"); + mu_assert(copy->test_data == test, "Incorrect copy test data"); + mu_assert(copy->performance == 11.11, "Incorrect copy performance"); + mu_assert(copy->kerneltype == K_LINEAR, "Incorrect copy kerneltype"); + mu_assert(copy->kernelparam == NULL, "Incorrect copy kernelparam"); + + // end test code // + gensvm_free_task(task); + gensvm_free_task(copy); + gensvm_free_data(train); + gensvm_free_data(test); + + return NULL; +} + +char *test_copy_task_rbf() +{ + struct GenTask *task = gensvm_init_task(); + struct GenTask *copy = NULL; + struct GenData *train = gensvm_init_data(); + struct GenData *test = gensvm_init_data(); + + // start test code // + + task->folds = 7; + task->ID = 13; + task->weight_idx = 2; + task->p = 1.3; + task->kappa = 0.1; + task->lambda = 1.4; + task->epsilon = 5e-3; + task->train_data = train; + task->test_data = test; + task->performance = 11.11; + task->kerneltype = K_RBF; + task->kernelparam = Malloc(double, 1); + task->kernelparam[0] = 3.1; + + copy = gensvm_copy_task(task); + + mu_assert(copy->folds == 7, "Incorrect copy folds"); + mu_assert(copy->ID == 13, "Incorrect copy ID"); + mu_assert(copy->weight_idx = 2, "Incorrect copy weight_idx"); + mu_assert(copy->p == 1.3, "Incorrect copy p"); + mu_assert(copy->kappa == 0.1, "Incorrect copy kappa"); + mu_assert(copy->lambda == 1.4, "Incorrect copy lambda"); + mu_assert(copy->epsilon == 5e-3, "Incorrect copy epsilon"); + mu_assert(copy->train_data == train, "Incorrect copy train data"); + mu_assert(copy->test_data == test, "Incorrect copy test data"); + mu_assert(copy->performance == 11.11, "Incorrect copy performance"); + mu_assert(copy->kerneltype == K_RBF, "Incorrect copy kerneltype"); + mu_assert(copy->kernelparam[0] == 3.1, "Incorrect copy kernelparam"); + + // end test code // + gensvm_free_task(copy); + gensvm_free_task(task); + gensvm_free_data(train); + gensvm_free_data(test); + + return NULL; +} + +char *test_copy_task_poly() +{ + struct GenTask *task = gensvm_init_task(); + struct GenTask *copy = NULL; + struct GenData *train = gensvm_init_data(); + struct GenData *test = gensvm_init_data(); + + // start test code // + task->folds = 7; + task->ID = 13; + task->weight_idx = 2; + task->p = 1.3; + task->kappa = 0.1; + task->lambda = 1.4; + task->epsilon = 5e-3; + task->train_data = train; + task->test_data = test; + task->performance = 11.11; + task->kerneltype = K_POLY; + task->kernelparam = Malloc(double, 3); + task->kernelparam[0] = 3.1; + task->kernelparam[1] = 2.1; + task->kernelparam[2] = 1.1; + + copy = gensvm_copy_task(task); + + mu_assert(copy->folds == 7, "Incorrect copy folds"); + mu_assert(copy->ID == 13, "Incorrect copy ID"); + mu_assert(copy->weight_idx = 2, "Incorrect copy weight_idx"); + mu_assert(copy->p == 1.3, "Incorrect copy p"); + mu_assert(copy->kappa == 0.1, "Incorrect copy kappa"); + mu_assert(copy->lambda == 1.4, "Incorrect copy lambda"); + mu_assert(copy->epsilon == 5e-3, "Incorrect copy epsilon"); + mu_assert(copy->train_data == train, "Incorrect copy train data"); + mu_assert(copy->test_data == test, "Incorrect copy test data"); + mu_assert(copy->performance == 11.11, "Incorrect copy performance"); + mu_assert(copy->kerneltype == K_POLY, "Incorrect copy kerneltype"); + mu_assert(copy->kernelparam[0] == 3.1, "Incorrect copy kernelparam"); + mu_assert(copy->kernelparam[1] == 2.1, "Incorrect copy kernelparam"); + mu_assert(copy->kernelparam[2] == 1.1, "Incorrect copy kernelparam"); + + // end test code // + gensvm_free_task(task); + gensvm_free_task(copy); + gensvm_free_data(train); + gensvm_free_data(test); + + return NULL; +} + +char *test_copy_task_sigmoid() +{ + struct GenTask *task = gensvm_init_task(); + struct GenTask *copy = NULL; + struct GenData *train = gensvm_init_data(); + struct GenData *test = gensvm_init_data(); + + // start test code // + task->folds = 7; + task->ID = 13; + task->weight_idx = 2; + task->p = 1.3; + task->kappa = 0.1; + task->lambda = 1.4; + task->epsilon = 5e-3; + task->train_data = train; + task->test_data = test; + task->performance = 11.11; + task->kerneltype = K_SIGMOID; + task->kernelparam = Malloc(double, 2); + task->kernelparam[0] = 3.1; + task->kernelparam[1] = 0.1; + + copy = gensvm_copy_task(task); + + mu_assert(copy->folds == 7, "Incorrect copy folds"); + mu_assert(copy->ID == 13, "Incorrect copy ID"); + mu_assert(copy->weight_idx = 2, "Incorrect copy weight_idx"); + mu_assert(copy->p == 1.3, "Incorrect copy p"); + mu_assert(copy->kappa == 0.1, "Incorrect copy kappa"); + mu_assert(copy->lambda == 1.4, "Incorrect copy lambda"); + mu_assert(copy->epsilon == 5e-3, "Incorrect copy epsilon"); + mu_assert(copy->train_data == train, "Incorrect copy train data"); + mu_assert(copy->test_data == test, "Incorrect copy test data"); + mu_assert(copy->performance == 11.11, "Incorrect copy performance"); + mu_assert(copy->kerneltype == K_SIGMOID, "Incorrect copy kerneltype"); + mu_assert(copy->kernelparam[0] == 3.1, "Incorrect copy kernelparam"); + mu_assert(copy->kernelparam[1] == 0.1, "Incorrect copy kernelparam"); + + // end test code // + gensvm_free_task(task); + gensvm_free_task(copy); + gensvm_free_data(train); + gensvm_free_data(test); + return NULL; +} + char *all_tests() { mu_suite_start(); mu_run_test(test_init_free_task); + mu_run_test(test_task_to_model_linear); + mu_run_test(test_task_to_model_rbf); + mu_run_test(test_task_to_model_sigmoid); + mu_run_test(test_task_to_model_poly); + mu_run_test(test_copy_task_linear); + mu_run_test(test_copy_task_rbf); + mu_run_test(test_copy_task_sigmoid); + mu_run_test(test_copy_task_poly); return NULL; } |
