Skip to content

Expectation::toBeCloseTo ​

Member of Expectation

idl
Expectation.toBeCloseTo, compare, $
  /_expect_failure, $
  /relative, $
  tolerance = value

Verifies that the expectation value is close to a number, which is useful for floating point math. If the value is an array, every element must be close.

By default the absolute difference must be less than or equal to the tolerance. With RELATIVE, the difference must be less than or equal to the tolerance times the absolute compare value (the absolute tolerance is used when the compare value is zero).

Examples ​

idl
(it.expects(0.1 + 0.2)).toBeCloseTo, 0.3
(it.expects(mean([9.8, 10.2]))).toBeCloseTo, 10.0, tolerance = 0.5
(it.expects(1001.0)).toBeCloseTo, 1000.0, tolerance = 0.01, /relative
(it.expects(1.5))._not_.toBeCloseTo, 1.0, tolerance = 0.1

Arguments ​

compare ​

requiredinputtype=Number

Specify a numeric scalar to compare against.

Keywords ​

_expect_failure {#kw-_expect_failure} ​

optionalinputtype=Boolean

If the test fails for some reason, set this to force passing because we expected failure. This keyword is for internal use only.

relative ​

optionalinputtype=Boolean

If set, tolerance is relative to the compare value.

tolerance ​

optionalinputtype=Number

Specify a non-negative numeric scalar for the allowed difference.

Licensed under MIT.