Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement testing for Multiclass_longdesc and Multiclass_shortdesc #1633

Merged
merged 60 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
bceed3d
#1402 I have gotten the file working, but I have not yet impemented a…
May 16, 2022
aa521b3
forgot to save...
May 16, 2022
9e85d1e
transferred code from task #1143 to complete task #1402
May 16, 2022
7906b34
#1402 moved updated multiclass_shortdesc and multiclass_longdesc func…
May 16, 2022
381228d
#1402 updated multiclass_shortdesc and multiclass_longdesc to include…
May 16, 2022
7a5a080
#1402 I have implemented a check so that the phrase Multiclass of isn…
May 16, 2022
a5e9159
#1402 added first instance of multiclass testing
May 16, 2022
5fd9a20
#1402 in progress of adding tests
May 16, 2022
5f0ef20
#1402 almost done with shortdesc testing
May 16, 2022
454aec7
#1402 finished writing tests for the multiclass module in test_multic…
May 16, 2022
997d398
I think I fixed some tests
May 22, 2022
5b1a4f8
I think I fixed everything
May 22, 2022
a1d7b85
working on fixing testing for multiclass
May 22, 2022
00f4389
i dont think I saved before the last commit
May 22, 2022
6a50c6e
AAAAAAAAAAAAAAAAAAAAAAAH
May 23, 2022
022e8d9
#1402 fixed a missing parentheses in a strstr call in multiclass
May 24, 2022
b06f0b1
#1402 forgot to include a function in the header file
May 24, 2022
782adb9
#1402 I literally never save and I hate myself for it. All old pushes…
May 24, 2022
51bc5ff
#1402 fixed a small bug where the number of parent classes was 2 too …
May 24, 2022
f2b88ea
Changed basic_shortdesc and iterated_shortdesc so the expected output…
May 24, 2022
4e5bcaf
#1306 debugging multiclassing
May 24, 2022
16f35fe
#1402 more debugging
May 24, 2022
d7cafb4
#1402 more debugging
May 24, 2022
01fa0f3
#1402 more debugging
May 24, 2022
600e392
#1402 debugging multiclass_shortdesc()
May 24, 2022
b76988d
#1402 more debugging
May 24, 2022
1d561f2
#1402 more debugging
May 24, 2022
a77fa69
#1402 debugging
May 24, 2022
ec1af9f
Revert "#1402 fixed a small bug where the number of parent classes wa…
May 24, 2022
57c92dd
Revert "#1402 I literally never save and I hate myself for it. All ol…
May 24, 2022
011bbe1
Revert "#1402 forgot to include a function in the header file"
May 24, 2022
104d84e
Revert "#1402 fixed a missing parentheses in a strstr call in multicl…
May 24, 2022
d159c5f
Revert "AAAAAAAAAAAAAAAAAAAAAAAH"
May 24, 2022
febea77
Revert "i dont think I saved before the last commit"
May 24, 2022
5b0887e
Revert "working on fixing testing for multiclass"
May 24, 2022
91eac26
Revert "I think I fixed everything"
May 24, 2022
f45b27e
Revert "I think I fixed some tests"
May 24, 2022
b2bd44c
#1402 removed tests with multi-multiclassing because this feature is …
May 25, 2022
08cc2d0
#1402 added a change to multiclass_inventory() in multiclass.c
May 25, 2022
1bcd170
#1402 fixed bugs in multiclass_shortdesc() and multiclass_longdesc()
May 25, 2022
49da90e
#1402 debugging
May 25, 2022
d6456c3
#1402 more debugging
May 25, 2022
437ef06
#1402 debugging
May 25, 2022
81d3524
#1402 debugging
May 25, 2022
c5b2056
debugging
May 25, 2022
8036808
#1402 it works git add -ugit add -ugit add -ugit add -u
May 25, 2022
afd1dde
working!
May 25, 2022
6963050
#1402 officially done
May 25, 2022
c04914e
#1402 done
May 25, 2022
beeef4c
I have fixed a few typos according to Van's recommendations
May 27, 2022
3e7626a
fixing merge conflicts
May 27, 2022
f69affa
Merge branch 'dev' into Multiclass_Test
May 27, 2022
b49afad
weird merge but I think its fixed
May 27, 2022
f86975f
finally fixed everything. Merge conflicts resolved I believe.
May 27, 2022
219647b
going to merge dev so this is scary
May 27, 2022
3563e34
Merge branch 'dev' into Multiclass_Test
May 27, 2022
d52f007
merge done, Lily's suggestions have been fixed
May 27, 2022
634f9cb
Merge branch 'dev' into Multiclass_Test
lilyehsani May 27, 2022
1740fa9
fixed the class count
May 27, 2022
23916b9
Merge branch 'dev' into Multiclass_Test
lilyehsani May 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/playerclass/multiclass.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* Enables multiclass functionality
*/
Expand Down Expand Up @@ -47,4 +48,9 @@ class_t* multiclass(class_t* base_class, class_t* second_class, char* name);
*/
int has_component_class(class_t* class, char* name);

/* these are only here so it can be included in testing. They should be ignored
if you are viewing this module to learn about the code */
char* multiclass_shortdesc(class_t* base_class, class_t* second_class, int *succ);
char* multiclass_longdesc(class_t* base_class, class_t* second_class, int *succ);

#endif /* MULTICLASS_H */
90 changes: 80 additions & 10 deletions src/playerclass/src/multiclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,77 @@
* Returns:
* - a pointer to a string with the new shortdesc.
*/
char* multiclass_shortdesc(class_t* base_class, class_t* second_class) {
char* multiclass_shortdesc(class_t* base_class, class_t* second_class, int *succ) {
lilyehsani marked this conversation as resolved.
Show resolved Hide resolved

int num_multiclass = base_class->num_parent_class + second_class->num_parent_class;

char* new_shortdesc = (char*) malloc(MAX_SHORT_DESC_LEN + 1);
strncat(new_shortdesc, "Multiclass of ", 15);
*succ = SUCCESS;
int len = 0;

if ((strstr(base_class->name, "Multiclass of ") == NULL)){
len += 14;
lilyehsani marked this conversation as resolved.
Show resolved Hide resolved
}
len += strlen(base_class->name);
if (num_multiclass == 2){
len += 2;
} else{
len += 5;
}
len += strlen(second_class->name);
for (int i = 0; i < base_class->num_parent_class; i++) {
if(i == base_class->num_parent_class - 1 && second_class->num_parent_class == 0){
len += 5;
} else{
len += 2;
}
len += strlen(base_class->parent_class_names[i]);
}
for (int i = 0; i < second_class->num_parent_class - 1; i++) {
if(i == second_class->num_parent_class - 1){
len += 5;
} else{
len += 2;
}
len += strlen(second_class->parent_class_names[i]);
}
len += 1;

if (len > MAX_SHORT_DESC_LEN + 1) {
fprintf(stderr, "multiclass_shortdesc: Shortdesc longer than max length, second shortdesc not appended");
*succ = FAILURE;
return base_class->shortdesc;
}

if ((strstr(base_class->name, "Multiclass of ") == NULL)){
strncat(new_shortdesc, "Multiclass of ", 15);
}
strncat(new_shortdesc, base_class->name, strlen(base_class->name));
strncat(new_shortdesc, ", ", 3);
if (num_multiclass == 2){
strncat(new_shortdesc, ", ", 3);
lilyehsani marked this conversation as resolved.
Show resolved Hide resolved
} else{
strncat(new_shortdesc, " and ", 6);
}
strncat(new_shortdesc, second_class->name, strlen(second_class->name));
for (int i = 0; i < base_class->num_parent_class; i++) {
strncat(new_shortdesc, ", ", 3);
if(i == base_class->num_parent_class - 1 && second_class->num_parent_class == 0){
strncat(new_shortdesc, " and ", 6);
} else{
strncat(new_shortdesc, ", ", 3);
}
strncat(new_shortdesc, base_class->parent_class_names[i], strlen(base_class->parent_class_names[i]));
}
for (int i = 0; i < second_class->num_parent_class; i++) {
strncat(new_shortdesc, ", ", 3);
for (int i = 0; i < second_class->num_parent_class - 1; i++) {
if(i == second_class->num_parent_class - 1){
strncat(new_shortdesc, " and ", 6);
} else{
strncat(new_shortdesc, ", ", 3);
}
strncat(new_shortdesc, second_class->parent_class_names[i], strlen(second_class->parent_class_names[i]));
}

strncat(new_shortdesc, ".", 2);

return new_shortdesc;
}

Expand All @@ -56,11 +112,21 @@ char* multiclass_shortdesc(class_t* base_class, class_t* second_class) {
* Returns:
lilyehsani marked this conversation as resolved.
Show resolved Hide resolved
* - a pointer to a string with the new longdesc.
*/
char* multiclass_longdesc(class_t* base_class, class_t* second_class) {
char* multiclass_longdesc(class_t* base_class, class_t* second_class, int *succ) {
lilyehsani marked this conversation as resolved.
Show resolved Hide resolved
char* new_longdesc = (char*) calloc(MAX_LONG_DESC_LEN + 1, sizeof(char));
*succ = SUCCESS;
int len = 0;
strncat(new_longdesc, base_class->shortdesc, strlen(base_class->shortdesc));
strncat(new_longdesc, "\n\n", 3);
strncat(new_longdesc, second_class->shortdesc, strlen(second_class->shortdesc));
len += strlen(base_class->shortdesc) + 2 + strlen(second_class->shortdesc);

if (len > MAX_LONG_DESC_LEN + 1) {
fprintf(stderr, "multiclass_longdesc: Longdesc longer than max length, second longdesc not appended");
*succ = FAILURE;
return base_class->longdesc;
}

return new_longdesc;
}

Expand Down Expand Up @@ -187,6 +253,9 @@ skill_inventory_t* multiclass_inventory(skill_inventory_t* base_inventory, skill
/* Calculate new inventory sizes */
unsigned int max_active;
unsigned int max_passive;
if (base_max_active == 0 && base_max_passive == 0) {
return base_inventory;
}
if (base_max_active >= second_max_active) {
max_active = base_max_active;
}
Expand Down Expand Up @@ -244,8 +313,9 @@ obj_t* multiclass_attributes(obj_t* base_attributes, obj_t* second_attributes, c

/* See multiclass.h */
class_t* multiclass(class_t* base_class, class_t* second_class, char* name) {
char* new_shortdesc = multiclass_shortdesc(base_class, second_class);
char* new_longdesc = multiclass_longdesc(base_class, second_class);
int shortdesc_succ, longdesc_succ;
char* new_shortdesc = multiclass_shortdesc(base_class, second_class, &shortdesc_succ);
char* new_longdesc = multiclass_longdesc(base_class, second_class, &longdesc_succ);
obj_t* combined_attr = multiclass_attributes(base_class->attributes, second_class->attributes, name);
effects_hash_t* combined_effects = multiclass_effects(base_class->effects, second_class->effects);

Expand Down Expand Up @@ -287,4 +357,4 @@ int has_component_class(class_t* class, char* name) {
}
}
return 0;
}
}
1 change: 1 addition & 0 deletions tests/playerclass/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(TEST_EXE test-playerclass)
add_executable(${TEST_EXE}
test_class.c
test_class_item.c
test_multiclass.c
test_class_prefabs.c
main.c)

Expand Down
44 changes: 22 additions & 22 deletions tests/playerclass/test_class_prefabs.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ chiventure_ctx_t* init_statless_context() {
}

/* Checks whether the class and its basic fields are not null */
void check_field_presence(class_t* c)
void check_field_pressence(class_t* c)
lilyehsani marked this conversation as resolved.
Show resolved Hide resolved
{
cr_assert_not_null(c, "failed to be initialized (NULL)");
cr_assert_not_null(c->name, "failed to initialize name");
Expand All @@ -69,7 +69,7 @@ void check_field_presence(class_t* c)

/* Checks whether skill fields are present, and whether the initialized skills
* match the expected list */
void check_skill_presence(class_t* c, int num_skills, char** names)
void check_skill_pressence(class_t* c, int num_skills, char** names)
{
cr_assert_not_null(c->skilltree, "failed to initialize skilltree");
cr_assert_not_null(c->starting_skills, "failed to initialize skill inventory");
Expand All @@ -84,14 +84,14 @@ Test(class_prefabs, Bard) {

/* Tests if we can find the name even if its case is wrong */
class_t *c = class_prefab_new(ctx->game, "BARD");
check_field_presence(c);
check_field_pressence(c);

cr_assert_eq(get_stat_current(c->base_stats, "max_health"), 15, "failed to initialize stat");

class_prefab_add_skills(c);

char* skill_list[] = {"Magic Word", "Poetic Line", "Enchanted Stanza"};
check_skill_presence(c, 3, skill_list);
check_skill_pressence(c, 3, skill_list);

cr_assert_str_eq(c->starting_skills->active[0]->name, "Magic Word", "failed to initialize skill inventory");
}
Expand All @@ -101,14 +101,14 @@ Test(class_prefabs, Monk) {
chiventure_ctx_t* ctx = init_statless_context();

class_t *c = class_prefab_new(ctx->game, "monk");
check_field_presence(c);
check_field_pressence(c);

cr_assert_eq(get_stat_current(c->base_stats, "max_health"), 25, "failed to initialize stat");

class_prefab_add_skills(c);

char* skill_list[] = {"Acrobatic Powers", "Spirit of Strength", "Supernova Circle"};
check_skill_presence(c, 3, skill_list);
check_skill_pressence(c, 3, skill_list);

cr_assert_str_eq(c->starting_skills->active[0]->name, "Acrobatic Powers", "failed to initialize skill inventory");
}
Expand All @@ -118,14 +118,14 @@ Test(class_prefabs, Ranger) {
chiventure_ctx_t* ctx = init_statless_context();

class_t *c = class_prefab_new(ctx->game, "ranger");
check_field_presence(c);
check_field_pressence(c);

cr_assert_eq(get_stat_current(c->base_stats, "max_health"), 10, "failed to initialize stat");

class_prefab_add_skills(c);

char* skill_list[] = {"Close Shot", "Mid-range Shot", "Long Shot"};
check_skill_presence(c, 3, skill_list);
check_skill_pressence(c, 3, skill_list);

cr_assert_str_eq(c->starting_skills->active[0]->name, "Close Shot", "failed to initialize skill inventory");
}
Expand All @@ -135,14 +135,14 @@ Test(class_prefabs, Rogue) {
chiventure_ctx_t* ctx = init_statless_context();

class_t *c = class_prefab_new(ctx->game, "rogue");
check_field_presence(c);
check_field_pressence(c);

cr_assert_eq(get_stat_current(c->base_stats, "max_health"), 10, "failed to initialize stat");

class_prefab_add_skills(c);

char* skill_list[] = {"Quick Hit", "Backstab", "Leg Swipe"};
check_skill_presence(c, 3, skill_list);
check_skill_pressence(c, 3, skill_list);

cr_assert_str_eq(c->starting_skills->active[0]->name, "Quick Hit", "failed to initialize skill inventory");
}
Expand All @@ -156,15 +156,15 @@ Test(class_prefabs, Warrior) {

/* Note that the name is always stored lowercase. */
class_t *c = class_prefab_new(ctx->game, "Warrior");
check_field_presence(c);
check_field_pressence(c);

cr_assert_eq(get_stat_current(c->base_stats, "max_health"), 20, "failed to initialize previously declared stat");
cr_assert_eq(get_stat_current(c->base_stats, "speed"), 15, "failed to initialize new stat");

class_prefab_add_skills(c);

char* skill_list[] = {"Sword Slash", "Double Slash", "Triple Slash"};
check_skill_presence(c, 3, skill_list);
check_skill_pressence(c, 3, skill_list);

cr_assert_str_eq(c->starting_skills->active[0]->name, "Sword Slash", "failed to initialize skill inventory");
}
Expand All @@ -175,14 +175,14 @@ Test(class_prefabs, Wizard) {
chiventure_ctx_t* ctx = init_statless_context();

class_t *c = class_prefab_new(ctx->game, "WIZARD");
check_field_presence(c);
check_field_pressence(c);

cr_assert_eq(get_stat_current(c->base_stats, "max_health"), 10, "failed to initialize stat");

class_prefab_add_skills(c);

char* skill_list[] = {"Blinding Charm", "Paralyze Spell", "Arcane Explosion"};
check_skill_presence(c, 3, skill_list);
check_skill_pressence(c, 3, skill_list);

cr_assert_str_eq(c->starting_skills->active[0]->name, "Blinding Charm", "failed to initialize skill inventory");
}
Expand All @@ -193,14 +193,14 @@ Test(class_prefabs, Druid) {
chiventure_ctx_t* ctx = init_statless_context();

class_t *c = class_prefab_new(ctx->game, "druid");
check_field_presence(c);
check_field_pressence(c);

cr_assert_eq(get_stat_current(c->base_stats, "max_health"), 15, "failed to initialize stat");

class_prefab_add_skills(c);

char* skill_list[] = {"frostbite", "control flames", "flame blade"};
check_skill_presence(c, 3, skill_list);
check_skill_pressence(c, 3, skill_list);

cr_assert_str_eq(c->starting_skills->active[0]->name, "frostbite", "failed to initialize skill inventory");
}
Expand All @@ -210,14 +210,14 @@ Test(class_prefabs, Elementalist) {
chiventure_ctx_t* ctx = init_statless_context();

class_t *c = class_prefab_new(ctx->game, "elementalist");
check_field_presence(c);
check_field_pressence(c);

cr_assert_eq(get_stat_current(c->base_stats, "max_health"), 20, "failed to initialize stat");

class_prefab_add_skills(c);

char* skill_list[] = {"stone shards", "arc lightning", "dragon's tooth"};
check_skill_presence(c, 3, skill_list);
check_skill_pressence(c, 3, skill_list);

cr_assert_str_eq(c->starting_skills->active[0]->name, "stone shards", "failed to initialize skill inventory");
}
Expand All @@ -228,14 +228,14 @@ Test(class_prefabs, Knight) {
chiventure_ctx_t* ctx = init_statless_context();

class_t *c = class_prefab_new(ctx->game, "knight");
check_field_presence(c);
check_field_pressence(c);

cr_assert_eq(get_stat_current(c->base_stats, "max_health"), 40, "failed to initialize stat");

class_prefab_add_skills(c);

char* skill_list[] = {"holy strike", "shield strike", "shackle strike"};
check_skill_presence(c, 3, skill_list);
check_skill_pressence(c, 3, skill_list);

cr_assert_str_eq(c->starting_skills->active[0]->name, "holy strike", "failed to initialize skill inventory");
}
Expand All @@ -245,14 +245,14 @@ Test(class_prefabs, Sorceror) {
chiventure_ctx_t* ctx = init_statless_context();

class_t *c = class_prefab_new(ctx->game, "sorceror");
check_field_presence(c);
check_field_pressence(c);

cr_assert_eq(get_stat_current(c->base_stats, "max_health"), 15, "failed to initialize stat");

class_prefab_add_skills(c);

char* skill_list[] = {"dark magic", "moon storm", "gates of rashonmon"};
check_skill_presence(c, 3, skill_list);
check_skill_pressence(c, 3, skill_list);

cr_assert_str_eq(c->starting_skills->active[0]->name, "dark magic", "failed to initialize skill inventory");
}
Loading