Removes unknown values from fill functions.

Indexes will no longer match Ids.
Updated all tests to use char* argv[] instead of char** argv.
This commit is contained in:
2023-04-22 00:38:48 -07:00
parent e8e9904de3
commit 1f45248ccd
20 changed files with 171 additions and 171 deletions

View File

@@ -34,24 +34,18 @@ void FillAbilitiesForAbilityGroup(vector<string>& abilities, int id) {
int numAbilities = GetNumItemsForAbilityGroup(id); int numAbilities = GetNumItemsForAbilityGroup(id);
switch (id) { switch (id) {
case kAbilityTalentsId: case kAbilityTalentsId:
for (int talentId = 0; talentId <= numAbilities; talentId++) { for (int talent_id = 1; talent_id <= numAbilities; talent_id++) {
if (talentId >= 0 && talentId <= kTalentsCount) { abilities.push_back(GetTalentLabel(talent_id));
abilities.push_back(kTalents[talentId]);
}
} }
break; break;
case kAbilitySkillsId: case kAbilitySkillsId:
for (int skillId = 0; skillId <= numAbilities; skillId++) { for (int skill_id = 1; skill_id <= numAbilities; skill_id++) {
if (skillId >= 0 && skillId <= kSkillsCount) { abilities.push_back(GetSkillLabel(skill_id));
abilities.push_back(kSkills[skillId]);
}
} }
break; break;
case kAbilityKnowledgesId: case kAbilityKnowledgesId:
for (int knowledgeId = 0; knowledgeId <= numAbilities; knowledgeId++) { for (int knowledge_id = 1; knowledge_id <= numAbilities; knowledge_id++) {
if (knowledgeId >= 0 && knowledgeId <= kKnowledgesCount) { abilities.push_back(GetKnowledgeLabel(knowledge_id));
abilities.push_back(kKnowledges[knowledgeId]);
}
} }
break; break;
} }
@@ -75,35 +69,29 @@ void FillAbilityLabels(vector<string>& labels, int id) {
void FillKnowledgeLabels(vector<string>& labels) { void FillKnowledgeLabels(vector<string>& labels) {
labels.clear(); labels.clear();
int numAbilities = GetNumItemsForAbilityGroup(kAbilityKnowledgesId); int numAbilities = GetNumItemsForAbilityGroup(kAbilityKnowledgesId);
for (int knowledgeId = 0; knowledgeId <= numAbilities; knowledgeId++) { for (int knowledge_id = 1; knowledge_id <= numAbilities; knowledge_id++) {
if (knowledgeId >= 0 && knowledgeId <= kKnowledgesCount) { labels.push_back(GetKnowledgeLabel(knowledge_id));
labels.push_back(kKnowledges[knowledgeId]);
}
} }
} }
void FillSkillLabels(vector<string>& labels) { void FillSkillLabels(vector<string>& labels) {
labels.clear(); labels.clear();
int numAbilities = GetNumItemsForAbilityGroup(kAbilitySkillsId); int numAbilities = GetNumItemsForAbilityGroup(kAbilitySkillsId);
for (int skillId = 0; skillId <= numAbilities; skillId++) { for (int skill_id = 1; skill_id <= numAbilities; skill_id++) {
if (skillId >= 0 && skillId <= kSkillsCount) { labels.push_back(GetSkillLabel(skill_id));
labels.push_back(kSkills[skillId]);
}
} }
} }
void FillTalentLabels(vector<string>& labels) { void FillTalentLabels(vector<string>& labels) {
labels.clear(); labels.clear();
int numAbilities = GetNumItemsForAbilityGroup(kAbilityTalentsId); int numAbilities = GetNumItemsForAbilityGroup(kAbilityTalentsId);
for (int talentId = 0; talentId <= numAbilities; talentId++) { for (int talent_id = 1; talent_id <= numAbilities; talent_id++) {
if (talentId >= 0 && talentId <= kTalentsCount) { labels.push_back(GetTalentLabel(talent_id));
labels.push_back(kTalents[talentId]);
}
} }
} }
const AbilityType& GetAbility(int abilityGroupId) { const AbilityType& GetAbility(int ability_group_id) {
switch (abilityGroupId) { switch (ability_group_id) {
case kAbilityTalentsId: case kAbilityTalentsId:
return kAbilityGroupTalents; return kAbilityGroupTalents;
case kAbilitySkillsId: case kAbilitySkillsId:
@@ -114,27 +102,27 @@ const AbilityType& GetAbility(int abilityGroupId) {
return kAbilityGroupUnknown; return kAbilityGroupUnknown;
} }
const string GetAbilityLabel(int abilityGroupId, int abilityId) { const string GetAbilityLabel(int ability_group_id, int ability_id) {
switch (abilityGroupId) { switch (ability_group_id) {
case kAbilityTalentsId: case kAbilityTalentsId:
return GetTalentLabel(abilityId); return GetTalentLabel(ability_id);
case kAbilitySkillsId: case kAbilitySkillsId:
return GetSkillLabel(abilityId); return GetSkillLabel(ability_id);
case kAbilityKnowledgesId: case kAbilityKnowledgesId:
return GetKnowledgeLabel(abilityId); return GetKnowledgeLabel(ability_id);
}; };
return ""; return "";
} }
const std::string GetKnowledgeLabel(int talentId) { const std::string GetKnowledgeLabel(int talent_id) {
if (talentId > 0 && talentId <= kKnowledgesCount) { if (talent_id > 0 && talent_id <= kKnowledgesCount) {
return kKnowledges[talentId]; return kKnowledges[talent_id];
} }
return ""; return "";
} }
int GetNumItemsForAbilityGroup(int abilityGroupId) { int GetNumItemsForAbilityGroup(int ability_group_id) {
switch (abilityGroupId) { switch (ability_group_id) {
case kAbilityTalentsId: case kAbilityTalentsId:
return kTalentsCount; return kTalentsCount;
case kAbilitySkillsId: case kAbilitySkillsId:
@@ -145,16 +133,16 @@ int GetNumItemsForAbilityGroup(int abilityGroupId) {
return 0; return 0;
} }
const std::string GetSkillLabel(int skillId) { const std::string GetSkillLabel(int skill_id) {
if (skillId > 0 && skillId <= kSkillsCount) { if (skill_id > 0 && skill_id <= kSkillsCount) {
return kSkills[skillId]; return kSkills[skill_id];
} }
return ""; return "";
} }
const std::string GetTalentLabel(int talentId) { const std::string GetTalentLabel(int talent_id) {
if (talentId > 0 && talentId <= kTalentsCount) { if (talent_id > 0 && talent_id <= kTalentsCount) {
return kTalents[talentId]; return kTalents[talent_id];
} }
return ""; return "";
} }

View File

@@ -145,44 +145,47 @@ TestResults test_FillAbilitiesForAbilityGroup() {
make_test<vector<string>, int>( make_test<vector<string>, int>(
"should clear the vector for group 0, kAbilityGropuUnknownId", {}, make_tuple(0)), "should clear the vector for group 0, kAbilityGropuUnknownId", {}, make_tuple(0)),
make_test<vector<string>, int>("should fill talents for group 1 kAbilityGroupTalentsId", make_test<vector<string>, int>("should fill talents for group 1 kAbilityGroupTalentsId",
{"", {
"Acting", "Acting",
"Alertness", "Alertness",
"Athletics", "Athletics",
"Brawl", "Brawl",
"Dodge", "Dodge",
"Empathy", "Empathy",
"Intimidation", "Intimidation",
"Leadership", "Leadership",
"Streetwise", "Streetwise",
"Subterfuge"}, //, "Alertness", "Athletics", "Brawl", "Dodge", "Empathy", "Subterfuge",
//"Intimidation", "Leadership", "Streetwise", "Subterfuge" }, //, "Alertness", "Athletics", "Brawl", "Dodge", "Empathy",
//"Intimidation", "Leadership", "Streetwise", "Subterfuge"
make_tuple(1)), make_tuple(1)),
make_test<vector<string>, int>("should fill skills for group 2 kAbilityGroupSkillsId", make_test<vector<string>, int>("should fill skills for group 2 kAbilityGroupSkillsId",
{"", {
"Animal Ken", "Animal Ken",
"Drive", "Drive",
"Etiquette", "Etiquette",
"Firearms", "Firearms",
"Melee", "Melee",
"Music", "Music",
"Repair", "Repair",
"Security", "Security",
"Stealth", "Stealth",
"Survival"}, "Survival",
},
make_tuple(2)), make_tuple(2)),
make_test<vector<string>, int>("should fill knowledges for group 3 kAbilityGroupKnowledgesId", make_test<vector<string>, int>("should fill knowledges for group 3 kAbilityGroupKnowledgesId",
{"", {
"Bureaucracy", "Bureaucracy",
"Computer", "Computer",
"Finance", "Finance",
"Investigation", "Investigation",
"Law", "Law",
"Linguistics", "Linguistics",
"Medicine", "Medicine",
"Occult", "Occult",
"Politics", "Politics",
"Science"}, "Science",
},
make_tuple(3)), make_tuple(3)),
make_test<vector<string>, int>("should clear the vector for group 4 an invalid id", {}, make_tuple(4)), make_test<vector<string>, int>("should clear the vector for group 4 an invalid id", {}, make_tuple(4)),
}))); })));
@@ -200,43 +203,46 @@ TestResults test_FillAbilityLabels() {
make_test<vector<string>, int>( make_test<vector<string>, int>(
"should clear the vector for group 0, kAbilityGropuUnknownId", {}, make_tuple(0)), "should clear the vector for group 0, kAbilityGropuUnknownId", {}, make_tuple(0)),
make_test<vector<string>, int>("should fill talents for group 1 kAbilityGroupTalentsId", make_test<vector<string>, int>("should fill talents for group 1 kAbilityGroupTalentsId",
{"", {
"Acting", "Acting",
"Alertness", "Alertness",
"Athletics", "Athletics",
"Brawl", "Brawl",
"Dodge", "Dodge",
"Empathy", "Empathy",
"Intimidation", "Intimidation",
"Leadership", "Leadership",
"Streetwise", "Streetwise",
"Subterfuge"}, "Subterfuge",
},
make_tuple(1)), make_tuple(1)),
make_test<vector<string>, int>("should fill skills for group 2 kAbilityGroupSkillsId", make_test<vector<string>, int>("should fill skills for group 2 kAbilityGroupSkillsId",
{"", {
"Animal Ken", "Animal Ken",
"Drive", "Drive",
"Etiquette", "Etiquette",
"Firearms", "Firearms",
"Melee", "Melee",
"Music", "Music",
"Repair", "Repair",
"Security", "Security",
"Stealth", "Stealth",
"Survival"}, "Survival",
},
make_tuple(2)), make_tuple(2)),
make_test<vector<string>, int>("should fill knowledges for group 3 kAbilityGroupKnowledgesId", make_test<vector<string>, int>("should fill knowledges for group 3 kAbilityGroupKnowledgesId",
{"", {
"Bureaucracy", "Bureaucracy",
"Computer", "Computer",
"Finance", "Finance",
"Investigation", "Investigation",
"Law", "Law",
"Linguistics", "Linguistics",
"Medicine", "Medicine",
"Occult", "Occult",
"Politics", "Politics",
"Science"}, "Science",
},
make_tuple(3)), make_tuple(3)),
make_test<vector<string>, int>("should clear the vector for group 4 an invalid id", {}, make_tuple(4)), make_test<vector<string>, int>("should clear the vector for group 4 an invalid id", {}, make_tuple(4)),
}))); })));
@@ -248,17 +254,18 @@ TestResults test_FillKnowledgeLabels() {
[]() -> string { []() -> string {
ostringstream error_message; ostringstream error_message;
vector<string> actual = {"This should be removed."}; vector<string> actual = {"This should be removed."};
vector<string> expected = {"", vector<string> expected = {
"Bureaucracy", "Bureaucracy",
"Computer", "Computer",
"Finance", "Finance",
"Investigation", "Investigation",
"Law", "Law",
"Linguistics", "Linguistics",
"Medicine", "Medicine",
"Occult", "Occult",
"Politics", "Politics",
"Science"}; "Science",
};
FillKnowledgeLabels(actual); FillKnowledgeLabels(actual);
compare(error_message, expected, actual); compare(error_message, expected, actual);
string error = error_message.str(); string error = error_message.str();
@@ -278,17 +285,18 @@ TestResults test_FillSkillLabels() {
[]() -> string { []() -> string {
ostringstream error_message; ostringstream error_message;
vector<string> actual = {"This should be removed."}; vector<string> actual = {"This should be removed."};
vector<string> expected = {"", vector<string> expected = {
"Animal Ken", "Animal Ken",
"Drive", "Drive",
"Etiquette", "Etiquette",
"Firearms", "Firearms",
"Melee", "Melee",
"Music", "Music",
"Repair", "Repair",
"Security", "Security",
"Stealth", "Stealth",
"Survival"}; "Survival",
};
FillSkillLabels(actual); FillSkillLabels(actual);
compare(error_message, expected, actual); compare(error_message, expected, actual);
string error = error_message.str(); string error = error_message.str();
@@ -308,17 +316,18 @@ TestResults test_FillTalentLabels() {
[]() -> string { []() -> string {
ostringstream error_message; ostringstream error_message;
vector<string> actual = {"This should be removed."}; vector<string> actual = {"This should be removed."};
vector<string> expected = {"", vector<string> expected = {
"Acting", "Acting",
"Alertness", "Alertness",
"Athletics", "Athletics",
"Brawl", "Brawl",
"Dodge", "Dodge",
"Empathy", "Empathy",
"Intimidation", "Intimidation",
"Leadership", "Leadership",
"Streetwise", "Streetwise",
"Subterfuge"}; "Subterfuge",
};
FillTalentLabels(actual); FillTalentLabels(actual);
compare(error_message, expected, actual); compare(error_message, expected, actual);
string error = error_message.str(); string error = error_message.str();

View File

@@ -4,16 +4,16 @@
#include <vector> #include <vector>
namespace SBF { namespace SBF {
std::string GetArchetypeLabel(int archetypeId) { std::string GetArchetypeLabel(int archetype_id) {
if (archetypeId >= 0 && archetypeId <= kArchetypesCount) { if (archetype_id >= 0 && archetype_id <= kArchetypesCount) {
return kArchetypes[archetypeId]; return kArchetypes[archetype_id];
} }
return ""; return "";
} }
void FillArchetypeLabels(std::vector<std::string>& labels) { void FillArchetypeLabels(std::vector<std::string>& labels) {
labels.clear(); labels.clear();
for (int id = 0; id <= kArchetypesCount; id++) { for (int id = 1; id <= kArchetypesCount; id++) {
labels.push_back(GetArchetypeLabel(id)); labels.push_back(GetArchetypeLabel(id));
} }
} }

View File

@@ -15,7 +15,7 @@ TestResults test_FillArchetypeLabels();
using namespace Test::Archetypes; using namespace Test::Archetypes;
TestResults main_test_Archetypes(int argc, char** argv) { TestResults main_test_Archetypes(int argc, char* argv[]) {
TestResults results; TestResults results;
results += test_GetArchetypeLabel(); results += test_GetArchetypeLabel();
@@ -70,11 +70,11 @@ TestResults test_FillArchetypeLabels() {
"SBF::FillArchetypeLabels", "SBF::FillArchetypeLabels",
[]() -> string { []() -> string {
ostringstream error_message; ostringstream error_message;
vector<string> expected = { vector<string> expected = {"Architect", "Autocrat", "Barbarian", "Bon Vivant", "Bravo", "Caregiver",
"", "Architect", "Autocrat", "Barbarian", "Bon Vivant", "Bravo", "Caregiver", "Caretaker", "Caretaker", "Celebrant", "Child", "Conformist", "Conniver", "Curmudgeon",
"Celebrant", "Child", "Conformist", "Conniver", "Curmudgeon", "Defender", "Deviant", "Director", "Defender", "Deviant", "Director", "Fanatic", "Gallant", "Innovator",
"Fanatic", "Gallant", "Innovator", "Jester", "Judge", "Loaner", "Martyr", "Monster", "Jester", "Judge", "Loaner", "Martyr", "Monster", "Penitent",
"Penitent", "Rebel", "Rogue", "Survivor", "Traditionalist", "Tyrant", "Visionary"}; "Rebel", "Rogue", "Survivor", "Traditionalist", "Tyrant", "Visionary"};
vector<string> actual = {"This should be removed."}; vector<string> actual = {"This should be removed."};
FillArchetypeLabels(actual); FillArchetypeLabels(actual);
compare(error_message, expected, actual); compare(error_message, expected, actual);

View File

@@ -31,7 +31,7 @@ TestResults test_FillMentalAttributeLabels();
using namespace Test::Attributes; using namespace Test::Attributes;
TestResults main_test_Attributes(int argc, char** argv) { TestResults main_test_Attributes(int argc, char* argv[]) {
TestResults results; TestResults results;
results += test_GetAttributeGroupLabel(); results += test_GetAttributeGroupLabel();

View File

@@ -18,7 +18,7 @@ TestResults test_FillBackgroundLabels();
using namespace Test::Backgrounds; using namespace Test::Backgrounds;
TestResults main_test_Backgrounds(int argc, char** argv) { TestResults main_test_Backgrounds(int argc, char* argv[]) {
TestResults results; TestResults results;
results += test_GetBackgroundLabel(); results += test_GetBackgroundLabel();

View File

@@ -4,7 +4,7 @@
using namespace SBF; using namespace SBF;
using namespace Test; using namespace Test;
TestResults main_test_Character(int argc, char** argv) { TestResults main_test_Character(int argc, char* argv[]) {
TestResults results; TestResults results;
return results; return results;

View File

@@ -4,9 +4,9 @@
#include <vector> #include <vector>
namespace SBF { namespace SBF {
std::string GetClanLabel(int clanId) { std::string GetClanLabel(int clan_id) {
if (clanId > 0 && clanId <= kClansCount) { if (clan_id > 0 && clan_id <= kClansCount) {
return kClanLabels[clanId]; return kClanLabels[clan_id];
} }
return ""; return "";
} }

View File

@@ -18,7 +18,7 @@ TestResults test_FillClanLabels();
using namespace Test::Clans; using namespace Test::Clans;
TestResults main_test_Clans(int argc, char** argv) { TestResults main_test_Clans(int argc, char* argv[]) {
TestResults results; TestResults results;
results += test_GetClanLabel(); results += test_GetClanLabel();

View File

@@ -25,7 +25,7 @@ extern uint8_t g_foregroundColor;
extern uint8_t g_backgroundColor; extern uint8_t g_backgroundColor;
} // namespace SBF } // namespace SBF
TestResults main_test_Colors(int argc, char** argv) { TestResults main_test_Colors(int argc, char* argv[]) {
TestResults results; TestResults results;
results += test_FillColors(); results += test_FillColors();

View File

@@ -27,7 +27,7 @@ DerangementType GetDerangement(int derangementId) {
if (derangementId > 0 && derangementId <= kDerangementsCount) { if (derangementId > 0 && derangementId <= kDerangementsCount) {
return kDerangements[derangementId]; return kDerangements[derangementId];
} }
return {}; return kDerangementUnknown;
} }
void FillDerangements(std::vector<DerangementType>& derangements) { void FillDerangements(std::vector<DerangementType>& derangements) {

View File

@@ -21,7 +21,7 @@ TestResults test_FillDerangements();
using namespace Test::Derangements; using namespace Test::Derangements;
TestResults main_test_Derangements(int argc, char** argv) { TestResults main_test_Derangements(int argc, char* argv[]) {
TestResults results; TestResults results;
results += test_DerangementType_operator_extract(); results += test_DerangementType_operator_extract();

View File

@@ -18,7 +18,7 @@ TestResults test_FillDisciplineLabels();
using namespace Test::Disciplines; using namespace Test::Disciplines;
TestResults main_test_Disciplines(int argc, char** argv) { TestResults main_test_Disciplines(int argc, char* argv[]) {
TestResults results; TestResults results;
results += test_GetDisciplineLabel(); results += test_GetDisciplineLabel();

View File

@@ -18,7 +18,7 @@ TestResults test_FillGenderLabels();
using namespace Test::Genders; using namespace Test::Genders;
TestResults main_test_Genders(int argc, char** argv) { TestResults main_test_Genders(int argc, char* argv[]) {
TestResults results; TestResults results;
results += test_GetGenderLabel(); results += test_GetGenderLabel();

View File

@@ -5,10 +5,13 @@
#include <vector> #include <vector>
namespace SBF { namespace SBF {
namespace {
using std::ostream;
using std::string; using std::string;
using std::vector; using std::vector;
} // End namespace
std::ostream& operator<<(std::ostream& os, const RankType& rank) { ostream& operator<<(ostream& os, const RankType& rank) {
os << "Rank: {id: " << rank.id << ", label: \"" << rank.label << "\"}"; os << "Rank: {id: " << rank.id << ", label: \"" << rank.label << "\"}";
return os; return os;
} }

View File

@@ -21,7 +21,7 @@ TestResults test_FillRanks();
using namespace Test::Ranks; using namespace Test::Ranks;
TestResults main_test_Ranks(int argc, char** argv) { TestResults main_test_Ranks(int argc, char* argv[]) {
TestResults results; TestResults results;
results += test_RankType_operator_extract(); results += test_RankType_operator_extract();

View File

@@ -21,7 +21,7 @@ TestResults test_word_wrap();
using namespace Test::Utils; using namespace Test::Utils;
TestResults main_test_Utils(int argc, char** argv) { TestResults main_test_Utils(int argc, char* argv[]) {
TestResults results; TestResults results;
results += test_get_index_of(); results += test_get_index_of();

View File

@@ -17,7 +17,7 @@ TestResults test_FillVirtueLabels();
using namespace Test::Virtues; using namespace Test::Virtues;
TestResults main_test_Virtues(int argc, char** argv) { TestResults main_test_Virtues(int argc, char* argv[]) {
TestResults results; TestResults results;
results += test_GetVirtueLabel(); results += test_GetVirtueLabel();

View File

@@ -88,9 +88,9 @@ namespace Test {
// ); // );
// The suites can be run from one file as such. From a file called ThingDoer_test.cpp to test the class/methods // The suites can be run from one file as such. From a file called ThingDoer_test.cpp to test the class/methods
// ThingDoer declared in ThingDoer.cpp. This isn't mandatory but is a best practice. You can use testFn without calling // ThingDoer declared in ThingDoer.cpp. This isn't mandatory but is a best practice. You can use testFn without calling
// collect_and_report_TestResults() and also could call it from a normal int main(int argc, char** argv) or other // collect_and_report_TestResults() and also could call it from a normal int main(int argc, char* argv[]) or other
// function. // function.
// TestResults test_main_ThingDoer(int argc, char** argv) { // TestResults test_main_ThingDoer(int argc, char* argv[]) {
// TestResults results; // TestResults results;
// results = collect_and_report_TestResults(results, testFn("doThing1", ...), argc, argv); // results = collect_and_report_TestResults(results, testFn("doThing1", ...), argc, argv);
// results = collect_and_report_TestResults(results, testFn("doThing2", ...), argc, argv); // results = collect_and_report_TestResults(results, testFn("doThing2", ...), argc, argv);

View File

@@ -293,7 +293,7 @@ using TestSuite = std::tuple<std::string,
// ThingDoer declared in ThingDoer.cpp. This isn't mandatory but is a best practice. You can use function_to_test // ThingDoer declared in ThingDoer.cpp. This isn't mandatory but is a best practice. You can use function_to_test
// without calling collect_and_report_test_results() and also could call it from a normal int main(int argc, char** // without calling collect_and_report_test_results() and also could call it from a normal int main(int argc, char**
// argv) or other function. // argv) or other function.
// TestResults test_main_ThingDoer(int argc, char** argv) { // TestResults test_main_ThingDoer(int argc, char* argv[]) {
// TestResults results; // TestResults results;
// results = collect_and_report_test_results(results, function_to_test("do_thing1", ...), argc, argv); // results = collect_and_report_test_results(results, function_to_test("do_thing1", ...), argc, argv);
// results = collect_and_report_test_results(results, function_to_test("do_thing2", ...), argc, argv); // results = collect_and_report_test_results(results, function_to_test("do_thing2", ...), argc, argv);