|
|
#ifdef TEST
#include "unity.h"
#include "inputHandling.h"
char halloWelt[]="Hallo Welt"; char halloWelt2[]="Hallo Welt"; char halloWelt3[]="Ha llo W el t "; char halloWelt4[]="Ha\n\nllo \r W el\r\r t "; calc_op formula = {0};
void setUp(void) { formula.functionsType = opNotSupported; }
void tearDown(void) { }
void test_inputHandling_deleteOneWhiteSpace(void) { deleteWhitespace(halloWelt, 10); TEST_ASSERT_EQUAL_STRING("HalloWelt", halloWelt); }
void test_inputHandling_deleteTwoWhiteSpaces(void) { deleteWhitespace(halloWelt2, 11); TEST_ASSERT_EQUAL_STRING("HalloWelt", halloWelt2); }
void test_inputHandling_deleteManyWhiteSpaces(void) { deleteWhitespace(halloWelt3, 16); TEST_ASSERT_EQUAL_STRING("HalloWelt", halloWelt3); }
void test_inputHandling_deleteAllOtherCharacter(void) { deleteWhitespace(halloWelt4, 19); TEST_ASSERT_EQUAL_STRING("HalloWelt", halloWelt4); }
void test_inputHandling_findAddFunctionType(void) { op type = opNotSupported; type = detectFunctionOperator("4+5", 3); TEST_ASSERT_TRUE(opAdd == type); }
void test_inputHandling_findSubFunctionType(void) { op type = opNotSupported; type = detectFunctionOperator("4-5", 3); TEST_ASSERT_TRUE(opSub == type); }
void test_inputHandling_findMultiFunctionType(void) { op type = opNotSupported; type = detectFunctionOperator("4*5", 3); TEST_ASSERT_TRUE(opMult == type); }
void test_inputHandling_findDivFunctionType(void) { op type = opNotSupported; type = detectFunctionOperator("4/5", 3); TEST_ASSERT_TRUE(opDiv == type); type = opNotSupported; type = detectFunctionOperator("4:5", 3); TEST_ASSERT_TRUE(opDiv == type); }
void test_inputHandling_findExpFunctionType(void) { op type = opNotSupported; type = detectFunctionOperator("4^5", 3); TEST_ASSERT_TRUE(opExp == type); }
void test_inputHandling_findEmptyFunctionType(void) { op type = opNotSupported; type = detectFunctionOperator(halloWelt, 10); TEST_ASSERT_TRUE(opEmpty == type); }
void test_inputHandling_getNumbersNoFormular(void) { char* pnt = NULL; pnt = getNumbers(halloWelt, 10, &formula); TEST_ASSERT_NULL(pnt); }
void test_inputHandling_getNumbersAddFormular(void) { char* pnt = NULL; char add[] = "4+5"; formula.functionsType = detectFunctionOperator(add,3); TEST_ASSERT_TRUE(formula.functionsType == opAdd); pnt = getNumbers(add, 3, &formula); showStruct(&formula); TEST_ASSERT_NULL(pnt); TEST_ASSERT_EQUAL_DOUBLE(4.0, formula.inputNumbers[0]); TEST_ASSERT_EQUAL_DOUBLE(5.0, formula.inputNumbers[1]); TEST_ASSERT_EQUAL_INT(2, formula.arrayLength); }
void test_inputHandling_getNumbersSubFormular(void) { char* pnt = NULL; char sub[] = "4-5"; formula.functionsType = detectFunctionOperator(sub,3); TEST_ASSERT_TRUE(formula.functionsType == opSub); pnt = getNumbers(sub, 3, &formula); showStruct(&formula); TEST_ASSERT_NULL(pnt); TEST_ASSERT_EQUAL_DOUBLE(4.0, formula.inputNumbers[0]); TEST_ASSERT_EQUAL_DOUBLE(5.0, formula.inputNumbers[1]); TEST_ASSERT_EQUAL_INT(2, formula.arrayLength); }
void test_inputHandling_getNumbersMultiFormular(void) { char* pnt = NULL; char multi[] = "4*5"; formula.functionsType = detectFunctionOperator(multi,3); TEST_ASSERT_TRUE(formula.functionsType == opMult); pnt = getNumbers(multi, 3, &formula); showStruct(&formula); TEST_ASSERT_NULL(pnt); TEST_ASSERT_EQUAL_DOUBLE(4.0, formula.inputNumbers[0]); TEST_ASSERT_EQUAL_DOUBLE(5.0, formula.inputNumbers[1]); TEST_ASSERT_EQUAL_INT(2, formula.arrayLength); }
void test_inputHandling_getNumbersDivFormular(void) { char* pnt = NULL; char div[] = "4/5"; formula.functionsType = detectFunctionOperator(div,3); TEST_ASSERT_TRUE(formula.functionsType == opDiv); pnt = getNumbers(div, 3, &formula); showStruct(&formula); TEST_ASSERT_NULL(pnt); TEST_ASSERT_EQUAL_DOUBLE(4.0, formula.inputNumbers[0]); TEST_ASSERT_EQUAL_DOUBLE(5.0, formula.inputNumbers[1]); TEST_ASSERT_EQUAL_INT(2, formula.arrayLength); } #endif // TEST
|