commit 4cb891113c4be72e8d71a6912e60a566f4169ea1 Author: Rendo Date: Wed Sep 2 19:21:33 2026 +0500 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b9865b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build*/ + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e69de29 diff --git a/test.cpp b/test.cpp new file mode 100644 index 0000000..9bbe081 --- /dev/null +++ b/test.cpp @@ -0,0 +1,80 @@ +#include +#include +#include + +typedef std::function TestFunction; + +class Test { + private: + TestFunction complete; + public: + std::string test_name; + Test(std::string name, TestFunction complete): test_name(name), complete(complete){}; + bool evaluate(); +}; + +bool Test::evaluate() { return complete(); } + +class TestSuite { + private: + std::string suite_name; + std::vector tests; + public: + TestSuite(std::string); + void run(); + template + TestSuite* eq(std::string, T, T); + template + TestSuite* neq(std::string, T, T); +}; + +TestSuite::TestSuite(std::string name): suite_name(name) { + tests = {}; +} + +template +TestSuite* TestSuite::eq(std::string test_name, T test_value, T expected_value) { + tests.push_back(Test(test_name, [=](){return test_value == expected_value;})); + return this; +} + +template +TestSuite* TestSuite::neq(std::string test_name, T test_value, T expected_value) { + tests.push_back(Test(test_name, [=](){return test_value != expected_value;})); + return this; +} + +void TestSuite::run() { + std::cout << "=== " << suite_name << " ===" << std::endl; + int completed = 0; + int amount = tests.size(); + for (int i = 0; i < amount; i++) { + try { + bool result = tests[i].evaluate(); + std::cout << "Running Test " << i + 1 << "/" << amount << " \"" << tests[i].test_name << "\": " << (result ? "SUCCESS" : "FAILED") << std::endl; + if (result) + completed++; + } catch (...) { + std::cout << "Test " << i + 1 << "/" << amount << " finished with exception."; + } + } + std::cout << "Tests completed: " << completed << "/" << amount << (completed == amount ? ". Well done!" : "... You've got a job to do") << std::endl; + +} + +#ifdef TEST_THE_TEST + +int sum(int a, int b) { + return a+b; +} + +int main() { + TestSuite tests = TestSuite("Test of test suite"); + tests.eq("Successful eq", sum(1,1), 2) + ->neq("Successful neq", sum(1,1), 1) + ->eq("Failed eq", sum(1,1), 1) + ->run(); + return 0; +} + +#endif