From cf383f27c7f001f90ac6cc42f32cfa23adc5e165 Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Wed, 3 May 2023 15:04:46 -0700 Subject: [PATCH] Refactors Abilities to Ability Groups. --- sbf-cpp/Abilities.cpp | 526 +++++++----- sbf-cpp/Abilities.h | 152 ++-- sbf-cpp/Abilities_test.cpp | 1446 +++++++++++++++++++++++--------- sbf-cpp/BUILD | 17 + sbf-cpp/Character.cpp | 20 +- sbf-cpp/CharacterGenerator.cpp | 16 +- sbf-cpp/test.cpp | 4 + sbf-cpp/test.h | 48 +- 8 files changed, 1496 insertions(+), 733 deletions(-) diff --git a/sbf-cpp/Abilities.cpp b/sbf-cpp/Abilities.cpp index f39fa81..8364245 100644 --- a/sbf-cpp/Abilities.cpp +++ b/sbf-cpp/Abilities.cpp @@ -4,41 +4,34 @@ #include namespace SBF { +namespace { using std::ostream; using std::string; using std::vector; +} // End namespace -const int kAbilitiesCount = 3; +const int kAbilityGroupUnknownId = 0; +const std::string kAbilityGroupUnknownLabel = ""; +const std::string kAbilityGroupTalentsSingular = "Talent"; +const std::string kAbilityGroupTalentsPlural = "Talents"; +const std::string kAbilityGroupSkillsSingular = "Skill"; +const std::string kAbilityGroupSkillsPlural = "Skills"; +const std::string kAbilityGroupKnowledgesSingular = "Knowledge"; +const std::string kAbilityGroupKnowledgesPlural = "Knowledges"; +const AbilityGroup kAbilityGroupUnknown = + AbilityGroup(kAbilityGroupUnknownId, kAbilityGroupUnknownLabel, kAbilityGroupUnknownLabel); +const AbilityGroup kAbilityGroupTalents = + AbilityGroup(kAbilityGroupTalentsId, kAbilityGroupTalentsSingular, kAbilityGroupTalentsPlural); +const AbilityGroup kAbilityGroupSkills = + AbilityGroup(kAbilityGroupSkillsId, kAbilityGroupSkillsSingular, kAbilityGroupSkillsPlural); +const AbilityGroup kAbilityGroupKnowledges = + AbilityGroup(kAbilityGroupKnowledgesId, kAbilityGroupKnowledgesSingular, kAbilityGroupKnowledgesPlural); +const vector kAbilityGroups = {kAbilityGroupTalents, kAbilityGroupSkills, kAbilityGroupKnowledges}; + +const int kAbilityUnknownId = 0; const std::string kAbilityUnknownLabel = ""; -const std::string kAbilityTalentsSingular = "Talent"; -const std::string kAbilityTalentsPlural = "Talents"; -const std::string kAbilitySkillsSingular = "Skill"; -const std::string kAbilitySkillsPlural = "Skills"; -const std::string kAbilityKnowledgesSingular = "Knowledge"; -const std::string kAbilityKnowledgesPlural = "Knowledges"; -const AbilityType kAbilityGroupUnknown = {0, "", ""}; -const AbilityType kAbilityGroupTalents = { - kAbilityTalentsId, - kAbilityTalentsSingular, - kAbilityTalentsPlural, -}; -const AbilityType kAbilityGroupSkills = { - kAbilitySkillsId, - kAbilitySkillsSingular, - kAbilitySkillsPlural, -}; -const AbilityType kAbilityGroupKnowledges = { - kAbilityKnowledgesId, - kAbilityKnowledgesSingular, - kAbilityKnowledgesPlural, -}; -const AbilityType kAbilities[]{ - kAbilityGroupUnknown, - kAbilityGroupTalents, - kAbilityGroupSkills, - kAbilityGroupKnowledges, -}; +const Ability kAbilityUnknown = Ability(kAbilityUnknownId, kAbilityGroupUnknownId, kAbilityUnknownLabel); const std::string kTalentActingLabel = "Acting"; const std::string kTalentAlertnessLabel = "Alertness"; @@ -50,6 +43,29 @@ const std::string kTalentIntimidationLabel = "Intimidation"; const std::string kTalentLeadershipLabel = "Leadership"; const std::string kTalentStreetwiseLabel = "Streetwise"; const std::string kTalentSubterfugeLabel = "Subterfuge"; +const Ability kTalentActing = Ability(kTalentActingId, kAbilityGroupTalentsId, kTalentActingLabel); +const Ability kTalentAlertness = Ability(kTalentAlertnessId, kAbilityGroupTalentsId, kTalentAlertnessLabel); +const Ability kTalentAthletics = Ability(kTalentAthleticsId, kAbilityGroupTalentsId, kTalentAthleticsLabel); +const Ability kTalentBrawl = Ability(kTalentBrawlId, kAbilityGroupTalentsId, kTalentBrawlLabel); +const Ability kTalentDodge = Ability(kTalentDodgeId, kAbilityGroupTalentsId, kTalentDodgeLabel); +const Ability kTalentEmpathy = Ability(kTalentEmpathyId, kAbilityGroupTalentsId, kTalentEmpathyLabel); +const Ability kTalentIntimidation = Ability(kTalentIntimidationId, kAbilityGroupTalentsId, kTalentIntimidationLabel); +const Ability kTalentLeadership = Ability(kTalentLeadershipId, kAbilityGroupTalentsId, kTalentLeadershipLabel); +const Ability kTalentStreetwise = Ability(kTalentStreetwiseId, kAbilityGroupTalentsId, kTalentStreetwiseLabel); +const Ability kTalentSubterfuge = Ability(kTalentSubterfugeId, kAbilityGroupTalentsId, kTalentSubterfugeLabel); +const vector kTalents = { + kTalentActing, + kTalentAlertness, + kTalentAthletics, + kTalentBrawl, + kTalentDodge, + kTalentEmpathy, + kTalentIntimidation, + kTalentLeadership, + kTalentStreetwise, + kTalentSubterfuge, +}; + const std::string kSkillAnimalKenLabel = "Animal Ken"; const std::string kSkillDriveLabel = "Drive"; const std::string kSkillEtiquetteLabel = "Etiquette"; @@ -60,6 +76,29 @@ const std::string kSkillRepairLabel = "Repair"; const std::string kSkillSecurityLabel = "Security"; const std::string kSkillStealthLabel = "Stealth"; const std::string kSkillSurvivalLabel = "Survival"; +const Ability kSkillAnimalKen = Ability(kSkillAnimalKenId, kAbilityGroupSkillsId, kSkillAnimalKenLabel); +const Ability kSkillDrive = Ability(kSkillDriveId, kAbilityGroupSkillsId, kSkillDriveLabel); +const Ability kSkillEtiquette = Ability(kSkillEtiquetteId, kAbilityGroupSkillsId, kSkillEtiquetteLabel); +const Ability kSkillFirearms = Ability(kSkillFirearmsId, kAbilityGroupSkillsId, kSkillFirearmsLabel); +const Ability kSkillMelee = Ability(kSkillMeleeId, kAbilityGroupSkillsId, kSkillMeleeLabel); +const Ability kSkillMusic = Ability(kSkillMusicId, kAbilityGroupSkillsId, kSkillMusicLabel); +const Ability kSkillRepair = Ability(kSkillRepairId, kAbilityGroupSkillsId, kSkillRepairLabel); +const Ability kSkillSecurity = Ability(kSkillSecurityId, kAbilityGroupSkillsId, kSkillSecurityLabel); +const Ability kSkillStealth = Ability(kSkillStealthId, kAbilityGroupSkillsId, kSkillStealthLabel); +const Ability kSkillSurvival = Ability(kSkillSurvivalId, kAbilityGroupSkillsId, kSkillSurvivalLabel); +const vector kSkills = { + kSkillAnimalKen, + kSkillDrive, + kSkillEtiquette, + kSkillFirearms, + kSkillMelee, + kSkillMusic, + kSkillRepair, + kSkillSecurity, + kSkillStealth, + kSkillSurvival, +}; + const std::string kKnowledgeBureaucracyLabel = "Bureaucracy"; const std::string kKnowledgeComputerLabel = "Computer"; const std::string kKnowledgeFinanceLabel = "Finance"; @@ -70,210 +109,269 @@ const std::string kKnowledgeMedicineLabel = "Medicine"; const std::string kKnowledgeOccultLabel = "Occult"; const std::string kKnowledgePoliticsLabel = "Politics"; const std::string kKnowledgeScienceLabel = "Science"; -const int kTalentsCount = 10; -const int kSkillsCount = 10; -const int kKnowledgesCount = 10; -const std::string kSkills[] = { - kAbilityUnknownLabel, - kSkillAnimalKenLabel, - kSkillDriveLabel, - kSkillEtiquetteLabel, - kSkillFirearmsLabel, - kSkillMeleeLabel, - kSkillMusicLabel, - kSkillRepairLabel, - kSkillSecurityLabel, - kSkillStealthLabel, - kSkillSurvivalLabel, -}; -const std::string kTalents[] = { - kAbilityUnknownLabel, - kTalentActingLabel, - kTalentAlertnessLabel, - kTalentAthleticsLabel, - kTalentBrawlLabel, - kTalentDodgeLabel, - kTalentEmpathyLabel, - kTalentIntimidationLabel, - kTalentLeadershipLabel, - kTalentStreetwiseLabel, - kTalentSubterfugeLabel, -}; -const std::string kKnowledges[] = { - kAbilityUnknownLabel, - kKnowledgeBureaucracyLabel, - kKnowledgeComputerLabel, - kKnowledgeFinanceLabel, - kKnowledgeInvestigationLabel, - kKnowledgeLawLabel, - kKnowledgeLinguisticsLabel, - kKnowledgeMedicineLabel, - kKnowledgeOccultLabel, - kKnowledgePoliticsLabel, - kKnowledgeScienceLabel, +const Ability kKnowledgeBureaucracy = + Ability(kKnowledgeBureaucracyId, kAbilityGroupKnowledgesId, kKnowledgeBureaucracyLabel); +const Ability kKnowledgeComputer = Ability(kKnowledgeComputerId, kAbilityGroupKnowledgesId, kKnowledgeComputerLabel); +const Ability kKnowledgeFinance = Ability(kKnowledgeFinanceId, kAbilityGroupKnowledgesId, kKnowledgeFinanceLabel); +const Ability kKnowledgeInvestigation = + Ability(kKnowledgeInvestigationId, kAbilityGroupKnowledgesId, kKnowledgeInvestigationLabel); +const Ability kKnowledgeLaw = Ability(kKnowledgeLawId, kAbilityGroupKnowledgesId, kKnowledgeLawLabel); +const Ability kKnowledgeLinguistics = + Ability(kKnowledgeLinguisticsId, kAbilityGroupKnowledgesId, kKnowledgeLinguisticsLabel); +const Ability kKnowledgeMedicine = Ability(kKnowledgeMedicineId, kAbilityGroupKnowledgesId, kKnowledgeMedicineLabel); +const Ability kKnowledgeOccult = Ability(kKnowledgeOccultId, kAbilityGroupKnowledgesId, kKnowledgeOccultLabel); +const Ability kKnowledgePolitics = Ability(kKnowledgePoliticsId, kAbilityGroupKnowledgesId, kKnowledgePoliticsLabel); +const Ability kKnowledgeScience = Ability(kKnowledgeScienceId, kAbilityGroupKnowledgesId, kKnowledgeScienceLabel); +const vector kKnowledges = { + kKnowledgeBureaucracy, + kKnowledgeComputer, + kKnowledgeFinance, + kKnowledgeInvestigation, + kKnowledgeLaw, + kKnowledgeLinguistics, + kKnowledgeMedicine, + kKnowledgeOccult, + kKnowledgePolitics, + kKnowledgeScience, }; -ostream& operator<<(ostream& os, const AbilityType& ability) { - os << "AbilityGroup: {id: " << ability.id << ", singular: \"" << ability.singular << "\", plural: \"" - << ability.plural << "\"}"; - return os; +vector AbilityGroup::GetAbilityLabels() const { + return AbilityGroup::GetAbilityLabels(id_); } -bool operator==(const AbilityType& left, const AbilityType& right) { - return left.id == right.id && left.singular == right.singular && left.plural == right.plural; -} - -bool operator!=(const AbilityType& left, const AbilityType& right) { - return !(left == right); -} - -void FillAbilities(vector& abilities) { - abilities.clear(); - abilities.push_back(kAbilityGroupTalents); - abilities.push_back(kAbilityGroupSkills); - abilities.push_back(kAbilityGroupKnowledges); -} - -vector GetAbilityGroupPluralLabels() { - vector labels; - - for (int id = 1; id <= kAbilitiesCount; id++) { - labels.push_back(GetAbility(id).plural); - } - - return labels; -} - -void FillAbilitiesForAbilityGroup(vector& abilities, int id) { - abilities.clear(); - int numAbilities = GetNumItemsForAbilityGroup(id); +vector AbilityGroup::GetAbilityLabels(int id) { switch (id) { - case kAbilityTalentsId: - for (int talent_id = 1; talent_id <= numAbilities; talent_id++) { - abilities.push_back(GetTalentLabel(talent_id)); - } - break; - case kAbilitySkillsId: - for (int skill_id = 1; skill_id <= numAbilities; skill_id++) { - abilities.push_back(GetSkillLabel(skill_id)); - } - break; - case kAbilityKnowledgesId: - for (int knowledge_id = 1; knowledge_id <= numAbilities; knowledge_id++) { - abilities.push_back(GetKnowledgeLabel(knowledge_id)); - } - break; - } -} - -vector GetAbilityLabelsForAbilityGroup(int group_id) { - vector labels; - - int count = GetNumItemsForAbilityGroup(group_id); - for (int id = 1; id <= count; id++) { - labels.push_back(GetAbilityLabel(group_id, id)); + case kAbilityGroupKnowledgesId: + return Ability::GetKnowledgeLabels(); + case kAbilityGroupSkillsId: + return Ability::GetSkillLabels(); + case kAbilityGroupTalentsId: + return Ability::GetTalentLabels(); } - return labels; -} - -void FillAbilityLabels(vector& labels, int id) { - labels.clear(); - switch (id) { - case kAbilityTalentsId: - FillTalentLabels(labels); - break; - case kAbilitySkillsId: - FillSkillLabels(labels); - break; - case kAbilityKnowledgesId: - FillKnowledgeLabels(labels); - break; - } -} - -void FillKnowledgeLabels(vector& labels) { - labels.clear(); - int numAbilities = GetNumItemsForAbilityGroup(kAbilityKnowledgesId); - for (int knowledge_id = 1; knowledge_id <= numAbilities; knowledge_id++) { - labels.push_back(GetKnowledgeLabel(knowledge_id)); - } -} - -void FillSkillLabels(vector& labels) { - labels.clear(); - int numAbilities = GetNumItemsForAbilityGroup(kAbilitySkillsId); - for (int skill_id = 1; skill_id <= numAbilities; skill_id++) { - labels.push_back(GetSkillLabel(skill_id)); - } -} - -void FillTalentLabels(vector& labels) { - labels.clear(); - int numAbilities = GetNumItemsForAbilityGroup(kAbilityTalentsId); - for (int talent_id = 1; talent_id <= numAbilities; talent_id++) { - labels.push_back(GetTalentLabel(talent_id)); - } -} - -const AbilityType& GetAbility(int ability_group_id) { - switch (ability_group_id) { - case kAbilityTalentsId: - return kAbilityGroupTalents; - case kAbilitySkillsId: - return kAbilityGroupSkills; - case kAbilityKnowledgesId: - return kAbilityGroupKnowledges; - }; - return kAbilityGroupUnknown; -} - -const string GetAbilityLabel(int ability_group_id, int ability_id) { - switch (ability_group_id) { - case kAbilityTalentsId: - return GetTalentLabel(ability_id); - case kAbilitySkillsId: - return GetSkillLabel(ability_id); - case kAbilityKnowledgesId: - return GetKnowledgeLabel(ability_id); - }; - return ""; -} - -const std::string GetKnowledgeLabel(int talent_id) { - if (talent_id > 0 && talent_id <= kKnowledgesCount) { - return kKnowledges[talent_id]; - } - return ""; + return vector(); } int GetNumItemsForAbilityGroup(int ability_group_id) { switch (ability_group_id) { - case kAbilityTalentsId: - return kTalentsCount; - case kAbilitySkillsId: - return kSkillsCount; - case kAbilityKnowledgesId: - return kKnowledgesCount; + case kAbilityGroupTalentsId: + return kTalents.size(); + case kAbilityGroupSkillsId: + return kSkills.size(); + case kAbilityGroupKnowledgesId: + return kKnowledges.size(); } return 0; } -const std::string GetSkillLabel(int skill_id) { - if (skill_id > 0 && skill_id <= kSkillsCount) { - return kSkills[skill_id]; - } - return ""; +int AbilityGroup::GetCount() { + return kAbilityGroups.size(); } -const std::string GetTalentLabel(int talent_id) { - if (talent_id > 0 && talent_id <= kTalentsCount) { - return kTalents[talent_id]; +int AbilityGroup::GetAbilityCount() const { + switch (id_) { + case kAbilityGroupKnowledgesId: + return kTalents.size(); + case kAbilityGroupSkillsId: + return kSkills.size(); + case kAbilityGroupTalentsId: + return kTalents.size(); } - return ""; + return 0; } -int GetNumAbilityGroups() { - return kAbilitiesCount; +AbilityGroup::AbilityGroup() : id_(0), singular_(""), plural_("") {} + +AbilityGroup::AbilityGroup(int id, const string& singular, const string& plural) + : id_(id), singular_(singular), plural_(plural) {} + +int AbilityGroup::id() const { + return id_; +} + +void AbilityGroup::id(int id) { + id_ = id; +} + +string AbilityGroup::plural() const { + return plural_; +} + +void AbilityGroup::plural(const string& plural) { + plural_ = plural; +} + +string AbilityGroup::singular() const { + return singular_; +} + +void AbilityGroup::singular(const string& singular) { + singular_ = singular; +} + +vector AbilityGroup::GetPluralLabels() { + vector labels; + + for_each(kAbilityGroups.begin(), kAbilityGroups.end(), [&labels](const auto& ability) { + labels.push_back(ability.plural()); + }); + + return labels; +} + +Ability::Ability() : id_(0), group_id_(0), label_("") {} + +Ability::Ability(int id, int group_id, const string& label) : id_(id), group_id_(group_id), label_(label) {} + +int Ability::id() const { + return id_; +} + +void Ability::id(int id) { + id_ = id; +} + +int Ability::group_id() const { + return group_id_; +} + +void Ability::group_id(int group_id) { + group_id_ = group_id; +} + +string Ability::label() const { + return label_; +} + +void Ability::label(const string& label) { + label_ = label; +} + +AbilityGroup AbilityGroup::FromId(int id) { + switch (id) { + case kAbilityGroupTalentsId: + return kAbilityGroupTalents; + case kAbilityGroupSkillsId: + return kAbilityGroupSkills; + case kAbilityGroupKnowledgesId: + return kAbilityGroupKnowledges; + } + return kAbilityGroupUnknown; +} + +ostream& operator<<(ostream& os, const AbilityGroup& ability_group) { + os << "AbilityGroup: {id: " << ability_group.id_ << ", singular: \"" << ability_group.singular_ << "\", plural: \"" + << ability_group.plural_ << "\"}"; + return os; +} + +bool AbilityGroup::operator==(const AbilityGroup& other) const { + return id_ == other.id_ && singular_ == other.singular_ && plural_ == other.plural_; +} + +bool AbilityGroup::operator!=(const AbilityGroup& other) const { + return !(*this == other); +} + +ostream& operator<<(ostream& os, const Ability& ability) { + os << "Ability: {id: " << ability.id_ << ", group_id: " << ability.group_id_ << ", label: \"" << ability.label_ + << "\"}"; + return os; +} + +bool Ability::operator==(const Ability& other) const { + return id_ == other.id_ && group_id_ == other.group_id_ && label_ == other.label_; +} + +bool Ability::operator!=(const Ability& other) const { + return !(*this == other); +} + +string Ability::GetSkillLabel(int id) { + return Ability::FromSkillId(id).label(); +} + +vector Ability::GetSkillLabels() { + vector labels; + for_each(kSkills.begin(), kSkills.end(), [&labels](const auto& ability) { labels.push_back(ability.label()); }); + return labels; +} + +string Ability::GetTalentLabel(int id) { + return Ability::FromTalentId(id).label(); +} + +vector Ability::GetTalentLabels() { + vector labels; + for_each(kTalents.begin(), kTalents.end(), [&labels](const auto& ability) { labels.push_back(ability.label()); }); + return labels; +} + +string Ability::GetKnowledgeLabel(int id) { + return Ability::FromKnowledgeId(id).label(); +} + +vector Ability::GetKnowledgeLabels() { + vector labels; + for_each( + kKnowledges.begin(), kKnowledges.end(), [&labels](const auto& ability) { labels.push_back(ability.label()); }); + return labels; +} + +Ability Ability::FromKnowledgeId(int id) { + if (id > 0 && id <= kKnowledges.size()) { + return kKnowledges.at(id - 1); + } + return kAbilityUnknown; +} + +Ability Ability::FromSkillId(int id) { + if (id > 0 && id <= kSkills.size()) { + return kSkills.at(id - 1); + } + return kAbilityUnknown; +} + +Ability Ability::FromTalentId(int id) { + if (id > 0 && id <= kTalents.size()) { + return kTalents.at(id - 1); + } + return kAbilityUnknown; +} + +Ability Ability::FromIds(int id, int group_id) { + switch (group_id) { + case kAbilityGroupKnowledgesId: + return Ability::FromKnowledgeId(id); + case kAbilityGroupSkillsId: + return Ability::FromSkillId(id); + case kAbilityGroupTalentsId: + return Ability::FromTalentId(id); + } + return kAbilityUnknown; +} + +int Ability::GetCount(int group_id) { + switch (group_id) { + case kAbilityGroupKnowledgesId: + return kKnowledges.size(); + case kAbilityGroupSkillsId: + return kSkills.size(); + case kAbilityGroupTalentsId: + return kTalents.size(); + } + return 0; +} + +int Ability::GetKnowledgesCount() { + return kKnowledges.size(); +} + +int Ability::GetSkillsCount() { + return kSkills.size(); +} + +int Ability::GetTalentsCount() { + return kTalents.size(); } } // End namespace SBF diff --git a/sbf-cpp/Abilities.h b/sbf-cpp/Abilities.h index c47e88e..845e189 100644 --- a/sbf-cpp/Abilities.h +++ b/sbf-cpp/Abilities.h @@ -16,9 +16,9 @@ * @{ */ namespace SBF { -const int kAbilityTalentsId = 1; -const int kAbilitySkillsId = 2; -const int kAbilityKnowledgesId = 3; +const int kAbilityGroupTalentsId = 1; +const int kAbilityGroupSkillsId = 2; +const int kAbilityGroupKnowledgesId = 3; const int kTalentActingId = 1; const int kTalentAlertnessId = 2; @@ -53,99 +53,73 @@ const int kKnowledgeOccultId = 8; const int kKnowledgePoliticsId = 9; const int kKnowledgeScienceId = 10; -/// @brief This type represents an ability group such as Talents, Skills or Knowledges. -struct AbilityType { - /// @brief The id of this ability group - int id; - /// @brief The singular form of this group i.e. Talent. - std::string singular; - /// @brief The plural form of this group i.e. Talents. - std::string plural; +class AbilityGroup { + public: + AbilityGroup(); + AbilityGroup(int id, const std::string& singular, const std::string& plural); + int GetAbilityCount() const; + std::vector GetAbilityLabels() const; + int id() const; + void id(int id); + std::string plural() const; + void plural(const std::string& plural); + std::string singular() const; + void singular(const std::string& singular); + bool operator==(const AbilityGroup& other) const; + bool operator!=(const AbilityGroup& other) const; + + static AbilityGroup FromId(int id); + static std::vector GetPluralLabels(); + static std::vector GetAbilityLabels(int id); + static int GetCount(); + + friend std::ostream& operator<<(std::ostream& os, const AbilityGroup& ability_group); + + private: + int id_; + std::string singular_; + std::string plural_; }; -/// @brief This function writes an AbilityType value to an output stream; -/// @param os The output stream to write to. -/// @param group The AbilityType to write. -/// @return Thw output stream for chaining. -std::ostream& operator<<(std::ostream& os, const AbilityType& group); +std::ostream& operator<<(std::ostream& os, const AbilityGroup& ability_group); -/// @brief This function compares two AbilityType values for equality. -/// @param left The first AbilityType. -/// @param right The second AbilityType. -/// @return True if left is equal to right and false otherwise. -bool operator==(const AbilityType& left, const AbilityType& right); +class Ability { + public: + Ability(); + Ability(int id, int group_id, const std::string& label); + int group_id() const; + void group_id(int group_id); + int id() const; + void id(int id); + std::string label() const; + void label(const std::string& label); + bool operator==(const Ability& other) const; + bool operator!=(const Ability& other) const; -/// @brief This function compares two AbilityType values for equality. -/// @param left The first AbilityType. -/// @param right The second AbilityType. -/// @return True if left and right are not equal and false otherwise. -bool operator!=(const AbilityType& left, const AbilityType& right); + static Ability FromIds(int id, int group_id); + static Ability FromKnowledgeId(int id); + static Ability FromSkillId(int id); + static Ability FromTalentId(int id); + static int GetCount(int group_id); + static std::string GetKnowledgeLabel(int id); + static std::vector GetKnowledgeLabels(); + static int GetKnowledgesCount(); + static std::string GetSkillLabel(int id); + static std::vector GetSkillLabels(); + static int GetSkillsCount(); + static std::string GetTalentLabel(int id); + static std::vector GetTalentLabels(); + static int GetTalentsCount(); -/// @brief Fills the provided vector with all of the available ability groups. It will be cleared before filling. -/// @param abilities The vector to fill. -void FillAbilities(std::vector& abilities); + friend std::ostream& operator<<(std::ostream& os, const Ability& ability); -std::vector GetAbilityGroupPluralLabels(); + private: + int id_; + int group_id_; + std::string label_; +}; -/// @brief Fills the provided vector with all of the ability labels in the specified group. It will be cleared before -/// filling. -/// @param abilities The vector to fill. -/// @param id The id of the ability group to fill for. -void FillAbilitiesForAbilityGroup(std::vector& abilities, int id); - -std::vector GetAbilityLabelsForAbilityGroup(int group_id); - -/// @brief Fills the provided vector with all of the ability labels in the specified group. It will be cleared before -/// filling. -/// @param labels The vector to fill. -/// @param id The id of the ability group to fill for. -void FillAbilityLabels(std::vector& labels, int id); - -/// @brief Fills the provided vector with all of the knowledge labels. It will be cleared before filling. -/// @param labels The vector to fill. -void FillKnowledgeLabels(std::vector& labels); - -/// @brief Fills the provided vector with all of the skill labels. It will be cleared before filling. -/// @param labels The vector to fill. -void FillSkillLabels(std::vector& labels); - -/// @brief Fills the provided vector with all of the talent labels. It will be cleared before filling. -/// @param labels The vector to fill. -void FillTalentLabels(std::vector& labels); - -/// @brief Gets an ability group for a given id. -/// @param id The id of the ability group to return. -/// @return The ability group with an id of id or kAbilityGroupUnknown if id is invalid. -const AbilityType& GetAbility(int id); - -/// @brief Gets the label for an ability given its ability group (talents/skills/knowledges) and its id (acting, brawl, -/// dodge, ...). -/// @param group_id The id for the ability group (talents/skills/knowledges). -/// @param id The id for the ability within the ability group (acting, dodge, brawl, ...). -/// @return The label for the specific ability ("Acting"). -const std::string GetAbilityLabel(int group_id, int id); - -/// @brief Gets the label for a knowledge ability given its id. -/// @param id The id of the ability to return the label for. -/// @return The label for the specific ability. -const std::string GetKnowledgeLabel(int id); - -/// @brief Gets the number of abilities in an ability group. -/// @param id The id of the ability group to return the number of abilities for. -/// @return The number of abilities in the specific ability group. -int GetNumItemsForAbilityGroup(int id); - -/// @brief Gets the label for a skill ability given its id. -/// @param id The id of the ability to return the label for. -/// @return The label of the specific ability. -const std::string GetSkillLabel(int id); - -/// @brief Gets the label for a talent ability given its id. -/// @param id The id of the ability to return. -/// @return The label for the specific ability. -const std::string GetTalentLabel(int id); - -int GetNumAbilityGroups(); +std::ostream& operator<<(std::ostream& os, const Ability& ability); } // End namespace SBF /** @}*/ diff --git a/sbf-cpp/Abilities_test.cpp b/sbf-cpp/Abilities_test.cpp index 2a873da..3ca5e3a 100644 --- a/sbf-cpp/Abilities_test.cpp +++ b/sbf-cpp/Abilities_test.cpp @@ -11,461 +11,1083 @@ using namespace Test; using namespace std; } // End namespace -TestResults test_AbilityType_operator_extract() { - return execute_suite(make_test_suite( - "SBF::AbilityType::operator<<", - [](const AbilityType& ability) { - ostringstream os; - os << ability; - return os.str(); - }, - vector>({ - make_test("should print talents", - "AbilityGroup: {id: 1, singular: \"Talent\", plural: \"Talents\"}", - make_tuple(GetAbility(kAbilityTalentsId))), - make_test("should print skills", - "AbilityGroup: {id: 2, singular: \"Skill\", plural: \"Skills\"}", - make_tuple(GetAbility(kAbilitySkillsId))), - make_test("should print knowledges", - "AbilityGroup: {id: 3, singular: \"Knowledge\", plural: \"Knowledges\"}", - make_tuple(GetAbility(kAbilityKnowledgesId))), - make_test("should print an unknown ability group", - "AbilityGroup: {id: 0, singular: \"\", plural: \"\"}", - make_tuple(GetAbility(0))), - }))); +const int kAbilityGroupUnknownId = 0; +const std::string kAbilityGroupUnknownLabel = ""; +const std::string kAbilityGroupTalentsSingular = "Talent"; +const std::string kAbilityGroupTalentsPlural = "Talents"; +const std::string kAbilityGroupSkillsSingular = "Skill"; +const std::string kAbilityGroupSkillsPlural = "Skills"; +const std::string kAbilityGroupKnowledgesSingular = "Knowledge"; +const std::string kAbilityGroupKnowledgesPlural = "Knowledges"; + +const AbilityGroup kAbilityGroupUnknown = + AbilityGroup(kAbilityGroupUnknownId, kAbilityGroupUnknownLabel, kAbilityGroupUnknownLabel); +const AbilityGroup kAbilityGroupTalents = + AbilityGroup(kAbilityGroupTalentsId, kAbilityGroupTalentsSingular, kAbilityGroupTalentsPlural); +const AbilityGroup kAbilityGroupSkills = + AbilityGroup(kAbilityGroupSkillsId, kAbilityGroupSkillsSingular, kAbilityGroupSkillsPlural); +const AbilityGroup kAbilityGroupKnowledges = + AbilityGroup(kAbilityGroupKnowledgesId, kAbilityGroupKnowledgesSingular, kAbilityGroupKnowledgesPlural); +const vector kAbilityGroups = {kAbilityGroupTalents, kAbilityGroupSkills, kAbilityGroupKnowledges}; + +const int kAbilityUnknownId = 0; +const std::string kAbilityUnknownLabel = ""; +const Ability kAbilityUnknown = Ability(kAbilityUnknownId, kAbilityGroupUnknownId, kAbilityUnknownLabel); + +const std::string kTalentActingLabel = "Acting"; +const std::string kTalentAlertnessLabel = "Alertness"; +const std::string kTalentAthleticsLabel = "Athletics"; +const std::string kTalentBrawlLabel = "Brawl"; +const std::string kTalentDodgeLabel = "Dodge"; +const std::string kTalentEmpathyLabel = "Empathy"; +const std::string kTalentIntimidationLabel = "Intimidation"; +const std::string kTalentLeadershipLabel = "Leadership"; +const std::string kTalentStreetwiseLabel = "Streetwise"; +const std::string kTalentSubterfugeLabel = "Subterfuge"; +const vector kTalentLabels = { + kTalentActingLabel, + kTalentAlertnessLabel, + kTalentAthleticsLabel, + kTalentBrawlLabel, + kTalentDodgeLabel, + kTalentEmpathyLabel, + kTalentIntimidationLabel, + kTalentLeadershipLabel, + kTalentStreetwiseLabel, + kTalentSubterfugeLabel, +}; +const Ability kTalentActing = Ability(kTalentActingId, kAbilityGroupTalentsId, kTalentActingLabel); +const Ability kTalentAlertness = Ability(kTalentAlertnessId, kAbilityGroupTalentsId, kTalentAlertnessLabel); +const Ability kTalentAthletics = Ability(kTalentAthleticsId, kAbilityGroupTalentsId, kTalentAthleticsLabel); +const Ability kTalentBrawl = Ability(kTalentBrawlId, kAbilityGroupTalentsId, kTalentBrawlLabel); +const Ability kTalentDodge = Ability(kTalentDodgeId, kAbilityGroupTalentsId, kTalentDodgeLabel); +const Ability kTalentEmpathy = Ability(kTalentEmpathyId, kAbilityGroupTalentsId, kTalentEmpathyLabel); +const Ability kTalentIntimidation = Ability(kTalentIntimidationId, kAbilityGroupTalentsId, kTalentIntimidationLabel); +const Ability kTalentLeadership = Ability(kTalentLeadershipId, kAbilityGroupTalentsId, kTalentLeadershipLabel); +const Ability kTalentStreetwise = Ability(kTalentStreetwiseId, kAbilityGroupTalentsId, kTalentStreetwiseLabel); +const Ability kTalentSubterfuge = Ability(kTalentSubterfugeId, kAbilityGroupTalentsId, kTalentSubterfugeLabel); +const vector kTalents = { + kTalentActing, + kTalentAlertness, + kTalentAthletics, + kTalentBrawl, + kTalentDodge, + kTalentEmpathy, + kTalentIntimidation, + kTalentLeadership, + kTalentStreetwise, + kTalentSubterfuge, +}; + +const std::string kSkillAnimalKenLabel = "Animal Ken"; +const std::string kSkillDriveLabel = "Drive"; +const std::string kSkillEtiquetteLabel = "Etiquette"; +const std::string kSkillFirearmsLabel = "Firearms"; +const std::string kSkillMeleeLabel = "Melee"; +const std::string kSkillMusicLabel = "Music"; +const std::string kSkillRepairLabel = "Repair"; +const std::string kSkillSecurityLabel = "Security"; +const std::string kSkillStealthLabel = "Stealth"; +const std::string kSkillSurvivalLabel = "Survival"; +const vector kSkillLabels = { + kSkillAnimalKenLabel, + kSkillDriveLabel, + kSkillEtiquetteLabel, + kSkillFirearmsLabel, + kSkillMeleeLabel, + kSkillMusicLabel, + kSkillRepairLabel, + kSkillSecurityLabel, + kSkillStealthLabel, + kSkillSurvivalLabel, +}; +const Ability kSkillAnimalKen = Ability(kSkillAnimalKenId, kAbilityGroupSkillsId, kSkillAnimalKenLabel); +const Ability kSkillDrive = Ability(kSkillDriveId, kAbilityGroupSkillsId, kSkillDriveLabel); +const Ability kSkillEtiquette = Ability(kSkillEtiquetteId, kAbilityGroupSkillsId, kSkillEtiquetteLabel); +const Ability kSkillFirearms = Ability(kSkillFirearmsId, kAbilityGroupSkillsId, kSkillFirearmsLabel); +const Ability kSkillMelee = Ability(kSkillMeleeId, kAbilityGroupSkillsId, kSkillMeleeLabel); +const Ability kSkillMusic = Ability(kSkillMusicId, kAbilityGroupSkillsId, kSkillMusicLabel); +const Ability kSkillRepair = Ability(kSkillRepairId, kAbilityGroupSkillsId, kSkillRepairLabel); +const Ability kSkillSecurity = Ability(kSkillSecurityId, kAbilityGroupSkillsId, kSkillSecurityLabel); +const Ability kSkillStealth = Ability(kSkillStealthId, kAbilityGroupSkillsId, kSkillStealthLabel); +const Ability kSkillSurvival = Ability(kSkillSurvivalId, kAbilityGroupSkillsId, kSkillSurvivalLabel); +const vector kSkills = { + kSkillAnimalKen, + kSkillDrive, + kSkillEtiquette, + kSkillFirearms, + kSkillMelee, + kSkillMusic, + kSkillRepair, + kSkillSecurity, + kSkillStealth, + kSkillSurvival, +}; + +const std::string kKnowledgeBureaucracyLabel = "Bureaucracy"; +const std::string kKnowledgeComputerLabel = "Computer"; +const std::string kKnowledgeFinanceLabel = "Finance"; +const std::string kKnowledgeInvestigationLabel = "Investigation"; +const std::string kKnowledgeLawLabel = "Law"; +const std::string kKnowledgeLinguisticsLabel = "Linguistics"; +const std::string kKnowledgeMedicineLabel = "Medicine"; +const std::string kKnowledgeOccultLabel = "Occult"; +const std::string kKnowledgePoliticsLabel = "Politics"; +const std::string kKnowledgeScienceLabel = "Science"; +const vector kKnowledgeLabels = { + kKnowledgeBureaucracyLabel, + kKnowledgeComputerLabel, + kKnowledgeFinanceLabel, + kKnowledgeInvestigationLabel, + kKnowledgeLawLabel, + kKnowledgeLinguisticsLabel, + kKnowledgeMedicineLabel, + kKnowledgeOccultLabel, + kKnowledgePoliticsLabel, + kKnowledgeScienceLabel, +}; +const Ability kKnowledgeBureaucracy = + Ability(kKnowledgeBureaucracyId, kAbilityGroupKnowledgesId, kKnowledgeBureaucracyLabel); +const Ability kKnowledgeComputer = Ability(kKnowledgeComputerId, kAbilityGroupKnowledgesId, kKnowledgeComputerLabel); +const Ability kKnowledgeFinance = Ability(kKnowledgeFinanceId, kAbilityGroupKnowledgesId, kKnowledgeFinanceLabel); +const Ability kKnowledgeInvestigation = + Ability(kKnowledgeInvestigationId, kAbilityGroupKnowledgesId, kKnowledgeInvestigationLabel); +const Ability kKnowledgeLaw = Ability(kKnowledgeLawId, kAbilityGroupKnowledgesId, kKnowledgeLawLabel); +const Ability kKnowledgeLinguistics = + Ability(kKnowledgeLinguisticsId, kAbilityGroupKnowledgesId, kKnowledgeLinguisticsLabel); +const Ability kKnowledgeMedicine = Ability(kKnowledgeMedicineId, kAbilityGroupKnowledgesId, kKnowledgeMedicineLabel); +const Ability kKnowledgeOccult = Ability(kKnowledgeOccultId, kAbilityGroupKnowledgesId, kKnowledgeOccultLabel); +const Ability kKnowledgePolitics = Ability(kKnowledgePoliticsId, kAbilityGroupKnowledgesId, kKnowledgePoliticsLabel); +const Ability kKnowledgeScience = Ability(kKnowledgeScienceId, kAbilityGroupKnowledgesId, kKnowledgeScienceLabel); +const vector kKnowledges = { + kKnowledgeBureaucracy, + kKnowledgeComputer, + kKnowledgeFinance, + kKnowledgeInvestigation, + kKnowledgeLaw, + kKnowledgeLinguistics, + kKnowledgeMedicine, + kKnowledgeOccult, + kKnowledgePolitics, + kKnowledgeScience, +}; + +TestResults test_AbilityGroup_constructor() { + auto fnToTest = []() { return AbilityGroup(); }; + return execute_suite(make_test_suite( + "SBF::AbilityGroup::AbilityGroup()", + fnToTest, + { + make_test("should construct the default unknown instance", kAbilityGroupUnknown, make_tuple()), + })); } -TestResults test_AbilityType_operator_equal_to() { - AbilityType skills = GetAbility(kAbilitySkillsId); - return execute_suite(make_test_suite( - "SBF::AbilityType::operator==", - [](const AbilityType& left, const AbilityType& right) { return left == right; }, - vector>({ - make_test( - "should return true when comparing an ability group to itself", - true, - make_tuple(GetAbility(kAbilityTalentsId), GetAbility(kAbilityTalentsId))), - make_test( - "should return true when comparing two different instances created with the same values", - true, - make_tuple(GetAbility(kAbilitySkillsId), - AbilityType({kAbilitySkillsId, skills.singular, skills.plural}))), - make_test( +TestResults test_AbilityGroup_constructor_int_string_string() { + AbilityGroup invalid_group; + invalid_group.id(12); + invalid_group.plural("plural form"); + invalid_group.singular("singular form"); + + auto fnToTest = [](int id, const char* singular, const char* plural) { return AbilityGroup(id, singular, plural); }; + return execute_suite(make_test_suite( + "SBF::AbilityGroup::AbilityGroup(int, string, string)", + fnToTest, + { + make_test( + "should construct an invalid instance", invalid_group, make_tuple(12, "singular form", "plural form")), + make_test("should construct knowledges", kAbilityGroupKnowledges, make_tuple(3, "Knowledge", "Knowledges")), + make_test("should construct skills", kAbilityGroupSkills, make_tuple(2, "Skill", "Skills")), + make_test("should construct talents", kAbilityGroupTalents, make_tuple(1, "Talent", "Talents")), + make_test("should construct the unknown instance", kAbilityGroupUnknown, make_tuple(0, "", "")), + })); +} + +TestResults test_AbilityGroup_GetAbilityCount() { + auto fnToTest = [](const AbilityGroup& group) { return group.GetAbilityCount(); }; + return execute_suite( + make_test_suite("SBF::AbilityGroup::GetAbilityCount()", + fnToTest, + { + make_test("should get 0 for an invalid instance", 0, make_tuple(kAbilityGroupUnknown)), + make_test("should get 10 for knowledges", 10, make_tuple(kAbilityGroupKnowledges)), + make_test("should get 10 for skills", 10, make_tuple(kAbilityGroupSkills)), + make_test("should get 10 for talents", 10, make_tuple(kAbilityGroupTalents)), + })); +} + +TestResults test_AbilityGroup_GetAbilityLabels() { + string no_errors = "no errors"; + auto fnToTest = [no_errors](vector expected, const AbilityGroup& group) { + ostringstream error_message; + vector actual = group.GetAbilityLabels(); + compare(error_message, expected, actual); + string error = error_message.str(); + if (error.size() > 0) { + return error; + } + return no_errors; + }; + return execute_suite(make_test_suite( + "SBF::AbilityGroup::GetAbilityLabels()", + fnToTest, + { + make_test("should get knowledges", + no_errors, + make_tuple(kKnowledgeLabels, AbilityGroup::FromId(kAbilityGroupKnowledgesId))), + make_test( + "should get skills", no_errors, make_tuple(kSkillLabels, AbilityGroup::FromId(kAbilityGroupSkillsId))), + make_test( + "should get talents", no_errors, make_tuple(kTalentLabels, AbilityGroup::FromId(kAbilityGroupTalentsId))), + make_test("should get empty for an invalid instance", + no_errors, + make_tuple(vector(), AbilityGroup::FromId(15))), + })); +} + +TestResults test_AbilityGroup_id_getter() { + auto fnToTest = [](int id) { + AbilityGroup ability_group(id, "", ""); + return ability_group.id(); + }; + return execute_suite(make_test_suite("SBF::AbilityGroup::id()", + fnToTest, + { + make_test("should get 12", 12, make_tuple(12)), + make_test("should get -1", -1, make_tuple(-1)), + make_test("should get 2", 2, make_tuple(2)), + })); +} + +TestResults test_AbilityGroup_id_setter() { + auto fnToTest = [](int id) { + AbilityGroup ability; + ability.id(id); + return ability.id(); + }; + return execute_suite(make_test_suite("SBF::AbilityGroup::id(int)", + fnToTest, + { + make_test("should set 16", 16, make_tuple(16)), + make_test("should set -99", -99, make_tuple(-99)), + make_test("should set 3", 3, make_tuple(3)), + })); +} + +TestResults test_AbilityGroup_plural_getter() { + auto fnToTest = [](const char* plural) { + AbilityGroup ability(-1, "singular", plural); + return ability.plural(); + }; + return execute_suite(make_test_suite("SBF::AbilityGroup::plural()", + fnToTest, + { + make_test("should get Talents", string("Talents"), make_tuple("Talents")), + make_test("should get birds", string("birds"), make_tuple("birds")), + make_test("should get an empty string", string(""), make_tuple("")), + })); +} + +TestResults test_AbilityGroup_plural_setter() { + auto fnToTest = [](const char* plural) { + AbilityGroup ability(-1, "singular", "plural"); + ability.plural(plural); + return ability.plural(); + }; + return execute_suite(make_test_suite("SBF::AbilityGroup::plural(string)", + fnToTest, + { + make_test("should set Talents", string("Talents"), make_tuple("Talents")), + make_test("should set birds", string("birds"), make_tuple("birds")), + make_test("should set an empty string", string(""), make_tuple("")), + })); +} + +TestResults test_AbilityGroup_singular_getter() { + auto fnToTest = [](const char* singular) { + AbilityGroup ability(-1, singular, "plural"); + return ability.singular(); + }; + return execute_suite(make_test_suite("SBF::AbilityGroup::singular()", + fnToTest, + { + make_test("should get Talents", string("Talents"), make_tuple("Talents")), + make_test("should get birds", string("birds"), make_tuple("birds")), + make_test("should get an empty string", string(""), make_tuple("")), + })); +} + +TestResults test_AbilityGroup_singular_setter() { + auto fnToTest = [](const char* singular) { + AbilityGroup ability(-1, "singular", "plural"); + ability.singular(singular); + return ability.singular(); + }; + return execute_suite(make_test_suite("SBF::AbilityGroup::singular(string)", + fnToTest, + { + make_test("should set Talents", string("Talents"), make_tuple("Talents")), + make_test("should set birds", string("birds"), make_tuple("birds")), + make_test("should set an empty string", string(""), make_tuple("")), + })); +} + +TestResults test_AbilityGroup_operator_equal_to() { + AbilityGroup skills = AbilityGroup::FromId(kAbilityGroupSkillsId); + AbilityGroup talents = AbilityGroup::FromId(kAbilityGroupTalentsId); + return execute_suite(make_test_suite( + "SBF::AbilityGroup::operator==", + [](const AbilityGroup& left, const AbilityGroup& right) { return left == right; }, + { + make_test("should return true when comparing an ability group to itself", true, make_tuple(talents, talents)), + make_test("should return true when comparing two different instances created with the same values", + true, + make_tuple(skills, AbilityGroup({skills.id(), skills.singular(), skills.plural()}))), + make_test( "should return false when comparing two different ability gropus", false, - make_tuple(GetAbility(kAbilityKnowledgesId), GetAbility(kAbilitySkillsId))), - }))); + make_tuple(AbilityGroup::FromId(kAbilityGroupKnowledgesId), AbilityGroup::FromId(kAbilityGroupSkillsId))), + })); } -TestResults test_AbilityType_operator_not_equal_to() { - AbilityType skills = GetAbility(kAbilitySkillsId); - return execute_suite(make_test_suite( - "SBF::AbilityType::operator!=", - [](const AbilityType& left, const AbilityType& right) { return left != right; }, - vector>({ - make_test( +TestResults test_AbilityGroup_operator_not_equal_to() { + AbilityGroup skills = AbilityGroup::FromId(kAbilityGroupSkillsId); + return execute_suite(make_test_suite( + "SBF::AbilityGroup::operator!=", + [](const AbilityGroup& left, const AbilityGroup& right) { return left != right; }, + { + make_test( "should return false when comparing an ability group to itself", false, - make_tuple(GetAbility(kAbilityTalentsId), GetAbility(kAbilityTalentsId))), - make_test( - "should return false when comparing two different instances created with the same values", - false, - make_tuple(GetAbility(kAbilitySkillsId), - AbilityType({kAbilitySkillsId, skills.singular, skills.plural}))), - make_test( + make_tuple(AbilityGroup::FromId(kAbilityGroupTalentsId), AbilityGroup::FromId(kAbilityGroupTalentsId))), + make_test("should return false when comparing two different instances created with the same values", + false, + make_tuple(skills, AbilityGroup({skills.id(), skills.singular(), skills.plural()}))), + make_test( "should return true when comparing two different ability gropus", true, - make_tuple(GetAbility(kAbilityKnowledgesId), GetAbility(kAbilitySkillsId))), + make_tuple(AbilityGroup::FromId(kAbilityGroupKnowledgesId), AbilityGroup::FromId(kAbilityGroupSkillsId))), + })); +} + +TestResults test_AbilityGroup_static_FromId() { + return execute_suite( + make_test_suite("SBF::AbilityGroup::FromId(int)", + AbilityGroup::FromId, + { + make_test("should get the unknown group for id 0", kAbilityGroupUnknown, make_tuple(0)), + make_test("should get knowledges for id 3", kAbilityGroupKnowledges, make_tuple(3)), + make_test("should get skills for id 2", kAbilityGroupSkills, make_tuple(2)), + make_test("should get talents for id 1", kAbilityGroupTalents, make_tuple(1)), + make_test("should get the unknown group for id 4", kAbilityGroupUnknown, make_tuple(4)), + })); +} + +TestResults test_AbilityGroup_static_GetPluralLabels() { + string no_errors = "no errors"; + auto fnToTest = [no_errors]() { + vector expected = {kAbilityGroupTalentsPlural, kAbilityGroupSkillsPlural, kAbilityGroupKnowledgesPlural}; + vector actual = AbilityGroup::GetPluralLabels(); + ostringstream error_message; + + compare(error_message, expected, actual); + string error = error_message.str(); + if (error.size() > 0) { + return error; + } + return no_errors; + }; + return execute_suite(make_test_suite("SBF::AbilityGroup::GetPluralLabels()", + fnToTest, + { + make_test("should get plural labels", no_errors, make_tuple()), + })); +} + +TestResults test_AbilityGroup_static_GetAbilityLabels() { + string no_errors = "no errors"; + auto fnToTest = [no_errors](vector expected, int id) { + vector actual = AbilityGroup::GetAbilityLabels(id); + ostringstream error_message; + + compare(error_message, expected, actual); + string error = error_message.str(); + if (error.size() > 0) { + return error; + } + return no_errors; + }; + return execute_suite( + make_test_suite("SBF::AbilityGroup::GetAbilityLabels(int)", + fnToTest, + { + make_test("should get an empty vector for an invalid id that is too small", + no_errors, + make_tuple(vector(), 0)), + make_test("should get knowledges", no_errors, make_tuple(kKnowledgeLabels, 3)), + make_test("should get skills", no_errors, make_tuple(kSkillLabels, 2)), + make_test("should get talents", no_errors, make_tuple(kTalentLabels, 1)), + make_test("should get an empty vector for an invalid id that is too big", + no_errors, + make_tuple(vector(), 4)), + })); +} + +TestResults test_AbilityGroup_static_GetCount() { + return execute_suite(make_test_suite("SBF::AbilityGroup::GetCount()", + AbilityGroup::GetCount, + { + make_test("should get 3", 3, make_tuple()), + })); +} + +TestResults test_AbilityGroup_friend_operator_extract() { + return execute_suite( + make_test_suite("SBF::AbilityGroup::operator<<", + [](const AbilityGroup& ability) { + ostringstream os; + os << ability; + return os.str(); + }, + { + make_test("should print talents", + "AbilityGroup: {id: 1, singular: \"Talent\", plural: \"Talents\"}", + make_tuple(AbilityGroup::FromId(kAbilityGroupTalentsId))), + make_test("should print skills", + "AbilityGroup: {id: 2, singular: \"Skill\", plural: \"Skills\"}", + make_tuple(AbilityGroup::FromId(kAbilityGroupSkillsId))), + make_test("should print knowledges", + "AbilityGroup: {id: 3, singular: \"Knowledge\", plural: \"Knowledges\"}", + make_tuple(AbilityGroup::FromId(kAbilityGroupKnowledgesId))), + make_test("should print an unknown ability group", + "AbilityGroup: {id: 0, singular: \"\", plural: \"\"}", + make_tuple(AbilityGroup::FromId(0))), + })); +} + +TestResults test_Ability_constructor() { + auto fnToTest = []() { return Ability(); }; + return execute_suite( + make_test_suite("SBF::Ability::Ability()", + fnToTest, + { + make_test("should construct the default unknown instance", kAbilityUnknown, make_tuple()), + })); +} + +TestResults test_Ability_constructor_int_int_string() { + Ability invalid_ability; + invalid_ability.id(-12); + invalid_ability.group_id(74); + invalid_ability.label("Custom"); + auto fnToTest = [](int id, int group_id, const string& label) { return Ability(id, group_id, label); }; + return execute_suite(make_test_suite( + "SBF::Ability::Ability(int, int, string)", + fnToTest, + { + make_test("should construct the unknown ability", kAbilityUnknown, make_tuple(0, 0, "")), + make_test("should construct the acting talent", + kTalentActing, + make_tuple(kTalentActing.id(), kTalentActing.group_id(), kTalentActing.label().c_str())), + make_test("should construct an invalid ability", invalid_ability, make_tuple(-12, 74, "Custom")), + })); +} + +TestResults test_Ability_group_id_getter() { + auto fnToTest = [](int id) { + Ability ability(0, id, ""); + return ability.group_id(); + }; + return execute_suite(make_test_suite("SBF::Ability::group_id()", + fnToTest, + { + make_test("should get 12", 12, make_tuple(12)), + make_test("should get -1", -1, make_tuple(-1)), + make_test("should get 2", 2, make_tuple(2)), + })); +} + +TestResults test_Ability_group_id_setter() { + auto fnToTest = [](int id) { + Ability ability(-1, -2, "label"); + ability.group_id(id); + return ability.group_id(); + }; + return execute_suite(make_test_suite("SBF::Ability::id(int)", + fnToTest, + { + make_test("should set 16", 16, make_tuple(16)), + make_test("should set -99", -99, make_tuple(-99)), + make_test("should set 3", 3, make_tuple(3)), + })); +} + +TestResults test_Ability_id_getter() { + auto fnToTest = [](int id) { + Ability ability(id, 0, ""); + return ability.id(); + }; + return execute_suite(make_test_suite("SBF::Ability::id()", + fnToTest, + { + make_test("should get 12", 12, make_tuple(12)), + make_test("should get -1", -1, make_tuple(-1)), + make_test("should get 2", 2, make_tuple(2)), + })); +} + +TestResults test_Ability_id_setter() { + auto fnToTest = [](int id) { + Ability ability(-1, -2, "label"); + ability.id(id); + return ability.id(); + }; + return execute_suite(make_test_suite("SBF::Ability::id(int)", + fnToTest, + { + make_test("should set 16", 16, make_tuple(16)), + make_test("should set -99", -99, make_tuple(-99)), + make_test("should set 3", 3, make_tuple(3)), + })); +} + +TestResults test_Ability_label_getter() { + auto fnToTest = [](const string& label) { + Ability ability(0, 0, label); + return ability.label(); + }; + return execute_suite(make_test_suite("SBF::Ability::label()", + fnToTest, + { + make_test("should get Talents", string("Talents"), make_tuple("Talents")), + make_test("should get birds", string("birds"), make_tuple("birds")), + make_test("should get an empty string", string(""), make_tuple("")), + })); +} + +TestResults test_Ability_label_setter() { + auto fnToTest = [](const string& label) { + Ability ability(-1, -2, "label"); + ability.label(label); + return ability.label(); + }; + return execute_suite(make_test_suite("SBF::Ability::label(string)", + fnToTest, + { + make_test("should set Acting", string("Acting"), make_tuple("Acting")), + make_test("should set birds", string("birds"), make_tuple("birds")), + make_test("should set an empty string", string(), make_tuple("")), + })); +} + +TestResults test_Ability_operator_equal_to() { + Ability security = Ability::FromIds(kSkillSecurityId, kAbilityGroupSkillsId); + Ability acting = Ability::FromIds(kTalentActingId, kAbilityGroupTalentsId); + return execute_suite(make_test_suite( + "SBF::Ability::operator==", + [](const Ability& left, const Ability& right) { return left == right; }, + vector({ + make_test("should return true when comparing an ability to itself", true, make_tuple(acting, acting)), + make_test("should return true when comparing two different instances created with the same values", + true, + make_tuple(security, Ability({security.id(), security.group_id(), security.label()}))), + make_test("should return false when comparing two different ability gropus", + false, + make_tuple(Ability::FromIds(kKnowledgeComputerId, kAbilityGroupKnowledgesId), + Ability::FromIds(kKnowledgeScienceId, kAbilityGroupKnowledgesId))), }))); } -TestResults test_FillAbilities() { - return execute_suite(make_test_suite( - "SBF::FillAbilities", - []() -> string { - ostringstream error_message; - vector actual = {{-1, "This should be removed.", "This should be removed."}}; - vector expected = { - GetAbility(kAbilityTalentsId), GetAbility(kAbilitySkillsId), GetAbility(kAbilityKnowledgesId)}; - FillAbilities(actual); - compare(error_message, expected, actual); - string error = error_message.str(); - if (error.size() > 0) { - return error; - } - return "no errors"; - }, - vector>({ - make_test("should fill abilities", "no errors", make_tuple()), +TestResults test_Ability_operator_not_equal_to() { + Ability security = Ability::FromIds(kSkillSecurityId, kAbilityGroupSkillsId); + Ability acting = Ability::FromIds(kTalentActingId, kAbilityGroupTalentsId); + return execute_suite(make_test_suite( + "SBF::Ability::operator!=", + [](const Ability& left, const Ability& right) { return left != right; }, + vector({ + make_test("should return fale when comparing an ability to itself", false, make_tuple(acting, acting)), + make_test("should return false when comparing two different instances created with the same values", + false, + make_tuple(security, Ability({security.id(), security.group_id(), security.label()}))), + make_test("should return true when comparing two different ability gropus", + true, + make_tuple(Ability::FromIds(kKnowledgeComputerId, kAbilityGroupKnowledgesId), + Ability::FromIds(kKnowledgeScienceId, kAbilityGroupKnowledgesId))), }))); } -TestResults test_FillAbilitiesForAbilityGroup() { - return execute_suite, int>(make_test_suite( - "SBF::FillAbilitiesForAbilityGroup", - [](int groupId) { - vector abilities = {"This should be removed."}; - FillAbilitiesForAbilityGroup(abilities, groupId); - return abilities; - }, - vector, int>>({ - make_test, int>( - "should clear the vector for group 0, kAbilityGropuUnknownId", {}, make_tuple(0)), - make_test, int>("should fill talents for group 1 GetAbility(kAbilityTalentsId)Id", - { - "Acting", - "Alertness", - "Athletics", - "Brawl", - "Dodge", - "Empathy", - "Intimidation", - "Leadership", - "Streetwise", - "Subterfuge", - }, //, "Alertness", "Athletics", "Brawl", "Dodge", "Empathy", - //"Intimidation", "Leadership", "Streetwise", "Subterfuge" - make_tuple(1)), - make_test, int>("should fill skills for group 2 kAbilityGroupSkillsId", - { - "Animal Ken", - "Drive", - "Etiquette", - "Firearms", - "Melee", - "Music", - "Repair", - "Security", - "Stealth", - "Survival", - }, - make_tuple(2)), - make_test, int>("should fill knowledges for group 3 GetAbility(kAbilityKnowledgesId)Id", - { - "Bureaucracy", - "Computer", - "Finance", - "Investigation", - "Law", - "Linguistics", - "Medicine", - "Occult", - "Politics", - "Science", - }, - make_tuple(3)), - make_test, int>("should clear the vector for group 4 an invalid id", {}, make_tuple(4)), - }))); +TestResults test_Ability_static_FromIds() { + return execute_suite(make_test_suite( + "SBF::Ability::FromIds(int, int)", + Ability::FromIds, + { + make_test("should get knowledge bureaucracy", + kKnowledgeBureaucracy, + make_tuple(kKnowledgeBureaucracyId, kAbilityGroupKnowledgesId)), + make_test("should get knowledge computer", + kKnowledgeComputer, + make_tuple(kKnowledgeComputerId, kAbilityGroupKnowledgesId)), + make_test("should get knowledge finance", + kKnowledgeFinance, + make_tuple(kKnowledgeFinanceId, kAbilityGroupKnowledgesId)), + make_test("should get knowledge investigation", + kKnowledgeInvestigation, + make_tuple(kKnowledgeInvestigationId, kAbilityGroupKnowledgesId)), + make_test("should get knowledge law", kKnowledgeLaw, make_tuple(kKnowledgeLawId, kAbilityGroupKnowledgesId)), + make_test("should get knowledge linguistics", + kKnowledgeLinguistics, + make_tuple(kKnowledgeLinguisticsId, kAbilityGroupKnowledgesId)), + make_test("should get knowledge medicine", + kKnowledgeMedicine, + make_tuple(kKnowledgeMedicineId, kAbilityGroupKnowledgesId)), + make_test("should get knowledge occult", + kKnowledgeOccult, + make_tuple(kKnowledgeOccultId, kAbilityGroupKnowledgesId)), + make_test("should get knowledge politics", + kKnowledgePolitics, + make_tuple(kKnowledgePoliticsId, kAbilityGroupKnowledgesId)), + make_test("should get knowledge science", + kKnowledgeScience, + make_tuple(kKnowledgeScienceId, kAbilityGroupKnowledgesId)), + make_test( + "should get skill animalKen", kSkillAnimalKen, make_tuple(kSkillAnimalKenId, kAbilityGroupSkillsId)), + make_test("should get skill drive", kSkillDrive, make_tuple(kSkillDriveId, kAbilityGroupSkillsId)), + make_test( + "should get skill etiquette", kSkillEtiquette, make_tuple(kSkillEtiquetteId, kAbilityGroupSkillsId)), + make_test("should get skill firearms", kSkillFirearms, make_tuple(kSkillFirearmsId, kAbilityGroupSkillsId)), + make_test("should get skill melee", kSkillMelee, make_tuple(kSkillMeleeId, kAbilityGroupSkillsId)), + make_test("should get skill music", kSkillMusic, make_tuple(kSkillMusicId, kAbilityGroupSkillsId)), + make_test("should get skill repair", kSkillRepair, make_tuple(kSkillRepairId, kAbilityGroupSkillsId)), + make_test("should get skill security", kSkillSecurity, make_tuple(kSkillSecurityId, kAbilityGroupSkillsId)), + make_test("should get skill stealth", kSkillStealth, make_tuple(kSkillStealthId, kAbilityGroupSkillsId)), + make_test("should get skill survival", kSkillSurvival, make_tuple(kSkillSurvivalId, kAbilityGroupSkillsId)), + make_test("should get talent acting", kTalentActing, make_tuple(kTalentActingId, kAbilityGroupTalentsId)), + make_test( + "should get talent alertness", kTalentAlertness, make_tuple(kTalentAlertnessId, kAbilityGroupTalentsId)), + make_test( + "should get talent athletics", kTalentAthletics, make_tuple(kTalentAthleticsId, kAbilityGroupTalentsId)), + make_test("should get talent brawl", kTalentBrawl, make_tuple(kTalentBrawlId, kAbilityGroupTalentsId)), + make_test("should get talent dodge", kTalentDodge, make_tuple(kTalentDodgeId, kAbilityGroupTalentsId)), + make_test("should get talent empathy", kTalentEmpathy, make_tuple(kTalentEmpathyId, kAbilityGroupTalentsId)), + make_test("should get talent intimidation", + kTalentIntimidation, + make_tuple(kTalentIntimidationId, kAbilityGroupTalentsId)), + make_test("should get talent leadership", + kTalentLeadership, + make_tuple(kTalentLeadershipId, kAbilityGroupTalentsId)), + make_test("should get talent streetwise", + kTalentStreetwise, + make_tuple(kTalentStreetwiseId, kAbilityGroupTalentsId)), + make_test("should get talent subterfuge", + kTalentSubterfuge, + make_tuple(kTalentSubterfugeId, kAbilityGroupTalentsId)), + make_test("should get unknown for an invalid id too small", kAbilityUnknown, make_tuple(0, 1)), + make_test("should get unknown for an invalid id too large", kAbilityUnknown, make_tuple(11, 1)), + make_test("should get unknown for an invalid group_id too small", kAbilityUnknown, make_tuple(1, 0)), + make_test("should get unknown for an invalid group_id too large", kAbilityUnknown, make_tuple(1, 4)), + make_test("should get unknown for an invalid id and group_id", kAbilityUnknown, make_tuple(-1, -1)), + })); } -TestResults test_FillAbilityLabels() { - return execute_suite, int>(make_test_suite( - "SBF::FillAbilityLabels", - [](int groupId) { - vector abilities = {"This should be removed."}; - FillAbilityLabels(abilities, groupId); - return abilities; - }, - vector, int>>({ - make_test, int>( - "should clear the vector for group 0, kAbilityGropuUnknownId", {}, make_tuple(0)), - make_test, int>("should fill talents for group 1 GetAbility(kAbilityTalentsId)Id", - { - "Acting", - "Alertness", - "Athletics", - "Brawl", - "Dodge", - "Empathy", - "Intimidation", - "Leadership", - "Streetwise", - "Subterfuge", - }, - make_tuple(1)), - make_test, int>("should fill skills for group 2 kAbilityGroupSkillsId", - { - "Animal Ken", - "Drive", - "Etiquette", - "Firearms", - "Melee", - "Music", - "Repair", - "Security", - "Stealth", - "Survival", - }, - make_tuple(2)), - make_test, int>("should fill knowledges for group 3 GetAbility(kAbilityKnowledgesId)Id", - { - "Bureaucracy", - "Computer", - "Finance", - "Investigation", - "Law", - "Linguistics", - "Medicine", - "Occult", - "Politics", - "Science", - }, - make_tuple(3)), - make_test, int>("should clear the vector for group 4 an invalid id", {}, make_tuple(4)), - }))); +TestResults test_Ability_static_FromKnowledgeId() { + return execute_suite(make_test_suite( + "SBF::Ability::FromKnowledgeId(int)", + Ability::FromKnowledgeId, + { + make_test("should bureaucracy", kKnowledgeBureaucracy, make_tuple(kKnowledgeBureaucracyId)), + make_test("should computer", kKnowledgeComputer, make_tuple(kKnowledgeComputerId)), + make_test("should finance", kKnowledgeFinance, make_tuple(kKnowledgeFinanceId)), + make_test("should investigation", kKnowledgeInvestigation, make_tuple(kKnowledgeInvestigationId)), + make_test("should law", kKnowledgeLaw, make_tuple(kKnowledgeLawId)), + make_test("should linguistics", kKnowledgeLinguistics, make_tuple(kKnowledgeLinguisticsId)), + make_test("should medicine", kKnowledgeMedicine, make_tuple(kKnowledgeMedicineId)), + make_test("should occult", kKnowledgeOccult, make_tuple(kKnowledgeOccultId)), + make_test("should politics", kKnowledgePolitics, make_tuple(kKnowledgePoliticsId)), + make_test("should science", kKnowledgeScience, make_tuple(kKnowledgeScienceId)), + make_test("should get unknown for an invalid id too small", kAbilityUnknown, make_tuple(0)), + make_test("should get unknown for an invalid negative id", kAbilityUnknown, make_tuple(-2)), + make_test("should get unknown for an invalid id too large", kAbilityUnknown, make_tuple(11)), + })); } -TestResults test_FillKnowledgeLabels() { - return execute_suite(make_test_suite( - "SBF::FillKnowlegeLabels", - []() -> string { - ostringstream error_message; - vector actual = {"This should be removed."}; - vector expected = { - "Bureaucracy", - "Computer", - "Finance", - "Investigation", - "Law", - "Linguistics", - "Medicine", - "Occult", - "Politics", - "Science", - }; - FillKnowledgeLabels(actual); - compare(error_message, expected, actual); - string error = error_message.str(); - if (error.size() > 0) { - return error; - } - return "no errors"; - }, - vector>({ - make_test("should fill knowledge labels", "no errors", make_tuple()), - }))); +TestResults test_Ability_static_FromSkillId() { + return execute_suite( + make_test_suite("SBF::Ability::FromSkillId(int)", + Ability::FromSkillId, + { + make_test("should animalKen", kSkillAnimalKen, make_tuple(kSkillAnimalKenId)), + make_test("should drive", kSkillDrive, make_tuple(kSkillDriveId)), + make_test("should etiquette", kSkillEtiquette, make_tuple(kSkillEtiquetteId)), + make_test("should firearms", kSkillFirearms, make_tuple(kSkillFirearmsId)), + make_test("should melee", kSkillMelee, make_tuple(kSkillMeleeId)), + make_test("should music", kSkillMusic, make_tuple(kSkillMusicId)), + make_test("should repair", kSkillRepair, make_tuple(kSkillRepairId)), + make_test("should security", kSkillSecurity, make_tuple(kSkillSecurityId)), + make_test("should stealth", kSkillStealth, make_tuple(kSkillStealthId)), + make_test("should survival", kSkillSurvival, make_tuple(kSkillSurvivalId)), + make_test("should get unknown for an invalid id too small", kAbilityUnknown, make_tuple(0)), + make_test("should get unknown for an invalid negative id", kAbilityUnknown, make_tuple(-2)), + make_test("should get unknown for an invalid id too large", kAbilityUnknown, make_tuple(11)), + })); } -TestResults test_FillSkillLabels() { - return execute_suite(make_test_suite( - "SBF::FillSkillLabels", - []() -> string { - ostringstream error_message; - vector actual = {"This should be removed."}; - vector expected = { - "Animal Ken", - "Drive", - "Etiquette", - "Firearms", - "Melee", - "Music", - "Repair", - "Security", - "Stealth", - "Survival", - }; - FillSkillLabels(actual); - compare(error_message, expected, actual); - string error = error_message.str(); - if (error.size() > 0) { - return error; - } - return "no errors"; - }, - vector>({ - make_test("should fill skill labels", "no errors", make_tuple()), - }))); +TestResults test_Ability_static_FromTalentId() { + return execute_suite( + make_test_suite("SBF::Ability::FromTalentId(int)", + Ability::FromTalentId, + { + make_test("should acting", kTalentActing, make_tuple(kTalentActingId)), + make_test("should alertness", kTalentAlertness, make_tuple(kTalentAlertnessId)), + make_test("should athletics", kTalentAthletics, make_tuple(kTalentAthleticsId)), + make_test("should brawl", kTalentBrawl, make_tuple(kTalentBrawlId)), + make_test("should dodge", kTalentDodge, make_tuple(kTalentDodgeId)), + make_test("should empathy", kTalentEmpathy, make_tuple(kTalentEmpathyId)), + make_test("should intimidation", kTalentIntimidation, make_tuple(kTalentIntimidationId)), + make_test("should leadership", kTalentLeadership, make_tuple(kTalentLeadershipId)), + make_test("should streetwise", kTalentStreetwise, make_tuple(kTalentStreetwiseId)), + make_test("should subterfuge", kTalentSubterfuge, make_tuple(kTalentSubterfugeId)), + make_test("should get unknown for an invalid id too small", kAbilityUnknown, make_tuple(0)), + make_test("should get unknown for an invalid negative id", kAbilityUnknown, make_tuple(-2)), + make_test("should get unknown for an invalid id too large", kAbilityUnknown, make_tuple(11)), + })); } -TestResults test_FillTalentLabels() { - return execute_suite(make_test_suite( - "SBF::FillTalentLabels", - []() -> string { - ostringstream error_message; - vector actual = {"This should be removed."}; - vector expected = { - "Acting", - "Alertness", - "Athletics", - "Brawl", - "Dodge", - "Empathy", - "Intimidation", - "Leadership", - "Streetwise", - "Subterfuge", - }; - FillTalentLabels(actual); - compare(error_message, expected, actual); - string error = error_message.str(); - if (error.size() > 0) { - return error; - } - return "no errors"; - }, - vector>({ - make_test("should fill knowledge labels", "no errors", make_tuple()), - }))); +TestResults test_Ability_static_GetCount() { + return execute_suite( + make_test_suite("SBF::Ability::GetCount(int)", + Ability::GetCount, + { + make_test("should get 10 knowledges", 10, make_tuple(kAbilityGroupKnowledgesId)), + make_test("should get 10 skills", 10, make_tuple(kAbilityGroupSkillsId)), + make_test("should get 10 talents", 10, make_tuple(kAbilityGroupTalentsId)), + make_test("should get 0 for an invalid id too small", 0, make_tuple(0)), + make_test("should get 0 for an invalid id too large", 0, make_tuple(4)), + })); } -TestResults test_GetAbility() { - return execute_suite(make_test_suite( - "SBF::GetAbility", - GetAbility, - vector>({ - make_test( - "should get talents", GetAbility(kAbilityTalentsId), make_tuple(kAbilityTalentsId)), - make_test("should get skills", GetAbility(kAbilitySkillsId), make_tuple(kAbilitySkillsId)), - make_test( - "should get knowledges", GetAbility(kAbilityKnowledgesId), make_tuple(kAbilityKnowledgesId)), - make_test("should get unknown for id 0", GetAbility(0), make_tuple(0)), - make_test("should get unknown for an invalid id", GetAbility(0), make_tuple(4)), - }))); +TestResults test_Ability_static_GetKnowledgeLabel() { + return execute_suite(make_test_suite( + "SBF::Ability::GetKnowledgeLabel(int)", + Ability::GetKnowledgeLabel, + { + make_test("should get \"Bureaucracy\" for kKnowledgeBureaucracyId", + kKnowledgeBureaucracyLabel, + make_tuple(kKnowledgeBureaucracyId)), + make_test("should get \"Computer\" for kKnowledgeComputerId", + kKnowledgeComputerLabel, + make_tuple(kKnowledgeComputerId)), + make_test("should get \"Finance\" for kKnowledgeFinanceId", + kKnowledgeFinanceLabel, + make_tuple(kKnowledgeFinanceId)), + make_test("should get \"Investigation\" for kKnowledgeInvestigationId", + kKnowledgeInvestigationLabel, + make_tuple(kKnowledgeInvestigationId)), + make_test("should get \"Law\" for kKnowledgeLawId", kKnowledgeLawLabel, make_tuple(kKnowledgeLawId)), + make_test("should get \"Linguistics\" for kKnowledgeLinguisticsId", + kKnowledgeLinguisticsLabel, + make_tuple(kKnowledgeLinguisticsId)), + make_test("should get \"Medicine\" for kKnowledgeMedicineId", + kKnowledgeMedicineLabel, + make_tuple(kKnowledgeMedicineId)), + make_test( + "should get \"Occult\" for kKnowledgeOccultId", kKnowledgeOccultLabel, make_tuple(kKnowledgeOccultId)), + make_test("should get \"Politics\" for kKnowledgePoliticsId", + kKnowledgePoliticsLabel, + make_tuple(kKnowledgePoliticsId)), + make_test("should get \"Science\" for kKnowledgeScienceId", + kKnowledgeScienceLabel, + make_tuple(kKnowledgeScienceId)), + make_test("should get an empty string for an invalid id too small", string(), make_tuple(0)), + make_test("should get an empty string for an invalid id too large", string(), make_tuple(11)), + })); } -TestResults test_GetAbilityLabel() { - return execute_suite(make_test_suite( - "SBF::GetAbilityLabel", - GetAbilityLabel, - vector>({ - make_test("should get Acting for group 1 and id 1", "Acting", make_tuple(1, 1)), - make_test("should get Alertness for group 1 and id 2", "Alertness", make_tuple(1, 2)), - make_test("should get Athletics for group 1 and id 3", "Athletics", make_tuple(1, 3)), - make_test("should get Brawl for group 1 and id 4", "Brawl", make_tuple(1, 4)), - make_test("should get Dodge for group 1 and id 5", "Dodge", make_tuple(1, 5)), - make_test("should get Empathy for group 1 and id 6", "Empathy", make_tuple(1, 6)), - make_test("should get Intimidation for group 1 and id 7", "Intimidation", make_tuple(1, 7)), - make_test("should get Leadership for group 1 and id 8", "Leadership", make_tuple(1, 8)), - make_test("should get Streetwise for group 1 and id 9", "Streetwise", make_tuple(1, 9)), - make_test("should get Subterfuge for group 1 and id 10", "Subterfuge", make_tuple(1, 10)), - make_test("should get Animal Ken for group 2 and id 1", "Animal Ken", make_tuple(2, 1)), - make_test("should get Drive for group 2 and id 2", "Drive", make_tuple(2, 2)), - make_test("should get Etiquette for group 2 and id 3", "Etiquette", make_tuple(2, 3)), - make_test("should get Firearms for group 2 and id 4", "Firearms", make_tuple(2, 4)), - make_test("should get Melee for group 2 and id 5", "Melee", make_tuple(2, 5)), - make_test("should get Music for group 2 and id 6", "Music", make_tuple(2, 6)), - make_test("should get Repair for group 2 and id 7", "Repair", make_tuple(2, 7)), - make_test("should get Security for group 2 and id 8", "Security", make_tuple(2, 8)), - make_test("should get Stealth for group 2 and id 9", "Stealth", make_tuple(2, 9)), - make_test("should get Survival for group 2 and id 10", "Survival", make_tuple(2, 10)), - make_test("should get Bureaucracy for group 3 and id 1", "Bureaucracy", make_tuple(3, 1)), - make_test("should get Computer for group 3 and id 2", "Computer", make_tuple(3, 2)), - make_test("should get Finance for group 3 and id 3", "Finance", make_tuple(3, 3)), - make_test( - "should get Investigation for group 3 and id 4", "Investigation", make_tuple(3, 4)), - make_test("should get Law for group 3 and id 5", "Law", make_tuple(3, 5)), - make_test("should get Linguistics for group 3 and id 6", "Linguistics", make_tuple(3, 6)), - make_test("should get Medicine for group 3 and id 7", "Medicine", make_tuple(3, 7)), - make_test("should get Occult for group 3 and id 8", "Occult", make_tuple(3, 8)), - make_test("should get Politics for group 3 and id 9", "Politics", make_tuple(3, 9)), - make_test("should get Science for group 3 and id 10", "Science", make_tuple(3, 10)), - make_test("should get and empty string for group 0 and id 0", "", make_tuple(0, 0)), - make_test("should get and empty string for group 1 and id 11", "", make_tuple(1, 11)), - make_test("should get and empty string for group 4 and id 1", "", make_tuple(4, 1)), - }))); +TestResults test_Ability_static_GetKnowledgeLabels() { + string no_errors = "no errors"; + auto fnToTest = [no_errors]() { + ostringstream error_message; + vector expected = kKnowledgeLabels; + vector actual = Ability::GetKnowledgeLabels(); + compare(error_message, expected, actual); + string error = error_message.str(); + if (error.size() > 0) { + return error; + } + return no_errors; + }; + return execute_suite(make_test_suite("SBF::Ability::GetKnowledgeLabels()", + fnToTest, + { + make_test("should get knowledge labels", no_errors, make_tuple()), + })); } -TestResults test_GetKnowledgeLabel() { - return execute_suite( - make_test_suite("SBF::GetKnowledgeLabel", - GetKnowledgeLabel, - vector>({ - make_test("should get Bureaucracy for id 1", "Bureaucracy", make_tuple(1)), - make_test("should get Computer for id 2", "Computer", make_tuple(2)), - make_test("should get Finance for id 3", "Finance", make_tuple(3)), - make_test("should get Investigation for id 4", "Investigation", make_tuple(4)), - make_test("should get Law for id 5", "Law", make_tuple(5)), - make_test("should get Linguistics for id 6", "Linguistics", make_tuple(6)), - make_test("should get Medicine for id 7", "Medicine", make_tuple(7)), - make_test("should get Occult for id 8", "Occult", make_tuple(8)), - make_test("should get Politics for id 9", "Politics", make_tuple(9)), - make_test("should get Science for id 10", "Science", make_tuple(10)), - make_test("should get and empty string for id 0", "", make_tuple(0)), - make_test("should get and empty string for id 11", "", make_tuple(11)), - }))); - return TestResults(); +TestResults test_Ability_static_GetKnowledgesCount() { + return execute_suite(make_test_suite("SBF::Ability::GetKnowledgesCount()", + Ability::GetKnowledgesCount, + { + make_test("should get 10 knowledges", 10, make_tuple()), + })); } -TestResults test_GetNumItemsForAbilityGroup() { - return execute_suite(make_test_suite( - "SBF::GetNumItemsForAbilityGroup", - GetNumItemsForAbilityGroup, - vector>({ - make_test("should get 10 abilities for talents", 10, make_tuple(kAbilityTalentsId)), - make_test("should get 10 abilities for skills", 10, make_tuple(kAbilitySkillsId)), - make_test("should get 10 abilities for knowledges", 10, make_tuple(kAbilityKnowledgesId)), - make_test("should get 0 abilities for 0", 0, make_tuple(0)), - make_test("should get 0 abilities for an invalid id", 0, make_tuple(4)), - }))); +TestResults test_Ability_static_GetSkillLabel() { + return execute_suite(make_test_suite( + "SBF::Ability::GetSkillLabel(int)", + Ability::GetSkillLabel, + { + make_test( + "should get \"Animal Ken\" for kSkillAnimalKenId", kSkillAnimalKenLabel, make_tuple(kSkillAnimalKenId)), + make_test("should get \"Drive\" for kSkillDriveId", kSkillDriveLabel, make_tuple(kSkillDriveId)), + make_test( + "should get \"Etiquette\" for kSkillEtiquetteId", kSkillEtiquetteLabel, make_tuple(kSkillEtiquetteId)), + make_test("should get \"Firearms\" for kSkillFirearmsId", kSkillFirearmsLabel, make_tuple(kSkillFirearmsId)), + make_test("should get \"Melee\" for kSkillMeleeId", kSkillMeleeLabel, make_tuple(kSkillMeleeId)), + make_test("should get \"Music\" for kSkillMusicId", kSkillMusicLabel, make_tuple(kSkillMusicId)), + make_test("should get \"Repair\" for kSkillRepairId", kSkillRepairLabel, make_tuple(kSkillRepairId)), + make_test("should get \"Security\" for kSkillSecurityId", kSkillSecurityLabel, make_tuple(kSkillSecurityId)), + make_test("should get \"Stealth\" for kSkillStealthId", kSkillStealthLabel, make_tuple(kSkillStealthId)), + make_test("should get \"Survival\" for kSkillSurvivalId", kSkillSurvivalLabel, make_tuple(kSkillSurvivalId)), + make_test("should get an empty string for an invalid id too small", string(), make_tuple(0)), + make_test("should get an empty string for an invalid id too large", string(), make_tuple(11)), + })); } -TestResults test_GetSkillLabel() { - return execute_suite( - make_test_suite("SBF::GetSkillLabel", - GetSkillLabel, - vector>({ - make_test("should get Animal Ken for id 1", "Animal Ken", make_tuple(1)), - make_test("should get Drive for id 2", "Drive", make_tuple(2)), - make_test("should get Etiquette for id 3", "Etiquette", make_tuple(3)), - make_test("should get Firearms for id 4", "Firearms", make_tuple(4)), - make_test("should get Melee for id 5", "Melee", make_tuple(5)), - make_test("should get Music for id 6", "Music", make_tuple(6)), - make_test("should get Repair for id 7", "Repair", make_tuple(7)), - make_test("should get Security for id 8", "Security", make_tuple(8)), - make_test("should get Stealth for id 9", "Stealth", make_tuple(9)), - make_test("should get Survival for id 10", "Survival", make_tuple(10)), - make_test("should get and empty string for id 0", "", make_tuple(0)), - make_test("should get and empty string for id 11", "", make_tuple(11)), - }))); +TestResults test_Ability_static_GetSkillLabels() { + string no_errors = "no errors"; + auto fnToTest = [no_errors]() { + ostringstream error_message; + vector expected = kSkillLabels; + vector actual = Ability::GetSkillLabels(); + compare(error_message, expected, actual); + string error = error_message.str(); + if (error.size() > 0) { + return error; + } + return no_errors; + }; + return execute_suite(make_test_suite("SBF::Abliity::GetSkillLabels()", + fnToTest, + { + make_test("should get skill labels", no_errors, make_tuple()), + })); } -TestResults test_GetTalentLabel() { - return execute_suite( - make_test_suite("SBF::GetTalentLabel", - GetTalentLabel, - vector>({ - make_test("should get Acting for id 1", "Acting", make_tuple(1)), - make_test("should get Alertness for id 2", "Alertness", make_tuple(2)), - make_test("should get Athletics for id 3", "Athletics", make_tuple(3)), - make_test("should get Brawl for id 4", "Brawl", make_tuple(4)), - make_test("should get Dodge for id 5", "Dodge", make_tuple(5)), - make_test("should get Empathy for id 6", "Empathy", make_tuple(6)), - make_test("should get Intimidation for id 7", "Intimidation", make_tuple(7)), - make_test("should get Leadership for id 8", "Leadership", make_tuple(8)), - make_test("should get Streetwise for id 9", "Streetwise", make_tuple(9)), - make_test("should get Subterfuge for id 10", "Subterfuge", make_tuple(10)), - make_test("should get and empty string for id 0", "", make_tuple(0)), - make_test("should get and empty string for id 11", "", make_tuple(11)), - }))); +TestResults test_Ability_static_GetSkillsCount() { + return execute_suite(make_test_suite("SBF::Ability::GetSkillsCount()", + Ability::GetSkillsCount, + { + make_test("should get 10 skills", 10, make_tuple()), + })); } -TestResults test_GetNumAbilityGroups() { - return execute_suite(make_test_suite("SBF::Abilities::GetNumAbilityGroups", - GetNumAbilityGroups, - vector>({ - make_test("should get 3", 3, make_tuple()), - }))); +TestResults test_Ability_static_GetTalentLabel() { + return execute_suite(make_test_suite( + "SBF::Ability::GetTalentLabel(int)", + Ability::GetTalentLabel, + { + make_test("should get \"Acting\" for kTalentActingId", kTalentActingLabel, make_tuple(kTalentActingId)), + make_test( + "should get \"Alertness\" for kTalentAlertnessId", kTalentAlertnessLabel, make_tuple(kTalentAlertnessId)), + make_test( + "should get \"Athletics\" for kTalentAthleticsId", kTalentAthleticsLabel, make_tuple(kTalentAthleticsId)), + make_test("should get \"Brawl\" for kTalentBrawlId", kTalentBrawlLabel, make_tuple(kTalentBrawlId)), + make_test("should get \"Dodge\" for kTalentDodgeId", kTalentDodgeLabel, make_tuple(kTalentDodgeId)), + make_test("should get \"Empathy\" for kTalentEmpathyId", kTalentEmpathyLabel, make_tuple(kTalentEmpathyId)), + make_test("should get \"Intimidation\" for kTalentIntimidationId", + kTalentIntimidationLabel, + make_tuple(kTalentIntimidationId)), + make_test("should get \"Leadership\" for kTalentLeadershipId", + kTalentLeadershipLabel, + make_tuple(kTalentLeadershipId)), + make_test("should get \"Streetwise\" for kTalentStreetwiseId", + kTalentStreetwiseLabel, + make_tuple(kTalentStreetwiseId)), + make_test("should get \"Subterfuge\" for kTalentSubterfugeId", + kTalentSubterfugeLabel, + make_tuple(kTalentSubterfugeId)), + make_test("should get an empty string for an invalid id too small", string(), make_tuple(0)), + make_test("should get an empty string for an invalid id too large", string(), make_tuple(11)), + })); +} + +TestResults test_Ability_static_GetTalentLabels() { + string no_errors = "no errors"; + auto fnToTest = [no_errors]() { + ostringstream error_message; + vector expected = kTalentLabels; + vector actual = Ability::GetTalentLabels(); + compare(error_message, expected, actual); + string error = error_message.str(); + if (error.size() > 0) { + return error; + } + return no_errors; + }; + return execute_suite(make_test_suite("SBF::Abliity::GetTalentLabels()", + fnToTest, + { + make_test("should get talent labels", no_errors, make_tuple()), + })); +} + +TestResults test_Ability_static_GetTalentsCount() { + return execute_suite(make_test_suite("SBF::Ability::GetTalentsCount()", + Ability::GetTalentsCount, + { + make_test("should get 10 talent", 10, make_tuple()), + })); +} + +TestResults test_Ability_friend_operator_extract() { + return execute_suite(make_test_suite("SBF::Ability::operator<<", + [](const Ability& ability) { + ostringstream os; + os << ability; + return os.str(); + }, + { + make_test("should print knowledge bureaucracy", + string("Ability: {id: 1, group_id: 3, label: \"Bureaucracy\"}"), + make_tuple(Ability::FromIds(1, 3))), + make_test("should print knowledge computer", + string("Ability: {id: 2, group_id: 3, label: \"Computer\"}"), + make_tuple(Ability::FromIds(2, 3))), + make_test("should print knowledge finance", + string("Ability: {id: 3, group_id: 3, label: \"Finance\"}"), + make_tuple(Ability::FromIds(3, 3))), + make_test("should print knowledge investigation", + string("Ability: {id: 4, group_id: 3, label: \"Investigation\"}"), + make_tuple(Ability::FromIds(4, 3))), + make_test("should print knowledge law", + string("Ability: {id: 5, group_id: 3, label: \"Law\"}"), + make_tuple(Ability::FromIds(5, 3))), + make_test("should print knowledge linguistics", + string("Ability: {id: 6, group_id: 3, label: \"Linguistics\"}"), + make_tuple(Ability::FromIds(6, 3))), + make_test("should print knowledge medicine", + string("Ability: {id: 7, group_id: 3, label: \"Medicine\"}"), + make_tuple(Ability::FromIds(7, 3))), + make_test("should print knowledge occult", + string("Ability: {id: 8, group_id: 3, label: \"Occult\"}"), + make_tuple(Ability::FromIds(8, 3))), + make_test("should print knowledge politics", + string("Ability: {id: 9, group_id: 3, label: \"Politics\"}"), + make_tuple(Ability::FromIds(9, 3))), + make_test("should print knowledge science", + string("Ability: {id: 10, group_id: 3, label: \"Science\"}"), + make_tuple(Ability::FromIds(10, 3))), + make_test("should print skill animal ken", + string("Ability: {id: 1, group_id: 2, label: \"Animal Ken\"}"), + make_tuple(Ability::FromIds(1, 2))), + make_test("should print skill drive", + string("Ability: {id: 2, group_id: 2, label: \"Drive\"}"), + make_tuple(Ability::FromIds(2, 2))), + make_test("should print skill etiquette", + string("Ability: {id: 3, group_id: 2, label: \"Etiquette\"}"), + make_tuple(Ability::FromIds(3, 2))), + make_test("should print skill firearms", + string("Ability: {id: 4, group_id: 2, label: \"Firearms\"}"), + make_tuple(Ability::FromIds(4, 2))), + make_test("should print skill melee", + string("Ability: {id: 5, group_id: 2, label: \"Melee\"}"), + make_tuple(Ability::FromIds(5, 2))), + make_test("should print skill music", + string("Ability: {id: 6, group_id: 2, label: \"Music\"}"), + make_tuple(Ability::FromIds(6, 2))), + make_test("should print skill repair", + string("Ability: {id: 7, group_id: 2, label: \"Repair\"}"), + make_tuple(Ability::FromIds(7, 2))), + make_test("should print skill security", + string("Ability: {id: 8, group_id: 2, label: \"Security\"}"), + make_tuple(Ability::FromIds(8, 2))), + make_test("should print skill stealth", + string("Ability: {id: 9, group_id: 2, label: \"Stealth\"}"), + make_tuple(Ability::FromIds(9, 2))), + make_test("should print skill survival", + string("Ability: {id: 10, group_id: 2, label: \"Survival\"}"), + make_tuple(Ability::FromIds(10, 2))), + make_test("should print talent acting", + string("Ability: {id: 1, group_id: 1, label: \"Acting\"}"), + make_tuple(Ability::FromIds(1, 1))), + make_test("should print talent alertness", + string("Ability: {id: 2, group_id: 1, label: \"Alertness\"}"), + make_tuple(Ability::FromIds(2, 1))), + make_test("should print talent athletics", + string("Ability: {id: 3, group_id: 1, label: \"Athletics\"}"), + make_tuple(Ability::FromIds(3, 1))), + make_test("should print talent brawl", + string("Ability: {id: 4, group_id: 1, label: \"Brawl\"}"), + make_tuple(Ability::FromIds(4, 1))), + make_test("should print talent dodge", + string("Ability: {id: 5, group_id: 1, label: \"Dodge\"}"), + make_tuple(Ability::FromIds(5, 1))), + make_test("should print talent empathy", + string("Ability: {id: 6, group_id: 1, label: \"Empathy\"}"), + make_tuple(Ability::FromIds(6, 1))), + make_test("should print talent intimidation", + string("Ability: {id: 7, group_id: 1, label: \"Intimidation\"}"), + make_tuple(Ability::FromIds(7, 1))), + make_test("should print talent leadership", + string("Ability: {id: 8, group_id: 1, label: \"Leadership\"}"), + make_tuple(Ability::FromIds(8, 1))), + make_test("should print talent streetwise", + string("Ability: {id: 9, group_id: 1, label: \"Streetwise\"}"), + make_tuple(Ability::FromIds(9, 1))), + make_test("should print talent subterfuge", + string("Ability: {id: 10, group_id: 1, label: \"Subterfuge\"}"), + make_tuple(Ability::FromIds(10, 1))), + })); } int main(int argc, char* argv[]) { TestResults results; - results += test_AbilityType_operator_extract(); - results += test_AbilityType_operator_equal_to(); - results += test_AbilityType_operator_not_equal_to(); - results += test_FillAbilities(); - results += test_FillAbilitiesForAbilityGroup(); - results += test_FillAbilityLabels(); - results += test_FillKnowledgeLabels(); - results += test_FillSkillLabels(); - results += test_FillTalentLabels(); - results += test_GetAbility(); - results += test_GetAbilityLabel(); - results += test_GetKnowledgeLabel(); - results += test_GetNumAbilityGroups(); - results += test_GetNumItemsForAbilityGroup(); - results += test_GetSkillLabel(); - results += test_GetTalentLabel(); + results += test_AbilityGroup_constructor(); + results += test_AbilityGroup_constructor_int_string_string(); + results += test_AbilityGroup_GetAbilityCount(); + results += test_AbilityGroup_GetAbilityLabels(); + results += test_AbilityGroup_id_getter(); + results += test_AbilityGroup_id_setter(); + results += test_AbilityGroup_plural_getter(); + results += test_AbilityGroup_plural_setter(); + results += test_AbilityGroup_singular_getter(); + results += test_AbilityGroup_singular_setter(); + results += test_AbilityGroup_operator_equal_to(); + results += test_AbilityGroup_operator_not_equal_to(); + + results += test_AbilityGroup_static_FromId(); + results += test_AbilityGroup_static_GetPluralLabels(); + results += test_AbilityGroup_static_GetAbilityLabels(); + results += test_AbilityGroup_static_GetCount(); + + results += test_AbilityGroup_friend_operator_extract(); + + results += test_Ability_constructor(); + results += test_Ability_constructor_int_int_string(); + results += test_Ability_group_id_getter(); + results += test_Ability_group_id_setter(); + results += test_Ability_id_getter(); + results += test_Ability_id_setter(); + results += test_Ability_label_getter(); + results += test_Ability_label_setter(); + results += test_Ability_operator_equal_to(); + results += test_Ability_operator_not_equal_to(); + + results += test_Ability_static_FromIds(); + results += test_Ability_static_FromKnowledgeId(); + results += test_Ability_static_FromSkillId(); + results += test_Ability_static_FromTalentId(); + results += test_Ability_static_GetCount(); + results += test_Ability_static_GetKnowledgeLabel(); + results += test_Ability_static_GetKnowledgeLabels(); + results += test_Ability_static_GetKnowledgesCount(); + results += test_Ability_static_GetSkillLabel(); + results += test_Ability_static_GetSkillLabels(); + results += test_Ability_static_GetSkillsCount(); + results += test_Ability_static_GetTalentLabel(); + results += test_Ability_static_GetTalentLabels(); + results += test_Ability_static_GetTalentsCount(); + + results += test_Ability_friend_operator_extract(); PrintResults(cout, results); diff --git a/sbf-cpp/BUILD b/sbf-cpp/BUILD index 595a5ff..02cf353 100644 --- a/sbf-cpp/BUILD +++ b/sbf-cpp/BUILD @@ -14,6 +14,7 @@ cc_library( cc_test( name = "abilities_test", + size = "small", srcs = ["Abilities_test.cpp"], deps = [ ":abilities", @@ -29,6 +30,7 @@ cc_library( cc_test( name = "archetypes_test", + size = "small", srcs = ["Archetypes_test.cpp"], deps = [ ":archetypes", @@ -44,6 +46,7 @@ cc_library( cc_test( name = "attributes_test", + size = "small", srcs = ["Attributes_test.cpp"], deps = [ ":attributes", @@ -59,6 +62,7 @@ cc_library( cc_test( name = "backgrounds_test", + size = "small", srcs = ["Backgrounds_test.cpp"], deps = [ ":backgrounds", @@ -85,6 +89,7 @@ cc_library( cc_test( name = "character_test", + size = "small", srcs = ["Character_test.cpp"], deps = [ ":character", @@ -100,6 +105,7 @@ cc_library( cc_test( name = "clans_test", + size = "small", srcs = ["Clans_test.cpp"], deps = [ ":clans", @@ -115,6 +121,7 @@ cc_library( cc_test( name = "colors_test", + size = "small", srcs = ["Colors_test.cpp"], deps = [ ":colors", @@ -131,6 +138,7 @@ cc_library( cc_test( name = "derangements_test", + size = "small", srcs = ["Derangements_test.cpp"], deps = [ ":derangements", @@ -146,6 +154,7 @@ cc_library( cc_test( name = "disciplines_test", + size = "small", srcs = ["Disciplines_test.cpp"], deps = [ ":disciplines", @@ -161,6 +170,7 @@ cc_library( cc_test( name = "freebies_test", + size = "small", srcs = ["Freebies_test.cpp"], deps = [ ":freebies", @@ -176,6 +186,7 @@ cc_library( cc_test( name = "genders_test", + size = "small", srcs = ["Genders_test.cpp"], deps = [ ":genders", @@ -198,6 +209,7 @@ cc_library( cc_test( name = "character_generator_test", + size = "small", srcs = ["CharacterGenerator_test.cpp"], deps = [ ":character_generator", @@ -233,6 +245,7 @@ cc_library( cc_test( name = "menus_test", + size = "small", srcs = ["Menus_test.cpp"], deps = [ ":menus", @@ -248,6 +261,7 @@ cc_library( cc_test( name = "random_test", + size = "small", srcs = ["Random_test.cpp"], deps = [ ":random", @@ -263,6 +277,7 @@ cc_library( cc_test( name = "ranks_test", + size = "small", srcs = ["Ranks_test.cpp"], deps = [ ":ranks", @@ -299,6 +314,7 @@ cc_library( cc_test( name = "utils_test", + size = "small", srcs = ["Utils_test.cpp"], deps = [ ":tinytest", @@ -314,6 +330,7 @@ cc_library( cc_test( name = "virtues_test", + size = "small", srcs = ["Virtues_test.cpp"], deps = [ ":tinytest", diff --git a/sbf-cpp/Character.cpp b/sbf-cpp/Character.cpp index 8a8f4cb..9e73414 100644 --- a/sbf-cpp/Character.cpp +++ b/sbf-cpp/Character.cpp @@ -47,8 +47,9 @@ CharacterType::CharacterType() { // Arrays/Objects // Abilities (Talents/Skills/Knowledges) - for (int group_id = 1; group_id <= GetNumAbilityGroups(); group_id++) { - const int num_abilities = GetNumItemsForAbilityGroup(group_id); + for (int group_id = 1; group_id <= AbilityGroup::GetCount(); group_id++) { + const AbilityGroup group = AbilityGroup::FromId(group_id); + const int num_abilities = group.GetAbilityCount(); for (int id = 1; id <= num_abilities; id++) { SetAbilityValue(group_id, id, 0); } @@ -401,13 +402,13 @@ int GetAttributePointsForRank(int id) { void CharacterType::SetAbilityValue(int group_id, int id, int value) { switch (group_id) { - case kAbilityTalentsId: + case kAbilityGroupTalentsId: SetTalentValue(id, value); break; - case kAbilitySkillsId: + case kAbilityGroupSkillsId: SetSkillValue(id, value); break; - case kAbilityKnowledgesId: + case kAbilityGroupKnowledgesId: SetKnowledgeValue(id, value); break; } @@ -415,11 +416,11 @@ void CharacterType::SetAbilityValue(int group_id, int id, int value) { int CharacterType::GetAbilityValue(int group_id, int id) const { switch (group_id) { - case kAbilityTalentsId: + case kAbilityGroupTalentsId: return GetTalentValue(id); - case kAbilityKnowledgesId: + case kAbilityGroupKnowledgesId: return GetKnowledgeValue(id); - case kAbilitySkillsId: + case kAbilityGroupSkillsId: return GetSkillValue(id); } return 0; @@ -438,7 +439,8 @@ int GetAbilityPointsForRank(int id) { } void CharacterType::FillAbilityValues(std::vector& values, int group_id) const { - int num_abilities = GetNumItemsForAbilityGroup(group_id); + const AbilityGroup group = AbilityGroup::FromId(group_id); + int num_abilities = group.GetAbilityCount(); values.clear(); for (int id = 0; id <= num_abilities; id++) { values[id] = GetAbilityValue(group_id, id); diff --git a/sbf-cpp/CharacterGenerator.cpp b/sbf-cpp/CharacterGenerator.cpp index d3f94c2..5ba1a65 100644 --- a/sbf-cpp/CharacterGenerator.cpp +++ b/sbf-cpp/CharacterGenerator.cpp @@ -273,18 +273,18 @@ void CGSpendAbilityPoint(CharacterType& ch) { bool done = false; while (!done) { MaybeClearScreen(); - ms.cancel_item_id = GetNumAbilityGroups(); + ms.cancel_item_id = AbilityGroup::GetCount(); int ability_group_id = - ChooseStringId(GetAbilityGroupPluralLabels(), ms, "What kind of ability would you like to add 1 dot to?"); + ChooseStringId(AbilityGroup::GetPluralLabels(), ms, "What kind of ability would you like to add 1 dot to?"); if (ability_group_id == ms.cancel_item_id) { return; } - AbilityType ability = GetAbility(ability_group_id); + AbilityGroup ability_group = AbilityGroup::FromId(ability_group_id); - vector labels = GetAbilityLabelsForAbilityGroup(ability_group_id); + vector labels = ability_group.GetAbilityLabels(); ms.cancel_item_id = labels.size() + 1; int ability_id = - ChooseStringId(labels, ms, "What " + ToLower(ability.singular) + " would you like to add 1 dot to?"); + ChooseStringId(labels, ms, "What " + ToLower(ability_group.singular()) + " would you like to add 1 dot to?"); if (ability_id != ms.cancel_item_id) { ch.SetAbilityValue(ability_group_id, ability_id, ch.GetAbilityValue(ability_group_id, ability_id) + 1); ch.SetFreebiePoints(ch.GetFreebiePoints() - GetFreebieCost(kFreebieAbilityId)); @@ -426,9 +426,9 @@ void ShowCharacterSheet(CharacterType& ch) { cout << "║ " << MakeFitC("Abilities", 76) << " ║" << endl; cout << "║ " << MakeFitC("Talents", 24) << MakeFitC("Skills", 24) << MakeFitC("Knowledges", 24) << " ║" << endl; for (index = 1; index <= 10; index++) { - cout << "║ " << FormatAbilityWithValue(GetTalentLabel(index), ch.GetTalentValue(index)) - << FormatAbilityWithValue(GetSkillLabel(index), ch.GetSkillValue(index)) - << FormatAbilityWithValue(GetKnowledgeLabel(index), ch.GetKnowledgeValue(index)) << " ║" << endl; + cout << "║ " << FormatAbilityWithValue(Ability::GetTalentLabel(index), ch.GetTalentValue(index)) + << FormatAbilityWithValue(Ability::GetSkillLabel(index), ch.GetSkillValue(index)) + << FormatAbilityWithValue(Ability::GetKnowledgeLabel(index), ch.GetKnowledgeValue(index)) << " ║" << endl; } cout << "╠══════════════════════════════════════╦═══════════════════════════════════════╣" << endl; cout << "║ " << MakeFitL("Backgrounds:", kLeftColumnWidth) << " ║ " << MakeFitL("Virtues:", kRightColumnWidth) << " ║" diff --git a/sbf-cpp/test.cpp b/sbf-cpp/test.cpp index 59ef6d2..0034036 100644 --- a/sbf-cpp/test.cpp +++ b/sbf-cpp/test.cpp @@ -276,4 +276,8 @@ void PrintResults(std::ostream& os, TestResults results) { os << "Skipped: " << results.skipped() << " 🚧" << endl; os << "Errors: " << results.errors() << " 🔥" << endl; } + +MaybeTestConfigureFunction DefaultTestConfigureFunction() { + return std::nullopt; +} } // End namespace Test diff --git a/sbf-cpp/test.h b/sbf-cpp/test.h index 626514e..46b1c69 100644 --- a/sbf-cpp/test.h +++ b/sbf-cpp/test.h @@ -205,8 +205,14 @@ using TestCompareFunction = std::function using MaybeTestCompareFunction = std::optional>; +template +MaybeTestCompareFunction DefaultTestCompareFunction() { + return std::nullopt; +} + using TestConfigureFunction = std::function; using MaybeTestConfigureFunction = std::optional; +MaybeTestConfigureFunction DefaultTestConfigureFunction(); // TODO: For some reason all hell breaks loose if test_name or expected output are const&. Figure out why. /// @brief @@ -410,6 +416,31 @@ TestResults execute_suite(std::string suite_label, return results; } +/// @brief +/// @tparam TResult The result type of the test. +/// @tparam TInputParams... The types of parameters sent to the test function. +/// @param suite_label The label for this test suite. For example a class name such as "MortgageCalculator". +/// @param function_to_test The function to be tested. It will be called with std::apply and a +/// std::tuple made from each item in tests. +/// @param tests A std::vector of test runs. +/// @param suite_compare A function used to compare the expected and actual test results. This can be +/// overridden per test by setting test_compare. +/// @param after_all This is called before each suite is started to setup the environment. This is where you should +/// build mocks, setup spies, and test fixtures. +/// @param before_all This is called after each suite has completed to cleanup anything allocated in suite_before_each. +/// @param is_enabled If false the test is reported as skipped. If true the test is run as normal. +template +TestResults execute_suite(std::string suite_label, + std::function function_to_test, + std::initializer_list> tests, + MaybeTestCompareFunction suite_compare = std::nullopt, + MaybeTestConfigureFunction before_all = std::nullopt, + MaybeTestConfigureFunction after_all = std::nullopt, + bool is_enabled = true) { + std::vector test_data = std::vector(tests); + return execute_suite(suite_label, function_to_test, tests, suite_compare, before_all, after_all, is_enabled); +} + /// @brief /// @tparam TResult The result type of the test. /// @tparam ...TInputParams The types of parameters sent to the test function. @@ -457,6 +488,22 @@ TestSuite make_test_suite(const string& suite_name, return make_tuple(suite_name, function_to_test, test_data, compare, before_each, after_each, is_enabled); } +template +TestSuite make_test_suite( + const string& suite_name, + TFunctionToTest function_to_test, + std::initializer_list> test_data, + MaybeTestCompareFunction compare = std::nullopt, + MaybeTestConfigureFunction before_each = std::nullopt, + MaybeTestConfigureFunction after_each = std::nullopt, + bool is_enabled = true) { + return make_tuple(suite_name, function_to_test, test_data, compare, before_each, after_each, is_enabled); +} + +/// @brief +/// @tparam TResult The result type of the test. +/// @tparam TInputParams... The types of parameters sent to the test function. +/// @param test_suite A tuple representing the test suite configuration. template TestResults execute_suite(const TestSuite& test_suite) { return execute_suite( @@ -493,7 +540,6 @@ MaybeTestConfigureFunction coalesce(MaybeTestConfigureFunction first, MaybeTestC void PrintResults(std::ostream& os, TestResults results); } // End namespace Test -// TODO: define operator<< for std::tuple. // TODO: Add TShared(*)(string /*test_name*/, UUID /*test_run_id*/) allocate_shared_data to the test tuple to make some // shared data that can be used in a thread safe way by setup, teardown, and evaluate steps of the test. // TODO: Add TShared to be returned by the setup functions, and consumed by the evaluate and teardown functions.