From 95189c0ff044d71de6b54cc4ca0fa0e60b5edd01 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 21 Jan 2023 18:12:13 +0100 Subject: [PATCH] prod/test: added functionality to levelUp created new Unittest for levelUp --- src/c/character.c | 1 + test/c/test_character.c | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/c/character.c b/src/c/character.c index f5a5bd4..9c436ff 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -92,5 +92,6 @@ void increaseStat (Character *character, int stat, int amount) { void levelUp (Character *character) { if (getCharacterExp(character) > getCharacterMaxExp(character)) { increaseStat(character,LEVEL,1); + setCharacterExp(character,getCharacterExp(character)-getCharacterMaxExp(character)); } } \ No newline at end of file diff --git a/test/c/test_character.c b/test/c/test_character.c index ba52049..6d9fd46 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -92,20 +92,29 @@ void test_calculateStatIncrease(void) { } void test_levelUp_enoughExp (void) { - TEST_ASSERT_EQUAL_INT(110,testCharacter2.exp); - TEST_ASSERT_EQUAL_INT(100,testCharacter2.maxExp); TEST_ASSERT_EQUAL_INT(5,testCharacter2.level); levelUp(&testCharacter2); TEST_ASSERT_EQUAL_INT(6,testCharacter2.level); } +void test_levelUp_enoughExp_loseExp (void) { + TEST_ASSERT_EQUAL_INT(110,testCharacter2.exp); + TEST_ASSERT_EQUAL_INT(100,testCharacter2.maxExp); + levelUp(&testCharacter2); + TEST_ASSERT_EQUAL_INT(10,testCharacter2.exp); +} + void test_levelUp_notEnoughExp (void) { - TEST_ASSERT_EQUAL_INT(50,testCharacter.exp); - TEST_ASSERT_EQUAL_INT(100,testCharacter.maxExp); TEST_ASSERT_EQUAL_INT(0,testCharacter.level); levelUp(&testCharacter); TEST_ASSERT_EQUAL_INT(0,testCharacter.level); } +void test_levelUp_notEnoughExp_loseExp (void) { + TEST_ASSERT_EQUAL_INT(50,testCharacter.exp); + TEST_ASSERT_EQUAL_INT(100,testCharacter.maxExp); + levelUp(&testCharacter); + TEST_ASSERT_EQUAL_INT(50,testCharacter.exp); +} #endif // TEST \ No newline at end of file