test.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. var should = require('chai').should();
  2. var mgrs = require('../dist/mgrs');
  3. describe('First MGRS set', function() {
  4. var mgrsStr = "33UXP04";
  5. var point = mgrs.toPoint(mgrsStr);
  6. it('Longitude of point from MGRS correct.', function() {
  7. point[0].should.be.closeTo(16.41450, 0.000001);
  8. });
  9. it('Latitude of point from MGRS correct.', function() {
  10. point[1].should.be.closeTo(48.24949, 0.000001);
  11. });
  12. it('MGRS reference with highest accuracy correct.', function() {
  13. mgrs.forward(point).should.equal("33UXP0500444998");
  14. });
  15. it('MGRS reference with 1-digit accuracy correct.', function() {
  16. mgrs.forward(point,1).should.equal(mgrsStr);
  17. });
  18. });
  19. describe('Second MGRS set', function() {
  20. var mgrsStr = "24XWT783908"; // near UTM zone border, so there are two ways to reference this
  21. var point = mgrs.toPoint(mgrsStr);
  22. it('Longitude of point from MGRS correct.', function() {
  23. point[0].should.be.closeTo(-32.66433, 0.00001);
  24. });
  25. it('Latitude of point from MGRS correct.', function() {
  26. point[1].should.be.closeTo(83.62778, 0.00001);
  27. });
  28. it('MGRS reference with 1-digit accuracy correct.', function() {
  29. mgrs.forward(point,3).should.equal('25XEN041865');
  30. });
  31. it('MGRS reference with 5-digit accuracy, northing all zeros', function(){
  32. mgrs.forward([0,0],5).should.equal('31NAA6602100000');
  33. });
  34. it('MGRS reference with 5-digit accuracy, northing one digit', function(){
  35. mgrs.forward([0,0.00001],5).should.equal('31NAA6602100001');
  36. });
  37. })