2013-11-08 05:54:33 +08:00
|
|
|
describe('LatLng', function () {
|
|
|
|
describe('constructor', function () {
|
|
|
|
it("sets lat and lng", function () {
|
2010-09-07 00:06:38 +08:00
|
|
|
var a = new L.LatLng(25, 74);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.lat).to.eql(25);
|
|
|
|
expect(a.lng).to.eql(74);
|
2012-12-12 18:04:54 +08:00
|
|
|
|
2013-02-20 00:18:15 +08:00
|
|
|
var b = new L.LatLng(-25, -74);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(b.lat).to.eql(-25);
|
|
|
|
expect(b.lng).to.eql(-74);
|
2010-09-07 00:06:38 +08:00
|
|
|
});
|
2013-02-05 21:21:40 +08:00
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('throws an error if invalid lat or lng', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
expect(function () {
|
|
|
|
var a = new L.LatLng(NaN, NaN);
|
2013-03-02 05:49:20 +08:00
|
|
|
}).to.throwError();
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
2013-11-08 05:54:33 +08:00
|
|
|
|
|
|
|
it('does not set altitude if undefined', function () {
|
2013-07-03 16:13:00 +08:00
|
|
|
var a = new L.LatLng(25, 74);
|
2013-07-03 21:44:57 +08:00
|
|
|
expect(typeof a.alt).to.eql('undefined');
|
2013-07-03 16:13:00 +08:00
|
|
|
});
|
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
it('sets altitude', function () {
|
2013-07-03 16:13:00 +08:00
|
|
|
var a = new L.LatLng(25, 74, 50);
|
2013-07-03 21:44:57 +08:00
|
|
|
expect(a.alt).to.eql(50);
|
2013-11-08 05:54:33 +08:00
|
|
|
|
2013-07-03 16:13:00 +08:00
|
|
|
var b = new L.LatLng(-25, -74, -50);
|
2013-07-03 21:44:57 +08:00
|
|
|
expect(b.alt).to.eql(-50);
|
2013-07-03 16:13:00 +08:00
|
|
|
});
|
2013-11-08 05:54:33 +08:00
|
|
|
|
2012-12-12 18:04:54 +08:00
|
|
|
});
|
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
describe('#equals', function () {
|
|
|
|
it("returns true if compared objects are equal within a certain margin", function () {
|
2012-12-12 18:04:54 +08:00
|
|
|
var a = new L.LatLng(10, 20);
|
|
|
|
var b = new L.LatLng(10 + 1.0E-10, 20 - 1.0E-10);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.equals(b)).to.eql(true);
|
2010-09-07 00:06:38 +08:00
|
|
|
});
|
2012-12-12 18:04:54 +08:00
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
it("returns false if compared objects are not equal within a certain margin", function () {
|
2012-12-12 18:04:54 +08:00
|
|
|
var a = new L.LatLng(10, 20);
|
|
|
|
var b = new L.LatLng(10, 23.3);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.equals(b)).to.eql(false);
|
2012-12-12 18:04:54 +08:00
|
|
|
});
|
2013-02-05 21:21:40 +08:00
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns false if passed non-valid object', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
var a = new L.LatLng(10, 20);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.equals(null)).to.eql(false);
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
2012-12-12 18:04:54 +08:00
|
|
|
});
|
|
|
|
|
2013-02-05 21:21:40 +08:00
|
|
|
describe('#toString', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('formats a string', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
var a = new L.LatLng(10.333333333, 20.2222222);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(a.toString(3)).to.eql('LatLng(10.333, 20.222)');
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#distanceTo', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('calculates distance in meters', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
var a = new L.LatLng(50.5, 30.5);
|
|
|
|
var b = new L.LatLng(50, 1);
|
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(Math.abs(Math.round(a.distanceTo(b) / 1000) - 2084) < 5).to.eql(true);
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
2014-05-28 22:26:37 +08:00
|
|
|
it('does not return NaN if input points are equal', function () {
|
|
|
|
var a = new L.LatLng(50.5, 30.5);
|
|
|
|
var b = new L.LatLng(50.5, 30.5);
|
|
|
|
|
|
|
|
expect(a.distanceTo(b)).to.eql(0);
|
|
|
|
});
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('L.latLng factory', function () {
|
2013-02-20 04:41:48 +08:00
|
|
|
it('returns LatLng instance as is', function () {
|
2013-02-05 21:21:40 +08:00
|
|
|
var a = new L.LatLng(50, 30);
|
|
|
|
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(L.latLng(a)).to.eql(a);
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('accepts an array of coordinates', function () {
|
2014-12-06 01:25:02 +08:00
|
|
|
expect(L.latLng([])).to.eql(null);
|
|
|
|
expect(L.latLng([50])).to.eql(null);
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(L.latLng([50, 30])).to.eql(new L.LatLng(50, 30));
|
2014-12-06 01:25:02 +08:00
|
|
|
expect(L.latLng([50, 30, 100])).to.eql(new L.LatLng(50, 30, 100));
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('passes null or undefined as is', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(L.latLng(undefined)).to.eql(undefined);
|
|
|
|
expect(L.latLng(null)).to.eql(null);
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('creates a LatLng object from two coordinates', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(L.latLng(50, 30)).to.eql(new L.LatLng(50, 30));
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
2013-02-20 00:01:53 +08:00
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('accepts an object with lat/lng', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(L.latLng({lat: 50, lng: 30})).to.eql(new L.LatLng(50, 30));
|
2013-02-20 00:01:53 +08:00
|
|
|
});
|
|
|
|
|
2013-02-20 04:41:48 +08:00
|
|
|
it('accepts an object with lat/lon', function () {
|
2013-03-02 05:49:20 +08:00
|
|
|
expect(L.latLng({lat: 50, lon: 30})).to.eql(new L.LatLng(50, 30));
|
2013-02-20 00:01:53 +08:00
|
|
|
});
|
2013-12-02 22:45:53 +08:00
|
|
|
|
|
|
|
it('returns null if lng not specified', function () {
|
|
|
|
expect(L.latLng(50)).to.be(null);
|
|
|
|
});
|
2014-12-01 21:02:43 +08:00
|
|
|
|
|
|
|
it('accepts altitude as third parameter', function () {
|
|
|
|
expect(L.latLng(50, 30, 100)).to.eql(new L.LatLng(50, 30, 100));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('accepts an object with alt', function () {
|
2015-01-13 03:03:42 +08:00
|
|
|
expect(L.latLng({lat: 50, lng: 30, alt: 100})).to.eql(new L.LatLng(50, 30, 100));
|
|
|
|
expect(L.latLng({lat: 50, lon: 30, alt: 100})).to.eql(new L.LatLng(50, 30, 100));
|
2014-12-01 21:02:43 +08:00
|
|
|
});
|
2013-02-05 21:21:40 +08:00
|
|
|
});
|
2010-09-07 00:06:38 +08:00
|
|
|
});
|