From 54156003b4fbf9c7f4f17a690352d0b5ec146466 Mon Sep 17 00:00:00 2001 From: Michael Gratton Date: Sun, 29 Dec 2019 17:00:07 +1030 Subject: [PATCH] Add TestCase.assert_double --- test/engine/util-timeout-manager-test.vala | 10 +++------- test/test-case.vala | 4 ++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/engine/util-timeout-manager-test.vala b/test/engine/util-timeout-manager-test.vala index a9a01a64..dcecba8d 100644 --- a/test/engine/util-timeout-manager-test.vala +++ b/test/engine/util-timeout-manager-test.vala @@ -87,7 +87,7 @@ class Geary.TimeoutManagerTest : TestCase { this.main_loop.iteration(true); } - assert_epsilon(timer.elapsed(), 1.0, SECONDS_EPSILON); + assert_double(timer.elapsed(), 1.0, SECONDS_EPSILON); } public void milliseconds() throws Error { @@ -101,7 +101,7 @@ class Geary.TimeoutManagerTest : TestCase { this.main_loop.iteration(true); } - assert_epsilon(timer.elapsed(), 0.1, MILLISECONDS_EPSILON); + assert_double(timer.elapsed(), 0.1, MILLISECONDS_EPSILON); } public void repeat_forever() throws Error { @@ -118,11 +118,7 @@ class Geary.TimeoutManagerTest : TestCase { } timer.stop(); - assert_epsilon(timer.elapsed(), 2.0, SECONDS_EPSILON * 2); - } - - private inline void assert_epsilon(double actual, double expected, double epsilon) { - assert(actual + epsilon >= expected && actual - epsilon <= expected); + assert_double(timer.elapsed(), 2.0, SECONDS_EPSILON * 2); } } diff --git a/test/test-case.vala b/test/test-case.vala index 7e65603d..6292c498 100644 --- a/test/test-case.vala +++ b/test/test-case.vala @@ -96,6 +96,10 @@ public void assert_int64(int64 expected, int64 actual, string? context = null) } } +public void assert_double(double actual, double expected, double epsilon) { + assert(actual + epsilon >= expected && actual - epsilon <= expected); +} + public void assert_uint(uint expected, uint actual, string? context = null) throws GLib.Error { if (expected != actual) {