Add tests for regular and irregular transformations

This commit is contained in:
Tom Hughes
2011-10-18 10:43:56 +01:00
parent 1b6eb38d46
commit 93f2a31253
2 changed files with 70 additions and 4 deletions
+32 -4
View File
@@ -34,6 +34,34 @@
}
}
/**
* Function assertFloatEqual
* Test two objects for floating point equivalence. Throw an exception
* if not equivalent.
*
* Parameters:
* got - {Object}
* expected - {Object}
* msg - {String} The message to be thrown. This message will be appended
* with ": got {got} but expected {expected}" where got and expected are
* replaced with string representations of the above arguments.
*/
function assertFloatEqual(got, expected, msg) {
if(got === undefined) {
got = "undefined";
} else if (got === null) {
got = "null";
}
if(expected === undefined) {
expected = "undefined";
} else if (expected === null) {
expected = "null";
}
if(Math.abs(got - expected) > 0.000000001) {
throw msg + ": got '" + got + "' but expected '" + expected + "'";
}
}
/**
* Function assertGeometryEqual
* Test two geometries for equivalence. Geometries are considered
@@ -58,9 +86,9 @@
if(got instanceof OpenLayers.Geometry.Point) {
// compare points
assertEqual(got.x, expected.x, "x mismatch");
assertEqual(got.y, expected.y, "y mismatch");
assertEqual(got.z, expected.z, "z mismatch");
assertFloatEqual(got.x, expected.x, "x mismatch");
assertFloatEqual(got.y, expected.y, "y mismatch");
assertFloatEqual(got.z, expected.z, "z mismatch");
} else {
// compare components
assertEqual(
@@ -107,4 +135,4 @@
}
}
})();
})();