diff options
| -rw-r--r-- | Makefile | 7 | ||||
| -rw-r--r-- | src/shell.c | 14 | ||||
| -rwxr-xr-x | test.sh | 1 | ||||
| -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 |
8 files changed, 85 insertions, 80 deletions
| @@ -13,7 +13,6 @@ DBGFLAGS = -std=c99 -pthread -pedantic -Wall -Wextra \ | |||
| 13 | 13 | ||
| 14 | CC = cc | 14 | CC = cc |
| 15 | 15 | ||
| 16 | |||
| 17 | all: nissy | 16 | all: nissy |
| 18 | 17 | ||
| 19 | nissy: clean | 18 | nissy: clean |
| @@ -25,6 +24,9 @@ nissy.exe: | |||
| 25 | debug: | 24 | debug: |
| 26 | ${CC} ${DBGFLAGS} -o nissy src/*.c | 25 | ${CC} ${DBGFLAGS} -o nissy src/*.c |
| 27 | 26 | ||
| 27 | test: | ||
| 28 | ${CC} ${CFLAGS} -DTEST -o tests/nissy_test src/*.c tests/*.c | ||
| 29 | |||
| 28 | clean: | 30 | clean: |
| 29 | rm -rf nissy nissy*.exe nissy*.tar.gz doc/nissy.html doc/nissy.pdf | 31 | rm -rf nissy nissy*.exe nissy*.tar.gz doc/nissy.html doc/nissy.pdf |
| 30 | 32 | ||
| @@ -63,5 +65,4 @@ uninstall: | |||
| 63 | rm -rf ${DESTDIR}${PREFIX}/bin/nissy ${DESTDIR}${MANPREFIX}/man1/nissy.1 | 65 | rm -rf ${DESTDIR}${PREFIX}/bin/nissy ${DESTDIR}${MANPREFIX}/man1/nissy.1 |
| 64 | for s in ${SCRIPTS}; do rm -rf ${DESTDIR}${PREFIX}/bin/$$s; done | 66 | for s in ${SCRIPTS}; do rm -rf ${DESTDIR}${PREFIX}/bin/$$s; done |
| 65 | 67 | ||
| 66 | .PHONY: all debug clean dist install test uninstall upload | 68 | .PHONY: all debug test clean dist install uninstall upload |
| 67 | |||
diff --git a/src/shell.c b/src/shell.c index c25b399..4faa0a8 100644 --- a/src/shell.c +++ b/src/shell.c | |||
| @@ -151,20 +151,6 @@ main(int argc, char *argv[]) | |||
| 151 | init_env(); | 151 | init_env(); |
| 152 | init_trans(); | 152 | init_trans(); |
| 153 | 153 | ||
| 154 | /* | ||
| 155 | Cube c; | ||
| 156 | make_solved(&c); | ||
| 157 | c.co[0] = 1; | ||
| 158 | c.co[6] = 2; | ||
| 159 | print_cube(&c); | ||
| 160 | apply_trans(uf_mirror, &c); | ||
| 161 | print_cube(&c); | ||
| 162 | */ | ||
| 163 | |||
| 164 | /* | ||
| 165 | test_coord(&coord_coud_cpudsep); | ||
| 166 | */ | ||
| 167 | |||
| 168 | if (!checkfiles()) { | 154 | if (!checkfiles()) { |
| 169 | fprintf(stderr, | 155 | fprintf(stderr, |
| 170 | "--- Warning ---\n" | 156 | "--- Warning ---\n" |
| @@ -11,6 +11,7 @@ test_module() { | |||
| 11 | done | 11 | done |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | make test | ||
| 14 | if [ -n "$@" ]; then | 15 | if [ -n "$@" ]; then |
| 15 | test_module $@ | 16 | test_module $@ |
| 16 | else | 17 | else |
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 | ||
