diff --git a/src/test/comparison/comparison.c b/src/test/comparison/comparison.c index 57c03ec..c6d12d4 100644 --- a/src/test/comparison/comparison.c +++ b/src/test/comparison/comparison.c @@ -12,38 +12,35 @@ int comparisonTest(char* name, int x, int y, int expected, int result) { } } -int runComparisonTests() { +void runComparisonTests() { printf("\nComparison Tests \n"); - int failed = 0; - failed += comparisonTest("==", 1, 1, 1, eq(1, 1)); - failed += comparisonTest("==", 1, 0, 0, eq(1, 0)); - failed += comparisonTest("==", 0, 1, 0, eq(0, 1)); - failed += comparisonTest("==", 0, 0, 1, eq(0, 0)); + comparisonTest("==", 1, 1, 1, eq(1, 1)); + comparisonTest("==", 1, 0, 0, eq(1, 0)); + comparisonTest("==", 0, 1, 0, eq(0, 1)); + comparisonTest("==", 0, 0, 1, eq(0, 0)); - failed += comparisonTest("!=", 1, 1, 0, neq(1, 1)); - failed += comparisonTest("!=", 1, 0, 1, neq(1, 0)); - failed += comparisonTest("!=", 0, 1, 1, neq(0, 1)); - failed += comparisonTest("!=", 0, 0, 0, neq(0, 0)); + comparisonTest("!=", 1, 1, 0, neq(1, 1)); + comparisonTest("!=", 1, 0, 1, neq(1, 0)); + comparisonTest("!=", 0, 1, 1, neq(0, 1)); + comparisonTest("!=", 0, 0, 0, neq(0, 0)); - failed += comparisonTest("<", 1, 1, 0, lt(1, 1)); - failed += comparisonTest("<", 1, 0, 0, lt(1, 0)); - failed += comparisonTest("<", 0, 1, 1, lt(0, 1)); - failed += comparisonTest("<", 0, 0, 0, lt(0, 0)); + comparisonTest("<", 1, 1, 0, lt(1, 1)); + comparisonTest("<", 1, 0, 0, lt(1, 0)); + comparisonTest("<", 0, 1, 1, lt(0, 1)); + comparisonTest("<", 0, 0, 0, lt(0, 0)); - failed += comparisonTest("<=", 1, 1, 1, lte(1, 1)); - failed += comparisonTest("<=", 1, 0, 0, lte(1, 0)); - failed += comparisonTest("<=", 0, 1, 1, lte(0, 1)); - failed += comparisonTest("<=", 0, 0, 1, lte(0, 0)); + comparisonTest("<=", 1, 1, 1, lte(1, 1)); + comparisonTest("<=", 1, 0, 0, lte(1, 0)); + comparisonTest("<=", 0, 1, 1, lte(0, 1)); + comparisonTest("<=", 0, 0, 1, lte(0, 0)); - failed += comparisonTest(">", 1, 1, 0, gt(1, 1)); - failed += comparisonTest(">", 1, 0, 1, gt(1, 0)); - failed += comparisonTest(">", 0, 1, 0, gt(0, 1)); - failed += comparisonTest(">", 0, 0, 0, gt(0, 0)); + comparisonTest(">", 1, 1, 0, gt(1, 1)); + comparisonTest(">", 1, 0, 1, gt(1, 0)); + comparisonTest(">", 0, 1, 0, gt(0, 1)); + comparisonTest(">", 0, 0, 0, gt(0, 0)); - failed += comparisonTest(">=", 1, 1, 1, gte(1, 1)); - failed += comparisonTest(">=", 1, 0, 1, gte(1, 0)); - failed += comparisonTest(">=", 0, 1, 0, gte(0, 1)); - failed += comparisonTest(">=", 0, 0, 1, gte(0, 0)); - - return failed; + comparisonTest(">=", 1, 1, 1, gte(1, 1)); + comparisonTest(">=", 1, 0, 1, gte(1, 0)); + comparisonTest(">=", 0, 1, 0, gte(0, 1)); + comparisonTest(">=", 0, 0, 1, gte(0, 0)); } \ No newline at end of file diff --git a/src/test/functionCall/functionCall.c b/src/test/functionCall/functionCall.c index decf48c..0ac208b 100644 --- a/src/test/functionCall/functionCall.c +++ b/src/test/functionCall/functionCall.c @@ -13,29 +13,27 @@ int argumentTest(char* name, int expected, int result) { } int runFunctionCallTests () { - int failed = 0; printf("\nFunction Call Tests \n"); // Checks that parameters are correctly passed from gcc to functions - failed += argumentTest("arg1(...args)", 1, arg1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); - failed += argumentTest("arg2(...args)", 2, arg2(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); - failed += argumentTest("arg3(...args)", 3, arg3(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); - failed += argumentTest("arg4(...args)", 4, arg4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); - failed += argumentTest("arg5(...args)", 5, arg5(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); - failed += argumentTest("arg6(...args)", 6, arg6(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); - failed += argumentTest("arg7(...args)", 7, arg7(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); - failed += argumentTest("arg8(...args)", 8, arg8(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); - failed += argumentTest("arg9(...args)", 9, arg9(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); - failed += argumentTest("arg10(...args)", 10, arg10(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + argumentTest("arg1(...args)", 1, arg1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + argumentTest("arg2(...args)", 2, arg2(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + argumentTest("arg3(...args)", 3, arg3(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + argumentTest("arg4(...args)", 4, arg4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + argumentTest("arg5(...args)", 5, arg5(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + argumentTest("arg6(...args)", 6, arg6(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + argumentTest("arg7(...args)", 7, arg7(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + argumentTest("arg8(...args)", 8, arg8(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + argumentTest("arg9(...args)", 9, arg9(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); + argumentTest("arg10(...args)", 10, arg10(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); // Checks that parameters are correctly passed from klang to functions - failed += argumentTest("get1(...args)", 1, get1()); - failed += argumentTest("get2(...args)", 2, get2()); - failed += argumentTest("get3(...args)", 3, get3()); - failed += argumentTest("get4(...args)", 4, get4()); - failed += argumentTest("get5(...args)", 5, get5()); - failed += argumentTest("get6(...args)", 6, get6()); - failed += argumentTest("get7(...args)", 7, get7()); - failed += argumentTest("get8(...args)", 8, get8()); - failed += argumentTest("get9(...args)", 9, get9()); - failed += argumentTest("get10(...args)", 10, get10()); - return failed; + argumentTest("get1(...args)", 1, get1()); + argumentTest("get2(...args)", 2, get2()); + argumentTest("get3(...args)", 3, get3()); + argumentTest("get4(...args)", 4, get4()); + argumentTest("get5(...args)", 5, get5()); + argumentTest("get6(...args)", 6, get6()); + argumentTest("get7(...args)", 7, get7()); + argumentTest("get8(...args)", 8, get8()); + argumentTest("get9(...args)", 9, get9()); + argumentTest("get10(...args)", 10, get10()); } \ No newline at end of file diff --git a/src/test/loop/loop.c b/src/test/loop/loop.c index 8de8840..57bb649 100644 --- a/src/test/loop/loop.c +++ b/src/test/loop/loop.c @@ -14,12 +14,10 @@ int loopTest(char* name, int x, int expected, int result) { int runLoopTests() { printf("\nLoop Tests \n"); - int failed = 0; - failed += loopTest("while", 5, 5, myWhile(5)); - failed += loopTest("doWhile", 0, 1, myDoWhile(0)); - failed += loopTest("doWhile", 1, 1, myDoWhile(1)); - failed += loopTest("for", 5, 5, myFor(5)); - failed += loopTest("for", 0, 0, myFor(0)); - - return failed; + + loopTest("while", 5, 5, myWhile(5)); + loopTest("doWhile", 0, 1, myDoWhile(0)); + loopTest("doWhile", 1, 1, myDoWhile(1)); + loopTest("for", 5, 5, myFor(5)); + loopTest("for", 0, 0, myFor(0)); } \ No newline at end of file diff --git a/src/test/math/math.c b/src/test/math/math.c index 174bcbd..9acd0ba 100644 --- a/src/test/math/math.c +++ b/src/test/math/math.c @@ -55,49 +55,46 @@ int math_testOneArg(char* name, int (*correctFunction)(int), int (*testFunction) } int runMathTests() { - int failed = 0; - printf("\nAddition Tests \n"); - failed += math_test("add", cAdd, add, 0, 0); - failed += math_test("add", cAdd, add, 1, 1); - failed += math_test("add", cAdd, add, 2, 0); - failed += math_test("add", cAdd, add, 1, 5); - failed += math_test("add", cAdd, add, -1, -1); + printf("\nAddition Tests \n"); + math_test("add", cAdd, add, 0, 0); + math_test("add", cAdd, add, 1, 1); + math_test("add", cAdd, add, 2, 0); + math_test("add", cAdd, add, 1, 5); + math_test("add", cAdd, add, -1, -1); printf("\nSubtraction Tests \n"); - failed += math_test("sub", cSub, sub, 0, 0); - failed += math_test("sub", cSub, sub, 1, 1); - failed += math_test("sub", cSub, sub, 2, 0); - failed += math_test("sub", cSub, sub, 1, 5); - failed += math_test("sub", cSub, sub, -1, -1); + math_test("sub", cSub, sub, 0, 0); + math_test("sub", cSub, sub, 1, 1); + math_test("sub", cSub, sub, 2, 0); + math_test("sub", cSub, sub, 1, 5); + math_test("sub", cSub, sub, -1, -1); printf("\nMultiplication Tests \n"); - failed += math_test("mul", cMul, mul, 0, 0); - failed += math_test("mul", cMul, mul, 1, 1); - failed += math_test("mul", cMul, mul, 2, 0); - failed += math_test("mul", cMul, mul, 1, 5); - failed += math_test("mul", cMul, mul, -1, -1); + math_test("mul", cMul, mul, 0, 0); + math_test("mul", cMul, mul, 1, 1); + math_test("mul", cMul, mul, 2, 0); + math_test("mul", cMul, mul, 1, 5); + math_test("mul", cMul, mul, -1, -1); printf("\nModulo Tests \n"); - failed += math_test("modulo", cModulo, modulo, 1, 1); - failed += math_test("modulo", cModulo, modulo, 1, 5); - failed += math_test("modulo", cModulo, modulo, -1, -1); - failed += math_test("modulo", cModulo, modulo, 1337, 42); + math_test("modulo", cModulo, modulo, 1, 1); + math_test("modulo", cModulo, modulo, 1, 5); + math_test("modulo", cModulo, modulo, -1, -1); + math_test("modulo", cModulo, modulo, 1337, 42); printf("\nNegative Tests\n"); - failed += math_testOneArg("neg", cNeg, neg, 0); - failed += math_testOneArg("neg", cNeg, neg, 1); - failed += math_testOneArg("neg", cNeg, neg, -1); + math_testOneArg("neg", cNeg, neg, 0); + math_testOneArg("neg", cNeg, neg, 1); + math_testOneArg("neg", cNeg, neg, -1); printf("\nIdentity Tests\n"); - failed += math_testOneArg("id", cId, id, 0); - failed += math_testOneArg("id", cId, id, -1); - failed += math_testOneArg("id", cId, id, 15); + math_testOneArg("id", cId, id, 0); + math_testOneArg("id", cId, id, -1); + math_testOneArg("id", cId, id, 15); printf("\nMisc Tests\n"); - failed += math_testOneArg("selfMinus", cSelfMinus, selfMinus, 5); - failed += math_testOneArg("selfMinus", cSelfMinus, selfMinus, 0); - failed += math_testOneArg("selfMinus", cSelfMinus, selfMinus, 100); - failed += math_testOneArg("selfMinus", cSelfMinus, selfMinus, -50); - - return failed; + math_testOneArg("selfMinus", cSelfMinus, selfMinus, 5); + math_testOneArg("selfMinus", cSelfMinus, selfMinus, 0); + math_testOneArg("selfMinus", cSelfMinus, selfMinus, 100); + math_testOneArg("selfMinus", cSelfMinus, selfMinus, -50); } \ No newline at end of file diff --git a/src/test/print/print.c b/src/test/print/print.c index a8e43bb..511a67e 100644 --- a/src/test/print/print.c +++ b/src/test/print/print.c @@ -2,33 +2,41 @@ #include "print.h" void succInfixTwo(char* name, int x, int y, int expected, int result) { + incSuccess(); printf("\033[0;32mSUCCESS:\t%d %s %d\tGOT: %d\tExpected: %d\033[0;0m\n", x, name, y, result, expected); } void errInfixTwo(char* name, int x, int y, int expected, int result) { + incFailure(); printf("\033[0;31mERROR:\t\t%d %s %d\tGOT: %d\tExpected: %d\033[0;0m\n", x, name, y, result, expected); } void succ(char* name, int expected, int result) { + incSuccess(); printf("\033[0;32mSUCCESS:\t%s:\tGOT: %d\tExpected: %d\033[0;0m\n", name, result, expected); } void err(char* name, int expected, int result) { + incFailure(); printf("\033[0;31mERROR:\t\t%s:\tGOT: %d\tExpected: %d\033[0;0m\n", name, result, expected); } void succPrefixOne(char* name, int x, int expected, int result) { + incSuccess(); printf("\033[0;32mSUCCESS:\t%s(%d)\tGOT: %d\tExpected: %d\033[0;0m\n", name, x, result, expected); } void errPrefixOne(char* name, int x, int expected, int result) { + incFailure(); printf("\033[0;31mERROR:\t\t%s(%d)\tGOT: %d\tExpected: %d\033[0;0m\n", name, x, result, expected); } void succPrefixTwo(char* name, int x, int y, int expected, int result) { + incSuccess(); printf("\033[0;32mSUCCESS:\t%s(%d, %d)\tGOT: %d\tExpected: %d\033[0;0m\n", name, x, y, result, expected); } void errPrefixTwo(char* name, int x, int y, int expected, int result) { + incFailure(); printf("\033[0;31mERROR:\t\t%s(%d, %d)\tGOT: %d\tExpected: %d\033[0;0m\n", name, x, y, result, expected); } \ No newline at end of file diff --git a/src/test/print/print.h b/src/test/print/print.h index 1d874cb..d274b51 100644 --- a/src/test/print/print.h +++ b/src/test/print/print.h @@ -1,3 +1,6 @@ +void incSuccess(); +void incFailure(); + void succ(char* name, int expected, int result); void err(char* name, int expected, int result); diff --git a/src/test/recursive/recursive.c b/src/test/recursive/recursive.c index 045a800..61ee88c 100644 --- a/src/test/recursive/recursive.c +++ b/src/test/recursive/recursive.c @@ -14,8 +14,6 @@ int recursiveTest(char* name, int x, int expected, int result) { int runRecursiveTests() { printf("\nRecursive Tests \n"); - int failed = 0; - failed += recursiveTest("fac", 5, 120, fac(5)); - return failed; + recursiveTest("fac", 5, 120, fac(5)); } \ No newline at end of file diff --git a/src/test/test.c b/src/test/test.c index 9b8797a..b5f5589 100644 --- a/src/test/test.c +++ b/src/test/test.c @@ -2,29 +2,41 @@ #include #include "test.h" -int main(){ - int failed = 0; +int successes, failures = 0; +void incSuccess() { + successes += 1; +} + +void incFailure() { + failures += 1; +} + +int main(){ // Tests for various math related functions - failed += runMathTests(); + runMathTests(); // Tests for passing arguments to functions - failed += runFunctionCallTests(); + runFunctionCallTests(); // Tests for recursive funtions - failed += runRecursiveTests(); + runRecursiveTests(); // Tests for comparison expressions - failed += runComparisonTests(); + runComparisonTests(); // Tests for while loop - failed += runLoopTests(); + runLoopTests(); - printf("\n=== Failed Tests: %d\n", failed); + printf("\n%d tests in total\n", successes + failures); - if (failed > 0) { + if (failures > 0) { + printf("\033[0;31m%d tests were successful\033[0;0m\n", successes); + printf("\033[0;31m%d tests failed\033[0;0m\n", failures); return EXIT_FAILURE; } else { + printf("\033[0;32m%d tests were successful\033[0;0m\n", successes); + printf("\033[0;32m%d tests failed\033[0;0m\n", failures); return EXIT_SUCCESS; } } diff --git a/src/test/test.h b/src/test/test.h index bfccf4b..be87439 100644 --- a/src/test/test.h +++ b/src/test/test.h @@ -2,8 +2,8 @@ Alle Test Module */ -int runFunctionCallTests(); -int runRecursiveTests(); -int runComparisonTests(); -int runLoopTests(); -int runMathTests(); \ No newline at end of file +void runFunctionCallTests(); +void runRecursiveTests(); +void runComparisonTests(); +void runLoopTests(); +void runMathTests(); \ No newline at end of file