s2-geometry.js/tests/js-vs-go.js

34 lines
942 B
JavaScript
Raw Normal View History

2016-08-03 07:20:48 +00:00
'use strict';
var tests = require('./generated-locations.json');
var jS2 = require('../src/s2geometry.js').S2;
function checkReal(loc) {
var jCell = jS2.S2Cell.FromLatLng({ lat: loc.lat, lng: loc.lng }, 15);
var jQuad = jCell.getFaceAndQuads();
var jKey = jQuad[0] + '/' + jQuad[1].join('');
if (loc.quadkey !== jKey) {
2016-08-03 23:43:35 +00:00
loc.badFace = jCell.face;
loc.badI = jCell.ij[0];
loc.badJ = jCell.ij[1];
loc.badQuad = jKey;
loc.badId = jS2.toId(jKey);
console.log(JSON.stringify(loc, null, ' ') + ',');
console.log('');
console.log('Lat/Lng:', loc.lat, loc.lng);
console.log('');
console.log('I, J:');
console.log('=', loc.i, loc.j);
console.log('j', jCell.ij.join(', '));
2016-08-03 07:20:48 +00:00
console.log('');
console.log('Quadkey');
console.log('=', loc.quadkey);
console.log('j', jKey);
throw new Error("values didn't match expected");
}
}
tests.forEach(checkReal);
console.log('PASS');