nissy

Where is nissy?
git clone https://git.tronto.net/nissy
Download | Log | Files | Refs | README

commit 455c7d9c8185acdd8c8fe74ad4a59a3e0756d75d
parent 092270834eac54ed33e634494f9f38ba7fd38fd4
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sat,  4 Feb 2023 18:00:31 +0100

Moved coordinate index consistency test to tests folder

Diffstat:
MTODO/refactoring.md | 2++
Msrc/coord.c | 37++++---------------------------------
Msrc/coord.h | 27++++++++++++++++++++++++++-
Atests/coord_tests.c | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/coord_tests.h | 13+++++++++++++
Mtests/fst_tests.c | 13+++++++------
Mtests/fst_tests.h | 2+-
Mtests/test.c | 5++++-
8 files changed, 107 insertions(+), 42 deletions(-)

diff --git a/TODO/refactoring.md b/TODO/refactoring.md @@ -25,4 +25,6 @@ * Sort function implementations alphabetically, ignore static vs non static. * Rename functions and variable to have a consistent naming scheme. * Functions that copy data: swap src and dest, follow memcpy standard. +* The way coord uses define guards to organize the .h file is good, apply it + to other modules too - including tests. * Read style(9) and decide what to implement. diff --git a/src/coord.c b/src/coord.c @@ -2,9 +2,6 @@ #include "coord.h" -static uint64_t indexers_getind(Indexer **is, Cube *c); -static uint64_t indexers_getmax(Indexer **is); -static void indexers_makecube(Indexer **is, uint64_t ind, Cube *c); static void gen_coord_comp(Coordinate *coord); static void gen_coord_sym(Coordinate *coord); static bool read_coord_mtable(Coordinate *coord); @@ -169,7 +166,7 @@ invindex_eposepe(uint64_t ind, Cube *cube) /* Other local functions *****************************************************/ -static uint64_t +uint64_t indexers_getmax(Indexer **is) { int i; @@ -181,7 +178,7 @@ indexers_getmax(Indexer **is) return max; } -static uint64_t +uint64_t indexers_getind(Indexer **is, Cube *c) { int i; @@ -195,12 +192,12 @@ indexers_getind(Indexer **is, Cube *c) return max; } -static void +void indexers_makecube(Indexer **is, uint64_t ind, Cube *c) { /* Warning: anti-indexers are applied in the same order as indexers. */ /* We assume order does not matter, but it would make more sense to */ - /* Apply them in reverse. */ + /* apply them in reverse. */ int i; uint64_t m; @@ -629,32 +626,6 @@ move_coord(Coordinate *coord, Move m, uint64_t ind, Trans *offtrans) return coord->max; /* Only reached in case of error */ } -bool -test_coord(Coordinate *coord) -{ - uint64_t ui, uj; - Cube c; - - if (coord->type != COMP_COORD) { - fprintf(stderr, "Can only test COMP_COORD\n"); - return false; - } - - 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, "%s: error: %" PRIu64 " different" - " from %" PRIu64 "\n", coord->name, uj, ui); - return false; - } - } - - fprintf(stderr, "%s: test passed\n", coord->name); - return true; -} - uint64_t trans_coord(Coordinate *coord, Trans t, uint64_t ind) { diff --git a/src/coord.h b/src/coord.h @@ -6,9 +6,10 @@ void gen_coord(Coordinate *coord); uint64_t index_coord(Coordinate *coord, Cube *cube, Trans *offtrans); +uint64_t indexers_getind(Indexer **is, Cube *c); +void indexers_makecube(Indexer **is, uint64_t ind, Cube *c); uint64_t move_coord(Coordinate *coord, Move m, uint64_t ind, Trans *offtrans); -bool test_coord(Coordinate *coord); uint64_t trans_coord(Coordinate *coord, Trans t, uint64_t ind); /* Base coordinates and their index functions ********************************/ @@ -32,6 +33,8 @@ extern Coordinate coord_drud_sym16; extern Coordinate coord_drudfin_noE_sym16; extern Coordinate coord_nxopt31; +extern Coordinate *all_coordinates[]; + #else /* Indexers ******************************************************************/ @@ -228,6 +231,28 @@ coord_nxopt31 = { .base = {&coord_eofbepos_sym16, &coord_coud_cpudsep}, }; +/* All coordinates ***********************************************************/ + +Coordinate *all_coordinates[] = { + &coord_eofb, + &coord_coud, + &coord_cp, + &coord_cpudsep, + &coord_epos, + &coord_epe, + &coord_eposepe, + &coord_epud, + &coord_eofbepos, + &coord_coud_cpudsep, + &coord_eofbepos_sym16, + &coord_cp_sym16, + &coord_corners_sym16, + &coord_drud_sym16, + &coord_drudfin_noE_sym16, + &coord_nxopt31, + NULL +}; + #endif #endif diff --git a/tests/coord_tests.c 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 @@ -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 @@ -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 @@ -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 @@ -1,5 +1,6 @@ #include <stdio.h> +#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 };