From 517f0cfafe1233c82e2aac4ac7ee8989c04ac7f4 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 04:06:38 +0100 Subject: [PATCH] added setFullName with test --- src/c/weapon.c | 14 +++++++++++--- src/c/weapon.h | 1 + test/c/test_weapon.c | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/c/weapon.c b/src/c/weapon.c index 50d8692..a506bb9 100644 --- a/src/c/weapon.c +++ b/src/c/weapon.c @@ -1,13 +1,21 @@ #include "weapon.h" -char *getName(Weapon *weapon){ +char *getName(Weapon *weapon) +{ return weapon->name; } -void setName(Weapon *weapon, char *nameToSet){ +void setName(Weapon *weapon, char *nameToSet) +{ weapon->name = nameToSet; } -char *getFullName(Weapon *weapon){ +char *getFullName(Weapon *weapon) +{ return weapon->fullName; +} + +void setFullName(Weapon *weapon, char *fullNameToSet) +{ + weapon->fullName = fullNameToSet; } \ No newline at end of file diff --git a/src/c/weapon.h b/src/c/weapon.h index 9f1febc..86d4209 100644 --- a/src/c/weapon.h +++ b/src/c/weapon.h @@ -22,5 +22,6 @@ char *getName(Weapon *weapon); void setName(Weapon *weapon, char *nameToSet); char *getFullName(Weapon *weapon); +void setFullName(Weapon *weapon, char *fullNameToSet); #endif \ No newline at end of file diff --git a/test/c/test_weapon.c b/test/c/test_weapon.c index bb24bd3..0998f6f 100644 --- a/test/c/test_weapon.c +++ b/test/c/test_weapon.c @@ -64,4 +64,21 @@ void test_getFullName(void) TEST_ASSERT_EQUAL(nameOfWeapon, result); } +void test_setFullName(void) +{ + // arrange + char *fullNameWeapon = "switchblade v2", *result; + + // act + Weapon test; + setFullName(&test, fullNameWeapon); + result = test.fullName; + + // output + printf("setFullName | fullName set to: %s -> after set: %s", fullNameWeapon, result); + + // assert + TEST_ASSERT_EQUAL(fullNameWeapon, result); +} + #endif // TEST