Browse Source

Änderung variablen durch neue

remotes/origin/erwin
fdai7820 11 months ago
parent
commit
e89e69e8bd
  1. 22
      src/main/duellist-spielesammlung-projekt.c
  2. 16
      src/test/test_duellist_spielesammlung_projekt.c

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

@ -427,13 +427,13 @@ int compare(int a, int b) {
} }
} }
int exponent(int base, int exponent) {
if (exponent < 0) {
int exponent(int base, int expo){
if (expo < 0) {
printf("Negative Exponenten werden nicht unterstützt.\n"); printf("Negative Exponenten werden nicht unterstützt.\n");
return 0; return 0;
} }
int result = 1; int result = 1;
for (int i = 0; i < exponent; ++i) {
for (int i = 0; i < expo; ++i) {
result *= base; result *= base;
} }
return result; return result;
@ -466,28 +466,28 @@ void playGame() {
int totalQuestions = 5; // Anzahl der Fragen im Spiel int totalQuestions = 5; // Anzahl der Fragen im Spiel
for (int i = 0; i < totalQuestions; ++i) { for (int i = 0; i < totalQuestions; ++i) {
int num1 = generateRandomNumber(1, 10);
int num2 = generateRandomNumber(1, 10);
int operation = generateRandomNumber(1, 8);
int num1 = zufallszahl(1, 10);
int num2 = zufallszahl(1, 10);
int operation = zufallszahl(1, 8);
int result; int result;
char operator; char operator;
switch (operation) { switch (operation) {
case 1: case 1:
result = addition(num1, num2);
result = add(num1, num2);
operator = '+'; operator = '+';
break; break;
case 2: case 2:
result = subtraction(num1, num2);
result = minus(num1, num2);
operator = '-'; operator = '-';
break; break;
case 3: case 3:
result = multiplication(num1, num2);
result = mal(num1, num2);
operator = '*'; operator = '*';
break; break;
case 4: case 4:
result = division(num1, num2);
result = durch(num1, num2);
operator = '/'; operator = '/';
break; break;
case 5: case 5:
@ -499,7 +499,7 @@ void playGame() {
operator = '='; operator = '=';
break; break;
case 7: case 7:
result = exponentiation(num1, num2);
result = exponent(num1, num2);
operator = '^'; operator = '^';
break; break;
case 8: case 8:

16
src/test/test_duellist_spielesammlung_projekt.c

@ -453,7 +453,7 @@ void test_generateRandomNumber_withinValidRange(void)
/* arrange */ /* arrange */
/* act */ /* act */
int result = generateRandomNumber(1, 100);
int result = zufallszahl(1, 100);
/* assert */ /* assert */
TEST_ASSERT_TRUE(result >= 1 && result <= 100); TEST_ASSERT_TRUE(result >= 1 && result <= 100);
@ -466,7 +466,7 @@ void test_addition(void)
int b = 10; int b = 10;
/* act */ /* act */
int result = addition(a, b);
int result = add(a, b);
/* assert */ /* assert */
TEST_ASSERT_EQUAL_INT(15, result); TEST_ASSERT_EQUAL_INT(15, result);
@ -479,7 +479,7 @@ void test_subtraction(void)
int b = 10; int b = 10;
/* act */ /* act */
int result = subtraction(a, b);
int result = minus(a, b);
/* assert */ /* assert */
TEST_ASSERT_EQUAL_INT(5, result); TEST_ASSERT_EQUAL_INT(5, result);
@ -493,7 +493,7 @@ void test_multiplication(void)
int b = 10; int b = 10;
/* act */ /* act */
int result = multiplication(a, b);
int result = mal(a, b);
/* assert */ /* assert */
TEST_ASSERT_EQUAL_INT(50, result); TEST_ASSERT_EQUAL_INT(50, result);
@ -506,7 +506,7 @@ void test_division(void)
int b = 3; int b = 3;
/* act */ /* act */
int result = division(a, b);
int result = durch(a, b);
/* assert */ /* assert */
TEST_ASSERT_EQUAL_INT(5, result); TEST_ASSERT_EQUAL_INT(5, result);
@ -519,7 +519,7 @@ void test_division_byZero_returnsZero(void)
int num2 = 0; int num2 = 0;
/* act */ /* act */
int result = division(num1, num2);
int result = durch(num1, num2);
/* assert */ /* assert */
TEST_ASSERT_EQUAL_INT(0, result); TEST_ASSERT_EQUAL_INT(0, result);
@ -584,7 +584,7 @@ void test_exponentiation(void)
int exponent = 3; int exponent = 3;
/* act */ /* act */
int result = exponentiation(base, exponent);
int result = exponent(base, expo);
/* assert */ /* assert */
TEST_ASSERT_EQUAL_INT(8, result); TEST_ASSERT_EQUAL_INT(8, result);
@ -597,7 +597,7 @@ void test_exponentiation_negativeExponent(void)
int exponent = -3; int exponent = -3;
/* act */ /* act */
int result = exponentiation(base, exponent);
int result = exponent(base, expo);
/* assert */ /* assert */
TEST_ASSERT_EQUAL_INT(0, result); TEST_ASSERT_EQUAL_INT(0, result);

Loading…
Cancel
Save