/// make check, mostly tests for the wrapping helpers #include #include #include #include "field.h" #include "config.h" #include "debug.h" #include "random.h" #include "stringio.h" #include "level.h" #include "lists.h" #include "engine.h" /* a parameter for optimize/optimize.py, no effect guaranteed :) */ #define NONSENSE_ /*!TRY: 1 2 3*/NONSENSE #ifndef DEBUG int tests() { fprintf(stderr, "Compiled without -DDEBUG, self-checks not available.\n"); exit(2); } #else int tests_failed=0; int tests_done=0; #define test(cond, comment) do_test(cond, comment, __FILE__, __LINE__) int do_test(int cond, char * comment, char * file, int line) { tests_done++; if (cond) { fprintf(stderr, "OK: %s\n", comment); } else { fprintf(stderr, "%s:%d: FAILED: %s\n", file, line, comment); tests_failed++; } return cond; } void TestInfo() { printf("sizeof(Mass) = %d\n", sizeof(Mass)); } void TestRandom() { int i, small; randareaseed(300); test(randarea(1, 353) == 44, "Predictable randarea1"); test(randarea(-11, 17) == 1, "Predictable randarea2"); for (i=0, small=0; i<200; i++) if (synced_random() < 0) small++; test(small == 0, "Strict positive synced_random"); } void Test_Parser() { } int tests() { /* stderr because mass debug messages go to stdout */ fprintf(stderr, "Doing some self-checks.\n"); TestInfo(); TestMath2d(); TestFieldwrap(); TestFieldcells(); TestStringio(); TestLevel(); TestRandom(); TestLists(); /* summary */ if (!tests_failed) { fprintf(stderr, "All %d tests succeeded.\n", tests_done); } else { fprintf(stderr, "%d tests of %d failed.\n", tests_failed, tests_done); } exit(tests_failed); } #endif // debugging enabled