diff --git a/lambda-test/avrjunit.h b/lambda-test/avrjunit.h index cfb844a..12a3b2b 100644 --- a/lambda-test/avrjunit.h +++ b/lambda-test/avrjunit.h @@ -4,9 +4,23 @@ * Created on: 06.03.2015 * Author: dode@luniks.net */ + +/** + * A test case with its name and pointer to the test function, + * which should return true on success and false on failure. + */ typedef struct { char* name; int (*test)(void); } test; +/** + * Runs the test cases in the given array and prints the results + * via USART in JUnit XML format, using the given test suite and + * test class names. The size of the array needs to be passed + * along. + * The printed JUnit XML can be read and written to a file + * on the receiving side with a command like: + * (stty sane; cat > tests.xml) < /dev/ttyUSB0 + */ void runTests(char* suite, char* class, test tests[], int count); diff --git a/lambda-test/lambda-test.c b/lambda-test/lambda-test.c index 832787d..077a6f1 100644 --- a/lambda-test/lambda-test.c +++ b/lambda-test/lambda-test.c @@ -5,40 +5,82 @@ * Author: dode@luniks.net * */ +#include #include +// #include #include "USART.h" #include "sensors.h" #include "avrjunit.h" +static const tableEntry testTable[] = { + {0, 0}, + {10, 10} +}; + +int testToLambdaValue(void) { + float lambda = toLambda(12); + + return lambda == 1.5; +} + +int testToLambdaInter(void) { + float lambda = toLambda(50); + + return round(lambda * 1000) == 1073; +} + int testToTempI(void) { int temp = toTempI(100); return temp == 20; } -int testToTempO0C(void) { +int testToTempOValue(void) { int temp = toTempO(454); return temp == 0; } -int testToTempO50C(void) { +int testToTempOInter(void) { int temp = toTempO(928); return temp == 50; } -int testToTempO100C(void) { - int temp = toTempO(1403); +int testLookupLinInterBelow(void) { + float value = lookupLinInter(-5, testTable, 2); - return temp == 100; + return value == 0; +} + +int testLookupLinInterAbove(void) { + float value = lookupLinInter(15, testTable, 2); + + return value == 10; +} + +int testLookupLinInterValue(void) { + float value = lookupLinInter(10, testTable, 2); + + return value == 10; +} + +int testLookupLinInterInter(void) { + float value = lookupLinInter(3, testTable, 2); + + return value == 3; } test tests[] = { - {"testToTempI", testToTempI}, - {"testToTempO0C", testToTempO0C}, - {"testToTempO50C", testToTempO50C}, - {"testToTempO100C", testToTempO100C} + {"testToLambdaValue", testToLambdaValue}, + {"testToLambdaInter", testToLambdaInter}, + {"testToTempI", testToTempI}, + {"testToTempOValue", testToTempOValue}, + {"testToTempOInter", testToTempOInter}, + {"testLookupLinInterValue", testLookupLinInterValue}, + {"testLookupLinInterInter", testLookupLinInterInter}, + {"testLookupLinInterBelow", testLookupLinInterBelow}, + {"testLookupLinInterAbove", testLookupLinInterAbove} }; int main(void) {