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.

135 lines
3.9 KiB

  1. #ifdef TEST
  2. #include <stdbool.h>
  3. #include <stdio.h>
  4. #include "unity.h"
  5. #include "casualQuiz.h"
  6. // Test setup function
  7. void setUp(void) {
  8. }
  9. // Test teardown function
  10. void tearDown(void) {
  11. }
  12. void test_FcheckaufRichtigkeit_correct_answer_atIndex1(void){
  13. int TESTeingabe = 1;
  14. int TESTindex = 0;
  15. int TESTrichtige_antwort[]={1};
  16. bool testfall;
  17. char* TESTantworten[]= {"The End", "The Termination", "Pizza's ready", "Hotdog Time"};
  18. testfall = fcheckaufRichtigkeit(TESTeingabe, TESTantworten, TESTrichtige_antwort, TESTindex);
  19. TEST_ASSERT_TRUE(testfall == true);
  20. }
  21. void test_FcheckaufRichtigkeit_correct_answer_atIndex2(void){
  22. int TESTeingabe = 2;
  23. int TESTindex = 0;
  24. int TESTrichtige_antwort[]={2};
  25. bool testfall;
  26. char* TESTantworten[]= {"The End", "The Termination", "Pizza's ready", "Hotdog Time"};
  27. testfall = fcheckaufRichtigkeit(TESTeingabe, TESTantworten, TESTrichtige_antwort, TESTindex);
  28. TEST_ASSERT_TRUE(testfall == true);
  29. }
  30. void test_FcheckaufRichtigkeit_correct_answer_atIndex3(void){
  31. int TESTeingabe = 3;
  32. int TESTindex = 0;
  33. int TESTrichtige_antwort[]={3};
  34. bool testfall;
  35. char* TESTantworten[]= {"The End", "The Termination", "Pizza's ready", "Hotdog Time"};
  36. testfall = fcheckaufRichtigkeit(TESTeingabe, TESTantworten, TESTrichtige_antwort, TESTindex);
  37. TEST_ASSERT_TRUE(testfall == true);
  38. }void test_FcheckaufRichtigkeit_correct_answer_atIndex4(void){
  39. int TESTeingabe = 4;
  40. int TESTindex = 0;
  41. int TESTrichtige_antwort[]={4};
  42. bool testfall;
  43. char* TESTantworten[]= {"The End", "The Termination", "Pizza's ready", "Hotdog Time"};
  44. testfall = fcheckaufRichtigkeit(TESTeingabe, TESTantworten, TESTrichtige_antwort, TESTindex);
  45. TEST_ASSERT_TRUE(testfall == true);
  46. }
  47. void test_FcheckaufRichtigkeit_incorrect_input_higher(void){
  48. int TESTeingabe = 5;
  49. int TESTindex = 0;
  50. int TESTrichtige_antwort[]={3};
  51. bool testfall;
  52. char* TESTantworten[]= {"The End", "The Termination", "Pizza's ready", "Hotdog Time"};
  53. testfall = fcheckaufRichtigkeit(TESTeingabe, TESTantworten, TESTrichtige_antwort, TESTindex);
  54. TEST_ASSERT_TRUE(testfall != true);
  55. }
  56. void test_FcheckaufRichtigkeit_incorrect_input_lower(void){
  57. int TESTeingabe = -1;
  58. int TESTindex = 0;
  59. int TESTrichtige_antwort[]={3};
  60. bool testfall;
  61. char* TESTantworten[]= {"The End", "The Termination", "Pizza's ready", "Hotdog Time"};
  62. testfall = fcheckaufRichtigkeit(TESTeingabe, TESTantworten, TESTrichtige_antwort, TESTindex);
  63. TEST_ASSERT_TRUE(testfall != true);
  64. }
  65. void test_FzaehlernachAuswahl(void){
  66. bool richtig = true;
  67. int correct = 0;
  68. int answered = 0;
  69. int* correctP = &correct;
  70. int* answeredP = &answered;
  71. fzaehlernachAuswahl(richtig, answeredP, correctP);
  72. TEST_ASSERT_EQUAL_INT(1, correct);
  73. TEST_ASSERT_EQUAL_INT(1, answered);
  74. }
  75. void test_FzaehlernachAuswahl_bei1(void){
  76. bool richtig = true;
  77. int correct = 1;
  78. int answered = 1;
  79. int* correctP = &correct;
  80. int* answeredP = &answered;
  81. fzaehlernachAuswahl(richtig, answeredP, correctP);
  82. TEST_ASSERT_EQUAL_INT(2, correct);
  83. TEST_ASSERT_EQUAL_INT(2, answered);
  84. }
  85. void test_FzaehlernachAuswahl_falsch_bei_0(void){
  86. bool richtig = false;
  87. int correct = 0;
  88. int answered = 0;
  89. int* correctP = &correct;
  90. int* answeredP = &answered;
  91. fzaehlernachAuswahl(richtig, answeredP, correctP);
  92. TEST_ASSERT_EQUAL_INT(0, correct);
  93. TEST_ASSERT_EQUAL_INT(1, answered);
  94. }
  95. void test_FzaehlernachAuswahl_falsch_bei_1(void){
  96. bool richtig = false;
  97. int correct = 1;
  98. int answered = 1;
  99. int* correctP = &correct;
  100. int* answeredP = &answered;
  101. fzaehlernachAuswahl(richtig, answeredP, correctP);
  102. TEST_ASSERT_EQUAL_INT(1, correct);
  103. TEST_ASSERT_EQUAL_INT(2, answered);
  104. }
  105. void test_FtryAgain_butalways_played_is_false(void){
  106. bool already_played = false;
  107. bool testbool = true;
  108. testbool = ftryAgain(already_played);
  109. TEST_ASSERT_TRUE(testbool == false);
  110. }
  111. #endif //Test