From 60186d007ffa9e23fe1cd646cc248f363066cffa Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 3 Aug 2016 00:33:20 -0600 Subject: [PATCH] fix #8 #6 --- tests/exhaustive.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/exhaustive.js diff --git a/tests/exhaustive.js b/tests/exhaustive.js new file mode 100644 index 0000000..3d35a84 --- /dev/null +++ b/tests/exhaustive.js @@ -0,0 +1,32 @@ +'use strict'; + +var jS2 = require('../src/s2geometry.js').S2; +var nS2 = require('s2geometry-node'); + +var x, y; + +function checkReal(lat, lng) { + var nS2LatLng = new nS2.S2LatLng(lat, lng).toPoint(); + var nCell = new nS2.S2CellId(nS2LatLng).parent(15); + var jCell = jS2.S2Cell.FromLatLng({ lat: lat, lng: lng }, 15); + var nKey = nCell.toString(); + var jQuad = jCell.getFaceAndQuads(); + var jKey = jQuad[0] + '/' + jQuad[1].join(''); + + if (nKey !== jKey) { + console.log(''); + console.log('Quadkey'); + console.log('=', nKey); + console.log('j', jKey); + throw new Error("values didn't match expected"); + } +} + +console.log('Exhaustive check of about 518,400 random lat,lng coordinates of the earth (about every 0.5°)'); +console.log('(this will take several seconds)'); +for (x = -180; x <= 180; x += (0 + Math.random())) { + for (y = -180; y <= 180; y += (0 + Math.random())) { + checkReal(x, y); + } +} +console.log('PASS');