Created testsuite and makefile to run testsuite
This commit is contained in:
14
makefile
Normal file
14
makefile
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
.PHONY: clean
|
||||||
|
|
||||||
|
runTest: ./src/test/test
|
||||||
|
./src/test/test
|
||||||
|
|
||||||
|
./src/test/test: ./src/test/tests.s
|
||||||
|
gcc -o ./src/test/test ./src/test/tests.s ./src/test/functionCall/functionCall.c ./src/test/testCode.c
|
||||||
|
|
||||||
|
./src/test/tests.s:
|
||||||
|
java -cp target/klang-1.0-jar-with-dependencies.jar de.hsrm.compiler.Klang.Klang < ./src/test/tests.k > ./src/test/tests.s
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f ./src/test/tests.s
|
||||||
|
rm -f ./src/test/test
|
||||||
32
src/test/functionCall/functionCall.c
Normal file
32
src/test/functionCall/functionCall.c
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "functionCall.h"
|
||||||
|
|
||||||
|
void printArgSuccess(char* name, int expected, int result) {
|
||||||
|
printf("SUCCESS:\t%s(<argumentList>)\tGOT: %d\tExpected: %d\n", name, result, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printArgError(char* name, int expected, int result) {
|
||||||
|
printf("ERROR:\t\t%s(<argumentList>)\tGOT: %d\tExpected: %d\n", name, result, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
void argumentTest(char* name, int expected, int result) {
|
||||||
|
if (expected == result) {
|
||||||
|
printArgSuccess(name, expected, result);
|
||||||
|
} else {
|
||||||
|
printArgError(name, expected, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void runFunctionCallTests () {
|
||||||
|
printf("\nFunctionCallTests Tests \n");
|
||||||
|
argumentTest("arg1", 1, arg1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||||
|
argumentTest("arg2", 2, arg2(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||||
|
argumentTest("arg3", 3, arg3(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||||
|
argumentTest("arg4", 4, arg4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||||
|
argumentTest("arg5", 5, arg5(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||||
|
argumentTest("arg6", 6, arg6(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||||
|
argumentTest("arg7", 7, arg7(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||||
|
argumentTest("arg8", 8, arg8(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||||
|
argumentTest("arg9", 9, arg9(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||||
|
argumentTest("arg10", 10, arg10(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||||
|
}
|
||||||
10
src/test/functionCall/functionCall.h
Normal file
10
src/test/functionCall/functionCall.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
int arg1(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j);
|
||||||
|
int arg2(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j);
|
||||||
|
int arg3(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j);
|
||||||
|
int arg4(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j);
|
||||||
|
int arg5(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j);
|
||||||
|
int arg6(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j);
|
||||||
|
int arg7(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j);
|
||||||
|
int arg8(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j);
|
||||||
|
int arg9(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j);
|
||||||
|
int arg10(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j);
|
||||||
108
src/test/testCode.c
Normal file
108
src/test/testCode.c
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "tests.h"
|
||||||
|
#include "testCode.h"
|
||||||
|
|
||||||
|
int cAdd(int x, int y) {
|
||||||
|
return x + y;
|
||||||
|
}
|
||||||
|
int cSub(int x, int y) {
|
||||||
|
return x - y;
|
||||||
|
}
|
||||||
|
int cMul(int x, int y) {
|
||||||
|
return x * y;
|
||||||
|
}
|
||||||
|
int cModulo(int x, int y) {
|
||||||
|
return x % y;
|
||||||
|
}
|
||||||
|
int cNeg(int x) {
|
||||||
|
return -x;
|
||||||
|
}
|
||||||
|
int cId(int x) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
void printSuccess(char* name, int x, int y, int expected, int result) {
|
||||||
|
printf("SUCCESS:\t%s(%d, %d)\tGOT: %d\tExpected: %d\n", name, x, y, result, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printSuccessOneArg(char* name, int x, int expected, int result) {
|
||||||
|
printf("SUCCESS:\t%s(%d)\tGOT: %d\tExpected: %d\n", name, x, result, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printError(char* name, int x, int y, int expected, int result) {
|
||||||
|
printf("ERROR:\t\t%s(%d, %d)\tGOT: %d\tExpected: %d\n", name, x, y, result, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printErrorOneArg(char* name, int x, int expected, int result) {
|
||||||
|
printf("ERROR:\t\t%s(%d)\tGOT: %d\tExpected: %d\n", name, x, result, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testExpected(char* name, int x, int y, int expected, int result) {
|
||||||
|
if (expected == result) {
|
||||||
|
printSuccess(name, x, y, expected, result);
|
||||||
|
} else {
|
||||||
|
printError(name, x, y, expected, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void test(char* name, int (*correctFunction)(int, int), int (*testFunction)(int, int), int x, int y) {
|
||||||
|
int expected = correctFunction(x, y);
|
||||||
|
int result = testFunction(x, y);
|
||||||
|
testExpected(name, x, y, expected, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testOneArg(char* name, int (*correctFunction)(int), int (*testFunction)(int), int x) {
|
||||||
|
int expected = correctFunction(x);
|
||||||
|
int result = testFunction(x);
|
||||||
|
if (expected == result) {
|
||||||
|
printSuccessOneArg(name, x, expected, result);
|
||||||
|
} else {
|
||||||
|
printErrorOneArg(name, x, expected, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
printf("\nAddition Tests \n");
|
||||||
|
test("add", cAdd, add, 0, 0);
|
||||||
|
test("add", cAdd, add, 1, 1);
|
||||||
|
test("add", cAdd, add, 2, 0);
|
||||||
|
test("add", cAdd, add, 1, 5);
|
||||||
|
test("add", cAdd, add, -1, -1);
|
||||||
|
|
||||||
|
printf("\nSubtraction Tests \n");
|
||||||
|
test("sub", cSub, sub, 0, 0);
|
||||||
|
test("sub", cSub, sub, 1, 1);
|
||||||
|
test("sub", cSub, sub, 2, 0);
|
||||||
|
test("sub", cSub, sub, 1, 5);
|
||||||
|
test("sub", cSub, sub, -1, -1);
|
||||||
|
|
||||||
|
printf("\nMultiplication Tests \n");
|
||||||
|
test("mul", cMul, mul, 0, 0);
|
||||||
|
test("mul", cMul, mul, 1, 1);
|
||||||
|
test("mul", cMul, mul, 2, 0);
|
||||||
|
test("mul", cMul, mul, 1, 5);
|
||||||
|
test("mul", cMul, mul, -1, -1);
|
||||||
|
|
||||||
|
printf("\nModulo Tests \n");
|
||||||
|
test("modulo", cModulo, modulo, 1, 1);
|
||||||
|
test("modulo", cModulo, modulo, 1, 5);
|
||||||
|
test("modulo", cModulo, modulo, -1, -1);
|
||||||
|
test("modulo", cModulo, modulo, 1337, 42);
|
||||||
|
|
||||||
|
printf("\nNegative Tests\n");
|
||||||
|
testOneArg("neg", cNeg, neg, 0);
|
||||||
|
testOneArg("neg", cNeg, neg, 1);
|
||||||
|
testOneArg("neg", cNeg, neg, -1);
|
||||||
|
|
||||||
|
printf("\nIdentity Tests\n");
|
||||||
|
testOneArg("id", cId, id, 0);
|
||||||
|
testOneArg("id", cId, id, -1);
|
||||||
|
testOneArg("id", cId, id, 15);
|
||||||
|
|
||||||
|
printf("\nFunction Argument Tests\n");
|
||||||
|
runFunctionCallTests();
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
10
src/test/testCode.h
Normal file
10
src/test/testCode.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
Die nachfolgenden Funktionen werden später dazu gelinkt
|
||||||
|
Der Ursprung ist die tests.k Datei, dort sind diese Funktionen implementiert
|
||||||
|
*/
|
||||||
|
int add(int x, int y);
|
||||||
|
int sub(int x, int y);
|
||||||
|
int mul(int x, int y);
|
||||||
|
int modulo(int x, int y);
|
||||||
|
int neg(int x);
|
||||||
|
int id(int x);
|
||||||
5
src/test/tests.h
Normal file
5
src/test/tests.h
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
/*
|
||||||
|
Alle Test Module
|
||||||
|
*/
|
||||||
|
|
||||||
|
void runFunctionCallTests ();
|
||||||
58
src/test/tests.k
Normal file
58
src/test/tests.k
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
function add(x, y) {
|
||||||
|
return (x + y);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sub (x, y) {
|
||||||
|
return (x - y);
|
||||||
|
}
|
||||||
|
|
||||||
|
function mul(x, y) {
|
||||||
|
return (x * y);
|
||||||
|
}
|
||||||
|
|
||||||
|
function modulo(x, y) {
|
||||||
|
return (x % y);
|
||||||
|
}
|
||||||
|
|
||||||
|
function neg(x) {
|
||||||
|
return -x;
|
||||||
|
}
|
||||||
|
|
||||||
|
function id(x) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
function arg1(a, b, c, d, e, f, g, h, i ,j) {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
function arg2(a, b, c, d, e, f, g, h, i ,j) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
function arg3(a, b, c, d, e, f, g, h, i ,j) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
function arg4(a, b, c, d, e, f, g, h, i ,j) {
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
function arg5(a, b, c, d, e, f, g, h, i ,j) {
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
function arg6(a, b, c, d, e, f, g, h, i ,j) {
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
function arg7(a, b, c, d, e, f, g, h, i ,j) {
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
function arg8(a, b, c, d, e, f, g, h, i ,j) {
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
function arg9(a, b, c, d, e, f, g, h, i ,j) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
function arg10(a, b, c, d, e, f, g, h, i ,j) {
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
|
||||||
|
add(1, 1);
|
||||||
Reference in New Issue
Block a user