From 2268897fb28778762c9fa6e36c5f2a0dfa852d21 Mon Sep 17 00:00:00 2001 From: Laurent Sansonetti Date: Sun, 20 Apr 2014 14:28:00 +0200 Subject: [PATCH] add be_close matcher + TOLERANCE constant --- test/test-android/app/main.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/test-android/app/main.rb b/test/test-android/app/main.rb index b1129062..93eff57f 100644 --- a/test/test-android/app/main.rb +++ b/test/test-android/app/main.rb @@ -181,6 +181,17 @@ class Object end end + TOLERANCE = 0.00003 + def be_close(expected, tolerance) + lambda do |obj, res| + if ((obj - expected).abs < tolerance) != res + puts "Expectation failed (expected `#{obj}' to be within #{expected} of tolerance #{tolerance}')" + $expectations_failures += 1 + end + $expectations_total += 1 + end + end + def mock(obj) # XXX we probably should be smarter here. obj