Removes a bunch of old comments.
This commit is contained in:
495
sbf-cpp/test.cpp
495
sbf-cpp/test.cpp
@@ -23,238 +23,11 @@ using std::for_each;
|
|||||||
|
|
||||||
// using namespace Test;
|
// using namespace Test;
|
||||||
|
|
||||||
// size_t get_index_of(const string& text, const string& search, size_t start);
|
|
||||||
// string word_wrap(const string& text, int maxWidth);
|
|
||||||
// string get_substring(const string& text, int32_t var1, int32_t var2);
|
|
||||||
// string make_fit_l(const string& text, size_t length, char paddCh);
|
|
||||||
// string left(const string& text, size_t length);
|
|
||||||
// string string_dollar(size_t length, char ch);
|
|
||||||
|
|
||||||
// int main(int argc, char* argv[]) {
|
|
||||||
// // TODO: Come up with a good way to enable/disable tests.
|
|
||||||
// // Maybe replace the expected, params pairs with another tuple for enabled, expected, params.
|
|
||||||
// // Maybe have the test functions take an enabled bool param.
|
|
||||||
|
|
||||||
// setlocale(LC_ALL, "");
|
|
||||||
|
|
||||||
// TestResults results;
|
|
||||||
|
|
||||||
// string longText = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
|
|
||||||
// results = results + Test::test_fn("get_index_of", get_index_of,
|
|
||||||
// vector<pair<size_t, tuple<string, string, size_t>>>({
|
|
||||||
// pair(22, make_tuple(longText, "dummy", 0)),
|
|
||||||
// pair(-1, make_tuple(longText, "acid", 0)),
|
|
||||||
// pair(120, make_tuple(longText, "dummy", 100)),
|
|
||||||
// pair(-1, make_tuple(longText, "dummy", longText.size())),
|
|
||||||
// pair(6, make_tuple("these are words", "are", 0)),
|
|
||||||
// pair(4, make_tuple("one two one two", "two", 0)),
|
|
||||||
// pair(12, make_tuple("one two one two", "two", 5)),
|
|
||||||
// }));
|
|
||||||
|
|
||||||
// results = results + test_fn("get_substring", get_substring, vector({
|
|
||||||
// pair("234", make_tuple("1234567890", 1, 3)),
|
|
||||||
// pair("Paris", make_tuple("Where is Paris?", 10-1, 5)),
|
|
||||||
// }));
|
|
||||||
|
|
||||||
// results = results + test_fn("left", left, vector({
|
|
||||||
// pair("Micro", make_tuple("Microsoft QBasic", 5)),
|
|
||||||
// }));
|
|
||||||
|
|
||||||
// results = results + test_fn("make_fit_l", make_fit_l, vector({
|
|
||||||
// pair("12___", make_tuple("12", 5, L'_')),
|
|
||||||
// }));
|
|
||||||
|
|
||||||
// results = results + test_fn("string_dollar", string_dollar, vector({
|
|
||||||
// pair("AAAAA", make_tuple(5, L'A')),
|
|
||||||
// }));
|
|
||||||
|
|
||||||
// results = results + test_fn("word_wrap", word_wrap, vector({
|
|
||||||
// pair("0123_", make_tuple("0123", 5)),
|
|
||||||
// pair("01234", make_tuple("01234", 5)),
|
|
||||||
// pair("01234\n5____", make_tuple("012345", 5)),
|
|
||||||
// pair("01234\n56789\n0____", make_tuple("01234567890", 5)),
|
|
||||||
// pair("01 23\n45 67\n89 01", make_tuple("01 23 45 67 89 01", 5)),
|
|
||||||
// pair("01 34\n67 90\n23 56\n89___", make_tuple("01 34 67 90 23 56 89 ", 5)),
|
|
||||||
// }));
|
|
||||||
|
|
||||||
// cout << "Total tests ran: " << get<0>(results) << endl;
|
|
||||||
// cout << "Total failures: " << get<1>(results) << endl;
|
|
||||||
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// string word_wrap(const string& text, int maxWidth) {
|
|
||||||
// string output = "";
|
|
||||||
// string thisLine = "";
|
|
||||||
// string nextChunk = "";
|
|
||||||
// int32_t thisLineStartPosition = 0;
|
|
||||||
// int32_t thisLineCurrentPosition = 0;
|
|
||||||
// int32_t nextSpace = -1;
|
|
||||||
// int32_t textLength = text.size();
|
|
||||||
// size_t thisLineLength = 0;
|
|
||||||
|
|
||||||
// bool done = false;
|
|
||||||
|
|
||||||
// while (!done) {
|
|
||||||
// nextSpace = get_index_of(text, " ", thisLineCurrentPosition);
|
|
||||||
// if (nextSpace < 0) {
|
|
||||||
// nextSpace = textLength;
|
|
||||||
// }
|
|
||||||
// nextChunk = get_substring(text, thisLineCurrentPosition, nextSpace - thisLineCurrentPosition);
|
|
||||||
// auto nextChunkLength = nextChunk.size();
|
|
||||||
// if (nextChunkLength > 0) {
|
|
||||||
// auto needsSpace = thisLine.size() > 0;
|
|
||||||
// if (needsSpace) {
|
|
||||||
// thisLine = thisLine + " ";
|
|
||||||
// }
|
|
||||||
// thisLineLength = thisLine.size();
|
|
||||||
// if (nextChunkLength > maxWidth) {
|
|
||||||
// nextChunk = get_substring(text, thisLineCurrentPosition, maxWidth - thisLineLength);
|
|
||||||
// nextSpace = thisLineStartPosition + maxWidth;
|
|
||||||
// thisLine = thisLine + nextChunk;
|
|
||||||
// thisLineCurrentPosition = nextSpace;
|
|
||||||
// } else if(thisLineLength + nextChunkLength > maxWidth) {
|
|
||||||
// thisLine = make_fit_l(thisLine, maxWidth, L' ');
|
|
||||||
// } else {
|
|
||||||
// thisLine = thisLine + nextChunk;
|
|
||||||
// thisLineCurrentPosition = nextSpace + 1;
|
|
||||||
// }
|
|
||||||
// thisLineLength = thisLine.size();
|
|
||||||
// } else {
|
|
||||||
// thisLineCurrentPosition = nextSpace + 1;
|
|
||||||
// }
|
|
||||||
// if (thisLineLength >= maxWidth || thisLineCurrentPosition > textLength) {
|
|
||||||
// if (thisLineCurrentPosition > textLength) {
|
|
||||||
// done = true;
|
|
||||||
// }
|
|
||||||
// thisLine = make_fit_l(thisLine, maxWidth, L'_');
|
|
||||||
// output += thisLine + (done ? "" : "\n");
|
|
||||||
// thisLine = "";
|
|
||||||
// thisLineLength = thisLine.size();
|
|
||||||
// thisLineStartPosition = thisLineCurrentPosition;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return output;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// string string_dollar(size_t length, char ch) {
|
|
||||||
// string str = "";
|
|
||||||
// for (size_t i = 0; i<length; i++) {
|
|
||||||
// str += ch;
|
|
||||||
// }
|
|
||||||
// return str;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// string left(const string& text, size_t length) {
|
|
||||||
// return text.substr(0, length);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// string make_fit_l(const string& text, size_t length, char paddCh) {
|
|
||||||
// return left(text + string_dollar(length, paddCh), length);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// string get_substring(const string& text, const int32_t var1, const int32_t var2) {
|
|
||||||
// return text.substr(std::min<int32_t>(var1, text.length()-1), std::max(var2, 0));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// size_t get_index_of(const string& text, const string& search, size_t start) {
|
|
||||||
// return text.find(search, start);
|
|
||||||
// }
|
|
||||||
|
|
||||||
namespace Test {
|
namespace Test {
|
||||||
const string fn1(const string& s, int l) {
|
const string fn1(const string& s, int l) {
|
||||||
return s.substr(0, l);
|
return s.substr(0, l);
|
||||||
}
|
}
|
||||||
|
|
||||||
// _Step_1
|
|
||||||
// template<typename _T1, typename F, typename... T2>
|
|
||||||
// TestResults test_fn(string test_name, F f, vector<pair<_T1, tuple<T2...>>> tests);
|
|
||||||
// TestResults dummyTest(){
|
|
||||||
// return test_fn("/Dummy", [](int id){return id==0?"":"Unknown";}, vector({
|
|
||||||
// pair("", make_tuple(0)),
|
|
||||||
// }));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// _Step_2
|
|
||||||
// template<typename _T1, typename F, typename... T2>
|
|
||||||
// TestResults test_fn(string test_name, F f, vector<tuple<_T1, tuple<T2...>>> tests);
|
|
||||||
// TestResults dummyTest(){
|
|
||||||
// return test_fn("/Dummy", [](int id){return id==0?"":"Unknown";}, vector({
|
|
||||||
// make_tuple("", make_tuple(0)),
|
|
||||||
// }));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// _Step_3
|
|
||||||
// template<typename TResult, typename FnToTest, typename... TInputParams>
|
|
||||||
// TestResults test_fn(string suite_label, FnToTest testFn, vector<tuple<TResult, tuple<TInputParams...>>> tests);
|
|
||||||
// TestResults dummyTest() {
|
|
||||||
// return test_fn("/Dummy", [](int id){return id==0?"":"Unknown";}, vector({
|
|
||||||
// make_tuple("", make_tuple(0)),
|
|
||||||
// }));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// _Step_4
|
|
||||||
// template<typename TResult, typename FnToTest, typename... TInputParams>
|
|
||||||
// TestResults test_fn(string suite_label, FnToTest testFn, vector<tuple<string, TResult, tuple<TInputParams...>>> tests);
|
|
||||||
// TestResults dummyTest() {
|
|
||||||
// return test_fn("/Dummy", [](int id){return id==0?"":"Unknown";}, vector({
|
|
||||||
// make_tuple((string)"", "", make_tuple(0)),
|
|
||||||
// }));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// _Step_5
|
|
||||||
// auto testFunction = [](int id){return id==0?"":"";};
|
|
||||||
// template<typename TResult, typename FnToTest, typename... TInputParams>
|
|
||||||
// TestResults test_fn(string suite_label, FnToTest testFn, vector<tuple<string, TResult, tuple<TInputParams...>>> tests);
|
|
||||||
// TestResults dummyTest() {
|
|
||||||
// return test_fn("/Dummy", testFunction, vector({
|
|
||||||
// make_tuple((string)"", "", make_tuple(0)),
|
|
||||||
// }));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// _Step_6
|
|
||||||
// auto testFunction = [](int id){return id==0?"":"";};
|
|
||||||
// auto compareFunction = [](string a, string b){return a==b;};
|
|
||||||
// template<typename TResult, typename FnToTest, typename... TInputParams>
|
|
||||||
// TestResults test_fn(
|
|
||||||
// string suite_label,
|
|
||||||
// FnToTest testFn,
|
|
||||||
// bool(*compare_function)(TResult a, TResult b),
|
|
||||||
// vector<tuple<string, TResult, tuple<TInputParams...>>> tests);
|
|
||||||
// TestResults dummyTest() {
|
|
||||||
// return test_fn<string>(
|
|
||||||
// "/Dummy",
|
|
||||||
// testFunction,
|
|
||||||
// compareFunction,
|
|
||||||
// vector({
|
|
||||||
// make_tuple((string)"", (string)"", make_tuple(0)),
|
|
||||||
// }));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// _Step_7
|
|
||||||
// auto testFunction = [](int id){return id==0?"":"";};
|
|
||||||
// auto compareFunction = [](const string a, const string b){return a==b;};
|
|
||||||
// template<typename TResult, typename FnToTest, typename... TInputParams>
|
|
||||||
// TestResults test_fn(
|
|
||||||
// string suite_label,
|
|
||||||
// FnToTest testFn,
|
|
||||||
// bool(*compare_function)(TResult a, TResult b),
|
|
||||||
// vector<tuple<string, bool, TResult, tuple<TInputParams...>>> tests);
|
|
||||||
// TestResults dummyTest() {
|
|
||||||
// // Parse argc/argv and return {0,0} if test is disabled.
|
|
||||||
// return test_fn<string>(
|
|
||||||
// // Suite Name
|
|
||||||
// "/Dummy",
|
|
||||||
// testFunction,
|
|
||||||
// compareFunction,
|
|
||||||
// vector({
|
|
||||||
// // Test Name, Expect Output, Inputs
|
|
||||||
// make_tuple((string)"", true, (string)"", make_tuple(0)),
|
|
||||||
// }));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// _Step_8 - Make compareFunction optional
|
|
||||||
// Test lifecycle
|
// Test lifecycle
|
||||||
// suiteSetupFn(); - This is called to allocate any suite level resources. This is called once when the suite begins.
|
// suiteSetupFn(); - This is called to allocate any suite level resources. This is called once when the suite begins.
|
||||||
// These functions may be called in parallel but execution will not proceed past this block until they have all finished.
|
// These functions may be called in parallel but execution will not proceed past this block until they have all finished.
|
||||||
@@ -312,70 +85,7 @@ namespace Test {
|
|||||||
// }
|
// }
|
||||||
// Then some test harness either generated or explicit can call test_main_ThingDoer(...) and optionally reported there. Reporting granularity is controlled by how frequently you call collect_and_report_TestResults(...).
|
// Then some test harness either generated or explicit can call test_main_ThingDoer(...) and optionally reported there. Reporting granularity is controlled by how frequently you call collect_and_report_TestResults(...).
|
||||||
// You can combine test results with results = results + testFn(..); and then collect_and_report_TestResults on the aggregate TestResults value.
|
// You can combine test results with results = results + testFn(..); and then collect_and_report_TestResults on the aggregate TestResults value.
|
||||||
// template<typename TResult, typename FnToTest, typename... TInputParams>
|
|
||||||
// TestResults test_fn(
|
|
||||||
// string suite_label, /* suite_label - This is the name of the test suite. It will be used in logs. */
|
|
||||||
// FnToTest testFn, /* testFn - This is the function to be tested. It will be called with std::apply and the inputParams from each test in tests below. */
|
|
||||||
// vector<
|
|
||||||
// tuple<
|
|
||||||
// string /* test_name */,
|
|
||||||
// TResult /* expectedOutput */,
|
|
||||||
// tuple<TInputParams...> /* inputParams - The input parameters for this test. These will be used when calling std::apply with testFn to execute the test. */,
|
|
||||||
// bool(*)(const TResult expected, const TResult actual) /* maybe_compare_function - If this is not nullprt then this function will be called instead of suite_compare_function to determine if the test passes. Use this to check for side effects of the test. Return true if the test passes and false otherwise. */,
|
|
||||||
// void(*)(TInputParams...) /* testSetupFn - If this is not nullptr this function is called before each test to setup the environment. It is called with std::apply and inputParams so you can use them to mock records with specific IDs or calculate an expected result. */,
|
|
||||||
// void(*)(TInputParams...) /* testTeardownFn - If this is not nullptr this function is called after each test to cleanup any allocated/shared resources. */,
|
|
||||||
// bool /* testIsEnabled - If this is false the test, setup, and teardown functions are not run. */
|
|
||||||
// > /* <no name> - This is the data and config functions for a specific test run. */
|
|
||||||
// > tests, /* tests - Each tuple in the vector is a test run with a name, enabledStatus, input, expected output, and optional compare, setup, and teardown functions. */
|
|
||||||
// bool(*suite_compare_function)(const TResult expected, const TResult actual) /* suite_compare_function used to compare*/,
|
|
||||||
// void(*suiteSetupFn)() /* suiteSetupFn called before running the test suite */,
|
|
||||||
// void(*suiteTeardownFn)() /* suiteTeardownFn called after all tests have run */,
|
|
||||||
// bool /* suiteIsEnabled - If this is false the entire test suite is skipped. The skipped tests will be reported as skipped/disabled. */
|
|
||||||
// ) {
|
|
||||||
// return {0,0};
|
|
||||||
// };
|
|
||||||
// auto testFunction = [](int id){return (string)(id==0?"IS_ZERO":"IS_NOT_ZERO");};
|
|
||||||
// auto compareFunction = [](const string a, const string b){return a==b;};
|
|
||||||
// auto evaluateFunction = [](const string expected, const string actual){return expected==actual;};
|
|
||||||
// auto suiteSetupFunction = [](){};
|
|
||||||
// auto suiteTeardownFunction = [](){};
|
|
||||||
// auto testSetupFunction = [](){};
|
|
||||||
// auto testTeardownFunction = [](){};
|
|
||||||
// TestResults doTestSuite() {
|
|
||||||
// return test_fn<string, string(*)(int), int>(
|
|
||||||
// (string)string("MyClass::MyMethod"),
|
|
||||||
// [](int id){return (string)string(id==0?"IS_ZERO":"IS_NOT_ZERO");},
|
|
||||||
// vector({
|
|
||||||
// make_tuple(
|
|
||||||
// (string)string("ShouldReturn_IS_ZERO_for_id_0"),
|
|
||||||
// (string)string("IS_ZERO"),
|
|
||||||
// make_tuple(0),
|
|
||||||
// [](const string left, const string right){return (bool)(left==right);},
|
|
||||||
// [](int id){},
|
|
||||||
// [](int id){},
|
|
||||||
// true
|
|
||||||
// )
|
|
||||||
// }),
|
|
||||||
// [](const string left, const string right){return left==right;},
|
|
||||||
// [](int id){},
|
|
||||||
// [](int id){},
|
|
||||||
// true
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// template<typename TResult, typename TFunctionToTest, typename... TInputParams>
|
|
||||||
// TestResults test_fn(
|
|
||||||
// string suite_name,
|
|
||||||
// TFunctionToTest test_function,
|
|
||||||
// vector<
|
|
||||||
// TestTuple<TResult, TInputParams...> /* <no name> - This is the data and config functions for a specific test run. */
|
|
||||||
// > tests,
|
|
||||||
// MaybeTestCompareFunction<TResult> suite_compare_function,
|
|
||||||
// MaybeTestConfigureFunction suite_before_each,
|
|
||||||
// MaybeTestConfigureFunction suite_after_each,
|
|
||||||
// bool is_enabled
|
|
||||||
// );
|
|
||||||
|
|
||||||
template <typename TResult, typename... TInputParams>
|
template <typename TResult, typename... TInputParams>
|
||||||
TestResults execute_suite(
|
TestResults execute_suite(
|
||||||
string suite_label,
|
string suite_label,
|
||||||
@@ -456,38 +166,6 @@ namespace Test {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// auto test_data9 = vector<tuple<
|
|
||||||
// string, string, tuple<const string&, int>,
|
|
||||||
// function<bool(const string&, const string&)>,
|
|
||||||
// function<void(const string&, int)>,
|
|
||||||
// function<void(const string&, int)>,
|
|
||||||
// bool
|
|
||||||
// >>({
|
|
||||||
|
|
||||||
// });
|
|
||||||
// test_fn_9<string, const string&, int>(
|
|
||||||
// "",
|
|
||||||
// (function<string(const string&, int)>)fn1,
|
|
||||||
// test_data9
|
|
||||||
// );
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// string /* test_name */,
|
|
||||||
// TResult /* expectedOutput */,
|
|
||||||
// tuple<TInputParams...> /* inputParams - The input parameters for this test. These will be used when calling std::apply with testFn to execute the test. */,
|
|
||||||
// bool(*)(const TResult expected, const TResult actual) /* maybe_compare_function - If this is not nullprt then this function will be called instead of suite_compare_function to determine if the test passes. Use this to check for side effects of the test. Return true if the test passes and false otherwise. */,
|
|
||||||
// void(*)(TInputParams...) /* testSetupFn - If this is not nullptr this function is called before each test to setup the environment. It is called with std::apply and inputParams so you can use them to mock records with specific IDs or calculate an expected result. */,
|
|
||||||
// void(*)(TInputParams...) /* testTeardownFn - If this is not nullptr this function is called after each test to cleanup any allocated/shared resources. */,
|
|
||||||
// bool /* testIsEnabled - If this is false the test, setup, and teardown functions are not run. */
|
|
||||||
|
|
||||||
//char pc3(function<bool(TInputParams...)> compare_function, TInputParams... input_params) {
|
|
||||||
|
|
||||||
// template<typename T>
|
|
||||||
// typedef function<bool(const T&, const T&)> compare_function2;
|
|
||||||
|
|
||||||
TestResults do_the_other_thing(){
|
TestResults do_the_other_thing(){
|
||||||
auto p1 = "Microsoft QBasic";
|
auto p1 = "Microsoft QBasic";
|
||||||
auto p2 = 5;
|
auto p2 = 5;
|
||||||
@@ -536,185 +214,16 @@ namespace Test {
|
|||||||
|
|
||||||
return tr;
|
return tr;
|
||||||
}
|
}
|
||||||
// void(*)(TInputParams...) /* testSetupFn - If this is not nullptr this function is called before each test to setup the environment. It is called with std::apply and inputParams so you can use them to mock records with specific IDs or calculate an expected result. */,
|
|
||||||
// void(*)(TInputParams...) /* testTeardownFn - If this is not nullptr this function is called after each test to cleanup any allocated/shared resources. */,
|
|
||||||
// bool /* testIsEnabled - If this is false the test, setup, and teardown functions are not run. */
|
|
||||||
|
|
||||||
// bool(*suite_compare_function)(const TResult expected, const TResult actual) /* suite_compare_function used to compare*/,
|
|
||||||
// void(*suiteSetupFn)() /* suiteSetupFn called before running the test suite */,
|
|
||||||
// void(*suiteTeardownFn)() /* suiteTeardownFn called after all tests have run */,
|
|
||||||
// bool /* suiteIsEnabled - If this is false the entire test suite is skipped. The skipped tests will be reported as skipped/disabled. */
|
|
||||||
|
|
||||||
|
|
||||||
// template<typename TResult, typename... TInputParams>
|
|
||||||
// TestResults test_fn(
|
|
||||||
// string suite_label, /* suite_label - This is the name of the test suite. It will be used in logs. */
|
|
||||||
// function<TResult(TInputParams...)> testFn, /* testFn - This is the function to be tested. It will be called with std::apply and the inputParams from each test in tests below. */
|
|
||||||
// vector<
|
|
||||||
// tuple<
|
|
||||||
// string /* test_name */,
|
|
||||||
// TResult /* expectedOutput */,
|
|
||||||
// tuple<TInputParams...> /* inputParams - The input parameters for this test. These will be used when calling std::apply with testFn to execute the test. */,
|
|
||||||
// bool(*)(const TResult expected, const TResult actual) /* maybe_compare_function - If this is not nullprt then this function will be called instead of suite_compare_function to determine if the test passes. Use this to check for side effects of the test. Return true if the test passes and false otherwise. */,
|
|
||||||
// void(*)(TInputParams...) /* testSetupFn - If this is not nullptr this function is called before each test to setup the environment. It is called with std::apply and inputParams so you can use them to mock records with specific IDs or calculate an expected result. */,
|
|
||||||
// void(*)(TInputParams...) /* testTeardownFn - If this is not nullptr this function is called after each test to cleanup any allocated/shared resources. */,
|
|
||||||
// bool /* testIsEnabled - If this is false the test, setup, and teardown functions are not run. */
|
|
||||||
// > /* <no name> - This is the data and config functions for a specific test run. */
|
|
||||||
// > tests, /* tests - Each tuple in the vector is a test run with a name, enabledStatus, input, expected output, and optional compare, setup, and teardown functions. */
|
|
||||||
// bool(*suite_compare_function)(const TResult expected, const TResult actual) /* suite_compare_function used to compare*/,
|
|
||||||
// void(*suiteSetupFn)() /* suiteSetupFn called before running the test suite */,
|
|
||||||
// void(*suiteTeardownFn)() /* suiteTeardownFn called after all tests have run */,
|
|
||||||
// bool /* suiteIsEnabled - If this is false the entire test suite is skipped. The skipped tests will be reported as skipped/disabled. */
|
|
||||||
// ) {
|
|
||||||
// return {0,0};
|
|
||||||
// };
|
|
||||||
// auto testFunction = [](int id){return (string)(id==0?"IS_ZERO":"IS_NOT_ZERO");};
|
|
||||||
// auto compareFunction = [](const string a, const string b){return a==b;};
|
|
||||||
// auto evaluateFunction = [](const string expected, const string actual){return expected==actual;};
|
|
||||||
// auto suiteSetupFunction = [](){};
|
|
||||||
// auto suiteTeardownFunction = [](){};
|
|
||||||
// auto testSetupFunction = [](){};
|
|
||||||
// auto testTeardownFunction = [](){};
|
|
||||||
// TestResults doTestSuite() {
|
|
||||||
// return test_fn<string, string(*)(int), int>(
|
|
||||||
// (string)string("MyClass::MyMethod"),
|
|
||||||
// [](int id){return (string)string(id==0?"IS_ZERO":"IS_NOT_ZERO");},
|
|
||||||
// vector({
|
|
||||||
// make_tuple(
|
|
||||||
// (string)string("ShouldReturn_IS_ZERO_for_id_0"),
|
|
||||||
// (string)string("IS_ZERO"),
|
|
||||||
// make_tuple(0),
|
|
||||||
// [](const string left, const string right){return (bool)(left==right);},
|
|
||||||
// [](int id){},
|
|
||||||
// [](int id){},
|
|
||||||
// true
|
|
||||||
// )
|
|
||||||
// }),
|
|
||||||
// [](const string left, const string right){return left==right;},
|
|
||||||
// [](int id){},
|
|
||||||
// [](int id){},
|
|
||||||
// true
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TestResults dummyTest() {
|
|
||||||
// // Parse argc/argv and return {0,0} if test is disabled.
|
|
||||||
// return test_fn<string>(
|
|
||||||
// // Suite Name
|
|
||||||
// "/Dummy",
|
|
||||||
// testFunction,
|
|
||||||
// vector({
|
|
||||||
// // Test Name, Expect Output, Inputs
|
|
||||||
// make_tuple((string)"", (string)"", make_tuple(0)),
|
|
||||||
// }),
|
|
||||||
// compareFunction
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// test_fn(
|
|
||||||
// "Suite Name",
|
|
||||||
// [](){}, // test fn
|
|
||||||
// vector({
|
|
||||||
// make_tuple(
|
|
||||||
// "Test Name",
|
|
||||||
// "Expected Result", // TODO: find a way for this to work with void fn tests
|
|
||||||
// [](string expected, string actual){return true;} // Evaluate fn nullptr allowed and default
|
|
||||||
// [](){}, // Suite setup fn nullptr allowed and default
|
|
||||||
// [](){}, // Suite teardown fn nullptr allowed and default
|
|
||||||
// make_tuple(), // Input params
|
|
||||||
// ),
|
|
||||||
// }),
|
|
||||||
// [](string a, string b) {return a==b;},// compare fn nullptr allowed and default
|
|
||||||
// [](){}, // Suite setup fn nullprt allowed and default
|
|
||||||
// [](){}, // Suite teardown fn nullptr allowed and default
|
|
||||||
// )
|
|
||||||
|
|
||||||
// _Step_9 - if T2 is a single value then make_tuple<T2>(T2) and call longer version
|
// _Step_9 - if T2 is a single value then make_tuple<T2>(T2) and call longer version
|
||||||
// auto testFunction = [](int id){return id==0?"":"";};
|
// auto testFunction = [](int id){return id==0?"":"";};
|
||||||
// auto compareFunction = [](const string a, const string b){return a==b;};
|
// auto compareFunction = [](const string a, const string b){return a==b;};
|
||||||
// template<typename TResult, typename FnToTest, typename... TInputParams>
|
// template<typename TResult, typename FnToTest, typename... TInputParams>
|
||||||
// TestResults test_fn(
|
|
||||||
// string suite_label,
|
|
||||||
// FnToTest testFn,
|
|
||||||
// vector<tuple<string, bool, TResult, tuple<TInputParams...>>> tests,
|
|
||||||
// bool(*compare_function)(TResult a, TResult b));
|
|
||||||
// TestResults dummyTest() {
|
|
||||||
// // Parse argc/argv and return {0,0} if test is disabled.
|
|
||||||
// return test_fn<string>(
|
|
||||||
// // Suite Name
|
|
||||||
// "/Dummy",
|
|
||||||
// testFunction,
|
|
||||||
// vector({
|
|
||||||
// // Test Name, Expect Output, Inputs
|
|
||||||
// make_tuple((string)"", true, (string)"", make_tuple(0)),
|
|
||||||
// }),
|
|
||||||
// compareFunction
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// _Step_10 -
|
// _Step_10 -
|
||||||
|
|
||||||
// test_fn(string, _FnToTest, vector<tuple<string, _T1, _CompareFn, <tuple<_T2...>>>)
|
// test_fn(string, _FnToTest, vector<tuple<string, _T1, _CompareFn, <tuple<_T2...>>>)
|
||||||
// Default to (string, _FnToTest, vector<tuple<"", _T1, [](a,b){return a==b;}, make_tuple())
|
// Default to (string, _FnToTest, vector<tuple<"", _T1, [](a,b){return a==b;}, make_tuple())
|
||||||
// Also allow make_tuple(T2) if the last param is not a tuple.
|
// Also allow make_tuple(T2) if the last param is not a tuple.
|
||||||
//bool(*compare_function)(_TResult, _TResult)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// return test_fn(
|
|
||||||
// "/Dummy",
|
|
||||||
// [](int id){ if (id==0) {return "";} return "Unknown";},
|
|
||||||
// [](string a, string b){ return a == b; },
|
|
||||||
// vector({
|
|
||||||
// make_tuple("ShouldReturnEmptyStringForIdZero", "", make_tuple(0))
|
|
||||||
// })
|
|
||||||
// );
|
|
||||||
// return test_fn(
|
|
||||||
// "/Dummy",
|
|
||||||
// [](int id){ if (id==0) {return "";} return "Unknown";},
|
|
||||||
// [](string a, string b){ return a == b; },
|
|
||||||
// vector({
|
|
||||||
// make_tuple("ShouldReturnEmptyStringForIdZero", "", make_tuple(0))
|
|
||||||
// })
|
|
||||||
// );
|
|
||||||
// return test_fn(
|
|
||||||
// "/Dummy",
|
|
||||||
// [](){},
|
|
||||||
// [](string a, string b){ return a == b; },
|
|
||||||
// vector({
|
|
||||||
// make_tuple("ShouldReturnEmptyStringForIdZero", "", make_tuple(0))
|
|
||||||
// })
|
|
||||||
// );
|
|
||||||
|
|
||||||
|
|
||||||
// Call like this `auto results = test_fn("left", left, vector({pair("Micro", make_tuple("Microsoft QBasic", 5))}));`
|
|
||||||
// template<typename _T1, typename F, typename... T2>
|
|
||||||
// TestResults test_fn(string test_name, F f, vector<pair<_T1, tuple<T2...>>> tests) {
|
|
||||||
// size_t testsRun = 0;
|
|
||||||
// uint32_t failures = 0;
|
|
||||||
// cout << "Testing function " << test_name << endl;
|
|
||||||
|
|
||||||
// for_each(tests.begin(), tests.end(), [&testsRun, &failures, test_name, &f](pair<_T1, tuple<T2...>> data) {
|
|
||||||
// const auto& expected = data.first;
|
|
||||||
// const auto& actual = std::apply(f, data.second);
|
|
||||||
// testsRun++;
|
|
||||||
// cout << "Expected: " << expected << endl;
|
|
||||||
// cout << "Actual: " << actual << endl;
|
|
||||||
// failures += do_pass_fail(expected == actual);
|
|
||||||
// if (expected!=actual) {
|
|
||||||
// wcerr << test_name << " failed for " << get<0>(data.second) << endl;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// cout << failures << " failures" << endl;
|
|
||||||
// return make_tuple(testsRun, failures);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TestResults::TestResults()
|
TestResults::TestResults()
|
||||||
: failed_(0)
|
: failed_(0)
|
||||||
|
|||||||
@@ -87,43 +87,6 @@ namespace Test {
|
|||||||
uint32_t total_;
|
uint32_t total_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This function is called to execute a test suite. You provide it with some configuration info, optional utility callback functions, and test data (input parameters for each call to function_to_test and the expected result). It returns a TestResults that should be treated as an opaque data type.
|
|
||||||
// Not all parameters are named in code, but they are named and explained in the comments and will be described by those names below.
|
|
||||||
// string suite_name - This is the name of this test suite. It is used for reporting messages.
|
|
||||||
// TFunctionToTest function_to_test - This is the function to test. This may be replaced if necessary by std::function. It may not currently support class methods, but that is planned.
|
|
||||||
// vector<tuple<...>> tests - This is the test run data. Each tuple in the vector is a single test run. It's members are explained below.
|
|
||||||
// string test_name - This is the name of this test. It is used for reporting messages.
|
|
||||||
// TResult expected_output - This is the expected result of executing this test.
|
|
||||||
// bool(*)(const TResult expected, const TResult actual) test_compare_function - This is optional. If unset or set to nullptr it is skipped. If set to a function it is called to evaluate the test results. It takes the expected and actual results as parameters and should return true if the test passed and false otherwise. This may be changed to return a TestResults at some point.
|
|
||||||
// void(*)(TInputParams...) test_setup_function - This is optional. If unset or set to nullptr it is skipped. If set to a function it is called before each test to setup the environment for the test. You may use it to allocate resources and setup mocks, stubs, and spies.
|
|
||||||
// void(*)(TInputParams...) test_teardown_function - This is optiona. If unset or set to nullptr it is skipped. If set to a function it is called after each test to cleanup the environment after the test. You should free resources allocated by test_setup_function.
|
|
||||||
// bool is_enabled - This is optional. If unset or set to true the test is run. If set to false this test is skipped. If skipped it will be reported as a skipped/disabled test.
|
|
||||||
// bool(*)(const TResult expected, const TResult actual) suite_compare_function - This is optional. If unset or set to nullptr it is skipped. If set to a function and test_compare_function is not called for a test run then this function is called to evaluate the test results. It takes the expected and actual results as parameters and should return true if the test passed and false otherwise. This may be changed to return a TestResults at some point.
|
|
||||||
// void(*)() suite_setup_function - This is optional. If unset or set to nullptr it is skipped. If set to a function it is called before starting this test suite to setup the environment. You may use it to allocate resources and setup mocks, stubs, and spies.
|
|
||||||
// void(*)() suite_teardown_function - This is optional. If unset or set to nullptr it is skipped. If set to a function it is called after all tests in this suite have finished and all reporting has finished. You should free resources allocated by suite_setup_function.
|
|
||||||
// This method should be called like so. This is the minimal call and omits all of the optional params. This is the most common usage. You should put one tuple of inputs and expected output for each test case.
|
|
||||||
// results = collect_and_report_test_resultstest_fn(
|
|
||||||
// "Test: function_under_test",
|
|
||||||
// function_under_test,
|
|
||||||
// vector({
|
|
||||||
// make_tuple(
|
|
||||||
// "ShouldReturnAppleForGroupId_1_and_ItemId_2",
|
|
||||||
// string("Apple"),
|
|
||||||
// make_tuple(1,2),
|
|
||||||
// ),
|
|
||||||
// }),
|
|
||||||
// );
|
|
||||||
// The suites can be run from one file as such. From a file called ThingDoer_test.cpp to test the class/methods ThingDoer declared in ThingDoer.cpp. This isn't mandatory but is a best practice.
|
|
||||||
// You can use function_to_test without calling collect_and_report_test_results() and also could call it from a normal int main(int argc, char** argv) or other function.
|
|
||||||
// TestResults test_main_ThingDoer(int argc, char** argv) {
|
|
||||||
// TestResults results;
|
|
||||||
// results = collect_and_report_test_results(results, function_to_test("do_thing1", ...), argc, argv);
|
|
||||||
// results = collect_and_report_test_results(results, function_to_test("do_thing2", ...), argc, argv);
|
|
||||||
// return results;
|
|
||||||
// }
|
|
||||||
// Then some test harness either generated or explicit can call test_main_ThingDoer(...) and optionally reported there. Reporting granularity is controlled by how frequently you call collect_and_report_test_results(...).
|
|
||||||
// You can combine test results with results = results + function_to_test(..); and then collect_and_report_test_results on the aggregate TestResults value.
|
|
||||||
|
|
||||||
/// @brief
|
/// @brief
|
||||||
/// @tparam TResult
|
/// @tparam TResult
|
||||||
template<typename TResult>
|
template<typename TResult>
|
||||||
@@ -165,6 +128,43 @@ namespace Test {
|
|||||||
bool
|
bool
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
// This function is called to execute a test suite. You provide it with some configuration info, optional utility callback functions, and test data (input parameters for each call to function_to_test and the expected result). It returns a TestResults that should be treated as an opaque data type.
|
||||||
|
// Not all parameters are named in code, but they are named and explained in the comments and will be described by those names below.
|
||||||
|
// string suite_name - This is the name of this test suite. It is used for reporting messages.
|
||||||
|
// TFunctionToTest function_to_test - This is the function to test. This may be replaced if necessary by std::function. It may not currently support class methods, but that is planned.
|
||||||
|
// vector<tuple<...>> tests - This is the test run data. Each tuple in the vector is a single test run. It's members are explained below.
|
||||||
|
// string test_name - This is the name of this test. It is used for reporting messages.
|
||||||
|
// TResult expected_output - This is the expected result of executing this test.
|
||||||
|
// bool(*)(const TResult expected, const TResult actual) test_compare_function - This is optional. If unset or set to nullptr it is skipped. If set to a function it is called to evaluate the test results. It takes the expected and actual results as parameters and should return true if the test passed and false otherwise. This may be changed to return a TestResults at some point.
|
||||||
|
// void(*)(TInputParams...) test_setup_function - This is optional. If unset or set to nullptr it is skipped. If set to a function it is called before each test to setup the environment for the test. You may use it to allocate resources and setup mocks, stubs, and spies.
|
||||||
|
// void(*)(TInputParams...) test_teardown_function - This is optiona. If unset or set to nullptr it is skipped. If set to a function it is called after each test to cleanup the environment after the test. You should free resources allocated by test_setup_function.
|
||||||
|
// bool is_enabled - This is optional. If unset or set to true the test is run. If set to false this test is skipped. If skipped it will be reported as a skipped/disabled test.
|
||||||
|
// bool(*)(const TResult expected, const TResult actual) suite_compare_function - This is optional. If unset or set to nullptr it is skipped. If set to a function and test_compare_function is not called for a test run then this function is called to evaluate the test results. It takes the expected and actual results as parameters and should return true if the test passed and false otherwise. This may be changed to return a TestResults at some point.
|
||||||
|
// void(*)() suite_setup_function - This is optional. If unset or set to nullptr it is skipped. If set to a function it is called before starting this test suite to setup the environment. You may use it to allocate resources and setup mocks, stubs, and spies.
|
||||||
|
// void(*)() suite_teardown_function - This is optional. If unset or set to nullptr it is skipped. If set to a function it is called after all tests in this suite have finished and all reporting has finished. You should free resources allocated by suite_setup_function.
|
||||||
|
// This method should be called like so. This is the minimal call and omits all of the optional params. This is the most common usage. You should put one tuple of inputs and expected output for each test case.
|
||||||
|
// results = collect_and_report_test_resultstest_fn(
|
||||||
|
// "Test: function_under_test",
|
||||||
|
// function_under_test,
|
||||||
|
// vector({
|
||||||
|
// make_tuple(
|
||||||
|
// "ShouldReturnAppleForGroupId_1_and_ItemId_2",
|
||||||
|
// string("Apple"),
|
||||||
|
// make_tuple(1,2),
|
||||||
|
// ),
|
||||||
|
// }),
|
||||||
|
// );
|
||||||
|
// The suites can be run from one file as such. From a file called ThingDoer_test.cpp to test the class/methods ThingDoer declared in ThingDoer.cpp. This isn't mandatory but is a best practice.
|
||||||
|
// You can use function_to_test without calling collect_and_report_test_results() and also could call it from a normal int main(int argc, char** argv) or other function.
|
||||||
|
// TestResults test_main_ThingDoer(int argc, char** argv) {
|
||||||
|
// TestResults results;
|
||||||
|
// results = collect_and_report_test_results(results, function_to_test("do_thing1", ...), argc, argv);
|
||||||
|
// results = collect_and_report_test_results(results, function_to_test("do_thing2", ...), argc, argv);
|
||||||
|
// return results;
|
||||||
|
// }
|
||||||
|
// Then some test harness either generated or explicit can call test_main_ThingDoer(...) and optionally reported there. Reporting granularity is controlled by how frequently you call collect_and_report_test_results(...).
|
||||||
|
// You can combine test results with results = results + function_to_test(..); and then collect_and_report_test_results on the aggregate TestResults value.
|
||||||
|
|
||||||
/// @brief
|
/// @brief
|
||||||
/// @tparam TResult The result type of the test.
|
/// @tparam TResult The result type of the test.
|
||||||
/// @tparam TInputParams... The types of parameters sent to the test function.
|
/// @tparam TInputParams... The types of parameters sent to the test function.
|
||||||
|
|||||||
Reference in New Issue
Block a user