Implements virtues and tests.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
#include "Virtues.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace SBF {
|
||||
|
||||
const std::string GetVirtueLabel(int id) {
|
||||
if (id > 0 && id <= kVirtuesCount) {
|
||||
return kVirtueLabels[id];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
void FillVirtueLabels(std::vector<std::string>& labels) {
|
||||
labels.clear();
|
||||
for (int id = 1; id <= kVirtuesCount; id++) {
|
||||
labels.push_back(GetVirtueLabel(id));
|
||||
}
|
||||
}
|
||||
|
||||
} // End namespace SBF
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
namespace SBF {
|
||||
const int kVirtuePoints = 7;
|
||||
const std::string kVirtueUnknownLabel = "";
|
||||
const int kVirtueSelfControlId = 1;
|
||||
const std::string kVirtueSelfControlLabel = "Self-Control";
|
||||
const int kVirtueCourageId = 2;
|
||||
@@ -23,14 +24,21 @@ namespace SBF {
|
||||
const int kVirtueConscienceId = 3;
|
||||
const std::string kVirtueConscienceLabel = "Conscience";
|
||||
const int kVirtuesCount = 3;
|
||||
const std::string kVirtues[] = {
|
||||
"",
|
||||
const std::string kVirtueLabels[] = {
|
||||
kVirtueUnknownLabel,
|
||||
kVirtueSelfControlLabel,
|
||||
kVirtueCourageLabel,
|
||||
kVirtueConscienceLabel,
|
||||
};
|
||||
const std::string GetVirtueLabel(int virtueId);
|
||||
void FillVirtueLabels(std::vector<std::string> virtueLabels);
|
||||
|
||||
/// @brief Gets the label for virtue with the specified id.
|
||||
/// @param virtue_id The id of the virtue to find.
|
||||
/// @return The label for the specified virtue.
|
||||
const std::string GetVirtueLabel(int virtue_id);
|
||||
|
||||
/// @brief Fills the vector with all of the valid virtue labels.
|
||||
/// @param virtue_labels The vector to fill.
|
||||
void FillVirtueLabels(std::vector<std::string>& virtue_labels);
|
||||
} // End namespace SBF
|
||||
/** @}*/
|
||||
#endif // End !defined VIRTUES_H__
|
||||
|
||||
@@ -1,10 +1,85 @@
|
||||
#include "Virtues.h"
|
||||
#include "test.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
using namespace SBF;
|
||||
using namespace Test;
|
||||
using namespace std;
|
||||
|
||||
namespace Test::Virtues {
|
||||
TestResults test_GetVirtueLabel();
|
||||
TestResults test_FillVirtueLabels();
|
||||
} // End namespace Test::Virtues
|
||||
using namespace Test::Virtues;
|
||||
|
||||
TestResults main_test_Virtues(int argc, char** argv) {
|
||||
TestResults results;
|
||||
|
||||
results += test_GetVirtueLabel();
|
||||
results += test_FillVirtueLabels();
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
namespace Test::Virtues {
|
||||
TestResults test_GetVirtueLabel() {
|
||||
return execute_suite<string, int>(make_test_suite(
|
||||
"SBF::GetVirtueLabel",
|
||||
GetVirtueLabel,
|
||||
vector<TestTuple<string, int>>({
|
||||
make_test<string, int>(
|
||||
"should get \"\" for invalid virtue id 0",
|
||||
"",
|
||||
make_tuple(0)),
|
||||
make_test<string, int>(
|
||||
"should get \"Self-Control\" for virtue id 1",
|
||||
"Self-Control",
|
||||
make_tuple(1)),
|
||||
make_test<string, int>(
|
||||
"should get \"Courage\" for virtue id 2",
|
||||
"Courage",
|
||||
make_tuple(2)),
|
||||
make_test<string, int>(
|
||||
"should get \"Conscience\" for virtue id 3",
|
||||
"Conscience",
|
||||
make_tuple(3)),
|
||||
make_test<string, int>(
|
||||
"should get \"\" for invalid virtue id 4",
|
||||
"",
|
||||
make_tuple(4)),
|
||||
})
|
||||
));
|
||||
}
|
||||
|
||||
TestResults test_FillVirtueLabels() {
|
||||
auto fnToTest = []()->string {
|
||||
ostringstream error_message;
|
||||
vector<string> expected = {
|
||||
kVirtueSelfControlLabel,
|
||||
kVirtueCourageLabel,
|
||||
kVirtueConscienceLabel,
|
||||
};
|
||||
vector<string> actual = {"This should be removed."};
|
||||
FillVirtueLabels(actual);
|
||||
compare(error_message, expected, actual);
|
||||
string error = error_message.str();
|
||||
if (error.size() > 0) {
|
||||
return error;
|
||||
}
|
||||
return "no errors";
|
||||
};
|
||||
return execute_suite<string>(make_test_suite(
|
||||
"SBF::FillVirtueLabels",
|
||||
fnToTest,
|
||||
vector<TestTuple<string>>({
|
||||
make_test<string>(
|
||||
"should fill ranks",
|
||||
"no errors",
|
||||
make_tuple()),
|
||||
})
|
||||
));
|
||||
}
|
||||
|
||||
} // End namespace Test::Virtues
|
||||
|
||||
Reference in New Issue
Block a user