diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index 4d1e33f..ef586f5 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -10,8 +10,7 @@ void slotMachine(){ while(balance > 0){ int bet = getBet(balance); - balance -= bet; - printf("%d\n", balance); + balance = subtractBetFromBalance(bet, balance); } @@ -47,6 +46,10 @@ int getBet(int balance){ } } +int subtractBetFromBalance(int bet, int balance){ + return balance - bet; +} + void welcomeMessage(){ printf("Herzlich Willkommen zur \n\n" " _ _ _ _ \n" diff --git a/src/main/c/Stefan/slot_machine.h b/src/main/c/Stefan/slot_machine.h index 14a3217..b0119f4 100644 --- a/src/main/c/Stefan/slot_machine.h +++ b/src/main/c/Stefan/slot_machine.h @@ -6,5 +6,6 @@ void welcomeMessage(); int getBalance(); int userInput(); int getBet(int balance); +int subtractBetFromBalance(int bet, int balance); #endif // SLOT_MACHINE_H \ No newline at end of file diff --git a/src/test/c/Stefan/test_slot_machine.c b/src/test/c/Stefan/test_slot_machine.c index b327568..4afa387 100644 --- a/src/test/c/Stefan/test_slot_machine.c +++ b/src/test/c/Stefan/test_slot_machine.c @@ -5,4 +5,14 @@ void setUp() {} void tearDown() {} -void test_test(){} \ No newline at end of file +void test_subtract_bet_10_from_balance_10() { + + //arrange + int expectedResult = 0; + + //act + int actualResult = subtractBetFromBalance(10, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} \ No newline at end of file