From ef8a6f5fe122e7e69a202453fa77c41f1e382505 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Thu, 12 Jan 2023 14:53:23 +0100 Subject: [PATCH 01/19] Prod/Test: created Character, setCharacterHealthPoints and test_setCharacterHealthPoints --- src/c/character.c | 10 ++++++++++ src/c/character.h | 12 ++++++++++++ test/c/test_character.c | 22 ++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 src/c/character.c create mode 100644 src/c/character.h create mode 100644 test/c/test_character.c diff --git a/src/c/character.c b/src/c/character.c new file mode 100644 index 0000000..5e9d001 --- /dev/null +++ b/src/c/character.c @@ -0,0 +1,10 @@ +#include +#include +#include + +#include "character.h" +Character character; + +void setCharacterHealthPoints (Character *character, int newHealthPoints){ + character->healthPoints = newHealthPoints; +} \ No newline at end of file diff --git a/src/c/character.h b/src/c/character.h new file mode 100644 index 0000000..be8bf95 --- /dev/null +++ b/src/c/character.h @@ -0,0 +1,12 @@ +#ifndef CHARACTER_H +#define CHARACTER_H + +typedef struct { + int strength,dexterity,intelligence,healthPoints,manaPoints; + char name [50]; +} Character; + +void setCharacterHealthPoints (Character *character,int newHealthPoints); + + +#endif \ No newline at end of file diff --git a/test/c/test_character.c b/test/c/test_character.c new file mode 100644 index 0000000..d4aca2f --- /dev/null +++ b/test/c/test_character.c @@ -0,0 +1,22 @@ +#ifdef TEST +#include "unity.h" +#include "character.h" +Character testCharacter; + +void setUp(void) +{ + testCharacter.healthPoints = 0; +} + +void tearDown(void) +{ +} + +void test_setCharacterHealthPoints(void) +{ + TEST_ASSERT_EQUAL_INT(0,testCharacter.healthPoints); + setCharacterHealthPoints(&testCharacter,50); + TEST_ASSERT_EQUAL_INT(50,testCharacter.healthPoints); +} + +#endif // TEST \ No newline at end of file From 4c638d6af2f31cd3520597e0d7be3432372171c1 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Thu, 12 Jan 2023 15:05:48 +0100 Subject: [PATCH 02/19] prod/test: created getCharacterHealthPoints and test_getCharacterHealthPoints --- src/c/character.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/c/character.c b/src/c/character.c index 5e9d001..3da86cd 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -7,4 +7,8 @@ Character character; void setCharacterHealthPoints (Character *character, int newHealthPoints){ character->healthPoints = newHealthPoints; +} + +int getCharacterHealthPoints (Character *character) { + return character->healthPoints; } \ No newline at end of file From b13d7494bbefbfbead968971341b5917cd973cd4 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Thu, 12 Jan 2023 18:36:34 +0100 Subject: [PATCH 03/19] prod/test: created setCharacterStrength and test_setCharacterStrength --- src/c/character.c | 7 ++++++- src/c/character.h | 5 +++++ test/c/test_character.c | 18 +++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/c/character.c b/src/c/character.c index 3da86cd..1664eea 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -11,4 +11,9 @@ void setCharacterHealthPoints (Character *character, int newHealthPoints){ int getCharacterHealthPoints (Character *character) { return character->healthPoints; -} \ No newline at end of file +} + +void setCharacterStrength(Character *character, int newStrength) +{ + character->strength = newStrength; +} diff --git a/src/c/character.h b/src/c/character.h index be8bf95..999692c 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -8,5 +8,10 @@ typedef struct { void setCharacterHealthPoints (Character *character,int newHealthPoints); +int getCharacterHealthPoints (Character *character); + +void setCharacterStrength (Character *character, int newStrength); + + #endif \ No newline at end of file diff --git a/test/c/test_character.c b/test/c/test_character.c index d4aca2f..3e26839 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -2,10 +2,14 @@ #include "unity.h" #include "character.h" Character testCharacter; +Character testCharacter2; void setUp(void) { - testCharacter.healthPoints = 0; + testCharacter.healthPoints = 0; + testCharacter2.healthPoints = 15; + testCharacter.strength = 0; + testCharacter2.strength = 5; } void tearDown(void) @@ -19,4 +23,16 @@ void test_setCharacterHealthPoints(void) TEST_ASSERT_EQUAL_INT(50,testCharacter.healthPoints); } +void test_getCharacterHealthPoints (void) { + TEST_ASSERT_EQUAL_INT(15,testCharacter2.healthPoints); +} +void test_setCharacterStrenght(void) +{ + TEST_ASSERT_EQUAL_INT(0,testCharacter.strength); + setCharacterStrength(&testCharacter,50); + TEST_ASSERT_EQUAL_INT(50,testCharacter.strength); +} + + + #endif // TEST \ No newline at end of file From 3d4a9e9f4dcc1711d952a7a7eb76512acef464f5 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Thu, 12 Jan 2023 19:02:46 +0100 Subject: [PATCH 04/19] prod/test: created getCharacterStrength and test_getCharacterStrength --- src/c/character.c | 4 ++++ src/c/character.h | 2 +- test/c/test_character.c | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/c/character.c b/src/c/character.c index 1664eea..9d3517e 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -17,3 +17,7 @@ void setCharacterStrength(Character *character, int newStrength) { character->strength = newStrength; } + +int getCharacterStrength(Character *character) { + return character->strength; +} diff --git a/src/c/character.h b/src/c/character.h index 999692c..2396bc7 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -12,6 +12,6 @@ int getCharacterHealthPoints (Character *character); void setCharacterStrength (Character *character, int newStrength); - +int getCharacterStrength(Character *character) #endif \ No newline at end of file diff --git a/test/c/test_character.c b/test/c/test_character.c index 3e26839..d4012d2 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -33,6 +33,8 @@ void test_setCharacterStrenght(void) TEST_ASSERT_EQUAL_INT(50,testCharacter.strength); } - +void test_getCharacterStrength(void) { + TEST_ASSERT_EQUAL_INT(5,testCharacter2.strength); +} #endif // TEST \ No newline at end of file From 1d083d7d5635e4030fca7e89588e956d6988b711 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Thu, 12 Jan 2023 19:11:42 +0100 Subject: [PATCH 05/19] prod/test: created setCharacterDexterity and test_setCharacterDexterity --- src/c/character.c | 9 ++++++--- src/c/character.h | 4 +++- test/c/test_character.c | 11 +++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/c/character.c b/src/c/character.c index 9d3517e..b0ff012 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -13,11 +13,14 @@ int getCharacterHealthPoints (Character *character) { return character->healthPoints; } -void setCharacterStrength(Character *character, int newStrength) -{ +void setCharacterStrength (Character *character, int newStrength) { character->strength = newStrength; } -int getCharacterStrength(Character *character) { +int getCharacterStrength (Character *character) { return character->strength; } + +void setCharacterDexterity (Character *character, int newDexterity) { + character->dexterity = newDexterity; +} \ No newline at end of file diff --git a/src/c/character.h b/src/c/character.h index 2396bc7..55ce4eb 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -12,6 +12,8 @@ int getCharacterHealthPoints (Character *character); void setCharacterStrength (Character *character, int newStrength); -int getCharacterStrength(Character *character) +int getCharacterStrength(Character *character); + +void setCharacterDexterity (Character *character, int newDexterity); #endif \ No newline at end of file diff --git a/test/c/test_character.c b/test/c/test_character.c index d4012d2..0119f86 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -10,6 +10,8 @@ void setUp(void) testCharacter2.healthPoints = 15; testCharacter.strength = 0; testCharacter2.strength = 5; + testCharacter.dexterity = 0; + testCharacter2.dexterity = 5; } void tearDown(void) @@ -26,8 +28,7 @@ void test_setCharacterHealthPoints(void) void test_getCharacterHealthPoints (void) { TEST_ASSERT_EQUAL_INT(15,testCharacter2.healthPoints); } -void test_setCharacterStrenght(void) -{ +void test_setCharacterStrenght(void) { TEST_ASSERT_EQUAL_INT(0,testCharacter.strength); setCharacterStrength(&testCharacter,50); TEST_ASSERT_EQUAL_INT(50,testCharacter.strength); @@ -37,4 +38,10 @@ void test_getCharacterStrength(void) { TEST_ASSERT_EQUAL_INT(5,testCharacter2.strength); } +void test_setCharacterDexterity(void) { + TEST_ASSERT_EQUAL_INT(0,testCharacter.dexterity); + setCharacterDexterity(&testCharacter,50); + TEST_ASSERT_EQUAL_INT(50,testCharacter.dexterity); +} + #endif // TEST \ No newline at end of file From 520b94900528428a6aec812ce7da43c011e28021 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Thu, 12 Jan 2023 19:15:22 +0100 Subject: [PATCH 06/19] prod/test: created getCharacterDexterity and test_getCharacterDexterity --- src/c/character.c | 4 ++++ src/c/character.h | 2 ++ test/c/test_character.c | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/src/c/character.c b/src/c/character.c index b0ff012..d9642ca 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -23,4 +23,8 @@ int getCharacterStrength (Character *character) { void setCharacterDexterity (Character *character, int newDexterity) { character->dexterity = newDexterity; +} + +int getCharacterDexterity (Character *character) { + return character->dexterity; } \ No newline at end of file diff --git a/src/c/character.h b/src/c/character.h index 55ce4eb..a0345e3 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -16,4 +16,6 @@ int getCharacterStrength(Character *character); void setCharacterDexterity (Character *character, int newDexterity); +int getCharacterDexterity(Character *character); + #endif \ No newline at end of file diff --git a/test/c/test_character.c b/test/c/test_character.c index 0119f86..0f12bcc 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -44,4 +44,9 @@ void test_setCharacterDexterity(void) { TEST_ASSERT_EQUAL_INT(50,testCharacter.dexterity); } + +void test_getCharacterDexterity(void) { + TEST_ASSERT_EQUAL_INT(5,testCharacter2.dexterity); +} + #endif // TEST \ No newline at end of file From df493e8f850084f0de1dee44cfa8a8d1de1ee30e Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Thu, 12 Jan 2023 19:22:54 +0100 Subject: [PATCH 07/19] prod/test: created setCharacterIntelligence and test_setCharacterIntelligence --- src/c/character.c | 4 ++++ src/c/character.h | 8 +++++--- test/c/test_character.c | 9 ++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/c/character.c b/src/c/character.c index d9642ca..5938afa 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -27,4 +27,8 @@ void setCharacterDexterity (Character *character, int newDexterity) { int getCharacterDexterity (Character *character) { return character->dexterity; +} + +void setCharacterIntelligence (Character *character, int newIntelligence) { + character->intelligence = newIntelligence; } \ No newline at end of file diff --git a/src/c/character.h b/src/c/character.h index a0345e3..a5960fe 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -6,16 +6,18 @@ typedef struct { char name [50]; } Character; -void setCharacterHealthPoints (Character *character,int newHealthPoints); +void setCharacterHealthPoints (Character *character, int newHealthPoints); int getCharacterHealthPoints (Character *character); void setCharacterStrength (Character *character, int newStrength); -int getCharacterStrength(Character *character); +int getCharacterStrength (Character *character); void setCharacterDexterity (Character *character, int newDexterity); -int getCharacterDexterity(Character *character); +int getCharacterDexterity (Character *character); + +void setCharacterIntelligence (Character *character, int newIntelligence); #endif \ No newline at end of file diff --git a/test/c/test_character.c b/test/c/test_character.c index 0f12bcc..c204b09 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -12,6 +12,8 @@ void setUp(void) testCharacter2.strength = 5; testCharacter.dexterity = 0; testCharacter2.dexterity = 5; + testCharacter.intelligence = 0; + testCharacter2.intelligence = 5; } void tearDown(void) @@ -44,9 +46,14 @@ void test_setCharacterDexterity(void) { TEST_ASSERT_EQUAL_INT(50,testCharacter.dexterity); } - void test_getCharacterDexterity(void) { TEST_ASSERT_EQUAL_INT(5,testCharacter2.dexterity); } +void test_setCharacterIntelligence(void) { + TEST_ASSERT_EQUAL_INT(0,testCharacter.intelligence); + setCharacterIntelligence(&testCharacter,45); + TEST_ASSERT_EQUAL_INT(45,testCharacter.intelligence); +} + #endif // TEST \ No newline at end of file From 3dab622ef26e55121601f98bd7e9f83c4050dc8f Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Thu, 12 Jan 2023 19:25:20 +0100 Subject: [PATCH 08/19] prod/test: created getCharacterIntelligence and test_getCharacterIntelligence --- src/c/character.c | 4 ++++ src/c/character.h | 2 ++ test/c/test_character.c | 6 +++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/c/character.c b/src/c/character.c index 5938afa..d529731 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -31,4 +31,8 @@ int getCharacterDexterity (Character *character) { void setCharacterIntelligence (Character *character, int newIntelligence) { character->intelligence = newIntelligence; +} + +int getCharacterIntelligence (Character *character) { + return character->intelligence; } \ No newline at end of file diff --git a/src/c/character.h b/src/c/character.h index a5960fe..80b6dd1 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -20,4 +20,6 @@ int getCharacterDexterity (Character *character); void setCharacterIntelligence (Character *character, int newIntelligence); +int getCharacterIntelligence (Character *character); + #endif \ No newline at end of file diff --git a/test/c/test_character.c b/test/c/test_character.c index c204b09..e216d43 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -13,7 +13,7 @@ void setUp(void) testCharacter.dexterity = 0; testCharacter2.dexterity = 5; testCharacter.intelligence = 0; - testCharacter2.intelligence = 5; + testCharacter2.intelligence = 7; } void tearDown(void) @@ -56,4 +56,8 @@ void test_setCharacterIntelligence(void) { TEST_ASSERT_EQUAL_INT(45,testCharacter.intelligence); } +void test_getCharacterIntelligence(void) { + TEST_ASSERT_EQUAL_INT(7,testCharacter2.intelligence); +} + #endif // TEST \ No newline at end of file From 129fb04dcb5a7177b879494477584a57c6944e32 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 14 Jan 2023 17:14:43 +0100 Subject: [PATCH 09/19] prod/test: created test_addCharacterHealthPoints and addCharacterHealthPoints --- src/c/character.c | 4 ++++ src/c/character.h | 2 ++ test/c/test_character.c | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/src/c/character.c b/src/c/character.c index d529731..2409dab 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -13,6 +13,10 @@ int getCharacterHealthPoints (Character *character) { return character->healthPoints; } +void addCharacterHealthPoints (Character *character, int addedHealthPoints) { + character->healthPoints += addedHealthPoints; +} + void setCharacterStrength (Character *character, int newStrength) { character->strength = newStrength; } diff --git a/src/c/character.h b/src/c/character.h index 80b6dd1..0c18944 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -10,6 +10,8 @@ void setCharacterHealthPoints (Character *character, int newHealthPoints); int getCharacterHealthPoints (Character *character); +void addCharacterHealthPoints (Character *character, int addedHealthPoints); + void setCharacterStrength (Character *character, int newStrength); int getCharacterStrength (Character *character); diff --git a/test/c/test_character.c b/test/c/test_character.c index e216d43..71b43ec 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -30,6 +30,13 @@ void test_setCharacterHealthPoints(void) void test_getCharacterHealthPoints (void) { TEST_ASSERT_EQUAL_INT(15,testCharacter2.healthPoints); } + +void test_addCharacterHealthPoints (void) { + addCharacterHealthPoints(&testCharacter2,5); + TEST_ASSERT_EQUAL_INT(20,testCharacter2.healthPoints); + +} + void test_setCharacterStrenght(void) { TEST_ASSERT_EQUAL_INT(0,testCharacter.strength); setCharacterStrength(&testCharacter,50); From 9cefe4afedc5e47bb79bf49182bdf425b5e964d9 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 14 Jan 2023 17:20:54 +0100 Subject: [PATCH 10/19] prod/test: created test_addCharacterStrength and addCharacterStrength --- src/c/character.c | 4 ++++ src/c/character.h | 2 ++ test/c/test_character.c | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/src/c/character.c b/src/c/character.c index 2409dab..c3010be 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -25,6 +25,10 @@ int getCharacterStrength (Character *character) { return character->strength; } +void addCharacterStrength (Character *character, int addStrength) { + character->strength += addStrength; +} + void setCharacterDexterity (Character *character, int newDexterity) { character->dexterity = newDexterity; } diff --git a/src/c/character.h b/src/c/character.h index 0c18944..5caca85 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -16,6 +16,8 @@ void setCharacterStrength (Character *character, int newStrength); int getCharacterStrength (Character *character); +void addCharacterStrength (Character *character, int addStrength); + void setCharacterDexterity (Character *character, int newDexterity); int getCharacterDexterity (Character *character); diff --git a/test/c/test_character.c b/test/c/test_character.c index 71b43ec..d948c3c 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -47,6 +47,11 @@ void test_getCharacterStrength(void) { TEST_ASSERT_EQUAL_INT(5,testCharacter2.strength); } +void test_addCharacterStrength (void) { + addCharacterStrength(&testCharacter2,15); + TEST_ASSERT_EQUAL_INT(20,testCharacter2.strength); +} + void test_setCharacterDexterity(void) { TEST_ASSERT_EQUAL_INT(0,testCharacter.dexterity); setCharacterDexterity(&testCharacter,50); From 4ac4f2b6d80352226b60b6fe2b4d5cbf1a6ff9d5 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 14 Jan 2023 17:55:34 +0100 Subject: [PATCH 11/19] refactoring: prod combined addCharacterHealthPoints and addCharacterStrength to increaseStat function also --- src/c/character.c | 28 ++++++++++++++++++++-------- src/c/character.h | 10 ++++++---- test/c/test_character.c | 7 +++---- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/c/character.c b/src/c/character.c index c3010be..40051d6 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -3,6 +3,7 @@ #include #include "character.h" + Character character; void setCharacterHealthPoints (Character *character, int newHealthPoints){ @@ -13,10 +14,6 @@ int getCharacterHealthPoints (Character *character) { return character->healthPoints; } -void addCharacterHealthPoints (Character *character, int addedHealthPoints) { - character->healthPoints += addedHealthPoints; -} - void setCharacterStrength (Character *character, int newStrength) { character->strength = newStrength; } @@ -25,10 +22,6 @@ int getCharacterStrength (Character *character) { return character->strength; } -void addCharacterStrength (Character *character, int addStrength) { - character->strength += addStrength; -} - void setCharacterDexterity (Character *character, int newDexterity) { character->dexterity = newDexterity; } @@ -43,4 +36,23 @@ void setCharacterIntelligence (Character *character, int newIntelligence) { int getCharacterIntelligence (Character *character) { return character->intelligence; +} + + +void increaseStat (Character *character, int Stat, int amount) { + switch (Stat) + { + case 1: + character->strength += amount;break; + case 2: + character->dexterity += amount;break; + case 3: + character->intelligence += amount;break; + case 4: + character->healthPoints += amount;break; + case 5: + character->manaPoints += amount;break; + default: + break; + } } \ No newline at end of file diff --git a/src/c/character.h b/src/c/character.h index 5caca85..02b4630 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -6,18 +6,18 @@ typedef struct { char name [50]; } Character; +enum { + STRENGTH = 1, DEXTERITY = 2, INTELLIGENCE = 3, HEALTHPOINTS = 4, MANAPOINTS = 5 +}; + void setCharacterHealthPoints (Character *character, int newHealthPoints); int getCharacterHealthPoints (Character *character); -void addCharacterHealthPoints (Character *character, int addedHealthPoints); - void setCharacterStrength (Character *character, int newStrength); int getCharacterStrength (Character *character); -void addCharacterStrength (Character *character, int addStrength); - void setCharacterDexterity (Character *character, int newDexterity); int getCharacterDexterity (Character *character); @@ -26,4 +26,6 @@ void setCharacterIntelligence (Character *character, int newIntelligence); int getCharacterIntelligence (Character *character); +void increaseStat (Character *character, int Stat, int amount); + #endif \ No newline at end of file diff --git a/test/c/test_character.c b/test/c/test_character.c index d948c3c..083b842 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -32,9 +32,8 @@ void test_getCharacterHealthPoints (void) { } void test_addCharacterHealthPoints (void) { - addCharacterHealthPoints(&testCharacter2,5); + increaseStat(&testCharacter2,HEALTHPOINTS,5); TEST_ASSERT_EQUAL_INT(20,testCharacter2.healthPoints); - } void test_setCharacterStrenght(void) { @@ -48,8 +47,8 @@ void test_getCharacterStrength(void) { } void test_addCharacterStrength (void) { - addCharacterStrength(&testCharacter2,15); - TEST_ASSERT_EQUAL_INT(20,testCharacter2.strength); + increaseStat(&testCharacter2,STRENGTH,5); + TEST_ASSERT_EQUAL_INT(10,testCharacter2.strength); } void test_setCharacterDexterity(void) { From 62b522558c546ea9c9533214082e27f3c6aeb71b Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 14 Jan 2023 17:59:03 +0100 Subject: [PATCH 12/19] refactoring: test combined the test_addCharacterHealthpoints and test_addCharacterStrength Unittests --- test/c/test_character.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/test/c/test_character.c b/test/c/test_character.c index 083b842..20d175c 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -31,11 +31,6 @@ void test_getCharacterHealthPoints (void) { TEST_ASSERT_EQUAL_INT(15,testCharacter2.healthPoints); } -void test_addCharacterHealthPoints (void) { - increaseStat(&testCharacter2,HEALTHPOINTS,5); - TEST_ASSERT_EQUAL_INT(20,testCharacter2.healthPoints); -} - void test_setCharacterStrenght(void) { TEST_ASSERT_EQUAL_INT(0,testCharacter.strength); setCharacterStrength(&testCharacter,50); @@ -46,11 +41,6 @@ void test_getCharacterStrength(void) { TEST_ASSERT_EQUAL_INT(5,testCharacter2.strength); } -void test_addCharacterStrength (void) { - increaseStat(&testCharacter2,STRENGTH,5); - TEST_ASSERT_EQUAL_INT(10,testCharacter2.strength); -} - void test_setCharacterDexterity(void) { TEST_ASSERT_EQUAL_INT(0,testCharacter.dexterity); setCharacterDexterity(&testCharacter,50); @@ -71,4 +61,11 @@ void test_getCharacterIntelligence(void) { TEST_ASSERT_EQUAL_INT(7,testCharacter2.intelligence); } +void test_increaseStat(void) { + increaseStat(&testCharacter2,STRENGTH,15); + TEST_ASSERT_EQUAL_INT(20,testCharacter2.strength); + increaseStat(&testCharacter2,INTELLIGENCE,15); + TEST_ASSERT_EQUAL_INT(22,testCharacter2.intelligence); +} + #endif // TEST \ No newline at end of file From 788b458687faf6499e98fb628b520a62ba6ec371 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 14 Jan 2023 18:24:02 +0100 Subject: [PATCH 13/19] prod/test: added Level stat and created test_setCharacterLevel and setCharacterLevel --- src/c/character.c | 10 +++++++--- src/c/character.h | 7 ++++--- test/c/test_character.c | 8 ++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/c/character.c b/src/c/character.c index 40051d6..1b12e2c 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -38,9 +38,13 @@ int getCharacterIntelligence (Character *character) { return character->intelligence; } +void setCharacterLevel (Character *character, int newLevel) { + character->level = newLevel; +} + -void increaseStat (Character *character, int Stat, int amount) { - switch (Stat) +void increaseStat (Character *character, int stat, int amount) { + switch (stat) { case 1: character->strength += amount;break; @@ -55,4 +59,4 @@ void increaseStat (Character *character, int Stat, int amount) { default: break; } -} \ No newline at end of file +} diff --git a/src/c/character.h b/src/c/character.h index 02b4630..411a1e3 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -2,12 +2,12 @@ #define CHARACTER_H typedef struct { - int strength,dexterity,intelligence,healthPoints,manaPoints; + int strength,dexterity,intelligence,healthPoints,manaPoints,level; char name [50]; } Character; enum { - STRENGTH = 1, DEXTERITY = 2, INTELLIGENCE = 3, HEALTHPOINTS = 4, MANAPOINTS = 5 + STRENGTH = 1, DEXTERITY = 2, INTELLIGENCE = 3, HEALTHPOINTS = 4, MANAPOINTS = 5, LEVEL = 6 }; void setCharacterHealthPoints (Character *character, int newHealthPoints); @@ -26,6 +26,7 @@ void setCharacterIntelligence (Character *character, int newIntelligence); int getCharacterIntelligence (Character *character); -void increaseStat (Character *character, int Stat, int amount); +void setCharacterLevel (Character *character, int newLevel); +void increaseStat (Character *character, int stat, int amount); #endif \ No newline at end of file diff --git a/test/c/test_character.c b/test/c/test_character.c index 20d175c..8dff325 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -14,6 +14,8 @@ void setUp(void) testCharacter2.dexterity = 5; testCharacter.intelligence = 0; testCharacter2.intelligence = 7; + testCharacter.level = 0; + testCharacter2.level = 5; } void tearDown(void) @@ -61,6 +63,12 @@ void test_getCharacterIntelligence(void) { TEST_ASSERT_EQUAL_INT(7,testCharacter2.intelligence); } +void test_setCharacterLevel(void) { + TEST_ASSERT_EQUAL_INT(0,testCharacter.level); + setCharacterLevel(&testCharacter,1); + TEST_ASSERT_EQUAL_INT(1,testCharacter.level); +} + void test_increaseStat(void) { increaseStat(&testCharacter2,STRENGTH,15); TEST_ASSERT_EQUAL_INT(20,testCharacter2.strength); From b2232479decc409718a189576f711b0a99d7683f Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 14 Jan 2023 18:27:40 +0100 Subject: [PATCH 14/19] prod/test: created getCharacterLevel and test_getCharacterLevel --- src/c/character.c | 4 ++++ src/c/character.h | 2 ++ test/c/test_character.c | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/src/c/character.c b/src/c/character.c index 1b12e2c..2229b51 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -42,6 +42,10 @@ void setCharacterLevel (Character *character, int newLevel) { character->level = newLevel; } +int getCharacterLevel (Character *character) { + return character->level; +} + void increaseStat (Character *character, int stat, int amount) { switch (stat) diff --git a/src/c/character.h b/src/c/character.h index 411a1e3..6e53350 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -28,5 +28,7 @@ int getCharacterIntelligence (Character *character); void setCharacterLevel (Character *character, int newLevel); +int getCharacterLevel (Character *character); + void increaseStat (Character *character, int stat, int amount); #endif \ No newline at end of file diff --git a/test/c/test_character.c b/test/c/test_character.c index 8dff325..44fdd1c 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -69,6 +69,10 @@ void test_setCharacterLevel(void) { TEST_ASSERT_EQUAL_INT(1,testCharacter.level); } +void test_getCharacterLevel(void) { + TEST_ASSERT_EQUAL_INT(5,testCharacter2.level); +} + void test_increaseStat(void) { increaseStat(&testCharacter2,STRENGTH,15); TEST_ASSERT_EQUAL_INT(20,testCharacter2.strength); From 98ea061df8f5ce703239effe313583ba0c72995e Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 14 Jan 2023 18:40:15 +0100 Subject: [PATCH 15/19] prod/test: created test_calculateStatIncrease and calculateStatIncrease --- src/c/character.c | 4 ++++ src/c/character.h | 2 ++ test/c/test_character.c | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/src/c/character.c b/src/c/character.c index 2229b51..cb8f3b8 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -46,6 +46,10 @@ int getCharacterLevel (Character *character) { return character->level; } +int calculateStatIncrease (Character *character, int amount) { + return character->level*amount; +} + void increaseStat (Character *character, int stat, int amount) { switch (stat) diff --git a/src/c/character.h b/src/c/character.h index 6e53350..633d3e1 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -31,4 +31,6 @@ void setCharacterLevel (Character *character, int newLevel); int getCharacterLevel (Character *character); void increaseStat (Character *character, int stat, int amount); + +int calculateStatIncrease (Character *character, int amount); #endif \ No newline at end of file diff --git a/test/c/test_character.c b/test/c/test_character.c index 44fdd1c..f6c9f75 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -80,4 +80,8 @@ void test_increaseStat(void) { TEST_ASSERT_EQUAL_INT(22,testCharacter2.intelligence); } +void test_calculateStatIncrease(void) { + TEST_ASSERT_EQUAL_INT(5,testCharacter2.level); + TEST_ASSERT_EQUAL_INT(25,calculateStatIncrease(&testCharacter2,5)); +} #endif // TEST \ No newline at end of file From a0c3371d454233f0097ff035b5e609d782a15e77 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 14 Jan 2023 18:43:23 +0100 Subject: [PATCH 16/19] test: updated test_get* Unittests as i had an error and didn't actually tested the correct value --- test/c/test_character.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/c/test_character.c b/test/c/test_character.c index f6c9f75..ad72b33 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -30,7 +30,7 @@ void test_setCharacterHealthPoints(void) } void test_getCharacterHealthPoints (void) { - TEST_ASSERT_EQUAL_INT(15,testCharacter2.healthPoints); + TEST_ASSERT_EQUAL_INT(15,getCharacterHealthPoints(&testCharacter2)); } void test_setCharacterStrenght(void) { @@ -40,7 +40,7 @@ void test_setCharacterStrenght(void) { } void test_getCharacterStrength(void) { - TEST_ASSERT_EQUAL_INT(5,testCharacter2.strength); + TEST_ASSERT_EQUAL_INT(5,getCharacterStrength(&testCharacter2)); } void test_setCharacterDexterity(void) { @@ -50,7 +50,7 @@ void test_setCharacterDexterity(void) { } void test_getCharacterDexterity(void) { - TEST_ASSERT_EQUAL_INT(5,testCharacter2.dexterity); + TEST_ASSERT_EQUAL_INT(5,getCharacterDexterity(&testCharacter2)); } void test_setCharacterIntelligence(void) { @@ -60,7 +60,7 @@ void test_setCharacterIntelligence(void) { } void test_getCharacterIntelligence(void) { - TEST_ASSERT_EQUAL_INT(7,testCharacter2.intelligence); + TEST_ASSERT_EQUAL_INT(7,getCharacterIntelligence(&testCharacter2)); } void test_setCharacterLevel(void) { @@ -70,7 +70,7 @@ void test_setCharacterLevel(void) { } void test_getCharacterLevel(void) { - TEST_ASSERT_EQUAL_INT(5,testCharacter2.level); + TEST_ASSERT_EQUAL_INT(5,getCharacterLevel(&testCharacter2)); } void test_increaseStat(void) { From 8b4b35b46138df882b991db83fd4cd38f481f431 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 21 Jan 2023 16:45:11 +0100 Subject: [PATCH 17/19] prod: Added new stats exp and maxExp and added their getter and setter no Unittest as that is apparently not neccessary for them --- src/c/character.c | 16 ++++++++++++++++ src/c/character.h | 10 +++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/c/character.c b/src/c/character.c index cb8f3b8..779e795 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -46,6 +46,22 @@ int getCharacterLevel (Character *character) { return character->level; } +void setCharacterExp (Character *character, int newExp) { + character->exp = newExp; +} + +int getCharacterExp (Character *character) { + return character->exp; +} + +void setCharacterMaxExp (Character *character, int newMaxExp) { + character->maxExp = newMaxExp; +} + +int getCharacterMaxExp (Character *character) { + return character->maxExp; +} + int calculateStatIncrease (Character *character, int amount) { return character->level*amount; } diff --git a/src/c/character.h b/src/c/character.h index 633d3e1..c7ee567 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -2,7 +2,7 @@ #define CHARACTER_H typedef struct { - int strength,dexterity,intelligence,healthPoints,manaPoints,level; + int strength,dexterity,intelligence,healthPoints,manaPoints,level,exp,maxExp; char name [50]; } Character; @@ -30,6 +30,14 @@ void setCharacterLevel (Character *character, int newLevel); int getCharacterLevel (Character *character); +void setCharacterExp (Character *character, int newExp); + +int getCharacterExp (Character *character); + +void setCharacterMaxExp (Character *character, int newMaxExp); + +int getCharacterMaxExp (Character *character); + void increaseStat (Character *character, int stat, int amount); int calculateStatIncrease (Character *character, int amount); From 3f03db161eecba8a883d191a286106ca2982458d Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 21 Jan 2023 18:05:18 +0100 Subject: [PATCH 18/19] prod/test: added new stats to increase stat function created levelUp function and 2 Unittests test_levelUp_* --- src/c/character.c | 12 +++++++++++- src/c/character.h | 4 +++- test/c/test_character.c | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/c/character.c b/src/c/character.c index 779e795..f5a5bd4 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -66,7 +66,6 @@ int calculateStatIncrease (Character *character, int amount) { return character->level*amount; } - void increaseStat (Character *character, int stat, int amount) { switch (stat) { @@ -80,7 +79,18 @@ void increaseStat (Character *character, int stat, int amount) { character->healthPoints += amount;break; case 5: character->manaPoints += amount;break; + case 6: + character->level += amount;break; + case 7: + character->exp += amount;break; + case 8: + character->maxExp += amount;break; default: break; } } +void levelUp (Character *character) { + if (getCharacterExp(character) > getCharacterMaxExp(character)) { + increaseStat(character,LEVEL,1); + } +} \ No newline at end of file diff --git a/src/c/character.h b/src/c/character.h index c7ee567..7ed09b4 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -7,7 +7,7 @@ typedef struct { } Character; enum { - STRENGTH = 1, DEXTERITY = 2, INTELLIGENCE = 3, HEALTHPOINTS = 4, MANAPOINTS = 5, LEVEL = 6 + STRENGTH = 1, DEXTERITY = 2, INTELLIGENCE = 3, HEALTHPOINTS = 4, MANAPOINTS = 5, LEVEL = 6, EXP = 7, MAXEXP = 8 }; void setCharacterHealthPoints (Character *character, int newHealthPoints); @@ -41,4 +41,6 @@ int getCharacterMaxExp (Character *character); void increaseStat (Character *character, int stat, int amount); int calculateStatIncrease (Character *character, int amount); + +void levelUp (Character *character); #endif \ No newline at end of file diff --git a/test/c/test_character.c b/test/c/test_character.c index ad72b33..ba52049 100644 --- a/test/c/test_character.c +++ b/test/c/test_character.c @@ -16,6 +16,10 @@ void setUp(void) testCharacter2.intelligence = 7; testCharacter.level = 0; testCharacter2.level = 5; + testCharacter.exp = 50; + testCharacter2.exp = 110; + testCharacter.maxExp = 100; + testCharacter2.maxExp = 100; } void tearDown(void) @@ -78,10 +82,30 @@ void test_increaseStat(void) { TEST_ASSERT_EQUAL_INT(20,testCharacter2.strength); increaseStat(&testCharacter2,INTELLIGENCE,15); TEST_ASSERT_EQUAL_INT(22,testCharacter2.intelligence); + increaseStat(&testCharacter2,LEVEL,15); + TEST_ASSERT_EQUAL_INT(20,testCharacter2.level); } void test_calculateStatIncrease(void) { TEST_ASSERT_EQUAL_INT(5,testCharacter2.level); TEST_ASSERT_EQUAL_INT(25,calculateStatIncrease(&testCharacter2,5)); } + +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_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); +} + + #endif // TEST \ No newline at end of file From 95189c0ff044d71de6b54cc4ca0fa0e60b5edd01 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 21 Jan 2023 18:12:13 +0100 Subject: [PATCH 19/19] 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