Commit d9d601d5 authored by Brice Videau's avatar Brice Videau
Browse files

Added transitivity test.

parent 12a06682
......@@ -86,8 +86,116 @@ test_simple() {
err = ccs_release_object(space);
}
void
test_transitive() {
ccs_hyperparameter_t hyperparameters[3];
ccs_configuration_space_t space;
ccs_expression_t expression;
ccs_configuration_t configuration;
ccs_datum_t values[3];
ccs_configuration_t configurations[100];
ccs_error_t err;
hyperparameters[0] = create_numerical("param1");
hyperparameters[1] = create_numerical("param2");
hyperparameters[2] = create_numerical("param3");
err = ccs_create_configuration_space("space", NULL, &space);
assert( err == CCS_SUCCESS );
err = ccs_configuration_space_add_hyperparameters(space, 3, hyperparameters,
NULL);
assert( err == CCS_SUCCESS );
err = ccs_create_binary_expression(CCS_LESS, ccs_object(hyperparameters[1]),
ccs_float(0.0), &expression);
assert( err == CCS_SUCCESS );
err = ccs_configuration_space_set_condition(space, 2, expression);
assert( err == CCS_SUCCESS );
err = ccs_release_object(expression);
assert( err == CCS_SUCCESS );
err = ccs_create_binary_expression(CCS_LESS, ccs_object(hyperparameters[2]),
ccs_float(0.0), &expression);
assert( err == CCS_SUCCESS );
err = ccs_configuration_space_set_condition(space, 0, expression);
assert( err == CCS_SUCCESS );
err = ccs_release_object(expression);
assert( err == CCS_SUCCESS );
for (int i = 0; i < 100; i ++) {
ccs_float_t f;
err = ccs_configuration_space_sample(space, &configuration);
assert( err == CCS_SUCCESS );
err = ccs_configuration_get_values(configuration, 3, values, NULL);
assert( err == CCS_SUCCESS );
assert( values[1].type == CCS_FLOAT );
f = values[1].value.f;
assert( f >= -1.0 && f < 1.0 );
if (f < 0.0) {
assert( values[2].type == CCS_FLOAT );
f = values[2].value.f;
assert( f >= -1.0 && f < 1.0 );
if (f < 0.0) {
assert( values[0].type == CCS_FLOAT );
f = values[0].value.f;
assert( f >= -1.0 && f < 1.0 );
}
else
assert( values[0].type == CCS_INACTIVE );
} else {
assert( values[2].type == CCS_INACTIVE );
assert( values[0].type == CCS_INACTIVE );
}
err = ccs_configuration_space_check_configuration(space, configuration);
assert( err == CCS_SUCCESS );
err = ccs_release_object(configuration);
assert( err == CCS_SUCCESS );
}
err = ccs_configuration_space_samples(space, 100, configurations);
assert( err == CCS_SUCCESS );
for (int i = 0; i < 100; i ++) {
ccs_float_t f;
err = ccs_configuration_get_values(configurations[i], 3, values, NULL);
assert( err == CCS_SUCCESS );
assert( values[1].type == CCS_FLOAT );
f = values[1].value.f;
assert( f >= -1.0 && f < 1.0 );
if (f < 0.0) {
assert( values[2].type == CCS_FLOAT );
f = values[2].value.f;
assert( f >= -1.0 && f < 1.0 );
if (f < 0.0) {
assert( values[0].type == CCS_FLOAT );
f = values[0].value.f;
assert( f >= -1.0 && f < 1.0 );
}
else
assert( values[0].type == CCS_INACTIVE );
} else {
assert( values[2].type == CCS_INACTIVE );
assert( values[0].type == CCS_INACTIVE );
}
err = ccs_configuration_space_check_configuration(space, configurations[i]);
assert( err == CCS_SUCCESS );
err = ccs_release_object(configurations[i]);
assert( err == CCS_SUCCESS );
}
for (int i =0; i < 3; i++) {
err = ccs_release_object(hyperparameters[i]);
assert( err == CCS_SUCCESS );
}
err = ccs_release_object(space);
assert( err == CCS_SUCCESS );
}
int main() {
ccs_init();
test_simple();
test_transitive();
return 0;
}
Markdown is supported
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