@@ -11,7 +11,7 @@ retained but no new code is pushed due to me using C++ full time so I gain
11
11
expertise in that.
12
12
13
13
For these practice programs I have borrowed working code from various online
14
- sources and relevant credits are given in code comments. So I hope anyone who
14
+ sources and relevant credits are given in code comments. So I hope anyone who
15
15
finds this repository may use it for their own learning of data structures and
16
16
algorithms. After learning from working solutions in this repository you may
17
17
practice solving problems on coding contest platforms with time limit.
@@ -29,7 +29,7 @@ Coding guidelines
29
29
* Every C++ source file must build & run as a single file target the focus is
30
30
on solving the problem correctly.
31
31
* Each C++ compiled binary must output test result as a single line in this
32
- format ` Executed M implementations with N tests. ` . This makes it easy to
32
+ format ` Executed M implementations with N tests. ` . This makes it easy to
33
33
get tests summary.
34
34
* For debugging each binary must print test name, test case number with input
35
35
and output in this format and only when enabled with environment variable
@@ -70,3 +70,33 @@ make cpp/arrays/2sum-01-format # format .cpp source file
70
70
71
71
SHOW_TEST_OUTPUT=1 make cpp/arrays/2sum-01-check # run test with debug output
72
72
```
73
+
74
+ Test framework
75
+ --------------
76
+
77
+ This repository uses a single header file test "framework" to write test cases
78
+ to verify the correctness of the algorithms and various implementations. It
79
+ is designed to execute test cases by providing definition to ` TEST() ` macros
80
+ with unique and name description to that test. This step registers the test
81
+ with the tests registry.
82
+
83
+ To check the test conditions with expected and actual values it provides
84
+ ` CHECK_EQ() ` macro. It checks a given condition and increments test case
85
+ count on success and reports error and exits on failure. To convert the
86
+ expected & actual data into printable strings helper functions such as
87
+ ` to_string() ` have to be provided. Use ` SUCCESS() ` & ` FAIL() ` macros to
88
+ create custom checks not provided by the framework.
89
+
90
+ The test output can be printed with ` SHOW_OUTPUT() ` macro to verify the inputs
91
+ passed to an algorithm and the output received from it. The output can be
92
+ manipulated by providing the list of IO manipulators to ` SET_IO() ` and reset
93
+ with ` RESET_IO() ` . Custom test can be provided using ` SET_CUSTOM_FAIL_MSG() `
94
+ or by providing ` to_string() ` overloads.
95
+
96
+ The test code is initialized with ` INIT_TEST_MAIN() ` macro that provides
97
+ ` main() ` function definition which includes ` RUN_ALL_TESTS() ` macro function
98
+ to run all the registered tests.
99
+
100
+ This framework removes the need to write test output and test logic code
101
+ across the implementations significantly reducing the number of source lines
102
+ in a single file and improves readability.
0 commit comments