aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile7
-rw-r--r--src/shell.c14
-rwxr-xr-xtest.sh1
-rw-r--r--tests/fst_tests.c48
-rw-r--r--tests/fst_tests.h54
-rw-r--r--tests/test.c6
-rw-r--r--tests/test.h16
-rw-r--r--tests/test_common.h19
8 files changed, 85 insertions, 80 deletions
diff --git a/Makefile b/Makefile
index 46234d5..e187a56 100644
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,6 @@ DBGFLAGS = -std=c99 -pthread -pedantic -Wall -Wextra \
13 13
14CC = cc 14CC = cc
15 15
16
17all: nissy 16all: nissy
18 17
19nissy: clean 18nissy: clean
@@ -25,6 +24,9 @@ nissy.exe:
25debug: 24debug:
26 ${CC} ${DBGFLAGS} -o nissy src/*.c 25 ${CC} ${DBGFLAGS} -o nissy src/*.c
27 26
27test:
28 ${CC} ${CFLAGS} -DTEST -o tests/nissy_test src/*.c tests/*.c
29
28clean: 30clean:
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"
diff --git a/test.sh b/test.sh
index b7882a4..6a30344 100755
--- a/test.sh
+++ b/test.sh
@@ -11,6 +11,7 @@ test_module() {
11 done 11 done
12} 12}
13 13
14make test
14if [ -n "$@" ]; then 15if [ -n "$@" ]; then
15 test_module $@ 16 test_module $@
16else 17else
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
3static bool testmethod_fst_is_consistent(void *);
4static bool testmethod_cube_to_fst_to_cube(void *);
5static bool testmethod_fst_move(void *);
6static bool testmethod_fst_inverse(void *);
7
3static bool check_equal_and_log(Cube *, Cube *); 8static bool check_equal_and_log(Cube *, Cube *);
4static void void_to_cube(void *, Cube *); 9static void void_to_cube(void *, Cube *);
5 10
@@ -18,6 +23,49 @@ char *algs[] = {
18 NULL, 23 NULL,
19}; 24};
20 25
26Test test_fst_is_consistent = {
27 .name = "Consitency of FST (converted from cube)",
28 .t = testmethod_fst_is_consistent,
29 .cases = (void **)algs,
30};
31Test 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};
36Test test_fst_move = {
37 .name = "FST move",
38 .t = testmethod_fst_move,
39 .cases = (void **)algs,
40};
41Test test_fst_inverse = {
42 .name = "FST inverse",
43 .t = testmethod_fst_inverse,
44 .cases = (void **)algs,
45};
46
47Test *pre_init[] = {
48 &test_fst_is_consistent,
49 &test_cube_to_fst_to_cube,
50 NULL
51};
52TestSuite fst_pre_init_suite = {
53 .setup = NULL,
54 .tests = pre_init,
55 .teardown = NULL,
56};
57
58Test *post_init[] = {
59 &test_fst_move,
60 &test_fst_inverse,
61 NULL
62};
63TestSuite fst_post_init_suite = {
64 .setup = init_fst,
65 .tests = post_init,
66 .teardown = NULL,
67};
68
21static bool 69static bool
22check_equal_and_log(Cube *c, Cube *d) 70check_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
7bool testmethod_fst_is_consistent(void *);
8bool testmethod_cube_to_fst_to_cube(void *);
9bool testmethod_fst_move(void *);
10bool testmethod_fst_inverse(void *);
11 6
12extern char *algs[]; 7extern char *algs[];
13 8
14Test test_fst_is_consistent = { 9extern Test test_fst_is_consistent;
15 .name = "Consitency of FST (converted from cube)", 10extern Test test_cube_to_fst_to_cube;
16 .t = testmethod_fst_is_consistent, 11extern Test test_fst_move;
17 .cases = (void **)algs, 12extern Test test_fst_inverse;
18};
19Test 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};
24Test test_fst_move = {
25 .name = "FST move",
26 .t = testmethod_fst_move,
27 .cases = (void **)algs,
28};
29Test test_fst_inverse = {
30 .name = "FST inverse",
31 .t = testmethod_fst_inverse,
32 .cases = (void **)algs,
33};
34
35Test *pre_init[] = {
36 &test_fst_is_consistent,
37 &test_cube_to_fst_to_cube,
38 NULL
39};
40TestSuite fst_pre_init_suite = {
41 .setup = NULL,
42 .tests = pre_init,
43 .teardown = NULL,
44};
45 13
46Test *post_init[] = { 14extern TestSuite fst_pre_init_suite;
47 &test_fst_move, 15extern TestSuite fst_post_init_suite;
48 &test_fst_inverse,
49 NULL
50};
51TestSuite 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
4static bool run_test(Test *); 3static bool run_test(Test *);
5static bool run_suite(TestSuite *); 4static bool run_suite(TestSuite *);
@@ -38,6 +37,9 @@ run_suite(TestSuite *suite)
38} 37}
39 38
40int main() { 39int 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
4typedef void (*VoidMethod)(void); 4#include <stdio.h>
5typedef bool (*TestMethod)(void *); 5#include "fst_tests.h"
6
7typedef struct {
8 char * name;
9 TestMethod t;
10 void ** cases;
11} Test;
12
13typedef 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
4typedef void (*VoidMethod)(void);
5typedef bool (*TestMethod)(void *);
6
7typedef struct {
8 char * name;
9 TestMethod t;
10 void ** cases;
11} Test;
12
13typedef struct {
14 VoidMethod setup;
15 Test ** tests;
16 VoidMethod teardown;
17} TestSuite;
18
19#endif

Generated with cgit - Back to sebastiano.tronto.net