diff options
Diffstat (limited to '')
| -rw-r--r-- | tests/fst_tests.c | 48 | ||||
| -rw-r--r-- | tests/fst_tests.h | 54 | ||||
| -rw-r--r-- | tests/test.c | 6 | ||||
| -rw-r--r-- | tests/test.h | 16 | ||||
| -rw-r--r-- | tests/test_common.h | 19 |
5 files changed, 80 insertions, 63 deletions
diff --git a/tests/fst_tests.c b/tests/fst_tests.c index 14aee1c..493f628 100644 --- a/tests/fst_tests.c +++ b/tests/fst_tests.c | |||
| @@ -1,5 +1,10 @@ | |||
| 1 | #include "fst_tests.h" | 1 | #include "fst_tests.h" |
| 2 | 2 | ||
| 3 | static bool testmethod_fst_is_consistent(void *); | ||
| 4 | static bool testmethod_cube_to_fst_to_cube(void *); | ||
| 5 | static bool testmethod_fst_move(void *); | ||
| 6 | static bool testmethod_fst_inverse(void *); | ||
| 7 | |||
| 3 | static bool check_equal_and_log(Cube *, Cube *); | 8 | static bool check_equal_and_log(Cube *, Cube *); |
| 4 | static void void_to_cube(void *, Cube *); | 9 | static void void_to_cube(void *, Cube *); |
| 5 | 10 | ||
| @@ -18,6 +23,49 @@ char *algs[] = { | |||
| 18 | NULL, | 23 | NULL, |
| 19 | }; | 24 | }; |
| 20 | 25 | ||
| 26 | Test test_fst_is_consistent = { | ||
| 27 | .name = "Consitency of FST (converted from cube)", | ||
| 28 | .t = testmethod_fst_is_consistent, | ||
| 29 | .cases = (void **)algs, | ||
| 30 | }; | ||
| 31 | Test test_cube_to_fst_to_cube = { | ||
| 32 | .name = "Cube to FST to cube", | ||
| 33 | .t = testmethod_cube_to_fst_to_cube, | ||
| 34 | .cases = (void **)algs, | ||
| 35 | }; | ||
| 36 | Test test_fst_move = { | ||
| 37 | .name = "FST move", | ||
| 38 | .t = testmethod_fst_move, | ||
| 39 | .cases = (void **)algs, | ||
| 40 | }; | ||
| 41 | Test test_fst_inverse = { | ||
| 42 | .name = "FST inverse", | ||
| 43 | .t = testmethod_fst_inverse, | ||
| 44 | .cases = (void **)algs, | ||
| 45 | }; | ||
| 46 | |||
| 47 | Test *pre_init[] = { | ||
| 48 | &test_fst_is_consistent, | ||
| 49 | &test_cube_to_fst_to_cube, | ||
| 50 | NULL | ||
| 51 | }; | ||
| 52 | TestSuite fst_pre_init_suite = { | ||
| 53 | .setup = NULL, | ||
| 54 | .tests = pre_init, | ||
| 55 | .teardown = NULL, | ||
| 56 | }; | ||
| 57 | |||
| 58 | Test *post_init[] = { | ||
| 59 | &test_fst_move, | ||
| 60 | &test_fst_inverse, | ||
| 61 | NULL | ||
| 62 | }; | ||
| 63 | TestSuite fst_post_init_suite = { | ||
| 64 | .setup = init_fst, | ||
| 65 | .tests = post_init, | ||
| 66 | .teardown = NULL, | ||
| 67 | }; | ||
| 68 | |||
| 21 | static bool | 69 | static bool |
| 22 | check_equal_and_log(Cube *c, Cube *d) | 70 | check_equal_and_log(Cube *c, Cube *d) |
| 23 | { | 71 | { |
diff --git a/tests/fst_tests.h b/tests/fst_tests.h index 2e11069..3a7496e 100644 --- a/tests/fst_tests.h +++ b/tests/fst_tests.h | |||
| @@ -2,56 +2,16 @@ | |||
| 2 | #define FST_TESTS_H | 2 | #define FST_TESTS_H |
| 3 | 3 | ||
| 4 | #include "../src/fst.h" | 4 | #include "../src/fst.h" |
| 5 | #include "test.h" | 5 | #include "test_common.h" |
| 6 | |||
| 7 | bool testmethod_fst_is_consistent(void *); | ||
| 8 | bool testmethod_cube_to_fst_to_cube(void *); | ||
| 9 | bool testmethod_fst_move(void *); | ||
| 10 | bool testmethod_fst_inverse(void *); | ||
| 11 | 6 | ||
| 12 | extern char *algs[]; | 7 | extern char *algs[]; |
| 13 | 8 | ||
| 14 | Test test_fst_is_consistent = { | 9 | extern Test test_fst_is_consistent; |
| 15 | .name = "Consitency of FST (converted from cube)", | 10 | extern Test test_cube_to_fst_to_cube; |
| 16 | .t = testmethod_fst_is_consistent, | 11 | extern Test test_fst_move; |
| 17 | .cases = (void **)algs, | 12 | extern Test test_fst_inverse; |
| 18 | }; | ||
| 19 | Test test_cube_to_fst_to_cube = { | ||
| 20 | .name = "Cube to FST to cube", | ||
| 21 | .t = testmethod_cube_to_fst_to_cube, | ||
| 22 | .cases = (void **)algs, | ||
| 23 | }; | ||
| 24 | Test test_fst_move = { | ||
| 25 | .name = "FST move", | ||
| 26 | .t = testmethod_fst_move, | ||
| 27 | .cases = (void **)algs, | ||
| 28 | }; | ||
| 29 | Test test_fst_inverse = { | ||
| 30 | .name = "FST inverse", | ||
| 31 | .t = testmethod_fst_inverse, | ||
| 32 | .cases = (void **)algs, | ||
| 33 | }; | ||
| 34 | |||
| 35 | Test *pre_init[] = { | ||
| 36 | &test_fst_is_consistent, | ||
| 37 | &test_cube_to_fst_to_cube, | ||
| 38 | NULL | ||
| 39 | }; | ||
| 40 | TestSuite fst_pre_init_suite = { | ||
| 41 | .setup = NULL, | ||
| 42 | .tests = pre_init, | ||
| 43 | .teardown = NULL, | ||
| 44 | }; | ||
| 45 | 13 | ||
| 46 | Test *post_init[] = { | 14 | extern TestSuite fst_pre_init_suite; |
| 47 | &test_fst_move, | 15 | extern TestSuite fst_post_init_suite; |
| 48 | &test_fst_inverse, | ||
| 49 | NULL | ||
| 50 | }; | ||
| 51 | TestSuite fst_post_init_suite = { | ||
| 52 | .setup = init_fst, | ||
| 53 | .tests = post_init, | ||
| 54 | .teardown = NULL, | ||
| 55 | }; | ||
| 56 | 16 | ||
| 57 | #endif | 17 | #endif |
diff --git a/tests/test.c b/tests/test.c index c122db8..2055c78 100644 --- a/tests/test.c +++ b/tests/test.c | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | #include <stdio.h> | 1 | #include "test.h" |
| 2 | #include "fst_tests.h" | ||
| 3 | 2 | ||
| 4 | static bool run_test(Test *); | 3 | static bool run_test(Test *); |
| 5 | static bool run_suite(TestSuite *); | 4 | static bool run_suite(TestSuite *); |
| @@ -38,6 +37,9 @@ run_suite(TestSuite *suite) | |||
| 38 | } | 37 | } |
| 39 | 38 | ||
| 40 | int main() { | 39 | int main() { |
| 40 | init_env(); | ||
| 41 | init_trans(); | ||
| 42 | |||
| 41 | if (!run_suite(&fst_pre_init_suite)) | 43 | if (!run_suite(&fst_pre_init_suite)) |
| 42 | return 1; | 44 | return 1; |
| 43 | if (!run_suite(&fst_post_init_suite)) | 45 | if (!run_suite(&fst_post_init_suite)) |
diff --git a/tests/test.h b/tests/test.h index 665127c..ac30cdb 100644 --- a/tests/test.h +++ b/tests/test.h | |||
| @@ -1,19 +1,7 @@ | |||
| 1 | #ifndef TEST_H | 1 | #ifndef TEST_H |
| 2 | #define TEST_H | 2 | #define TEST_H |
| 3 | 3 | ||
| 4 | typedef void (*VoidMethod)(void); | 4 | #include <stdio.h> |
| 5 | typedef bool (*TestMethod)(void *); | 5 | #include "fst_tests.h" |
| 6 | |||
| 7 | typedef struct { | ||
| 8 | char * name; | ||
| 9 | TestMethod t; | ||
| 10 | void ** cases; | ||
| 11 | } Test; | ||
| 12 | |||
| 13 | typedef struct { | ||
| 14 | VoidMethod setup; | ||
| 15 | Test ** tests; | ||
| 16 | VoidMethod teardown; | ||
| 17 | } TestSuite; | ||
| 18 | 6 | ||
| 19 | #endif | 7 | #endif |
diff --git a/tests/test_common.h b/tests/test_common.h new file mode 100644 index 0000000..ea35ecd --- /dev/null +++ b/tests/test_common.h | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | #ifndef TEST_COMMON_H | ||
| 2 | #define TEST_COMMON_H | ||
| 3 | |||
| 4 | typedef void (*VoidMethod)(void); | ||
| 5 | typedef bool (*TestMethod)(void *); | ||
| 6 | |||
| 7 | typedef struct { | ||
| 8 | char * name; | ||
| 9 | TestMethod t; | ||
| 10 | void ** cases; | ||
| 11 | } Test; | ||
| 12 | |||
| 13 | typedef struct { | ||
| 14 | VoidMethod setup; | ||
| 15 | Test ** tests; | ||
| 16 | VoidMethod teardown; | ||
| 17 | } TestSuite; | ||
| 18 | |||
| 19 | #endif | ||
