mgrs-pole-test
Version:
Get MGRS coordinate for North Pole/South Pole
198 lines (159 loc) • 20.5 kB
JavaScript
import MgrsPole from '../mgrs-pole.js';
if (typeof window == 'undefined') { // node
const { default: chai } = await import('chai');
global.should = chai.should();
}
describe('South Pole', function() {
const mgrspole = new MgrsPole();
describe('To MGRS', function() {
it('input (-89.4 , -124.54) => output A ZM 45127 62230', () => mgrspole.toMgrs(-89.4, -124.54).should.equal('A ZM 45127 62230'));
it('input (-90.0 , 0.0 ) => output B AN 00000 00000', () => mgrspole.toMgrs(-90.0, 0.0 ).should.equal('B AN 00000 00000'));
});
describe('To Degree', function() {
const [lat, lon] = mgrspole.toDegree("B AN 00000 00000");
it('input B AN 00000 00000 => output (-90, 0)', () => parseFloat(lat.toFixed(5)).should.equal(-90) && parseFloat(lon.toFixed(5)).should.equal(0));
const [lat1, lon1] = mgrspole.toDegree("A ZN 00000 00000");
it('input A ZN 00000 00000 => output (-89.09931, -90)', () => parseFloat(lat1.toFixed(5)).should.equal(-89.09931) && parseFloat(lon1.toFixed(5)).should.equal(-90));
const [lat2, lon2] = mgrspole.toDegree("B AB 00000 00000");
it('input B AB 00000 00000 => output (-80.11581108958083, 180)', () => lat2.should.equal(-80.11581108958083) && lon2.should.equal(180));
const [lat3, lon3] = mgrspole.toDegree("B AY 00000 00000");
it('input B AY 00000 00000 => output (-81.01066338749857, 0)', () => lat3.should.equal(-81.01066338749857) && lon3.should.equal(0));
const [lat4, lon4] = mgrspole.toDegree("B QN 00000 00000");
it('input B QN 00000 00000 => output (-81.01066338749857, 90)', () => lat4.should.equal(-81.01066338749857) && lon4.should.equal(90));
const [lat5, lon5] = mgrspole.toDegree("A KN 00000 00000");
it('input A KN 00000 00000 => output (-80.11581108958083, -90)', () => lat5.should.equal(-80.11581108958083) && lon5.should.equal(-90));
const [lat6, lon6] = mgrspole.toDegree("B KV 00000 00000");
it('input B KV 00000 00000 => output (-81.10066069064223, 45)', () => lat6.should.equal(-81.10066069064223) && lon6.should.equal(45));
const [lat7, lon7] = mgrspole.toDegree("A QV 00000 00000");
it('input A QV 00000 00000 => output (-80.44664636312663, -48.81407483429035)', () => lat7.should.equal(-80.44664636312663) && lon7.should.equal(-48.81407483429035));
const [lat8, lon8] = mgrspole.toDegree("B LF 00000 00000");
it('input B LF 00000 00000 => output (-80.44664636312663, 131.18592516570965)', () => lat8.should.equal(-80.44664636312663) && lon8.should.equal(131.18592516570965));
const [lat9, lon9] = mgrspole.toDegree("A QF 00000 00000");
it('input A QF 00000 00000 => output (-80.44664636312663, -131.18592516570965)', () => lat9.should.equal(-80.44664636312663) && lon9.should.equal(-131.18592516570965));
const [lat10, lon10] = mgrspole.toDegree("B KW 00000 00000");
it('input B KW 00000 00000 => output (-80.44664636312663, 41.18592516570965)', () => lat10.should.equal(-80.44664636312663) && lon10.should.equal(41.18592516570965));
const [lat11, lon11] = mgrspole.toDegree("A RW 00000 00000");
it('input B RW 00000 00000 => output (-80.44664636312663, -41.18592516570965)', () => lat11.should.equal(-80.44664636312663) && lon11.should.equal(-41.18592516570965));
const [lat13, lon13] = mgrspole.toDegree("B AN 1 6");
it('input `B AN 1 6` => output (-89.45212493960805, 9.462322208025617)', () => lat13.should.equal(-89.45212493960805) && lon13.should.equal(9.462322208025617));
const [lat14, lon14] = mgrspole.toDegree("B AN 12 67");
it('input `B AN 12 67` => output (-89.38692865323186, 10.154266580200263)', () => lat14.should.equal(-89.38692865323186) && lon14.should.equal(10.154266580200263));
const [lat15, lon15] = mgrspole.toDegree("B AN 123 678");
it('input `B AN 123 678` => output (-89.37935813037085, 10.282535029273433)', () => lat15.should.equal(-89.37935813037085) && lon15.should.equal(10.282535029273433));
const [lat16, lon16] = mgrspole.toDegree("B AN 1234 6789");
it('input `B AN 1234 6789` => output (-89.37849619026939, 10.301875736036996)', () => lat16.should.equal(-89.37849619026939) && lon16.should.equal(10.301875736036996));
const [lat17, lon17] = mgrspole.toDegree("B AN 12345 67890");
it('input `B AN 12345 67890` => output (-89.3784881350407, 10.305960479100179)', () => lat17.should.equal(-89.3784881350407) && lon17.should.equal(10.305960479100179));
});
describe('Exception', function() {
it('longitude out of range `1000.0`', () => should.Throw(function() { mgrspole.toMgrs(-89.4, 1000.0); }));
it('longitude out of range `-375.0`', () => should.Throw(function() { mgrspole.toMgrs(-89.4, -375.0); }));
it('latitude out of range `-94.4`', () => should.Throw(function() { mgrspole.toMgrs(-94.4, 360.0); }));
// it('wrong MGRS `A ZA 00000 00000`', () => should.Throw(function() { mgrspole.toDegree("A ZA 00000 00000"); }));
// it('wrong MGRS `B PU 99999 99999`', () => should.Throw(function() { mgrspole.toDegree("B PU 99999 99999"); }));
// it('wrong MGRS `A LW 99999 99999`', () => should.Throw(function() { mgrspole.toDegree("A LW 99999 99999"); }));
// not existing MGRS
it('wrong MGRS `B SN 12345 12345`', () => should.Throw(function() { mgrspole.toDegree("B SN 12345 12345"); }));
it('wrong MGRS `A HN 12345 12345`', () => should.Throw(function() { mgrspole.toDegree("A HN 12345 12345"); }));
it('wrong MGRS `B ZY 12345 12345`', () => should.Throw(function() { mgrspole.toDegree("B ZY 12345 12345"); }));
it('wrong MGRS `A BY 12345 12345`', () => should.Throw(function() { mgrspole.toDegree("A BY 12345 12345"); }));
// not Easting Northing
it('wrong MGRS `A ZA`', () => should.Throw(function() { mgrspole.toDegree("Z AH"); }));
});
describe('Call getOnCirclePointY()', () => {
it('input "B AZ 00000 00000" => output "B AZ 00000 12951"', () => mgrspole.getOnCirclePointY("B AZ 00000 00000").should.equal('B AZ 00000 12951'));
it('input "B BZ 00000 00000" => output "B BZ 00000 08449"', () => mgrspole.getOnCirclePointY("B BZ 00000 00000").should.equal('B BZ 00000 08449'));
it('input "B CY 00000 00000" => output "B CY 00000 94833"', () => mgrspole.getOnCirclePointY("B CY 00000 00000").should.equal('B CY 00000 94833'));
it('input "B FY 00000 00000" => output "B FY 00000 71755"', () => mgrspole.getOnCirclePointY("B FY 00000 00000").should.equal('B FY 00000 71755'));
it('input "B GY 00000 00000" => output "B GY 00000 38585"', () => mgrspole.getOnCirclePointY("B GY 00000 00000").should.equal('B GY 00000 38585'));
it('input "B HX 00000 00000" => output "B HX 00000 94313"', () => mgrspole.getOnCirclePointY("B HX 00000 00000").should.equal('B HX 00000 94313'));
it('input "B JX 00000 00000" => output "B JX 00000 37368"', () => mgrspole.getOnCirclePointY("B JX 00000 00000").should.equal('B JX 00000 37368'));
it('input "B KW 00000 00000" => output "B KW 00000 65251"', () => mgrspole.getOnCirclePointY("B KW 00000 00000").should.equal('B KW 00000 65251'));
it('input "B LV 00000 00000" => output "B LV 00000 73731"', () => mgrspole.getOnCirclePointY("B LV 00000 00000").should.equal('B LV 00000 73731'));
it('input "B PU 00000 00000" => output "B PU 00000 54721"', () => mgrspole.getOnCirclePointY("B PU 00000 00000").should.equal('B PU 00000 54721'));
it('input "B QS 00000 00000" => output "B QS 00000 88528"', () => mgrspole.getOnCirclePointY("B QS 00000 00000").should.equal('B QS 00000 88528'));
it('input "B RP 00000 00000" => output "B RP 00000 69290"', () => mgrspole.getOnCirclePointY("B RP 00000 00000").should.equal('B RP 00000 69290'));
it('input "A ZZ 00000 00000" => output "A ZZ 00000 08449"', () => mgrspole.getOnCirclePointY("A ZZ 00000 00000").should.equal('A ZZ 00000 08449'));
it('input "A YY 00000 00000" => output "A YY 00000 94833"', () => mgrspole.getOnCirclePointY("A YY 00000 00000").should.equal('A YY 00000 94833'));
it('input "A XY 00000 00000" => output "A XY 00000 71755"', () => mgrspole.getOnCirclePointY("A XY 00000 00000").should.equal('A XY 00000 71755'));
it('input "A UY 00000 00000" => output "A UY 00000 38585"', () => mgrspole.getOnCirclePointY("A UY 00000 00000").should.equal('A UY 00000 38585'));
it('input "A TX 00000 00000" => output "A TX 00000 94313"', () => mgrspole.getOnCirclePointY("A TX 00000 00000").should.equal('A TX 00000 94313'));
it('input "A SX 00000 00000" => output "A SX 00000 37368"', () => mgrspole.getOnCirclePointY("A SX 00000 00000").should.equal('A SX 00000 37368'));
it('input "A RW 00000 00000" => output "A RW 00000 65251"', () => mgrspole.getOnCirclePointY("A RW 00000 00000").should.equal('A RW 00000 65251'));
it('input "A QV 00000 00000" => output "A QV 00000 73731"', () => mgrspole.getOnCirclePointY("A QV 00000 00000").should.equal('A QV 00000 73731'));
it('input "A PU 00000 00000" => output "A PU 00000 54721"', () => mgrspole.getOnCirclePointY("A PU 00000 00000").should.equal('A PU 00000 54721'));
it('input "A LS 00000 00000" => output "A LS 00000 88528"', () => mgrspole.getOnCirclePointY("A LS 00000 00000").should.equal('A LS 00000 88528'));
it('input "A KP 00000 00000" => output "A KP 00000 69290"', () => mgrspole.getOnCirclePointY("A KP 00000 00000").should.equal('A KP 00000 69290'));
it('input "B AA 00000 00000" => output "B AA 00000 87049"', () => mgrspole.getOnCirclePointY("B AA 00000 00000").should.equal('B AA 00000 87049'));
it('input "B BA 00000 00000" => output "B BA 00000 91551"', () => mgrspole.getOnCirclePointY("B BA 00000 00000").should.equal('B BA 00000 91551'));
it('input "B CB 00000 00000" => output "B CB 00000 05167"', () => mgrspole.getOnCirclePointY("B CB 00000 00000").should.equal('B CB 00000 05167'));
it('input "B FB 00000 00000" => output "B FB 00000 28245"', () => mgrspole.getOnCirclePointY("B FB 00000 00000").should.equal('B FB 00000 28245'));
it('input "B GB 00000 00000" => output "B GB 00000 61415"', () => mgrspole.getOnCirclePointY("B GB 00000 00000").should.equal('B GB 00000 61415'));
it('input "B HC 00000 00000" => output "B HC 00000 05687"', () => mgrspole.getOnCirclePointY("B HC 00000 00000").should.equal('B HC 00000 05687'));
it('input "B JC 00000 00000" => output "B JC 00000 62632"', () => mgrspole.getOnCirclePointY("B JC 00000 00000").should.equal('B JC 00000 62632'));
it('input "B KD 00000 00000" => output "B KD 00000 34749"', () => mgrspole.getOnCirclePointY("B KD 00000 00000").should.equal('B KD 00000 34749'));
it('input "B LE 00000 00000" => output "B LE 00000 26269"', () => mgrspole.getOnCirclePointY("B LE 00000 00000").should.equal('B LE 00000 26269'));
it('input "B PF 00000 00000" => output "B PF 00000 45279"', () => mgrspole.getOnCirclePointY("B PF 00000 00000").should.equal('B PF 00000 45279'));
it('input "B QH 00000 00000" => output "B QH 00000 11472"', () => mgrspole.getOnCirclePointY("B QH 00000 00000").should.equal('B QH 00000 11472'));
it('input "B RL 00000 00000" => output "B RL 00000 30710"', () => mgrspole.getOnCirclePointY("B RL 00000 00000").should.equal('B RL 00000 30710'));
it('input "A ZA 00000 00000" => output "A ZA 00000 91551"', () => mgrspole.getOnCirclePointY("A ZA 00000 00000").should.equal('A ZA 00000 91551'));
it('input "A YB 00000 00000" => output "A YB 00000 05167"', () => mgrspole.getOnCirclePointY("A YB 00000 00000").should.equal('A YB 00000 05167'));
it('input "A XB 00000 00000" => output "A XB 00000 28245"', () => mgrspole.getOnCirclePointY("A XB 00000 00000").should.equal('A XB 00000 28245'));
it('input "A UB 00000 00000" => output "A UB 00000 61415"', () => mgrspole.getOnCirclePointY("A UB 00000 00000").should.equal('A UB 00000 61415'));
it('input "A TC 00000 00000" => output "A TC 00000 05687"', () => mgrspole.getOnCirclePointY("A TC 00000 00000").should.equal('A TC 00000 05687'));
it('input "A SC 00000 00000" => output "A SC 00000 62632"', () => mgrspole.getOnCirclePointY("A SC 00000 00000").should.equal('A SC 00000 62632'));
it('input "A RD 00000 00000" => output "A RD 00000 34749"', () => mgrspole.getOnCirclePointY("A RD 00000 00000").should.equal('A RD 00000 34749'));
it('input "A QE 00000 00000" => output "A QE 00000 26269"', () => mgrspole.getOnCirclePointY("A QE 00000 00000").should.equal('A QE 00000 26269'));
it('input "A PF 00000 00000" => output "A PF 00000 45279"', () => mgrspole.getOnCirclePointY("A PF 00000 00000").should.equal('A PF 00000 45279'));
it('input "A LH 00000 00000" => output "A LH 00000 11472"', () => mgrspole.getOnCirclePointY("A LH 00000 00000").should.equal('A LH 00000 11472'));
it('input "A KL 00000 00000" => output "A KL 00000 30710"', () => mgrspole.getOnCirclePointY("A KL 00000 00000").should.equal('A KL 00000 30710'));
});
describe('Call getOnCirclePointX()', () => {
it('input "B RN 00000 00000" => output "B RN 12951 00000"', () => mgrspole.getOnCirclePointX("B RN 00000 00000").should.equal('B RN 12951 00000'));
it('input "B RP 00000 00000" => output "B RP 08449 00000"', () => mgrspole.getOnCirclePointX("B RP 00000 00000").should.equal('B RP 08449 00000'));
it('input "B QQ 00000 00000" => output "B QQ 94833 00000"', () => mgrspole.getOnCirclePointX("B QQ 00000 00000").should.equal('B QQ 94833 00000'));
it('input "B QR 00000 00000" => output "B QR 71755 00000"', () => mgrspole.getOnCirclePointX("B QR 00000 00000").should.equal('B QR 71755 00000'));
it('input "B QS 00000 00000" => output "B QS 38585 00000"', () => mgrspole.getOnCirclePointX("B QS 00000 00000").should.equal('B QS 38585 00000'));
it('input "B PT 00000 00000" => output "B PT 94313 00000"', () => mgrspole.getOnCirclePointX("B PT 00000 00000").should.equal('B PT 94313 00000'));
it('input "B PU 00000 00000" => output "B PU 37368 00000"', () => mgrspole.getOnCirclePointX("B PU 00000 00000").should.equal('B PU 37368 00000'));
it('input "B LV 00000 00000" => output "B LV 65251 00000"', () => mgrspole.getOnCirclePointX("B LV 00000 00000").should.equal('B LV 65251 00000'));
it('input "B KW 00000 00000" => output "B KW 73731 00000"', () => mgrspole.getOnCirclePointX("B KW 00000 00000").should.equal('B KW 73731 00000'));
it('input "B JX 00000 00000" => output "B JX 54721 00000"', () => mgrspole.getOnCirclePointX("B JX 00000 00000").should.equal('B JX 54721 00000'));
it('input "B GY 00000 00000" => output "B GY 88528 00000"', () => mgrspole.getOnCirclePointX("B GY 00000 00000").should.equal('B GY 88528 00000'));
it('input "B BZ 00000 00000" => output "B BZ 69290 00000"', () => mgrspole.getOnCirclePointX("B BZ 00000 00000").should.equal('B BZ 69290 00000'));
it('input "B RM 00000 00000" => output "B RM 08449 00000"', () => mgrspole.getOnCirclePointX("B RM 00000 00000").should.equal('B RM 08449 00000'));
it('input "B QL 00000 00000" => output "B QL 94833 00000"', () => mgrspole.getOnCirclePointX("B QL 00000 00000").should.equal('B QL 94833 00000'));
it('input "B QK 00000 00000" => output "B QK 71755 00000"', () => mgrspole.getOnCirclePointX("B QK 00000 00000").should.equal('B QK 71755 00000'));
it('input "B QJ 00000 00000" => output "B QJ 38585 00000"', () => mgrspole.getOnCirclePointX("B QJ 00000 00000").should.equal('B QJ 38585 00000'));
it('input "B PH 00000 00000" => output "B PH 94313 00000"', () => mgrspole.getOnCirclePointX("B PH 00000 00000").should.equal('B PH 94313 00000'));
it('input "B PG 00000 00000" => output "B PG 37368 00000"', () => mgrspole.getOnCirclePointX("B PG 00000 00000").should.equal('B PG 37368 00000'));
it('input "B LF 00000 00000" => output "B LF 65251 00000"', () => mgrspole.getOnCirclePointX("B LF 00000 00000").should.equal('B LF 65251 00000'));
it('input "B KE 00000 00000" => output "B KE 73731 00000"', () => mgrspole.getOnCirclePointX("B KE 00000 00000").should.equal('B KE 73731 00000'));
it('input "B JD 00000 00000" => output "B JD 54721 00000"', () => mgrspole.getOnCirclePointX("B JD 00000 00000").should.equal('B JD 54721 00000'));
it('input "B GC 00000 00000" => output "B GC 88528 00000"', () => mgrspole.getOnCirclePointX("B GC 00000 00000").should.equal('B GC 88528 00000'));
it('input "B BB 00000 00000" => output "B BB 69290 00000"', () => mgrspole.getOnCirclePointX("B BB 00000 00000").should.equal('B BB 69290 00000'));
it('input "A JN 00000 00000" => output "A JN 87049 00000"', () => mgrspole.getOnCirclePointX("A JN 00000 00000").should.equal('A JN 87049 00000'));
it('input "A JP 00000 00000" => output "A JP 91551 00000"', () => mgrspole.getOnCirclePointX("A JP 00000 00000").should.equal('A JP 91551 00000'));
it('input "A KQ 00000 00000" => output "A KQ 05167 00000"', () => mgrspole.getOnCirclePointX("A KQ 00000 00000").should.equal('A KQ 05167 00000'));
it('input "A KR 00000 00000" => output "A KR 28245 00000"', () => mgrspole.getOnCirclePointX("A KR 00000 00000").should.equal('A KR 28245 00000'));
it('input "A KS 00000 00000" => output "A KS 61415 00000"', () => mgrspole.getOnCirclePointX("A KS 00000 00000").should.equal('A KS 61415 00000'));
it('input "A LT 00000 00000" => output "A LT 05687 00000"', () => mgrspole.getOnCirclePointX("A LT 00000 00000").should.equal('A LT 05687 00000'));
it('input "A LU 00000 00000" => output "A LU 62632 00000"', () => mgrspole.getOnCirclePointX("A LU 00000 00000").should.equal('A LU 62632 00000'));
it('input "A PV 00000 00000" => output "A PV 34749 00000"', () => mgrspole.getOnCirclePointX("A PV 00000 00000").should.equal('A PV 34749 00000'));
it('input "A QW 00000 00000" => output "A QW 26269 00000"', () => mgrspole.getOnCirclePointX("A QW 00000 00000").should.equal('A QW 26269 00000'));
it('input "A RX 00000 00000" => output "A RX 45279 00000"', () => mgrspole.getOnCirclePointX("A RX 00000 00000").should.equal('A RX 45279 00000'));
it('input "A TY 00000 00000" => output "A TY 11472 00000"', () => mgrspole.getOnCirclePointX("A TY 00000 00000").should.equal('A TY 11472 00000'));
it('input "A YZ 00000 00000" => output "A YZ 30710 00000"', () => mgrspole.getOnCirclePointX("A YZ 00000 00000").should.equal('A YZ 30710 00000'));
it('input "A JM 00000 00000" => output "A JM 91551 00000"', () => mgrspole.getOnCirclePointX("A JM 00000 00000").should.equal('A JM 91551 00000'));
it('input "A KL 00000 00000" => output "A KL 05167 00000"', () => mgrspole.getOnCirclePointX("A KL 00000 00000").should.equal('A KL 05167 00000'));
it('input "A KK 00000 00000" => output "A KK 28245 00000"', () => mgrspole.getOnCirclePointX("A KK 00000 00000").should.equal('A KK 28245 00000'));
it('input "A KJ 00000 00000" => output "A KJ 61415 00000"', () => mgrspole.getOnCirclePointX("A KJ 00000 00000").should.equal('A KJ 61415 00000'));
it('input "A LH 00000 00000" => output "A LH 05687 00000"', () => mgrspole.getOnCirclePointX("A LH 00000 00000").should.equal('A LH 05687 00000'));
it('input "A LG 00000 00000" => output "A LG 62632 00000"', () => mgrspole.getOnCirclePointX("A LG 00000 00000").should.equal('A LG 62632 00000'));
it('input "A PF 00000 00000" => output "A PF 34749 00000"', () => mgrspole.getOnCirclePointX("A PF 00000 00000").should.equal('A PF 34749 00000'));
it('input "A QE 00000 00000" => output "A QE 26269 00000"', () => mgrspole.getOnCirclePointX("A QE 00000 00000").should.equal('A QE 26269 00000'));
it('input "A RD 00000 00000" => output "A RD 45279 00000"', () => mgrspole.getOnCirclePointX("A RD 00000 00000").should.equal('A RD 45279 00000'));
it('input "A TC 00000 00000" => output "A TC 11472 00000"', () => mgrspole.getOnCirclePointX("A TC 00000 00000").should.equal('A TC 11472 00000'));
it('input "A YB 00000 00000" => output "A YB 30710 00000"', () => mgrspole.getOnCirclePointX("A YB 00000 00000").should.equal('A YB 30710 00000'));
});
});