You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
4.4 KiB

11 months ago
11 months ago
11 months ago
  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "inputHandling.h"
  4. char halloWelt[]="Hallo Welt";
  5. char halloWelt2[]="Hallo Welt";
  6. char halloWelt3[]="Ha llo W el t ";
  7. char halloWelt4[]="Ha\n\nllo \r W el\r\r t ";
  8. calc_op formula = {0};
  9. void setUp(void)
  10. {
  11. formula.functionsType = opNotSupported;
  12. }
  13. void tearDown(void)
  14. {
  15. }
  16. void test_inputHandling_deleteOneWhiteSpace(void)
  17. {
  18. deleteWhitespace(halloWelt, 10);
  19. TEST_ASSERT_EQUAL_STRING("HalloWelt", halloWelt);
  20. }
  21. void test_inputHandling_deleteTwoWhiteSpaces(void)
  22. {
  23. deleteWhitespace(halloWelt2, 11);
  24. TEST_ASSERT_EQUAL_STRING("HalloWelt", halloWelt2);
  25. }
  26. void test_inputHandling_deleteManyWhiteSpaces(void)
  27. {
  28. deleteWhitespace(halloWelt3, 16);
  29. TEST_ASSERT_EQUAL_STRING("HalloWelt", halloWelt3);
  30. }
  31. void test_inputHandling_deleteAllOtherCharacter(void)
  32. {
  33. deleteWhitespace(halloWelt4, 19);
  34. TEST_ASSERT_EQUAL_STRING("HalloWelt", halloWelt4);
  35. }
  36. void test_inputHandling_findAddFunctionType(void)
  37. {
  38. op type = opNotSupported;
  39. type = detectFunctionOperator("4+5", 3);
  40. TEST_ASSERT_TRUE(opAdd == type);
  41. }
  42. void test_inputHandling_findSubFunctionType(void)
  43. {
  44. op type = opNotSupported;
  45. type = detectFunctionOperator("4-5", 3);
  46. TEST_ASSERT_TRUE(opSub == type);
  47. }
  48. void test_inputHandling_findMultiFunctionType(void)
  49. {
  50. op type = opNotSupported;
  51. type = detectFunctionOperator("4*5", 3);
  52. TEST_ASSERT_TRUE(opMult == type);
  53. }
  54. void test_inputHandling_findDivFunctionType(void)
  55. {
  56. op type = opNotSupported;
  57. type = detectFunctionOperator("4/5", 3);
  58. TEST_ASSERT_TRUE(opDiv == type);
  59. type = opNotSupported;
  60. type = detectFunctionOperator("4:5", 3);
  61. TEST_ASSERT_TRUE(opDiv == type);
  62. }
  63. void test_inputHandling_findExpFunctionType(void)
  64. {
  65. op type = opNotSupported;
  66. type = detectFunctionOperator("4^5", 3);
  67. TEST_ASSERT_TRUE(opExp == type);
  68. }
  69. void test_inputHandling_findEmptyFunctionType(void)
  70. {
  71. op type = opNotSupported;
  72. type = detectFunctionOperator(halloWelt, 10);
  73. TEST_ASSERT_TRUE(opEmpty == type);
  74. }
  75. void test_inputHandling_getNumbersNoFormular(void)
  76. {
  77. char* pnt = NULL;
  78. pnt = getNumbers(halloWelt, 10, &formula);
  79. TEST_ASSERT_NULL(pnt);
  80. }
  81. void test_inputHandling_getNumbersAddFormular(void)
  82. {
  83. char* pnt = NULL;
  84. char add[] = "4+5";
  85. formula.functionsType = detectFunctionOperator(add,3);
  86. TEST_ASSERT_TRUE(formula.functionsType == opAdd);
  87. pnt = getNumbers(add, 3, &formula);
  88. showStruct(&formula);
  89. TEST_ASSERT_NULL(pnt);
  90. TEST_ASSERT_EQUAL_DOUBLE(4.0, formula.inputNumbers[0]);
  91. TEST_ASSERT_EQUAL_DOUBLE(5.0, formula.inputNumbers[1]);
  92. TEST_ASSERT_EQUAL_INT(2, formula.arrayLength);
  93. }
  94. void test_inputHandling_getNumbersSubFormular(void)
  95. {
  96. char* pnt = NULL;
  97. char sub[] = "4-5";
  98. formula.functionsType = detectFunctionOperator(sub,3);
  99. TEST_ASSERT_TRUE(formula.functionsType == opSub);
  100. pnt = getNumbers(sub, 3, &formula);
  101. showStruct(&formula);
  102. TEST_ASSERT_NULL(pnt);
  103. TEST_ASSERT_EQUAL_DOUBLE(4.0, formula.inputNumbers[0]);
  104. TEST_ASSERT_EQUAL_DOUBLE(5.0, formula.inputNumbers[1]);
  105. TEST_ASSERT_EQUAL_INT(2, formula.arrayLength);
  106. }
  107. void test_inputHandling_getNumbersMultiFormular(void)
  108. {
  109. char* pnt = NULL;
  110. char multi[] = "4*5";
  111. formula.functionsType = detectFunctionOperator(multi,3);
  112. TEST_ASSERT_TRUE(formula.functionsType == opMult);
  113. pnt = getNumbers(multi, 3, &formula);
  114. showStruct(&formula);
  115. TEST_ASSERT_NULL(pnt);
  116. TEST_ASSERT_EQUAL_DOUBLE(4.0, formula.inputNumbers[0]);
  117. TEST_ASSERT_EQUAL_DOUBLE(5.0, formula.inputNumbers[1]);
  118. TEST_ASSERT_EQUAL_INT(2, formula.arrayLength);
  119. }
  120. void test_inputHandling_getNumbersDivFormular(void)
  121. {
  122. char* pnt = NULL;
  123. char div[] = "4/5";
  124. formula.functionsType = detectFunctionOperator(div,3);
  125. TEST_ASSERT_TRUE(formula.functionsType == opDiv);
  126. pnt = getNumbers(div, 3, &formula);
  127. showStruct(&formula);
  128. TEST_ASSERT_NULL(pnt);
  129. TEST_ASSERT_EQUAL_DOUBLE(4.0, formula.inputNumbers[0]);
  130. TEST_ASSERT_EQUAL_DOUBLE(5.0, formula.inputNumbers[1]);
  131. TEST_ASSERT_EQUAL_INT(2, formula.arrayLength);
  132. }
  133. void test_inputHandling_getNextCalc(void)
  134. {
  135. calc_op* pnt = NULL;
  136. char add[] = "4+5";
  137. processInput(add, 3);
  138. pnt = getNextCalc();
  139. TEST_ASSERT_NOT_NULL(pnt);
  140. TEST_ASSERT_TRUE(pnt->functionsType == opAdd);
  141. pnt = getNextCalc();
  142. TEST_ASSERT_NOT_NULL(pnt);
  143. TEST_ASSERT_TRUE(pnt->functionsType == opResult);
  144. pnt = getNextCalc();
  145. TEST_ASSERT_NULL(pnt);
  146. }
  147. #endif // TEST