testwhat icon indicating copy to clipboard operation
testwhat copied to clipboard

Allow tolerance, scale args in equality checks

Open richierocks opened this issue 7 years ago • 1 comments

Currently, check_equal() calls is_equal(), which uses all.equal() to provide the equality checks when eq_condition = "equal" or eq_condition = "equivalent".

It is occasionally useful to be able to control the tolerance of the equality check. For example, exercises involving timing code have a random nature that can't be controlled by setting a seed.

To test

timings <- microbenchmark(qr.solve(matrix(runif(4e4), 2e2)))

I want to write an SCT like this

ex() %>% {
  check_object(., "timings") %>% {
    check_column(., "expr") %>% check_equal()
    check_column(., "time") %>% check_equal(tolerance = 1)
  }
}

That is, increasing the tolerance so the timings can be checked for equality within a wider range. The idea would be to have tolerance pass through ... from check_equal() to all.equal(). Similarly with the scale argument.

cc: @ramnathv

richierocks avatar May 10 '17 15:05 richierocks

Currently, the workaround looks like maybe..

ex() %>% check_expr("round(timings$time, TOLERANCE)") %>% check_result() %>% check_equal()

I agree that if check_equal always uses all.equal, then allowing tolerance and scale arguments would be useful.

machow avatar May 16 '17 19:05 machow