| | 106 | |
| | 107 | === Testing Geometry Equivalence === |
| | 108 | |
| | 109 | Test objects have been extended to include an {{{geom_eq}}} method. The [source:trunk/openlayers/tests/run-tests.html run-tests.html] page includes the [source:trunk/openlayers/tests/geom_eq.js geom_eq.js] script to get this functionality. With the {{{geom_eq}}} method you can compare two geometry objects for equivalence. This effectively compares geometry type, all components for equivalence, and all coordinates of points. |
| | 110 | |
| | 111 | |
| | 112 | The {{{geom_eq}}} method takes three arguments: |
| | 113 | * {{{got}}} - ''{OpenLayers.Geometry}'' The geometry object you are testing. |
| | 114 | * {{{expected}}} - ''{OpenLayers.Geometry}'' The geometry object you expect (not based on identity, based on equivalence). |
| | 115 | * {{{msg}}} - ''{String}'' Message for test output. |
| | 116 | |
| | 117 | A test function on a test page might look something like the following: |
| | 118 | |
| | 119 | {{{ |
| | 120 | function test_soup(t) { |
| | 121 | |
| | 122 | t.plan(4); |
| | 123 | var format = new OpenLayers.Format.WKT(); |
| | 124 | var doc, got, exp; |
| | 125 | |
| | 126 | var wkt = "POINT(10 20)"; |
| | 127 | var geom = new OpenLayers.Geometry.Point(10, 20); |
| | 128 | |
| | 129 | var feature = format.read(wkt); |
| | 130 | t.geom_eq(feature.geometry, geom, "point read"); |
| | 131 | } |
| | 132 | }}} |