From 670c5173267a8dc8288117feb9be0c14a6b0212b Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Sat, 15 Apr 2023 22:54:04 -0700 Subject: [PATCH] Implements backgrounds and tests. --- sbf-cpp/Backgrounds.cpp | 19 +++++++ sbf-cpp/Backgrounds.h | 4 +- sbf-cpp/Backgrounds_test.cpp | 101 ++++++++++++++++++++++++++++++++++- 3 files changed, 121 insertions(+), 3 deletions(-) diff --git a/sbf-cpp/Backgrounds.cpp b/sbf-cpp/Backgrounds.cpp index e69de29..f29fc95 100644 --- a/sbf-cpp/Backgrounds.cpp +++ b/sbf-cpp/Backgrounds.cpp @@ -0,0 +1,19 @@ +#include "Backgrounds.h" +#include +#include + +namespace SBF { +std::string GetBackgroundLabel(int backgroundId) { + if (backgroundId > 0 && backgroundId <= kBackgroundsCount) { + return kBackgroundLabels[backgroundId]; + } + return ""; +} + +void FillBackgroundLabels(std::vector& labels) { + labels.clear(); + for (int id = 1; id <= kBackgroundsCount; id++) { + labels.push_back(kBackgroundLabels[id]); + } +} +} // End namespace SBF diff --git a/sbf-cpp/Backgrounds.h b/sbf-cpp/Backgrounds.h index 11970c2..6363731 100644 --- a/sbf-cpp/Backgrounds.h +++ b/sbf-cpp/Backgrounds.h @@ -39,7 +39,7 @@ namespace SBF { kBackgroundRetainersLabel, kBackgroundStatusLabel, }; - const std::string& GetBackgroundLabel(int backgroundId); - void FillBackgroundLabels(std::vector backgroundLabels); + std::string GetBackgroundLabel(int backgroundId); + void FillBackgroundLabels(std::vector& backgroundLabels); } // End namespace SBF #endif // End !defined BACKGROUNDS_H__ diff --git a/sbf-cpp/Backgrounds_test.cpp b/sbf-cpp/Backgrounds_test.cpp index 1e1e6cb..c950267 100644 --- a/sbf-cpp/Backgrounds_test.cpp +++ b/sbf-cpp/Backgrounds_test.cpp @@ -1,10 +1,109 @@ #include "Backgrounds.h" #include "test.h" +#include +#include +#include +#include + using namespace SBF; using namespace Test; +using namespace std; + +namespace Test::Backgrounds { +TestResults test_GetBackgroundLabel(); +TestResults test_FillBackgroundLabels(); +} // End namespace Test::Attributes +using namespace Test::Backgrounds; TestResults main_test_Backgrounds(int argc, char** argv) { TestResults results; - + + results += test_GetBackgroundLabel(); + results += test_FillBackgroundLabels(); + return results; } + +namespace Test::Backgrounds { +TestResults test_GetBackgroundLabel() { + return execute_suite(make_test_suite( + "SBF::GetBackgroundLabel", + GetBackgroundLabel, + vector>({ + make_test( + "should get \"\" for invalid background 0", + "", + make_tuple(0)), + make_test( + "should get \"Allies\" for background 1 kBackgroundAlliesLabel", + "Allies", + make_tuple(1)), + make_test( + "should get \"Contacts\" for background 2 kBackgroundContactsLabel", + "Contacts", + make_tuple(2)), + make_test( + "should get \"Fame\" for background 3 kBackgroundFameLabel", + "Fame", + make_tuple(3)), + make_test( + "should get \"Generation\" for background 4 kBackgroundGenerationLabel", + "Generation", + make_tuple(4)), + make_test( + "should get \"Herd\" for background 5 kBackgroundHerdLabel", + "Herd", + make_tuple(5)), + make_test( + "should get \"Influence\" for background 6 kBackgroundInfluenceLabel", + "Influence", + make_tuple(6)), + make_test( + "should get \"Mentor\" for background 7 kBackgroundMentorLabel", + "Mentor", + make_tuple(7)), + make_test( + "should get \"Resources\" for background 8 kBackgroundResourcesLabel", + "Resources", + make_tuple(8)), + make_test( + "should get \"Retainers\" for background 9 kBackgroundRetainersLabel", + "Retainers", + make_tuple(9)), + make_test( + "should get \"Status\" for background 10 kBackgroundStatusLabel", + "Status", + make_tuple(10)), + make_test( + "should get \"\" for invalid background 11", + "", + make_tuple(11)), + }) + )); +} + +TestResults test_FillBackgroundLabels() { + return execute_suite(make_test_suite( + "SBF::FillBackgroundLabels", + []()->string { + ostringstream error_message; + vector expected = {"Allies", "Contacts", "Fame", "Generation", "Herd", "Influence", "Mentor", "Resources", "Retainers", "Status" }; + vector actual = {"This should be removed."}; + FillBackgroundLabels(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 background labels", + "no errors", + make_tuple()), + }) + + )); +} +} // End namespace Test::Backgrounds