From 30ab46f265480ec0a5d56e9276794f3baefeaaef Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Tue, 9 Sep 2008 00:10:59 +0000 Subject: [PATCH] Adding a geom_eq method for Test.AnotherWay. This can be used to test two geometries for equivalence. (see #1639) git-svn-id: http://svn.openlayers.org/trunk/openlayers@7983 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- tests/geom_eq.js | 110 +++++++++++++++++++++++++++++++++++++++++++ tests/run-tests.html | 1 + 2 files changed, 111 insertions(+) create mode 100644 tests/geom_eq.js diff --git a/tests/geom_eq.js b/tests/geom_eq.js new file mode 100644 index 0000000000..26f3a95034 --- /dev/null +++ b/tests/geom_eq.js @@ -0,0 +1,110 @@ +/** + * File: xml_eq.js + * Adds a xml_eq method to AnotherWay test objects. + * + */ + +(function() { + + /** + * Function assertEqual + * Test two objects for equivalence (based on ==). 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 assertEqual(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(got != expected) { + throw msg + ": got '" + got + "' but expected '" + expected + "'"; + } + } + + /** + * Function assertGeometryEqual + * Test two geometries for equivalence. Geometries are considered + * equivalent if they are of the same class, and given component + * geometries, if all components are equivalent. Throws a message as + * exception if not equivalent. + * + * Parameters: + * got - {OpenLayers.Geometry} + * expected - {OpenLayers.Geometry} + * options - {Object} Optional object for configuring test options. + */ + function assertGeometryEqual(got, expected, options) { + + var OpenLayers = Test.AnotherWay._g_test_iframe.OpenLayers; + + // compare types + assertEqual(typeof got, typeof expected, "Object types mismatch"); + + // compare classes + assertEqual(got.CLASS_NAME, expected.CLASS_NAME, "Object class mismatch"); + + 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"); + } else { + // compare components + assertEqual( + got.components.length, expected.components.length, + "Component length mismatch for " + got.CLASS_NAME + ); + for(var i=0; i +