Browse Source

lokalen speicher aktualisieren

main
fdai7892 11 months ago
parent
commit
8793c7063d
  1. 526
      build/test/cache/test_duellist_spielesammlung_projekt.c
  2. BIN
      build/test/out/c/duellist-spielesammlung-projekt.o
  3. BIN
      build/test/out/c/test_duellist_spielesammlung_projekt.o
  4. BIN
      build/test/out/c/test_duellist_spielesammlung_projekt_runner.o
  5. BIN
      build/test/out/test_duellist_spielesammlung_projekt.out
  6. 526
      build/test/preprocess/files/test_duellist_spielesammlung_projekt.c
  7. 118
      build/test/results/test_duellist_spielesammlung_projekt.pass
  8. 38
      build/test/runners/test_duellist_spielesammlung_projekt_runner.c
  9. 161
      src/main/duellist-spielesammlung-projekt.c
  10. 47
      src/main/duellist-spielesammlung-projekt.h
  11. 324
      src/test/test_duellist_spielesammlung_projekt.c

526
build/test/cache/test_duellist_spielesammlung_projekt.c

@ -962,4 +962,530 @@ void test_calculate_mines_HeightWidthFinal(void)
), (UNITY_UINT)(423), UNITY_DISPLAY_STYLE_INT);
}
void test_generateRandomNumber_withinValidRange(void)
{
int result = zufallszahl(1, 100);
do {if ((result >= 1 && result <= 100)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(459)));}} while(0);
}
void test_addition(void)
{
int a = 5;
int b = 10;
int result = add(a, b);
UnityAssertEqualNumber((UNITY_INT)((15)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(472), UNITY_DISPLAY_STYLE_INT);
}
void test_subtraction(void)
{
int a = 15;
int b = 10;
int result = minus(a, b);
UnityAssertEqualNumber((UNITY_INT)((5)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(485), UNITY_DISPLAY_STYLE_INT);
}
void test_multiplication(void)
{
int a = 5;
int b = 10;
int result = mal(a, b);
UnityAssertEqualNumber((UNITY_INT)((50)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(499), UNITY_DISPLAY_STYLE_INT);
}
void test_division(void)
{
int a = 15;
int b = 3;
int result = durch(a, b);
UnityAssertEqualNumber((UNITY_INT)((5)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(512), UNITY_DISPLAY_STYLE_INT);
}
void test_division_byZero_returnsZero(void)
{
int num1 = 8;
int num2 = 0;
int result = durch(num1, num2);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(525), UNITY_DISPLAY_STYLE_INT);
}
void test_modulo(void)
{
int a = 15;
int b = 7;
int result = modulo(a, b);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(538), UNITY_DISPLAY_STYLE_INT);
}
void test_compare_equalNumbers(void)
{
int a = 5;
int b = 5;
int result = compare(a, b);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(551), UNITY_DISPLAY_STYLE_INT);
}
void test_compare_aLessThanB(void)
{
int a = 3;
int b = 8;
int result = compare(a, b);
UnityAssertEqualNumber((UNITY_INT)((-1)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(564), UNITY_DISPLAY_STYLE_INT);
}
void test_compare_aGreaterThanB(void)
{
int a = 10;
int b = 7;
int result = compare(a, b);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(577), UNITY_DISPLAY_STYLE_INT);
}
void test_exponentiation(void)
{
int base = 2;
int expo = 3;
int result = exponent(base, expo);
UnityAssertEqualNumber((UNITY_INT)((8)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(590), UNITY_DISPLAY_STYLE_INT);
}
void test_exponentiation_negativeExponent(void)
{
int base = 2;
int expo = -3;
int result = exponent(base, expo);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(603), UNITY_DISPLAY_STYLE_INT);
}
void test_squareRoot_validNumber(void)
{
int number = 25;
int result = squareRoot(number);
UnityAssertEqualNumber((UNITY_INT)((5)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(615), UNITY_DISPLAY_STYLE_INT);
}
void test_squareRoot_negativeNumber(void)
{
int number = -5;
int result = squareRoot(number);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(627), UNITY_DISPLAY_STYLE_INT);
}
void test_displayResult_correctResult(void)
{
int correctAnswers = 3;
int totalQuestions = 5;
displayResult(correctAnswers, totalQuestions);
}
void test_displayMenu_validMenu(void)
{
displayMenu();
}
void test_getUserChoice_invalidInput(void)
{
freopen("invalid_input.txt", "r",
(&_iob[0])
);
int result = getUserChoice();
}
void test_playGame_correctResult(void)
{
playGame();
}
void test_getUserAnswer_invalidInput(void)
{
freopen("invalid_input.txt", "r",
(&_iob[0])
);
int result = getUserAnswer();
}

BIN
build/test/out/c/duellist-spielesammlung-projekt.o

BIN
build/test/out/c/test_duellist_spielesammlung_projekt.o

BIN
build/test/out/c/test_duellist_spielesammlung_projekt_runner.o

BIN
build/test/out/test_duellist_spielesammlung_projekt.out

526
build/test/preprocess/files/test_duellist_spielesammlung_projekt.c

@ -962,4 +962,530 @@ void test_calculate_mines_HeightWidthFinal(void)
), (UNITY_UINT)(423), UNITY_DISPLAY_STYLE_INT);
}
void test_generateRandomNumber_withinValidRange(void)
{
int result = zufallszahl(1, 100);
do {if ((result >= 1 && result <= 100)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(459)));}} while(0);
}
void test_addition(void)
{
int a = 5;
int b = 10;
int result = add(a, b);
UnityAssertEqualNumber((UNITY_INT)((15)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(472), UNITY_DISPLAY_STYLE_INT);
}
void test_subtraction(void)
{
int a = 15;
int b = 10;
int result = minus(a, b);
UnityAssertEqualNumber((UNITY_INT)((5)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(485), UNITY_DISPLAY_STYLE_INT);
}
void test_multiplication(void)
{
int a = 5;
int b = 10;
int result = mal(a, b);
UnityAssertEqualNumber((UNITY_INT)((50)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(499), UNITY_DISPLAY_STYLE_INT);
}
void test_division(void)
{
int a = 15;
int b = 3;
int result = durch(a, b);
UnityAssertEqualNumber((UNITY_INT)((5)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(512), UNITY_DISPLAY_STYLE_INT);
}
void test_division_byZero_returnsZero(void)
{
int num1 = 8;
int num2 = 0;
int result = durch(num1, num2);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(525), UNITY_DISPLAY_STYLE_INT);
}
void test_modulo(void)
{
int a = 15;
int b = 7;
int result = modulo(a, b);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(538), UNITY_DISPLAY_STYLE_INT);
}
void test_compare_equalNumbers(void)
{
int a = 5;
int b = 5;
int result = compare(a, b);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(551), UNITY_DISPLAY_STYLE_INT);
}
void test_compare_aLessThanB(void)
{
int a = 3;
int b = 8;
int result = compare(a, b);
UnityAssertEqualNumber((UNITY_INT)((-1)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(564), UNITY_DISPLAY_STYLE_INT);
}
void test_compare_aGreaterThanB(void)
{
int a = 10;
int b = 7;
int result = compare(a, b);
UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(577), UNITY_DISPLAY_STYLE_INT);
}
void test_exponentiation(void)
{
int base = 2;
int expo = 3;
int result = exponent(base, expo);
UnityAssertEqualNumber((UNITY_INT)((8)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(590), UNITY_DISPLAY_STYLE_INT);
}
void test_exponentiation_negativeExponent(void)
{
int base = 2;
int expo = -3;
int result = exponent(base, expo);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(603), UNITY_DISPLAY_STYLE_INT);
}
void test_squareRoot_validNumber(void)
{
int number = 25;
int result = squareRoot(number);
UnityAssertEqualNumber((UNITY_INT)((5)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(615), UNITY_DISPLAY_STYLE_INT);
}
void test_squareRoot_negativeNumber(void)
{
int number = -5;
int result = squareRoot(number);
UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), (
((void *)0)
), (UNITY_UINT)(627), UNITY_DISPLAY_STYLE_INT);
}
void test_displayResult_correctResult(void)
{
int correctAnswers = 3;
int totalQuestions = 5;
displayResult(correctAnswers, totalQuestions);
}
void test_displayMenu_validMenu(void)
{
displayMenu();
}
void test_getUserChoice_invalidInput(void)
{
freopen("invalid_input.txt", "r",
(&_iob[0])
);
int result = getUserChoice();
}
void test_playGame_correctResult(void)
{
playGame();
}
void test_getUserAnswer_invalidInput(void)
{
freopen("invalid_input.txt", "r",
(&_iob[0])
);
int result = getUserAnswer();
}

118
build/test/results/test_duellist_spielesammlung_projekt.pass

@ -119,12 +119,122 @@
:line: 412
:message: ''
:unity_test_time: 0
- :test: test_generateRandomNumber_withinValidRange
:line: 451
:message: ''
:unity_test_time: 0
- :test: test_addition
:line: 462
:message: ''
:unity_test_time: 0
- :test: test_subtraction
:line: 475
:message: ''
:unity_test_time: 0
- :test: test_multiplication
:line: 489
:message: ''
:unity_test_time: 0
- :test: test_division
:line: 502
:message: ''
:unity_test_time: 0
- :test: test_division_byZero_returnsZero
:line: 515
:message: ''
:unity_test_time: 0
- :test: test_modulo
:line: 528
:message: ''
:unity_test_time: 0
- :test: test_compare_equalNumbers
:line: 541
:message: ''
:unity_test_time: 0
- :test: test_compare_aLessThanB
:line: 554
:message: ''
:unity_test_time: 0
- :test: test_compare_aGreaterThanB
:line: 567
:message: ''
:unity_test_time: 0
- :test: test_exponentiation
:line: 580
:message: ''
:unity_test_time: 0
- :test: test_exponentiation_negativeExponent
:line: 593
:message: ''
:unity_test_time: 0
- :test: test_squareRoot_validNumber
:line: 606
:message: ''
:unity_test_time: 0
- :test: test_squareRoot_negativeNumber
:line: 618
:message: ''
:unity_test_time: 0
- :test: test_displayResult_correctResult
:line: 630
:message: ''
:unity_test_time: 0
- :test: test_displayMenu_validMenu
:line: 643
:message: ''
:unity_test_time: 0
- :test: test_getUserChoice_invalidInput
:line: 653
:message: ''
:unity_test_time: 0
- :test: test_playGame_correctResult
:line: 665
:message: ''
:unity_test_time: 0
- :test: test_getUserAnswer_invalidInput
:line: 673
:message: ''
:unity_test_time: 0
:failures: []
:ignores: []
:counts:
:total: 29
:passed: 29
:total: 48
:passed: 48
:failed: 0
:ignored: 0
:stdout: []
:time: 0.13763090001884848
:stdout:
- Division durch Null nicht erlaubt. Gib eine andere Zahl ein.
- Negative Exponenten werden nicht unterstützt.
- Die Quadratwurzel aus einer negativen Zahl ist nicht definiert.
- ''
- 'Spiel beendet. Ergebnis: 3 von 5 Fragen richtig beantwortet.'
- ''
- 'Hauptmenü:'
- 1. Spiel starten
- 2. Beenden
- 'Auswahl treffen: '
- Ungültige Eingabe. Bitte eine Zahl eingeben.
- ''
- 'Frage 1: Was ist 3 = 10?'
- Ungültige Eingabe. Bitte eine Zahl eingeben.
- 'Falsch. Die richtige Antwort ist: -1'
- ''
- 'Frage 2: Was ist 7 - 5?'
- Ungültige Eingabe. Bitte eine Zahl eingeben.
- 'Falsch. Die richtige Antwort ist: 2'
- ''
- 'Frage 3: Was ist 10 / 9?'
- Ungültige Eingabe. Bitte eine Zahl eingeben.
- 'Falsch. Die richtige Antwort ist: 1'
- ''
- 'Frage 4: Was ist 6 % 8?'
- Ungültige Eingabe. Bitte eine Zahl eingeben.
- 'Falsch. Die richtige Antwort ist: 6'
- ''
- 'Frage 5: Was ist 8 - 2?'
- Ungültige Eingabe. Bitte eine Zahl eingeben.
- 'Falsch. Die richtige Antwort ist: 6'
- ''
- 'Spiel beendet. Ergebnis: 0 von 5 Fragen richtig beantwortet.'
- Ungültige Eingabe. Bitte eine Zahl eingeben.
:time: 0.024828299996443093

38
build/test/runners/test_duellist_spielesammlung_projekt_runner.c

@ -39,6 +39,25 @@ extern void test_calculate_mines_HeightWidthAgan(void);
extern void test_calculate_mines_HeightWidthRoundUp(void);
extern void test_calculate_mines_HeightWidthNoRound(void);
extern void test_calculate_mines_HeightWidthFinal(void);
extern void test_generateRandomNumber_withinValidRange(void);
extern void test_addition(void);
extern void test_subtraction(void);
extern void test_multiplication(void);
extern void test_division(void);
extern void test_division_byZero_returnsZero(void);
extern void test_modulo(void);
extern void test_compare_equalNumbers(void);
extern void test_compare_aLessThanB(void);
extern void test_compare_aGreaterThanB(void);
extern void test_exponentiation(void);
extern void test_exponentiation_negativeExponent(void);
extern void test_squareRoot_validNumber(void);
extern void test_squareRoot_negativeNumber(void);
extern void test_displayResult_correctResult(void);
extern void test_displayMenu_validMenu(void);
extern void test_getUserChoice_invalidInput(void);
extern void test_playGame_correctResult(void);
extern void test_getUserAnswer_invalidInput(void);
/*=======Mock Management=====*/
@ -132,6 +151,25 @@ int main(void)
run_test(test_calculate_mines_HeightWidthRoundUp, "test_calculate_mines_HeightWidthRoundUp", 384);
run_test(test_calculate_mines_HeightWidthNoRound, "test_calculate_mines_HeightWidthNoRound", 398);
run_test(test_calculate_mines_HeightWidthFinal, "test_calculate_mines_HeightWidthFinal", 412);
run_test(test_generateRandomNumber_withinValidRange, "test_generateRandomNumber_withinValidRange", 451);
run_test(test_addition, "test_addition", 462);
run_test(test_subtraction, "test_subtraction", 475);
run_test(test_multiplication, "test_multiplication", 489);
run_test(test_division, "test_division", 502);
run_test(test_division_byZero_returnsZero, "test_division_byZero_returnsZero", 515);
run_test(test_modulo, "test_modulo", 528);
run_test(test_compare_equalNumbers, "test_compare_equalNumbers", 541);
run_test(test_compare_aLessThanB, "test_compare_aLessThanB", 554);
run_test(test_compare_aGreaterThanB, "test_compare_aGreaterThanB", 567);
run_test(test_exponentiation, "test_exponentiation", 580);
run_test(test_exponentiation_negativeExponent, "test_exponentiation_negativeExponent", 593);
run_test(test_squareRoot_validNumber, "test_squareRoot_validNumber", 606);
run_test(test_squareRoot_negativeNumber, "test_squareRoot_negativeNumber", 618);
run_test(test_displayResult_correctResult, "test_displayResult_correctResult", 630);
run_test(test_displayMenu_validMenu, "test_displayMenu_validMenu", 643);
run_test(test_getUserChoice_invalidInput, "test_getUserChoice_invalidInput", 653);
run_test(test_playGame_correctResult, "test_playGame_correctResult", 665);
run_test(test_getUserAnswer_invalidInput, "test_getUserAnswer_invalidInput", 673);
return UnityEnd();
}

161
src/main/duellist-spielesammlung-projekt.c

@ -384,3 +384,164 @@ int minesweeper() {
return 1;
}
/*------------------------------------------------------------------------------------------*/
int zufallszahl(int min, int max)
{return rand() % (max - min + 1) + min;}
int add(int a, int b)
{return a + b;}
int minus(int a, int b)
{return a - b;}
int mal(int a, int b)
{return a * b;}
int durch(int a, int b) {
if (b != 0) {
return a / b;
} else {
printf("Division durch Null nicht erlaubt. Gib eine andere Zahl ein.\n");
return 0;
}
}
int modulo(int a, int b) {
if (b != 0) {
return a % b;
} else {
printf("Modulo durch Null nicht erlaubt. Gib eine andere Zahl ein.\n");
return 0;
}
}
int compare(int a, int b) {
if (a == b) {
return 0;
} else if (a < b) {
return -1;
} else {
return 1;
}
}
int exponent(int base, int expo){
if (expo < 0) {
printf("Negative Exponenten werden nicht unterstützt.\n");
return 0;
}
int result = 1;
for (int i = 0; i < expo; ++i) {
result *= base;
}
return result;
}
int squareRoot(int number) {
if (number >= 0) {
return (int)sqrt(number);
} else {
printf("Die Quadratwurzel aus einer negativen Zahl ist nicht definiert.\n");
return 0;
}
}
void displayMenu() {
printf("\nHauptmenü:\n1. Spiel starten\n2. Beenden\nAuswahl treffen: ");
}
int getUserChoice() {
int choice;
if (scanf("%d", &choice) != 1) {
printf("Ungültige Eingabe. Bitte eine Zahl eingeben.\n");
// Optional: Hier könntest du die Funktion rekursiv aufrufen oder einen Standardwert zurückgeben.
}
return choice;
}
void playGame() {
int correctAnswers = 0;
int totalQuestions = 5; // Anzahl der Fragen im Spiel
for (int i = 0; i < totalQuestions; ++i) {
int num1 = zufallszahl(1, 10);
int num2 = zufallszahl(1, 10);
int operation = zufallszahl(1, 8);
int result;
char operator;
switch (operation) {
case 1:
result = add(num1, num2);
operator = '+';
break;
case 2:
result = minus(num1, num2);
operator = '-';
break;
case 3:
result = mal(num1, num2);
operator = '*';
break;
case 4:
result = durch(num1, num2);
operator = '/';
break;
case 5:
result = modulo(num1, num2);
operator = '%';
break;
case 6:
result = compare(num1, num2);
operator = '=';
break;
case 7:
result = exponent(num1, num2);
operator = '^';
break;
case 8:
result = squareRoot(num1);
operator= "Wurzel";
break;
default:
printf("Ungültige Operation.\n");
break;
}
printf("\nFrage %d: Was ist %d %c %d?\n", i + 1, num1, operator, num2);
int userAnswer = getUserAnswer();
if (userAnswer == result) {
printf("Richtig!\n");
correctAnswers++;
} else {
printf("Falsch. Die richtige Antwort ist: %d\n", result);
}
}
displayResult(correctAnswers, totalQuestions);
}
int getUserAnswer() {
int answer;
if (scanf("%d", &answer) != 1) {
printf("Ungültige Eingabe. Bitte eine Zahl eingeben.\n");
// Optional: Hier könntest du die Funktion rekursiv aufrufen oder einen Standardwert zurückgeben.
}
return answer;
}
void displayResult(int correctAnswers, int totalQuestions) {
printf("\nSpiel beendet. Ergebnis: %d von %d Fragen richtig beantwortet.\n", correctAnswers, totalQuestions);
}

47
src/main/duellist-spielesammlung-projekt.h

@ -40,6 +40,7 @@ Player playRockPaperScissors();
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
@ -57,5 +58,51 @@ int calculate_mines(int height, int width);
char** create_minefield(int height, int width, char within);
void distribute_mines(char** mines, int height, int width, int num_mines);
int minesweeper();
int zufallszahl(int min, int max);
int add(int a, int b);
int minus(int a, int b);
int mal(int a, int b);
int durch(int a, int b);
int modulo(int a, int b);
int compare(int a, int b);
int exponent(int base, int exponent);
int squareRoot(int number);
void displayMenu();
int getUserChoice();
int getUserAnswer();
void displayResult(int correctAnswers, int totalQuestions);
#endif // DUEELIST_SPIELESAMMLUNG_PROJEKT_H

324
src/test/test_duellist_spielesammlung_projekt.c

@ -422,4 +422,328 @@ void test_calculate_mines_HeightWidthFinal(void)
/* assert */
TEST_ASSERT_EQUAL_INT(expected, result);
}
void test_generateRandomNumber_withinValidRange(void)
{
/* arrange */
/* act */
int result = zufallszahl(1, 100);
/* assert */
TEST_ASSERT_TRUE(result >= 1 && result <= 100);
}
void test_addition(void)
{
/* arrange */
int a = 5;
int b = 10;
/* act */
int result = add(a, b);
/* assert */
TEST_ASSERT_EQUAL_INT(15, result);
}
void test_subtraction(void)
{
/* arrange */
int a = 15;
int b = 10;
/* act */
int result = minus(a, b);
/* assert */
TEST_ASSERT_EQUAL_INT(5, result);
}
void test_multiplication(void)
{
/* arrange */
int a = 5;
int b = 10;
/* act */
int result = mal(a, b);
/* assert */
TEST_ASSERT_EQUAL_INT(50, result);
}
void test_division(void)
{
/* arrange */
int a = 15;
int b = 3;
/* act */
int result = durch(a, b);
/* assert */
TEST_ASSERT_EQUAL_INT(5, result);
}
void test_division_byZero_returnsZero(void)
{
/* arrange */
int num1 = 8;
int num2 = 0;
/* act */
int result = durch(num1, num2);
/* assert */
TEST_ASSERT_EQUAL_INT(0, result);
}
void test_modulo(void)
{
/* arrange */
int a = 15;
int b = 7;
/* act */
int result = modulo(a, b);
/* assert */
TEST_ASSERT_EQUAL_INT(1, result);
}
void test_compare_equalNumbers(void)
{
/* arrange */
int a = 5;
int b = 5;
/* act */
int result = compare(a, b);
/* assert */
TEST_ASSERT_EQUAL_INT(0, result);
}
void test_compare_aLessThanB(void)
{
/* arrange */
int a = 3;
int b = 8;
/* act */
int result = compare(a, b);
/* assert */
TEST_ASSERT_EQUAL_INT(-1, result);
}
void test_compare_aGreaterThanB(void)
{
/* arrange */
int a = 10;
int b = 7;
/* act */
int result = compare(a, b);
/* assert */
TEST_ASSERT_EQUAL_INT(1, result);
}
void test_exponentiation(void)
{
/* arrange */
int base = 2;
int expo = 3;
/* act */
int result = exponent(base, expo);
/* assert */
TEST_ASSERT_EQUAL_INT(8, result);
}
void test_exponentiation_negativeExponent(void)
{
/* arrange */
int base = 2;
int expo = -3;
/* act */
int result = exponent(base, expo);
/* assert */
TEST_ASSERT_EQUAL_INT(0, result);
}
void test_squareRoot_validNumber(void)
{
/* arrange */
int number = 25;
/* act */
int result = squareRoot(number);
/* assert */
TEST_ASSERT_EQUAL_INT(5, result);
}
void test_squareRoot_negativeNumber(void)
{
/* arrange */
int number = -5;
/* act */
int result = squareRoot(number);
/* assert */
TEST_ASSERT_EQUAL_INT(0, result);
}
void test_displayResult_correctResult(void)
{
/* arrange */
int correctAnswers = 3;
int totalQuestions = 5;
/* act */
displayResult(correctAnswers, totalQuestions);
/* assert */
}
void test_displayMenu_validMenu(void)
{
/* arrange */
/* act */
// Since displayMenu() only prints to the console, we can't use TEST_ASSERT.
// Manually verify the output in the console during test execution.
displayMenu();
}
void test_getUserChoice_invalidInput(void)
{
/* arrange */
freopen("invalid_input.txt", "r", stdin);
/* act */
int result = getUserChoice();
/* assert */
}
void test_playGame_correctResult(void)
{
/* arrange */
/* act */
playGame();
}
void test_getUserAnswer_invalidInput(void)
{
/* arrange */
freopen("invalid_input.txt", "r", stdin);
/* act */
int result = getUserAnswer();
/* assert */
}
#endif // TEST
Loading…
Cancel
Save