@@ -106,6 +106,8 @@ Running tests in tests/test_core.sh
106106 Running test_assert_status_code_fails ... SUCCESS
107107 Running test_assert_status_code_succeeds ... SUCCESS
108108 Running test_assert_succeeds ... SUCCESS
109+ Running test_assert_within_delta_fails ... SUCCESS
110+ Running test_assert_within_delta_succeeds ... SUCCESS
109111 Running test_fail_fails ... SUCCESS
110112 Running test_fail_prints_failure_message ... SUCCESS
111113 Running test_fail_prints_where_is_error ... SUCCESS
@@ -147,6 +149,8 @@ Running tests in tests/test_core.sh
147149 Running test_assert_status_code_fails ... SUCCESS
148150 Running test_assert_status_code_succeeds ... SUCCESS
149151 Running test_assert_succeeds ... SUCCESS
152+ Running test_assert_within_delta_fails ... SUCCESS
153+ Running test_assert_within_delta_succeeds ... SUCCESS
150154 Running test_fail_fails ... SUCCESS
151155Overall result: SUCCESS
152156```
@@ -178,6 +182,8 @@ ok - test_assert_shows_stdout_on_failure
178182ok - test_assert_status_code_fails
179183ok - test_assert_status_code_succeeds
180184ok - test_assert_succeeds
185+ ok - test_assert_within_delta_fails
186+ ok - test_assert_within_delta_succeeds
181187ok - test_fail_fails
182188ok - test_fail_prints_failure_message
183189ok - test_fail_prints_where_is_error
@@ -473,6 +479,35 @@ doc:2:test_obvious_matching_with_assert_not_matches()
473479 Running test_obvious_notmatching_with_assert_not_matches ... SUCCESS
474480```
475481
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+
476511=== *assert_no_diff*
477512
478513 assert_no_diff <expected> <actual> [message]
0 commit comments