@@ -106,6 +106,8 @@ Running tests in tests/test_core.sh
106
106
Running test_assert_status_code_fails ... SUCCESS
107
107
Running test_assert_status_code_succeeds ... SUCCESS
108
108
Running test_assert_succeeds ... SUCCESS
109
+ Running test_assert_within_delta_fails ... SUCCESS
110
+ Running test_assert_within_delta_succeeds ... SUCCESS
109
111
Running test_fail_fails ... SUCCESS
110
112
Running test_fail_prints_failure_message ... SUCCESS
111
113
Running test_fail_prints_where_is_error ... SUCCESS
@@ -147,6 +149,8 @@ Running tests in tests/test_core.sh
147
149
Running test_assert_status_code_fails ... SUCCESS
148
150
Running test_assert_status_code_succeeds ... SUCCESS
149
151
Running test_assert_succeeds ... SUCCESS
152
+ Running test_assert_within_delta_fails ... SUCCESS
153
+ Running test_assert_within_delta_succeeds ... SUCCESS
150
154
Running test_fail_fails ... SUCCESS
151
155
Overall result: SUCCESS
152
156
```
@@ -178,6 +182,8 @@ ok - test_assert_shows_stdout_on_failure
178
182
ok - test_assert_status_code_fails
179
183
ok - test_assert_status_code_succeeds
180
184
ok - test_assert_succeeds
185
+ ok - test_assert_within_delta_fails
186
+ ok - test_assert_within_delta_succeeds
181
187
ok - test_fail_fails
182
188
ok - test_fail_prints_failure_message
183
189
ok - test_fail_prints_where_is_error
@@ -473,6 +479,35 @@ doc:2:test_obvious_matching_with_assert_not_matches()
473
479
Running test_obvious_notmatching_with_assert_not_matches ... SUCCESS
474
480
```
475
481
482
+ === *assert_within_delta*
483
+
484
+ assert_within_delta <expected num> <actual num> <max delta> [message]
485
+
486
+ Asserts that the expected num matches the actual num up to a given max delta.
487
+ This function only support integers.
488
+ Given an expectation of 5 and a delta of 2 this would match 3, 4, 5, 6, and 7:
489
+
490
+ ```test
491
+ test_matches_within_delta(){
492
+ assert_within_delta 5 3 2
493
+ assert_within_delta 5 4 2
494
+ assert_within_delta 5 5 2
495
+ assert_within_delta 5 6 2
496
+ assert_within_delta 5 7 2
497
+ }
498
+ test_does_not_match_within_delta(){
499
+ assert_within_delta 5 2 2
500
+ }
501
+
502
+ ```
503
+
504
+ ```output
505
+ Running test_does_not_match_within_delta ... FAILURE
506
+ expected value [5] to match [2] with a maximum delta of [2]
507
+ doc:9:test_does_not_match_within_delta()
508
+ Running test_matches_within_delta ... SUCCESS
509
+ ```
510
+
476
511
=== *assert_no_diff*
477
512
478
513
assert_no_diff <expected> <actual> [message]
0 commit comments