Add TestCase.assert_double

This commit is contained in:
Michael Gratton 2019-12-29 17:00:07 +10:30 committed by Michael James Gratton
parent ca7cc04ab2
commit 54156003b4
2 changed files with 7 additions and 7 deletions

View file

@ -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);
}
}

View file

@ -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) {