Skip to content

Commit

Permalink
Merge pull request #47 from DanielJDufour/GEOTRANS_CHECK
Browse files Browse the repository at this point in the history
GEOTRANS check
  • Loading branch information
DanielJDufour committed May 7, 2019
2 parents 1f116f4 + 56401a8 commit 1780ee7
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ node_modules
.DS_STORE
coverage
.nyc_output
*.csv
*.tgz
geotrans3.7/
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"module": "mgrs.js",
"scripts": {
"lint": "eslint mgrs.js && eslint test",
"test": "npm run build && nyc mocha",
"test": "npm run build && nyc mocha test/test.js",
"build": "mkdir -p dist && rollup -c"
},
"repository": {
Expand All @@ -27,6 +27,7 @@
"chai": "^4.2.0",
"eslint": "^5.16.0",
"mocha": "^6.1.1",
"node-fetch": "^2.5.0",
"nyc": "^13.3.0",
"rollup": "^1.9.0"
}
Expand Down
36 changes: 36 additions & 0 deletions test/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { writeFileSync } = require('fs');
const fetch = require('node-fetch');

async function process() {
// originally downloaded from
// http://earth-info.nga.mil/GandG/update/index.php?action=home
// and found in the unpacked downloaded GEOTRANS folder at
// geotrans3.7/SpreadsheetTester/TestFiles/outputs/output/mgrsToGeo_WE.txt
const url = 'https://s3.amazonaws.com/mgrs.io/mgrsToGeo_WE.txt';

let text = await fetch(url).then(response => response.text());

const [header, description, blank, ...rows] = text.split('\r\n');

let testCases = rows
.filter(testCase => {
return testCase.includes('Successful-Equivalent');
})
.map(row => {
const cells = row.replace(/\t+/g, '\t').split('\t');
return {
latitude: cells[6].trim(),
longitude: cells[7].trim(),
mgrs: cells[5].trim()
};
})


console.log("testCases", testCases);
const csv = testCases.map(({mgrs, latitude, longitude}) => `${mgrs}\t${latitude}\t${longitude}`).join('\n');
writeFileSync('testing-data.csv', csv, 'utf8');

console.log("wrote testing-data.csv");
}

process();
21 changes: 21 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const should = require('chai').should(); // eslint-disable-line no-unused-vars
const mgrs = require('../dist/mgrs');
const { readFileSync } = require('fs');

describe('First MGRS set', () => {
const mgrsStr = '33UXP04';
Expand Down Expand Up @@ -111,3 +112,23 @@ describe ('data validation', () => {
});
});
});

if (process.env.CHECK_GEOTRANS) {
describe('Consistency with GEOTRANS', () => {
it('Should be consistent with GEOTRANS', () => {
const fileText = readFileSync('./test/testing-data.csv', 'utf8');
const lines = fileText.split('\n').filter(Boolean);
lines.forEach(line => {
const [ mgrsString, expectedLatitude, expectedLongitude ] = line.split('\t');
const [ actualLongitude, actualLatitude ] = mgrs.toPoint(mgrsString);
try {
actualLatitude.should.equal(expectedLatitude);
actualLongitude.should.equal(expectedLongitude);
} catch (error) {
console.error('mgrsString:', mgrsString);
throw error;
}
});
});
});
}

0 comments on commit 1780ee7

Please sign in to comment.