Skip to content

Commit

Permalink
Refactored tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerilk committed May 7, 2024
1 parent 07b698c commit d5d63ac
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 392 deletions.
10 changes: 8 additions & 2 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
AM_COLOR_TESTS = yes

AM_CFLAGS = -I$(top_srcdir)/include -Wall -Wextra -Wpedantic $(GSL_CFLAGS)
AM_CFLAGS = -I$(top_srcdir)/include -Wall -Wextra -Wpedantic $(GSL_CFLAGS) -I$(srcdir)

if STRICT
AM_CFLAGS += -Werror
endif

AM_LDFLAGS = ../src/libcconfigspace.la $(GSL_LIBS)
noinst_LTLIBRARIES = libccstest.la
libccstest_la_SOURCES = \
test_utils.h \
test_utils.c
libccstest_la_LDFLAGS = ../src/libcconfigspace.la

AM_LDFLAGS = ../src/libcconfigspace.la libccstest.la $(GSL_LIBS)

CCONFIGSPACE_TESTS = \
test_rng \
Expand Down
23 changes: 6 additions & 17 deletions tests/test_condition.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,7 @@
#include <cconfigspace.h>
#include <string.h>
#include <math.h>

ccs_parameter_t
create_numerical(const char *name)
{
ccs_parameter_t parameter;
ccs_result_t err;
err = ccs_create_numerical_parameter(
name, CCS_NUMERIC_TYPE_FLOAT, CCSF(-1.0), CCSF(1.0), CCSF(0.0),
CCSF(0), &parameter);
assert(err == CCS_RESULT_SUCCESS);
return parameter;
}
#include "test_utils.h"

void
test_simple(void)
Expand All @@ -28,8 +17,8 @@ test_simple(void)
ccs_configuration_t configurations[100];
ccs_result_t err;

parameters[0] = parameter1 = create_numerical("param1");
parameters[1] = parameter2 = create_numerical("param2");
parameters[0] = parameter1 = create_numerical("param1", -1.0, 1.0);
parameters[1] = parameter2 = create_numerical("param2", -1.0, 1.0);
err = ccs_create_binary_expression(
CCS_EXPRESSION_TYPE_LESS, ccs_object(parameter1),
ccs_float(0.0), &conditions[1]);
Expand Down Expand Up @@ -109,9 +98,9 @@ test_transitive(void)
ccs_configuration_t configurations[100];
ccs_result_t err;

parameters[0] = create_numerical("param1");
parameters[1] = create_numerical("param2");
parameters[2] = create_numerical("param3");
parameters[0] = create_numerical("param1", -1.0, 1.0);
parameters[1] = create_numerical("param2", -1.0, 1.0);
parameters[2] = create_numerical("param3", -1.0, 1.0);

err = ccs_create_binary_expression(
CCS_EXPRESSION_TYPE_LESS, ccs_object(parameters[1]),
Expand Down
25 changes: 7 additions & 18 deletions tests/test_configuration_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <assert.h>
#include <cconfigspace.h>
#include <string.h>
#include "test_utils.h"

double d = -2.0;

Expand Down Expand Up @@ -225,18 +226,6 @@ test_sample(void)
assert(err == CCS_RESULT_SUCCESS);
}

ccs_parameter_t
create_numerical(const char *name)
{
ccs_parameter_t parameter;
ccs_result_t err;
err = ccs_create_numerical_parameter(
name, CCS_NUMERIC_TYPE_FLOAT, CCSF(-5.0), CCSF(5.0), CCSF(0.0),
CCSF(0.0), &parameter);
assert(err == CCS_RESULT_SUCCESS);
return parameter;
}

void
test_configuration_deserialize(void)
{
Expand All @@ -250,9 +239,9 @@ test_configuration_deserialize(void)
ccs_result_t err;
int cmp;

parameters[0] = create_numerical("param1");
parameters[1] = create_numerical("param2");
parameters[2] = create_numerical("param3");
parameters[0] = create_numerical("param1", -5.0, 5.0);
parameters[1] = create_numerical("param2", -5.0, 5.0);
parameters[2] = create_numerical("param3", -5.0, 5.0);

err = ccs_create_configuration_space(
"my_config_space", 3, parameters, NULL, 0, NULL, NULL,
Expand Down Expand Up @@ -333,9 +322,9 @@ test_deserialize(void)
ccs_datum_t d;
ccs_result_t err;

parameters[0] = create_numerical("param1");
parameters[1] = create_numerical("param2");
parameters[2] = create_numerical("param3");
parameters[0] = create_numerical("param1", -5.0, 5.0);
parameters[1] = create_numerical("param2", -5.0, 5.0);
parameters[2] = create_numerical("param3", -5.0, 5.0);

err = ccs_create_binary_expression(
CCS_EXPRESSION_TYPE_LESS, ccs_object(parameters[0]),
Expand Down
19 changes: 4 additions & 15 deletions tests/test_distribution_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <assert.h>
#include <cconfigspace.h>
#include <string.h>
#include "test_utils.h"

double d = -2.0;

Expand Down Expand Up @@ -269,18 +270,6 @@ test_set_distribution(void)
assert(err == CCS_RESULT_SUCCESS);
}

ccs_parameter_t
create_numerical(const char *name)
{
ccs_parameter_t parameter;
ccs_result_t err;
err = ccs_create_numerical_parameter(
name, CCS_NUMERIC_TYPE_FLOAT, CCSF(-5.0), CCSF(5.0), CCSF(0.0),
CCSF(0.0), &parameter);
assert(err == CCS_RESULT_SUCCESS);
return parameter;
}

void
test_deserialize(void)
{
Expand All @@ -298,9 +287,9 @@ test_deserialize(void)
ccs_datum_t d;
ccs_result_t err;

parameters[0] = create_numerical("param1");
parameters[1] = create_numerical("param2");
parameters[2] = create_numerical("param3");
parameters[0] = create_numerical("param1", -5.0, 5.0);
parameters[1] = create_numerical("param2", -5.0, 5.0);
parameters[2] = create_numerical("param3", -5.0, 5.0);

err = ccs_create_configuration_space(
"my_config_space", 3, parameters, NULL, 0, NULL, NULL, &space);
Expand Down
23 changes: 6 additions & 17 deletions tests/test_forbidden.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,7 @@
#include <cconfigspace.h>
#include <string.h>
#include <math.h>

ccs_parameter_t
create_numerical(const char *name)
{
ccs_parameter_t parameter;
ccs_result_t err;
err = ccs_create_numerical_parameter(
name, CCS_NUMERIC_TYPE_FLOAT, CCSF(-1.0), CCSF(1.0), CCSF(0.0),
CCSF(0), &parameter);
assert(err == CCS_RESULT_SUCCESS);
return parameter;
}
#include "test_utils.h"

void
test_simple(void)
Expand All @@ -28,8 +17,8 @@ test_simple(void)
ccs_configuration_t configurations[100];
ccs_result_t err;

parameters[0] = parameter1 = create_numerical("param1");
parameters[1] = parameter2 = create_numerical("param2");
parameters[0] = parameter1 = create_numerical("param1", -1.0, 1.0);
parameters[1] = parameter2 = create_numerical("param2", -1.0, 1.0);
err = ccs_create_binary_expression(
CCS_EXPRESSION_TYPE_LESS, ccs_object(parameter1),
ccs_float(0.0), &expression);
Expand Down Expand Up @@ -106,9 +95,9 @@ test_combined(void)
ccs_configuration_t configurations[100];
ccs_result_t err;

parameters[0] = create_numerical("param1");
parameters[1] = create_numerical("param2");
parameters[2] = create_numerical("param3");
parameters[0] = create_numerical("param1", -1.0, 1.0);
parameters[1] = create_numerical("param2", -1.0, 1.0);
parameters[2] = create_numerical("param3", -1.0, 1.0);

err = ccs_create_binary_expression(
CCS_EXPRESSION_TYPE_LESS, ccs_object(parameters[0]),
Expand Down
116 changes: 15 additions & 101 deletions tests/test_random_features_tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,28 @@
#include <assert.h>
#include <cconfigspace.h>
#include <string.h>

ccs_parameter_t
create_numerical(const char *name, double lower, double upper)
{
ccs_parameter_t parameter;
ccs_result_t err;
err = ccs_create_numerical_parameter(
name, CCS_NUMERIC_TYPE_FLOAT, CCSF(lower), CCSF(upper),
CCSF(0.0), CCSF(0), &parameter);
assert(err == CCS_RESULT_SUCCESS);
return parameter;
}
#include "test_utils.h"

void
test(void)
{
ccs_parameter_t parameter1, parameter2;
ccs_parameter_t parameters[2];
ccs_parameter_t parameter3;
ccs_parameter_t feature;
ccs_configuration_space_t cspace;
ccs_feature_space_t fspace;
ccs_objective_space_t ospace;
ccs_expression_t expression;
ccs_objective_type_t otype;
ccs_features_tuner_t tuner, tuner_copy;
ccs_result_t err;
ccs_features_t features_on, features_off;
ccs_datum_t knobs_values[2] = {ccs_string("on"), ccs_string("off")};
ccs_datum_t d;
char *buff;
size_t buff_size;
ccs_map_t map;

parameters[0] = parameter1 = create_numerical("x", -5.0, 5.0);
parameters[1] = parameter2 = create_numerical("y", -5.0, 5.0);

err = ccs_create_configuration_space(
"2dplane", 2, parameters, NULL, 0, NULL, NULL, &cspace);
assert(err == CCS_RESULT_SUCCESS);

parameter3 = create_numerical("z", -CCS_INFINITY, CCS_INFINITY);
err = ccs_create_variable(parameter3, &expression);
assert(err == CCS_RESULT_SUCCESS);
otype = CCS_OBJECTIVE_TYPE_MINIMIZE;

err = ccs_create_objective_space(
"height", 1, &parameter3, 1, &expression, &otype, &ospace);
assert(err == CCS_RESULT_SUCCESS);

err = ccs_create_categorical_parameter(
"red knob", 2, knobs_values, 0, &feature);
assert(err == CCS_RESULT_SUCCESS);
ccs_datum_t d;
char *buff;
size_t buff_size;
ccs_map_t map;

err = ccs_create_feature_space("knobs", 1, &feature, &fspace);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_create_features(fspace, 1, knobs_values, &features_on);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_create_features(fspace, 1, knobs_values + 1, &features_off);
assert(err == CCS_RESULT_SUCCESS);
cspace = create_2d_plane();
ospace = create_height_objective();
fspace = create_knobs(&features_on, &features_off);

err = ccs_create_random_features_tuner(
"problem", cspace, fspace, ospace, &tuner);
err = ccs_create_random_features_tuner(
"problem", cspace, fspace, ospace, &tuner);
assert(err == CCS_RESULT_SUCCESS);

for (size_t i = 0; i < 50; i++) {
Expand Down Expand Up @@ -215,16 +174,6 @@ test(void)
assert(err == CCS_RESULT_SUCCESS);
err = ccs_release_object(tuner_copy);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_release_object(expression);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_release_object(parameter1);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_release_object(parameter2);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_release_object(parameter3);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_release_object(feature);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_release_object(features_on);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_release_object(features_off);
Expand All @@ -242,50 +191,25 @@ test(void)
void
test_evaluation_deserialize(void)
{
ccs_parameter_t parameter1, parameter2;
ccs_parameter_t parameters[2];
ccs_parameter_t parameter3;
ccs_parameter_t feature;
ccs_configuration_space_t cspace;
ccs_feature_space_t fspace;
ccs_objective_space_t ospace;
ccs_expression_t expression;
ccs_objective_type_t otype;
ccs_result_t err;
ccs_configuration_t configuration;
ccs_features_t features_on;
ccs_datum_t knobs_values[2] = {ccs_string("on"), ccs_string("off")};
ccs_features_evaluation_t evaluation_ref, evaluation;
ccs_datum_t res, d;
char *buff;
size_t buff_size;
ccs_map_t map;
int cmp;

parameters[0] = parameter1 = create_numerical("x", -5.0, 5.0);
parameters[1] = parameter2 = create_numerical("y", -5.0, 5.0);

err = ccs_create_configuration_space(
"2dplane", 2, parameters, NULL, 0, NULL, NULL, &cspace);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_configuration_space_sample(
cspace, NULL, NULL, &configuration);
assert(err == CCS_RESULT_SUCCESS);

parameter3 = create_numerical("z", -CCS_INFINITY, CCS_INFINITY);
err = ccs_create_variable(parameter3, &expression);
assert(err == CCS_RESULT_SUCCESS);
otype = CCS_OBJECTIVE_TYPE_MINIMIZE;
cspace = create_2d_plane();
ospace = create_height_objective();
fspace = create_knobs(&features_on, NULL);

err = ccs_create_categorical_parameter(
"red knob", 2, knobs_values, 0, &feature);
assert(err == CCS_RESULT_SUCCESS);

err = ccs_create_feature_space("knobs", 1, &feature, &fspace);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_create_features(fspace, 1, knobs_values, &features_on);
err = ccs_create_objective_space(
"height", 1, &parameter3, 1, &expression, &otype, &ospace);
err = ccs_configuration_space_sample(
cspace, NULL, NULL, &configuration);
assert(err == CCS_RESULT_SUCCESS);

res = ccs_float(1.5);
Expand Down Expand Up @@ -359,8 +283,6 @@ test_evaluation_deserialize(void)
assert(!cmp);

free(buff);
err = ccs_release_object(feature);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_release_object(features_on);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_release_object(map);
Expand All @@ -371,14 +293,6 @@ test_evaluation_deserialize(void)
assert(err == CCS_RESULT_SUCCESS);
err = ccs_release_object(configuration);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_release_object(expression);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_release_object(parameter1);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_release_object(parameter2);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_release_object(parameter3);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_release_object(cspace);
assert(err == CCS_RESULT_SUCCESS);
err = ccs_release_object(fspace);
Expand Down
13 changes: 1 addition & 12 deletions tests/test_random_tree_tuner.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,7 @@
#include <assert.h>
#include <cconfigspace.h>
#include <string.h>

ccs_parameter_t
create_numerical(const char *name, double lower, double upper)
{
ccs_parameter_t parameter;
ccs_result_t err;
err = ccs_create_numerical_parameter(
name, CCS_NUMERIC_TYPE_FLOAT, CCSF(lower), CCSF(upper),
CCSF(0.0), CCSF(0), &parameter);
assert(err == CCS_RESULT_SUCCESS);
return parameter;
}
#include "test_utils.h"

void
generate_tree(ccs_tree_t *tree, size_t depth, size_t rank)
Expand Down
Loading

0 comments on commit d5d63ac

Please sign in to comment.