blob: 36a5598cb06c04e58941d3b5226feade679a0f1e [file] [log] [blame]
@test
operation testCompareIntegers() {
assertEquals(1>2, false);
assertEquals(2>1, true);
assertEquals(3<1, false);
assertEquals(1<3, true);
assertEquals(1 >= 2, false);
assertEquals(1 >= 1, true);
assertEquals(9223372036854775807l == 9223372036854775807l, true);
assertEquals(9223372036854775807l == 9223372036854775806l, false);
}
@test
operation testCompareDoubles() {
assertEquals(0.1f, 0.1f);
assertEquals(0.1d, 0.1d);
// Not *exactly* equal, due to floating-point precision
assertNotEquals("Floating point precision should make 0.3 and 10 * 0.03 different", 0.3f, 0.03f * 10);
assertNotEquals(0.3d, 0.1d + 0.1d + 0.1d);
// Normally, you should use approximate equality. "ulps" seems to be
// a very good way to compare IEEE 754 floating point numbers, as it
// takes into account the fact that the precision changes with the
// magnitude of the number. 4 or 5 ulps seems to be OK most of the time.
assertEquals(0.3f, 0.03f * 10, 4);
assertEquals("0.3d and 0.01d+0.01d+.01d should be approximately equal", 0.3d, 0.1d+0.1d+0.1d, 4);
}