Browse Source

added setName with test

remotes/origin/navigation
KRUGSON 2 years ago
parent
commit
ff33db459d
  1. 4
      src/c/weapon.c
  2. 4
      src/c/weapon.h
  3. 19
      test/c/test_weapon.c

4
src/c/weapon.c

@ -2,4 +2,8 @@
char *getName(Weapon *weapon){ char *getName(Weapon *weapon){
return weapon->name; return weapon->name;
}
void setName(Weapon *weapon, char *nameToSet){
weapon->name = nameToSet;
} }

4
src/c/weapon.h

@ -11,11 +11,15 @@ typedef struct
int id; int id;
char *fullName; char *fullName;
char *name; char *name;
int typeID;
char *typeName;
int damageModifier; int damageModifier;
int baseDamage; int baseDamage;
bool canBeUsed; bool canBeUsed;
} Weapon; } Weapon;
char *getName(Weapon *weapon); char *getName(Weapon *weapon);
void setName(Weapon *weapon, char *nameToSet);
#endif #endif

19
test/c/test_weapon.c

@ -5,14 +5,12 @@
void setUp(void) void setUp(void)
{ {
} }
void tearDown(void) void tearDown(void)
{ {
} }
void test_getName(void) void test_getName(void)
{ {
// arrange // arrange
@ -31,4 +29,21 @@ void test_getName(void)
TEST_ASSERT_EQUAL(nameOfWeapon, result); TEST_ASSERT_EQUAL(nameOfWeapon, result);
} }
void test_setName(void)
{
// arrange
char *nameWeapon = "switchblade", *result;
// act
Weapon test;
setName(&test, nameWeapon);
result = test.name;
// output
printf("setName | name set to: %s -> after set: %s", nameWeapon, result);
// assert
TEST_ASSERT_EQUAL(nameWeapon, result);
}
#endif // TEST #endif // TEST
Loading…
Cancel
Save