diff --git a/sbf-cpp/Attributes.cpp b/sbf-cpp/Attributes.cpp index e69de29..936aeb6 100644 --- a/sbf-cpp/Attributes.cpp +++ b/sbf-cpp/Attributes.cpp @@ -0,0 +1,140 @@ +#include "Attributes.h" +#include +#include +#include + +namespace SBF{ +using std::string; + +string GetAttributeGroupLabel(int attributeGroupId) { + if (attributeGroupId > 0 && attributeGroupId <= kAttributeGroupsCount) { + return kAttributeGroups[attributeGroupId]; + } + return ""; +} + +string GetAttributeLabel(int attributeGroupId, int attributeId) { + switch (attributeGroupId) { + case kAttributeGroupPhysicalId: + return GetPhysicalAttributeLabel(attributeId); + case kAttributeGroupSocialId: + return GetSocialAttributeLabel(attributeId); + case kAttributeGroupMentalId: + return GetMentalAttributeLabel(attributeId); + default: + return ""; + } +} + +string GetAttributeLabelAbbreviation(int attributeGroupId, int attributeId) { + switch (attributeGroupId) { + case kAttributeGroupPhysicalId: + return GetPhysicalAttributeLabelAbbreviation(attributeId); + case kAttributeGroupSocialId: + return GetSocialAttributeLabelAbbreviation(attributeId); + case kAttributeGroupMentalId: + return GetMentalAttributeLabelAbbreviation(attributeId); + default: + return ""; + } +} + +int GetNumAttributesInGroup(int attributeGroupId) { + switch (attributeGroupId) { + case kAttributeGroupPhysicalId: + return kPhysicalAttributesCount; + case kAttributeGroupSocialId: + return kSocialAttributesCount; + case kAttributeGroupMentalId: + return kMentalAttributesCount; + } + return 0; +} + +string GetPhysicalAttributeLabel(int attributeId) { + if (attributeId > 0 && attributeId <= kPhysicalAttributesCount) { + return kPhysicalAttributeLabels[attributeId]; + } + return ""; +} + +string GetPhysicalAttributeLabelAbbreviation(int attributeId) { + if (attributeId > 0 && attributeId <= kPhysicalAttributesCount) { + return kPhysicalAttributeLabelAbbreviations[attributeId]; + } + return ""; +} + +string GetSocialAttributeLabel(int attributeId) { + if (attributeId > 0 && attributeId <= kSocialAttributesCount) { + return kSocialAttributeLabels[attributeId]; + } + return ""; +} + +string GetSocialAttributeLabelAbbreviation(int attributeId) { + if (attributeId > 0 && attributeId <= kSocialAttributesCount) { + return kSocialAttributeLabelAbbreviations[attributeId]; + } + return ""; +} + +string GetMentalAttributeLabel(int attributeId) { + if (attributeId > 0 && attributeId <= kMentalAttributesCount) { + return kMentalAttributeLabels[attributeId]; + } + return ""; +} + +string GetMentalAttributeLabelAbbreviation(int attributeId) { + if (attributeId > 0 && attributeId <= kMentalAttributesCount) { + return kMentalAttributeLabelAbbreviations[attributeId]; + } + return ""; +} + +void FillAttributeGroupLabels(std::vector& labels) { + labels.clear(); + for (int id = 1; id <= kAttributeGroupsCount; id++) { + labels.push_back(kAttributeGroups[id]); + } +} + +void FillAttributeLabelsInGroup(std::vector& labels, int groupId) { + labels.clear(); + switch (groupId) { + case kAttributeGroupPhysicalId: + FillPhysicalAttributeLabels(labels); + break; + case kAttributeGroupSocialId: + FillSocialAttributeLabels(labels); + break; + case kAttributeGroupMentalId: + FillMentalAttributeLabels(labels); + break; + } +} + +void FillPhysicalAttributeLabels(std::vector& labels) { + labels.clear(); + for (int id = 1; id <= kPhysicalAttributesCount; id++) { + labels.push_back(kPhysicalAttributeLabels[id]); + } +} + +void FillSocialAttributeLabels(std::vector& labels) { + labels.clear(); + for (int id = 1; id <= kSocialAttributesCount; id++) { + labels.push_back(kSocialAttributeLabels[id]); + } +} + +void FillMentalAttributeLabels(std::vector& labels) { + labels.clear(); + for (int id = 1; id <= kMentalAttributesCount; id++) { + labels.push_back(kMentalAttributeLabels[id]); + } +} + +} // End namespace SBF + diff --git a/sbf-cpp/Attributes.h b/sbf-cpp/Attributes.h index a47c946..55d5469 100644 --- a/sbf-cpp/Attributes.h +++ b/sbf-cpp/Attributes.h @@ -20,7 +20,7 @@ namespace SBF { kPhysicalAttributeDexterityLabel, kPhysicalAttributeStaminaLabel, }; - const std::string kPhysicalAttributeAbbreviations[] = { + const std::string kPhysicalAttributeLabelAbbreviations[] = { "", kPhysicalAttributeStrengthAbbreviation, kPhysicalAttributeDexterityAbbreviation, @@ -43,7 +43,7 @@ namespace SBF { kSocialAttributeManipulationLabel, kSocialAttributeAppearanceLabel, }; - const std::string kSocialAttributeAbbreviations[] = { + const std::string kSocialAttributeLabelAbbreviations[] = { "", kSocialAttributeCharismaAbbreviation, kSocialAttributeManipulationAbbreviation, @@ -66,9 +66,9 @@ namespace SBF { kMentalAttributePerceptionLabel, kMentalAttributeWitsLabel, }; - const std::string kMentalAttributeAbbreviations[] = { + const std::string kMentalAttributeLabelAbbreviations[] = { "", - kMentalAttributeIntelligenceLabel, + kMentalAttributeIntelligenceAbbreviation, kMentalAttributePerceptionAbbreviation, kMentalAttributeWitsAbbreviation, }; @@ -87,15 +87,20 @@ namespace SBF { kAttributeGroupMentalLabel, }; - const std::string& GetAttributeGroupLabel(int attributeGroupId); - const std::string& GetAtttributeLabel(int attributeGroupId, int attributeId); - const std::string& GetPhysicalAttributeLabel(int attributeId); - const std::string& GetSocialAttributeLabel(int attributeId); - const std::string& GetMentalAttributeLabel(int attributeId); - void FillAttributeGroupLabels(std::vector attributeGroupLabels); - void FillAttributeLabelInGroup(std::vector attributeLabels); - void FillPhysicalAttributeLabels(std::vector physicalAttributeLabels); - void FillSocialAttributeLabels(std::vector socialAttributeLabels); - void FillMentalAttributeLabels(std::vector mentalAttributeLabels); + std::string GetAttributeGroupLabel(int attributeGroupId); + std::string GetAttributeLabel(int attributeGroupId, int attributeId); + std::string GetAttributeLabelAbbreviation(int attributeGroupId, int attributeId); + std::string GetPhysicalAttributeLabel(int attributeId); + std::string GetPhysicalAttributeLabelAbbreviation(int attributeId); + int GetNumAttributesInGroup(int attributeGroupId); + std::string GetSocialAttributeLabel(int attributeId); + std::string GetSocialAttributeLabelAbbreviation(int attributeId); + std::string GetMentalAttributeLabel(int attributeId); + std::string GetMentalAttributeLabelAbbreviation(int attributeId); + void FillAttributeGroupLabels(std::vector& attributeGroupLabels); + void FillAttributeLabelsInGroup(std::vector& attributeLabels, int groupId); + void FillPhysicalAttributeLabels(std::vector& physicalAttributeLabels); + void FillSocialAttributeLabels(std::vector& socialAttributeLabels); + void FillMentalAttributeLabels(std::vector& mentalAttributeLabels); } // End namespace SBF #endif // End !defined ATTRIBUTES_H__ diff --git a/sbf-cpp/Attributes_test.cpp b/sbf-cpp/Attributes_test.cpp index f4e2344..eda34d2 100644 --- a/sbf-cpp/Attributes_test.cpp +++ b/sbf-cpp/Attributes_test.cpp @@ -1,10 +1,542 @@ #include "Attributes.h" #include "test.h" +#include +#include +#include +#include + using namespace SBF; using namespace Test; +using namespace std; + +namespace Test::Attributes { +TestResults test_GetAttributeGroupLabel(); +TestResults test_GetAttributeLabel(); +TestResults test_GetAttributeLabelAbbreviation(); +TestResults test_GetNumAttributesInGroup(); +TestResults test_GetPhysicalAttributeLabel(); +TestResults test_GetPhysicalAttributeLabelAbbreviation(); +TestResults test_GetSocialAttributeLabel(); +TestResults test_GetSocialAttributeLabelAbbreviation(); +TestResults test_GetMentalAttributeLabel(); +TestResults test_GetMentalAttributeLabelAbbreviation(); +TestResults test_FillAttributeGroupLabels(); +TestResults test_FillAttributeLabelsInGroup(); +TestResults test_FillPhysicalAttributeLabels(); +TestResults test_FillSocialAttributeLabels(); +TestResults test_FillMentalAttributeLabels(); +} // End namespace Test::Attributes +using namespace Test::Attributes; TestResults main_test_Attributes(int argc, char** argv) { TestResults results; + results += test_GetAttributeGroupLabel(); + results += test_GetAttributeLabel(); + results += test_GetAttributeLabelAbbreviation(); + results += test_GetNumAttributesInGroup(); + results += test_GetPhysicalAttributeLabel(); + results += test_GetPhysicalAttributeLabelAbbreviation(); + results += test_GetSocialAttributeLabel(); + results += test_GetSocialAttributeLabelAbbreviation(); + results += test_GetMentalAttributeLabel(); + results += test_GetMentalAttributeLabelAbbreviation(); + results += test_FillAttributeGroupLabels(); + results += test_FillAttributeLabelsInGroup(); + results += test_FillPhysicalAttributeLabels(); + results += test_FillSocialAttributeLabels(); + results += test_FillMentalAttributeLabels(); + return results; } + +namespace Test::Attributes { +TestResults test_GetAttributeGroupLabel() { + return execute_suite(make_test_suite( + "SBF::GetAttributeGroupLabel", + GetAttributeGroupLabel, + vector>({ + make_test( + "should get \"\" for id 0", + "", + make_tuple(0)), + make_test( + "should get \"Physical\" for id 1", + "Physical", + make_tuple(1)), + make_test( + "should get \"Social\" for id 2", + "Social", + make_tuple(2)), + make_test( + "should get \"Mental\" for id 3", + "Mental", + make_tuple(3)), + make_test( + "should get \"\" for id 4", + "", + make_tuple(4)), + }) + )); +} + +TestResults test_GetAttributeLabel() { + return execute_suite(make_test_suite( + "SBF::GetAttributeLabel", + GetAttributeLabel, + vector>({ + make_test( + "should get \"Strength\" for group id 1 and id 1", + "Strength", + make_tuple(1, 1)), + make_test( + "should get \"Dexterity\" for group id 1 and id 2", + "Dexterity", + make_tuple(1, 2)), + make_test( + "should get \"Stamina\" for group id 1 and id 3", + "Stamina", + make_tuple(1, 3)), + make_test( + "should get \"Charisma\" for group id 2 and id 1", + "Charisma", + make_tuple(2, 1)), + make_test( + "should get \"Manipulation\" for group id 2 and id 2", + "Manipulation", + make_tuple(2, 2)), + make_test( + "should get \"Appearance\" for group id 2 and id 3", + "Appearance", + make_tuple(2, 3)), + make_test( + "should get \"Intelligence\" for group id 3 and id 1", + "Intelligence", + make_tuple(3, 1)), + make_test( + "should get \"Perception\" for group id 3 and id 2", + "Perception", + make_tuple(3, 2)), + make_test( + "should get \"Wits\" for group id 3 and id 3", + "Wits", + make_tuple(3, 3)), + make_test( + "should get \"\" for an invalid group id 0", + "", + make_tuple(0, 1)), + make_test( + "should get \"\" for an invalid id 0", + "", + make_tuple(1, 0)), + make_test( + "should get \"\" for invalid group id 4", + "", + make_tuple(4, 1)), + make_test( + "should get \"\" for an invalid id 4", + "", + make_tuple(1, 4)), + }) + )); +} + +TestResults test_GetAttributeLabelAbbreviation() { + return execute_suite(make_test_suite( + "SBF::GetAttributeLabelAbbreviation", + GetAttributeLabelAbbreviation, + vector>({ + make_test( + "should get \"Str.\" for group id 1 and id 1", + "Str.", + make_tuple(1, 1)), + make_test( + "should get \"Dex.\" for group id 1 and id 2", + "Dex.", + make_tuple(1, 2)), + make_test( + "should get \"Sta.\" for group id 1 and id 3", + "Sta.", + make_tuple(1, 3)), + make_test( + "should get \"Cha.\" for group id 2 and id 1", + "Cha.", + make_tuple(2, 1)), + make_test( + "should get \"Man.\" for group id 2 and id 2", + "Man.", + make_tuple(2, 2)), + make_test( + "should get \"App.\" for group id 2 and id 3", + "App.", + make_tuple(2, 3)), + make_test( + "should get \"Int.\" for group id 3 and id 1", + "Int.", + make_tuple(3, 1)), + make_test( + "should get \"Per.\" for group id 3 and id 2", + "Per.", + make_tuple(3, 2)), + make_test( + "should get \"Wits\" for group id 3 and id 3", + "Wits", + make_tuple(3, 3)), + make_test( + "should get \"\" for an invalid group id 0", + "", + make_tuple(0, 1)), + make_test( + "should get \"\" for an invalid id 0", + "", + make_tuple(1, 0)), + make_test( + "should get \"\" for invalid group id 4", + "", + make_tuple(4, 1)), + make_test( + "should get \"\" for an invalid id 4", + "", + make_tuple(1, 4)), + }) + )); +} + +TestResults test_GetPhysicalAttributeLabel() { + return execute_suite(make_test_suite( + "SBF::GetPhysicalAttributeLabel", + GetPhysicalAttributeLabel, + vector>({ + make_test( + "should get \"Strength\" for id 1", + "Strength", + make_tuple(1)), + make_test( + "should get \"Dexterity\" for id 2", + "Dexterity", + make_tuple(2)), + make_test( + "should get \"Stamina\" for id 3", + "Stamina", + make_tuple(3)), + make_test( + "should get \"\" for invalid id 0", + "", + make_tuple(0)), + make_test( + "should get \"\" for invalid id 4", + "", + make_tuple(4)), + }) + )); +} + +TestResults test_GetPhysicalAttributeLabelAbbreviation() { + return execute_suite(make_test_suite( + "SBF::GetPhysicalAttributeLabelAbbreviation", + GetPhysicalAttributeLabelAbbreviation, + vector>({ + make_test( + "should get \"Str.\" for id 1", + "Str.", + make_tuple(1)), + make_test( + "should get \"Dex.\" for id 2", + "Dex.", + make_tuple(2)), + make_test( + "should get \"Sta.\" for id 3", + "Sta.", + make_tuple(3)), + make_test( + "should get \"\" for invalid id 0", + "", + make_tuple(0)), + make_test( + "should get \"\" for invalid id 4", + "", + make_tuple(4)), + }) + )); +} + +TestResults test_GetSocialAttributeLabel() { + return execute_suite(make_test_suite( + "SBF::GetSocialAttributeLabel", + GetSocialAttributeLabel, + vector>({ + make_test( + "should get \"Charisma\" for id 1", + "Charisma", + make_tuple(1)), + make_test( + "should get \"Manipulation\" for id 2", + "Manipulation", + make_tuple(2)), + make_test( + "should get \"Appearance\" for id 3", + "Appearance", + make_tuple(3)), + make_test( + "should get \"\" for invalid id 0", + "", + make_tuple(0)), + make_test( + "should get \"\" for invalid id 4", + "", + make_tuple(4)), + }) + )); +} + +TestResults test_GetSocialAttributeLabelAbbreviation() { + return execute_suite(make_test_suite( + "SBF::GetSocialAttributeLabelAbbreviation", + GetSocialAttributeLabelAbbreviation, + vector>({ + make_test( + "should get \"Cha.\" for id 1", + "Cha.", + make_tuple(1)), + make_test( + "should get \"Man.\" for id 2", + "Man.", + make_tuple(2)), + make_test( + "should get \"App.\" for id 3", + "App.", + make_tuple(3)), + make_test( + "should get \"\" for invalid id 0", + "", + make_tuple(0)), + make_test( + "should get \"\" for invalid id 4", + "", + make_tuple(4)), + }) + )); +} + +TestResults test_GetMentalAttributeLabel() { + return execute_suite(make_test_suite( + "SBF::GetMentalAttributeLabel", + GetMentalAttributeLabel, + vector>({ + make_test( + "should get \"Intelligence\" for id 1", + "Intelligence", + make_tuple(1)), + make_test( + "should get \"Perception\" for id 2", + "Perception", + make_tuple(2)), + make_test( + "should get \"Wits\" for id 3", + "Wits", + make_tuple(3)), + make_test( + "should get \"\" for invalid id 0", + "", + make_tuple(0)), + make_test( + "should get \"\" for invalid id 4", + "", + make_tuple(4)), + }) + )); +} + +TestResults test_GetMentalAttributeLabelAbbreviation() { + return execute_suite(make_test_suite( + "SBF::GetMentalAttributeLabelAbbreviation", + GetMentalAttributeLabelAbbreviation, + vector>({ + make_test( + "should get \"Int.\" for id 1", + "Int.", + make_tuple(1)), + make_test( + "should get \"Per.\" for id 2", + "Per.", + make_tuple(2)), + make_test( + "should get \"Wits\" for id 3", + "Wits", + make_tuple(3)), + make_test( + "should get \"\" for invalid id 0", + "", + make_tuple(0)), + make_test( + "should get \"\" for invalid id 4", + "", + make_tuple(4)), + }) + )); +} + +TestResults test_GetNumAttributesInGroup() { + return execute_suite(make_test_suite( + "SBF::GetNumAttributesInGroup", + GetNumAttributesInGroup, + vector>({ + make_test( + "should get 0 for invalid group 0", + 0, + make_tuple(0)), + make_test( + "should get 3 for group 1 kAttributeGroupPhysicalId", + 3, + make_tuple(1)), + make_test( + "should get 3 for group 2 kAttributeGropuSocialId", + 3, + make_tuple(2)), + make_test( + "should get 3 for group 3 kAttributeGroupMentalId", + 3, + make_tuple(3)), + make_test( + "should get 0 for invalid group 4", + 0, + make_tuple(4)), + }) + )); +} + +TestResults test_FillAttributeGroupLabels() { + return execute_suite(make_test_suite( + "SBF::FillAttributeGroupLabels", + []()->string { + ostringstream error_message; + vector expected = {"Physical", "Social", "Mental"}; + vector actual = {"This should be removed."}; + FillAttributeGroupLabels(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 attribute group labels", + "no errors", + make_tuple()), + }) + )); +} +// void FillAttributeLabelInGroup(std::vector attributeLabels); +TestResults test_FillAttributeLabelsInGroup() { + return execute_suite>(make_test_suite( + "SBF::FillAttributeLabelsInGroup", + [](int id, vector expected)->string { + ostringstream error_message; + vector actual = {"This should be removed."}; + FillAttributeLabelsInGroup(actual, id); + compare(error_message, expected, actual); + string error = error_message.str(); + if (error.size() > 0) { + return error; + } + return "no errors"; + }, + vector>>({ + make_test>( + "should fill an empty list for invalid group 0", + "no errors", + make_tuple(0, vector({}))), + make_test>( + "should fill physical attribute labels for group 1 kAttributeGropuPhysicalId", + "no errors", + make_tuple(1, vector({"Strength", "Dexterity", "Stamina"}))), + make_test>( + "should fill social attribute labels for group 2 kAttributeGroupSocialId", + "no errors", + make_tuple(2, vector({"Charisma", "Manipulation", "Appearance"}))), + make_test>( + "should should fill mental attribute labels for group 3 kAttributeGroupMentalId", + "no errors", + make_tuple(3, vector({"Intelligence", "Perception", "Wits"}))), + make_test>( + "should fill an empty list for invalid group 4", + "no errors", + make_tuple(4, vector({}))), + }) + )); +} + +TestResults test_FillPhysicalAttributeLabels() { + return execute_suite(make_test_suite( + "SBF::FillPhysicalAttributeLabels", + []()->string { + ostringstream error_message; + vector expected = {"Strength", "Dexterity", "Stamina"}; + vector actual = {"This should be removed."}; + FillPhysicalAttributeLabels(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 physical attribute labels", + "no errors", + make_tuple()), + }) + )); +} +// void FillSocialAttributeLabels(std::vector socialAttributeLabels); +TestResults test_FillSocialAttributeLabels() { + return execute_suite(make_test_suite( + "SBF::FillSocialAttributeLabels", + []()->string { + ostringstream error_message; + vector expected = {"Charisma", "Manipulation", "Appearance"}; + vector actual = {"This should be removed."}; + FillSocialAttributeLabels(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 social attribute labels", + "no errors", + make_tuple()), + }) + )); +} +// void FillMentalAttributeLabels(std::vector mentalAttributeLabels); +TestResults test_FillMentalAttributeLabels() { + return execute_suite(make_test_suite( + "SBF::FillMentalAttributeLabels", + []()->string { + ostringstream error_message; + vector expected = {"Intelligence", "Perception", "Wits"}; + vector actual = {"This should be removed."}; + FillMentalAttributeLabels(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 mental attribute labels", + "no errors", + make_tuple()), + }) + )); +} +} diff --git a/sbf-cpp/Character.cpp b/sbf-cpp/Character.cpp index 06375ec..7562fa1 100644 --- a/sbf-cpp/Character.cpp +++ b/sbf-cpp/Character.cpp @@ -5,19 +5,6 @@ namespace SBF { using std::string; using std::vector; - int GetNumAttributesInGroup(int groupId) { - switch (groupId) { - case kAttributeGroupPhysicalId: - return kPhysicalAttributesCount; - case kAttributeGroupSocialId: - return kSocialAttributesCount; - case kAttributeGroupMentalId: - return kMentalAttributesCount; - default: - return 0; - } - } - CharacterType::CharacterType() { // Scalars name = ""; @@ -262,19 +249,6 @@ namespace SBF { } } - string GetAttributeLabel(int attributeGroupId, int attributeId) { - switch (attributeGroupId) { - case kAttributeGroupPhysicalId: - return kPhysicalAttributeLabels[attributeId]; - case kAttributeGroupSocialId: - return kSocialAttributeLabels[attributeId]; - case kAttributeGroupMentalId: - return kMentalAttributeLabels[attributeId]; - default: - return ""; - } - } - void FillAttributeLabelsInGroup(std::vector attributeLabels, int attributeGroupId) { attributeLabels.clear(); switch (attributeGroupId) { @@ -301,17 +275,17 @@ namespace SBF { switch (attributeGroupId) { case kAttributeGroupPhysicalId: for (int attributeId = 0; attributeId <= kPhysicalAttributesCount; attributeId++) { - attributeAbbreviations[attributeId] = kPhysicalAttributeAbbreviations[attributeId]; + attributeAbbreviations[attributeId] = kPhysicalAttributeLabelAbbreviations[attributeId]; } break; case kAttributeGroupSocialId: for (int attributeId = 0; attributeId <= kSocialAttributesCount; attributeId++) { - attributeAbbreviations[attributeId] = kSocialAttributeAbbreviations[attributeId]; + attributeAbbreviations[attributeId] = kSocialAttributeLabelAbbreviations[attributeId]; } break; case kAttributeGroupMentalId: for (int attributeId = 0; attributeId <= kMentalAttributesCount; attributeId++) { - attributeAbbreviations[attributeId] = kMentalAttributeAbbreviations[attributeId]; + attributeAbbreviations[attributeId] = kMentalAttributeLabelAbbreviations[attributeId]; } break; }