From 455c7d9c8185acdd8c8fe74ad4a59a3e0756d75d Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sat, 4 Feb 2023 18:00:31 +0100 Subject: Moved coordinate index consistency test to tests folder --- tests/coord_tests.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/coord_tests.h | 13 +++++++++++++ tests/fst_tests.c | 13 +++++++------ tests/fst_tests.h | 2 +- tests/test.c | 5 ++++- 5 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 tests/coord_tests.c create mode 100644 tests/coord_tests.h (limited to 'tests') diff --git a/tests/coord_tests.c b/tests/coord_tests.c new file mode 100644 index 0000000..8d6b6d3 --- /dev/null +++ b/tests/coord_tests.c @@ -0,0 +1,50 @@ +#include "coord_tests.h" + +bool testmethod_indexes_consistent(void *); + +Test test_indexes_consistent = { + .name = "Consitency of index and anti-index", + .t = testmethod_indexes_consistent, + .cases = (void **)all_coordinates, +}; +Test *coord_pre_init[] = { + &test_indexes_consistent, + NULL +}; +TestSuite coord_pre_init_suite = { + .setup = NULL, + .tests = coord_pre_init, + .teardown = NULL, +}; + +TestSuite *coord_suites[] = { + &coord_pre_init_suite, + NULL +}; + +bool +testmethod_indexes_consistent(void *a) +{ + uint64_t ui, uj; + Cube c; + Coordinate *coord; + + coord = (Coordinate *)a; + + if (coord->type != COMP_COORD) + return true; /* Not applicable */ + + gen_coord(coord); + for (ui = 0; ui < coord->max; ui++) { + indexers_makecube(coord->i, ui, &c); + uj = indexers_getind(coord->i, &c); + if (ui != uj) { + fprintf(stderr, "Error with coordinate %s: " + "%" PRIu64 " != %" PRIu64 "\n", + coord->name, uj, ui); + return false; + } + } + + return true; +} diff --git a/tests/coord_tests.h b/tests/coord_tests.h new file mode 100644 index 0000000..0cfd145 --- /dev/null +++ b/tests/coord_tests.h @@ -0,0 +1,13 @@ +#ifndef COORD_TESTS_H +#define COORD_TESTS_H + +#include "../src/coord.h" +#include "test_common.h" + +extern Test test_indexes_consistent; + +extern TestSuite coord_pre_init_suite; + +extern TestSuite *coord_suites[]; + +#endif diff --git a/tests/fst_tests.c b/tests/fst_tests.c index dfaab39..1a9bedd 100644 --- a/tests/fst_tests.c +++ b/tests/fst_tests.c @@ -3,7 +3,8 @@ static bool testmethod_fst_is_consistent(void *); static bool testmethod_cube_to_fst_to_cube(void *); static bool testmethod_fst_move(void *); -static bool testmethod_fst_inverse(void *); static bool check_equal_and_log(Cube *, Cube *); +static bool testmethod_fst_inverse(void *); +static bool check_equal_and_log(Cube *, Cube *); static void void_to_cube(void *, Cube *); char *algs[] = { @@ -42,29 +43,29 @@ Test test_fst_inverse = { .cases = (void **)algs, }; -Test *pre_init[] = { +Test *fst_pre_init[] = { &test_fst_is_consistent, &test_cube_to_fst_to_cube, NULL }; TestSuite fst_pre_init_suite = { .setup = NULL, - .tests = pre_init, + .tests = fst_pre_init, .teardown = NULL, }; -Test *post_init[] = { +Test *fst_post_init[] = { &test_fst_move, &test_fst_inverse, NULL }; TestSuite fst_post_init_suite = { .setup = init_fst, - .tests = post_init, + .tests = fst_post_init, .teardown = NULL, }; -TestSuite *fst_testsuites[] = { +TestSuite *fst_suites[] = { &fst_pre_init_suite, &fst_post_init_suite, NULL diff --git a/tests/fst_tests.h b/tests/fst_tests.h index 324028e..68bbf04 100644 --- a/tests/fst_tests.h +++ b/tests/fst_tests.h @@ -14,6 +14,6 @@ extern Test test_fst_inverse; extern TestSuite fst_pre_init_suite; extern TestSuite fst_post_init_suite; -extern TestSuite *fst_testsuites[]; +extern TestSuite *fst_suites[]; #endif diff --git a/tests/test.c b/tests/test.c index cc14456..a1a382c 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1,5 +1,6 @@ #include +#include "coord_tests.h" #include "fst_tests.h" static bool run_test(Test *); @@ -53,9 +54,11 @@ int main(int argc, char *argv[]) { init_trans(); /**************************************/ - TestModule fst = { .name = "fst", .suites = fst_testsuites }; + TestModule fst = { .name = "fst", .suites = fst_suites }; + TestModule coord = { .name = "coord", .suites = coord_suites }; TestModule *modules[999] = { &fst, + &coord, NULL }; -- cgit v1.3