Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/globeCoordinate/globeCoordinate.GlobeCoordinate.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ globeCoordinate.GlobeCoordinate = ( function( globeCoordinate ) {
var gc1Iso6709 = globeCoordinate.iso6709( this.getDecimal() ),
gc2Iso6709 = globeCoordinate.iso6709( otherGlobeCoordinate.getDecimal() );

return this.getPrecision() === otherGlobeCoordinate.getPrecision()
return Math.abs( this.getPrecision() - otherGlobeCoordinate.getPrecision() ) < 0.00000001
&& gc1Iso6709 === gc2Iso6709;
}

Expand Down
53 changes: 45 additions & 8 deletions tests/lib/globeCoordinate/globeCoordinate.GlobeCoordinate.tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* @licence GNU GPL v2+
* @author H. Snater < mediawiki@snater.com >
* @author Thiemo Mättig
*/
define( [
'globeCoordinate/globeCoordinate',
Expand Down Expand Up @@ -92,7 +93,7 @@ define( [

} );

QUnit.test( 'equals()', function( assert ) {
QUnit.test( 'Strict (in)equality', function( assert ) {
var gcDefs = [
{ latitude: 0, longitude: 0, precision: 1 },
{ latitude: -3, longitude: 2, precision: 1 },
Expand All @@ -114,28 +115,64 @@ define( [
$.each( gcDefs, function( i2, gcDef2 ) {
c2 = new globeCoordinate.GlobeCoordinate( gcDef2 );

if(
gcDef1.latitude === gcDef2.latitude
if( gcDef1.latitude === gcDef2.latitude
&& gcDef1.longitude === gcDef2.longitude
&& gcDef1.precision === gcDef2.precision
) {

assert.ok(
c1.equals( c2 ),
'Validated equality for data set #' + i1 + '.'
);

} else {

assert.ok(
!c1.equals( c2 ),
'Validated inequality of data set #' + i1 + ' to #' + i2 + '.'
);

}

} );
} );

} );

QUnit.test( 'Loose equality', function( assert ) {
var gcDefs = [
{ latitude: 0, longitude: 0, precision: 1 },
{ latitude: 0.01, longitude: 0, precision: 1 },
{ latitude: 0.1, longitude: 0, precision: 1 },
{ latitude: 0, longitude: 0.01, precision: 1 },
{ latitude: 0, longitude: 0.1, precision: 1 },
{ latitude: 0, longitude: 0, precision: 1.000000001 },
{ latitude: 0, longitude: 0, precision: 1.00000001 }
],
c1 = new globeCoordinate.GlobeCoordinate( gcDefs[0] );

$.each( gcDefs, function( i2, gcDef2 ) {
var c2 = new globeCoordinate.GlobeCoordinate( gcDef2 );
assert.ok(
c1.equals( c2 ),
'Validated equality of data set #0 to #' + i2 + '.'
);
} );

} );

QUnit.test( 'Loose inequality', function( assert ) {
var c1 = new globeCoordinate.GlobeCoordinate(
{ latitude: 0, longitude: 0, precision: 1 / 3600 }
),
gcDefs = [
{ latitude: 0.0002, longitude: 0, precision: 1 / 3600 },
{ latitude: 0, longitude: 0.0002, precision: 1 / 3600 },
{ latitude: 0, longitude: 0, precision: 1 / 3600 + 0.0000001 },
{ latitude: 0, longitude: 0, precision: 1 / 3600 - 0.0000001 }
];

$.each( gcDefs, function( i2, gcDef2 ) {
var c2 = new globeCoordinate.GlobeCoordinate( gcDef2 );
assert.ok(
!c1.equals( c2 ),
'Validated inequality to data set #' + i2 + '.'
);
} );

} );
Expand Down