mgrs-pole-test
Version:
Get MGRS coordinate for North Pole/South Pole
170 lines (133 loc) • 16.5 kB
JavaScript
import MgrsPole, { MgrsError } from '../mgrs-pole.js';
if (typeof window == 'undefined') { // node
const { default: chai } = await import('chai');
global.should = chai.should();
}
describe('North Pole', () => {
const mgrspole = new MgrsPole();
describe('To MGRS', () => {
it('input ( 89.4 , -124.54 ) => output Y ZH 45127 37769', () => mgrspole.toMgrs(89.4, -124.54).should.equal('Y ZH 45127 37769'));
it(`input ( 90.0 , 0.0 ) => output Z AH 00000 00000`, () => mgrspole.toMgrs(90.0, 0.0).should.equal('Z AH 00000 00000'));
it(`input ( 85.49868, 180 ) => output Z AN 00000 00000`, () => mgrspole.toMgrs(85.49868, 180).should.equal('Z AN 00000 00000'));
it(`input ( 84.974211, 174.289458 ) => output Z AN 55555 55555`, () => mgrspole.toMgrs(84.974211, 174.289458).should.equal('Z AN 55555 55555'));
it(`input ( 84.30793, 161.56511 ) => output Z BN 99999 99999`, () => mgrspole.toMgrs(84.30793, 161.56511).should.equal('Z BN 99999 99999'));
it(`input ( 85.4986848, 90 ) => output Z HH 00000 00000`, () => mgrspole.toMgrs(85.4986848, 90).should.equal('Z HH 00000 00000'));
it(`input ( 85.49868485,-90 ) => output Y TH 00000 00000`, () => mgrspole.toMgrs(85.49868485, -90).should.equal('Y TH 00000 00000'));
it(`input ( 84.92113141, -19.425812 ) => output Y YB 12345 67890`, () => mgrspole.toMgrs(84.92113141, -19.425812).should.equal('Y YB 12345 67890'));
it(`input ( 84.30791588, -108.43483423 ) => output Y RJ 99999 99999`, () => mgrspole.toMgrs(84.30791588, -108.43483423).should.equal('Y RJ 99999 99999'));
it(`input ( 84.525201427, 9.46230672 ) => output Z BA 00000 99999`, () => mgrspole.toMgrs(84.52520142658405, 9.462306722704914).should.equal('Z BA 00000 99999'));
it(`input ( 84.30791304032213, -18.434920175075227 ) => output Y YA 00000 99999`, () => mgrspole.toMgrs(84.30791304032213, -18.434920175075227).should.equal('Y XA 99999 99999'));
});
describe('To Degree', () => {
const [lat, lon] = mgrspole.toDegree("Y ZH 45127 37769");
it('input Y ZH 45127 37769 => output (89.4, -124.53958)', () => parseFloat(lat.toFixed(5)).should.equal(89.4) && parseFloat(lon.toFixed(5)).should.equal(-124.53958));
const [lat1, lon1] = mgrspole.toDegree("Z AH 00000 00000");
it('input `Z AH 00000 00000` => output (90, 0)', () => parseFloat(lat1.toFixed(5)).should.equal(90) && parseFloat(lon1.toFixed(5)).should.equal(0));
const [lat2, lon2] = mgrspole.toDegree("Z AN 00000 00000");
it('input `Z AN 00000 00000` => output (85.49868, 180)', () => parseFloat(lat2.toFixed(5)).should.equal(85.49868) && parseFloat(lon2.toFixed(5)).should.equal(180));
const [lat3, lon3] = mgrspole.toDegree("Z AN 55555 55555");
it('input `Z AN 55555 55555` => output (84.97421, 174.28946)', () => parseFloat(lat3.toFixed(6)).should.equal(84.974211) && parseFloat(lon3.toFixed(6)).should.equal(174.289458));
const [lat4, lon4] = mgrspole.toDegree("Z HH 00000 00000");
it('input `Z HH 00000 00000` => output (85.4986848, 90)', () => parseFloat(lat4.toFixed(7)).should.equal(85.4986848) && parseFloat(lon4.toFixed(5)).should.equal(90));
const [lat5, lon5] = mgrspole.toDegree("Y TH 00000 00000");
it('input `Z TH 00000 00000` => output (85.49868485, -90)', () => parseFloat(lat5.toFixed(8)).should.equal(85.49868485) && parseFloat(lon5.toFixed(7)).should.equal(-90));
const [lat6, lon6] = mgrspole.toDegree("Y YB 12345 67890");
it('input `Y YB 12345 67890` => output (84.92113141, -19.425812)', () => parseFloat(lat6.toFixed(8)).should.equal(84.92113141) && parseFloat(lon6.toFixed(7)).should.equal(-19.425812));
const [lat7, lon7] = mgrspole.toDegree("Z JJ 00000 00000");
it('input `Z JJ 00000 00000` => output (84.52521029, 99.46232221)', () => parseFloat(lat7.toFixed(8)).should.equal(84.52521029) && parseFloat(lon7.toFixed(8)).should.equal(99.46232221));
const [lat8, lon8] = mgrspole.toDegree("Y RJ 99999 99999");
it('input `Y RJ 99999 99999` => output (84.30791588, -108.43483423)', () => parseFloat(lat8.toFixed(8)).should.equal(84.30791588) && parseFloat(lon8.toFixed(8)).should.equal(-108.43483423));
const [lat9, lon9] = mgrspole.toDegree("Z BA 00000 99999");
it('input `Z BA 00000 99999` => output (84.52520142658405, 9.462306722704914)', () => lat9.should.equal(84.52520142658405) && lon9.should.equal(9.462306722704914));
const [lat10, lon10] = mgrspole.toDegree("Z BN 99999 99999");
it('input `Z BN 99999 99999` => output (84.30793, 161.56511)', () => parseFloat(lat10.toFixed(5)).should.equal(84.30793) && parseFloat(lon10.toFixed(5)).should.equal(161.56511));
const [lat11, lon11] = mgrspole.toDegree("Y YA 00000 99999");
it('input `Y YA 00000 99999` => output (84.30791304032213, -18.434920175075227)', () => lat11.should.equal(84.30791304032213) && lon11.should.equal(-18.434920175075227));
const [lat12, lon12] = mgrspole.toDegree("31U DQ 48251 11932");
it('input `31U DQ 48251 11932` => output (48.858193837921434, 2.2944892452301553)', () => lat12.should.equal(48.858193837921434) && lon12.should.equal(2.2944892452301553));
const [lat13, lon13] = mgrspole.toDegree("Z AH 1 6");
it('input `Z AH 1 6` => output (89.45212493960805, 170.53767779197437)', () => lat13.should.equal(89.45212493960805) && lon13.should.equal(170.53767779197437));
const [lat14, lon14] = mgrspole.toDegree("Z AH 12 67");
it('input `Z AH 12 67` => output (89.38692865323186, 169.84573341979976)', () => lat14.should.equal(89.38692865323186) && lon14.should.equal(169.84573341979976));
const [lat15, lon15] = mgrspole.toDegree("Z AH 123 678");
it('input `Z AH 123 678` => output (89.37935813037085, 169.71746497072658)', () => lat15.should.equal(89.37935813037085) && lon15.should.equal(169.71746497072658));
const [lat16, lon16] = mgrspole.toDegree("Z AH 1234 6789");
it('input `Z AH 1234 6789` => output (89.37849619026939, 169.698124263963)', () => lat16.should.equal(89.37849619026939) && lon16.should.equal(169.698124263963));
const [lat17, lon17] = mgrspole.toDegree("Z AH 12345 67890");
it('input `Z AH 12345 67890` => output (89.3784881350407, 169.69403952089982)', () => lat17.should.equal(89.3784881350407) && lon17.should.equal(169.69403952089982));
});
describe('Exception', () => {
it('longitude `1000.0` out of range', () => should.Throw(function() { mgrspole.toMgrs(89.4, 1000.0); }));
it('longitude `-375.0` out of range', () => should.Throw(function() { mgrspole.toMgrs(89.4, -375.0); }));
it('latitude `94.4` out of range', () => should.Throw(function() { mgrspole.toMgrs(94.4, 360.0); }));
it('latitude `-94.4` out of range', () => should.Throw(function() { mgrspole.toMgrs(-94.4, 360.0); }));
// it('wrong MGRS `Y XA 00000 00000`', () => should.Throw(function() { mgrspole.toDegree("Y XA 00000 00000"); }));
// it('wrong MGRS `Z CA 00000 00000`', () => should.Throw(function() { mgrspole.toDegree("Z CA 00000 00000"); }));
it('wrong MGRS `Y XX 00000 00000`', () => should.Throw(function() { mgrspole.toDegree("Y XX 00000 00000"); }));
// it('wrong MGRS `Z CP 99999 99999`', () => should.Throw(function() { mgrspole.toDegree("Z CP 99999 99999"); }));
// it('wrong MGRS `Y XP 99999 99999`', () => should.Throw(function() { mgrspole.toDegree("Y XP 99999 99999"); }));
// not existing MGRS
it('wrong MGRS `Z KH 12345 12345`', () => should.Throw(function() { mgrspole.toDegree("Z KH 12345 12345"); }));
// it('wrong MGRS `Y PH 12345 12345`', () => should.Throw(function() { mgrspole.toDegree("Y PH 12345 12345"); }));
it('wrong MGRS `Z ZP 12345 12345`', () => should.Throw(function() { mgrspole.toDegree("Z ZP 12345 12345"); }));
it('wrong MGRS `Y BP 12345 12345`', () => should.Throw(function() { mgrspole.toDegree("Y BP 12345 12345"); }));
// not Easting Northing
it('wrong MGRS `Z AH`', () => should.Throw(function() { mgrspole.toDegree("Z AH"); }));
});
describe('Call getOnCirclePointY()', () => {
it('input "Z AP 00000 00000" => output "Z AP 00000 66727"', () => mgrspole.getOnCirclePointY("Z AP 00000 00000").should.equal('Z AP 00000 66727'));
it('input "Z BP 00000 00000" => output "Z BP 00000 59185"', () => mgrspole.getOnCirclePointY("Z BP 00000 00000").should.equal('Z BP 00000 59185'));
it('input "Z CP 00000 00000" => output "Z CP 00000 36023"', () => mgrspole.getOnCirclePointY("Z CP 00000 00000").should.equal('Z CP 00000 36023'));
it('input "Z FN 00000 00000" => output "Z FN 00000 95420"', () => mgrspole.getOnCirclePointY("Z FN 00000 00000").should.equal('Z FN 00000 95420'));
it('input "Z GN 00000 00000" => output "Z GN 00000 33409"', () => mgrspole.getOnCirclePointY("Z GN 00000 00000").should.equal('Z GN 00000 33409'));
it('input "Z HM 00000 00000" => output "Z HM 00000 41050"', () => mgrspole.getOnCirclePointY("Z HM 00000 00000").should.equal('Z HM 00000 41050'));
it('input "Z JK 00000 00000" => output "Z JK 00000 90732"', () => mgrspole.getOnCirclePointY("Z JK 00000 00000").should.equal('Z JK 00000 90732'));
it('input "Y ZP 00000 00000" => output "Y ZP 00000 59185"', () => mgrspole.getOnCirclePointY("Y ZP 00000 00000").should.equal('Y ZP 00000 59185'));
it('input "Y YP 00000 00000" => output "Y YP 00000 36023"', () => mgrspole.getOnCirclePointY("Y YP 00000 00000").should.equal('Y YP 00000 36023'));
it('input "Y XN 00000 00000" => output "Y XN 00000 95420"', () => mgrspole.getOnCirclePointY("Y XN 00000 00000").should.equal('Y XN 00000 95420'));
it('input "Y UN 00000 00000" => output "Y UN 00000 33409"', () => mgrspole.getOnCirclePointY("Y UN 00000 00000").should.equal('Y UN 00000 33409'));
it('input "Y TM 00000 00000" => output "Y TM 00000 41050"', () => mgrspole.getOnCirclePointY("Y TM 00000 00000").should.equal('Y TM 00000 41050'));
it('input "Y SK 00000 00000" => output "Y SK 00000 90732"', () => mgrspole.getOnCirclePointY("Y SK 00000 00000").should.equal('Y SK 00000 90732'));
it('input "Z AA 00000 00000" => output "Z AA 00000 33273"', () => mgrspole.getOnCirclePointY("Z AA 00000 00000").should.equal('Z AA 00000 33273'));
it('input "Z BA 00000 00000" => output "Z BA 00000 40815"', () => mgrspole.getOnCirclePointY("Z BA 00000 00000").should.equal('Z BA 00000 40815'));
it('input "Z CA 00000 00000" => output "Z CA 00000 63977"', () => mgrspole.getOnCirclePointY("Z CA 00000 00000").should.equal('Z CA 00000 63977'));
it('input "Z FB 00000 00000" => output "Z FB 00000 04580"', () => mgrspole.getOnCirclePointY("Z FB 00000 00000").should.equal('Z FB 00000 04580'));
it('input "Z GB 00000 00000" => output "Z GB 00000 66591"', () => mgrspole.getOnCirclePointY("Z GB 00000 00000").should.equal('Z GB 00000 66591'));
it('input "Z HC 00000 00000" => output "Z HC 00000 58950"', () => mgrspole.getOnCirclePointY("Z HC 00000 00000").should.equal('Z HC 00000 58950'));
it('input "Z JE 00000 00000" => output "Z JE 00000 09268"', () => mgrspole.getOnCirclePointY("Z JE 00000 00000").should.equal('Z JE 00000 09268'));
it('input "Y ZA 00000 00000" => output "Y ZA 00000 40815"', () => mgrspole.getOnCirclePointY("Y ZA 00000 00000").should.equal('Y ZA 00000 40815'));
it('input "Y YA 00000 00000" => output "Y YA 00000 63977"', () => mgrspole.getOnCirclePointY("Y YA 00000 00000").should.equal('Y YA 00000 63977'));
it('input "Y XB 00000 00000" => output "Y XB 00000 04580"', () => mgrspole.getOnCirclePointY("Y XB 00000 00000").should.equal('Y XB 00000 04580'));
it('input "Y UB 00000 00000" => output "Y UB 00000 66591"', () => mgrspole.getOnCirclePointY("Y UB 00000 00000").should.equal('Y UB 00000 66591'));
it('input "Y TC 00000 00000" => output "Y TC 00000 58950"', () => mgrspole.getOnCirclePointY("Y TC 00000 00000").should.equal('Y TC 00000 58950'));
it('input "Y SE 00000 00000" => output "Y SE 00000 09268"', () => mgrspole.getOnCirclePointY("Y SE 00000 00000").should.equal('Y SE 00000 09268'));
});
describe('Call getOnCirclePointX()', () => {
it('input "Z JH 00000 00000" => output "Z JH 66727 00000"', () => mgrspole.getOnCirclePointX("Z JH 00000 00000").should.equal('Z JH 66727 00000'));
it('input "Z JJ 00000 00000" => output "Z JJ 59185 00000"', () => mgrspole.getOnCirclePointX("Z JJ 00000 00000").should.equal('Z JJ 59185 00000'));
it('input "Z JK 00000 00000" => output "Z JK 36023 00000"', () => mgrspole.getOnCirclePointX("Z JK 00000 00000").should.equal('Z JK 36023 00000'));
it('input "Z HL 00000 00000" => output "Z HL 95420 00000"', () => mgrspole.getOnCirclePointX("Z HL 00000 00000").should.equal('Z HL 95420 00000'));
it('input "Z HM 00000 00000" => output "Z HM 33409 00000"', () => mgrspole.getOnCirclePointX("Z HM 00000 00000").should.equal('Z HM 33409 00000'));
it('input "Z GN 00000 00000" => output "Z GN 41050 00000"', () => mgrspole.getOnCirclePointX("Z GN 00000 00000").should.equal('Z GN 41050 00000'));
it('input "Z CP 00000 00000" => output "Z CP 90732 00000"', () => mgrspole.getOnCirclePointX("Z CP 00000 00000").should.equal('Z CP 90732 00000'));
it('input "Y RH 00000 00000" => output "Y RH 33273 00000"', () => mgrspole.getOnCirclePointX("Y RH 00000 00000").should.equal('Y RH 33273 00000'));
it('input "Y RJ 00000 00000" => output "Y RJ 40815 00000"', () => mgrspole.getOnCirclePointX("Y RJ 00000 00000").should.equal('Y RJ 40815 00000'));
it('input "Y RK 00000 00000" => output "Y RK 63977 00000"', () => mgrspole.getOnCirclePointX("Y RK 00000 00000").should.equal('Y RK 63977 00000'));
it('input "Y SL 00000 00000" => output "Y SL 04580 00000"', () => mgrspole.getOnCirclePointX("Y SL 00000 00000").should.equal('Y SL 04580 00000'));
it('input "Y SM 00000 00000" => output "Y SM 66591 00000"', () => mgrspole.getOnCirclePointX("Y SM 00000 00000").should.equal('Y SM 66591 00000'));
it('input "Y TN 00000 00000" => output "Y TN 58950 00000"', () => mgrspole.getOnCirclePointX("Y TN 00000 00000").should.equal('Y TN 58950 00000'));
it('input "Y XP 00000 00000" => output "Y XP 09268 00000"', () => mgrspole.getOnCirclePointX("Y XP 00000 00000").should.equal('Y XP 09268 00000'));
it('input "Z JG 00000 00000" => output "Z JG 59185 00000"', () => mgrspole.getOnCirclePointX("Z JG 00000 00000").should.equal('Z JG 59185 00000'));
it('input "Z JF 00000 00000" => output "Z JF 36023 00000"', () => mgrspole.getOnCirclePointX("Z JF 00000 00000").should.equal('Z JF 36023 00000'));
it('input "Z HE 00000 00000" => output "Z HE 95420 00000"', () => mgrspole.getOnCirclePointX("Z HE 00000 00000").should.equal('Z HE 95420 00000'));
it('input "Z HD 00000 00000" => output "Z HD 33409 00000"', () => mgrspole.getOnCirclePointX("Z HD 00000 00000").should.equal('Z HD 33409 00000'));
it('input "Z GC 00000 00000" => output "Z GC 41050 00000"', () => mgrspole.getOnCirclePointX("Z GC 00000 00000").should.equal('Z GC 41050 00000'));
it('input "Z CB 00000 00000" => output "Z CB 90732 00000"', () => mgrspole.getOnCirclePointX("Z CB 00000 00000").should.equal('Z CB 90732 00000'));
it('input "Y RG 00000 00000" => output "Y RG 40815 00000"', () => mgrspole.getOnCirclePointX("Y RG 00000 00000").should.equal('Y RG 40815 00000'));
it('input "Y RF 00000 00000" => output "Y RF 63977 00000"', () => mgrspole.getOnCirclePointX("Y RF 00000 00000").should.equal('Y RF 63977 00000'));
it('input "Y SE 00000 00000" => output "Y SE 04580 00000"', () => mgrspole.getOnCirclePointX("Y SE 00000 00000").should.equal('Y SE 04580 00000'));
it('input "Y SD 00000 00000" => output "Y SD 66591 00000"', () => mgrspole.getOnCirclePointX("Y SD 00000 00000").should.equal('Y SD 66591 00000'));
it('input "Y TC 00000 00000" => output "Y TC 58950 00000"', () => mgrspole.getOnCirclePointX("Y TC 00000 00000").should.equal('Y TC 58950 00000'));
it('input "Y XB 00000 00000" => output "Y XB 09268 00000"', () => mgrspole.getOnCirclePointX("Y XB 00000 00000").should.equal('Y XB 09268 00000'));
});
});