Skip to content

Commit ad86e15

Browse files
author
Alex Overchenko
committed
Adding docs to TEST_RANGE formats.
Adding parameterizedDemo tests as an independent file
1 parent cef2275 commit ad86e15

File tree

2 files changed

+78
-4
lines changed

2 files changed

+78
-4
lines changed

docs/UnityHelperScriptsGuide.md

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,73 @@ script will generate 2 test calls:
227227

228228
```C
229229
test_demoParamFunction(1, 2, 5);
230-
test_demoParamFunction(3, 7, 20);
230+
test_demoParamFunction(10, 7, 20);
231231
```
232232
233233
That calls will be wrapped with `setUp`, `tearDown` and other
234-
usual Unity calls, as an independent unit tests.
234+
usual Unity calls, as for independent unit tests.
235235
The following output can be generated after test executable startup:
236236
237237
```Log
238-
tests/test_unity_parameterized.c:9:test_demoParamFunction(1, 2, 5):PASS
239-
tests/test_unity_parameterized.c:9:test_demoParamFunction(3, 7, 20):PASS
238+
tests/test_unity_parameterizedDemo.c:14:test_demoParamFunction(1, 2, 5):PASS
239+
tests/test_unity_parameterizedDemo.c:14:test_demoParamFunction(10, 7, 20):PASS
240+
```
241+
242+
##### `TEST_RANGE`
243+
244+
Test range is an advanced generator. It single call can be converted to zero,
245+
one or few `TEST_CASE` equivalent commands.
246+
247+
That generator can be used for creating numeric ranges in decimal representation
248+
only: integers & floating point numbers. It uses few formats for every parameter:
249+
250+
1. `[start, stop, step]` is stop-inclusive format
251+
2. `<start, stop, step>` is stop-exclusive formats
252+
253+
Format providers 1 and 2 accept only three arguments:
254+
255+
* `start` is start number
256+
* `stop` is end number (can or cannot exists in result sequence for format 1,
257+
will be always skipped for format 2)
258+
* `step` is incrementing step: can be either positive or negative value.
259+
260+
Let's use our `test_demoParamFunction` test for checking, what ranges
261+
will be generated for our single `TEST_RANGE` row:
262+
263+
```C
264+
TEST_RANGE([3, 4, 1], [10, 5, -2], <30, 31, 1>)
265+
```
266+
267+
Tests execution output will be similar to that text:
268+
269+
```Log
270+
tests/test_unity_parameterizedDemo.c:14:test_demoParamFunction(3, 10, 30):PASS
271+
tests/test_unity_parameterizedDemo.c:14:test_demoParamFunction(3, 8, 30):PASS
272+
tests/test_unity_parameterizedDemo.c:14:test_demoParamFunction(3, 6, 30):PASS
273+
tests/test_unity_parameterizedDemo.c:14:test_demoParamFunction(4, 10, 30):PASS
274+
tests/test_unity_parameterizedDemo.c:14:test_demoParamFunction(4, 8, 30):PASS
275+
tests/test_unity_parameterizedDemo.c:14:test_demoParamFunction(4, 6, 30):PASS
276+
```
277+
278+
As we can see:
279+
280+
| Parameter | Format | Possible values | Total of values | Format number |
281+
|---|---|---|---|---|
282+
| `a` | `[3, 4, 1]` | `3`, `4` | 2 | Format 1 |
283+
| `b` | `[10, 5, -2]` | `10`, `8`, `6` | 3 | Format 1, negative step, end number is not included |
284+
| `c` | `<30, 31, 1>` | `30` | 1 | Format 2 |
285+
286+
_Note_, that format 2 also supports negative step.
287+
288+
We totally have 2 * 3 * 1 = 6 equal test cases, that can be written as following:
289+
290+
```C
291+
TEST_CASE(3, 10, 30)
292+
TEST_CASE(3, 8, 30)
293+
TEST_CASE(3, 6, 30)
294+
TEST_CASE(4, 10, 30)
295+
TEST_CASE(4, 8, 30)
296+
TEST_CASE(4, 6, 30)
240297
```
241298
242299
### `unity_test_summary.rb`
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "unity.h"
2+
3+
/* Support for Meta Test Rig */
4+
#ifndef TEST_CASE
5+
#define TEST_CASE(...)
6+
#endif
7+
#ifndef TEST_RANGE
8+
#define TEST_RANGE(...)
9+
#endif
10+
11+
TEST_CASE(1, 2, 5)
12+
TEST_CASE(10, 7, 20)
13+
TEST_RANGE([3, 4, 1], [10, 5, -2], <30, 31, 1>)
14+
void test_demoParamFunction(int a, int b, int c)
15+
{
16+
TEST_ASSERT_GREATER_THAN_INT(a + b, c);
17+
}

0 commit comments

Comments
 (0)