Code coverage report for ./suites/geo/LatLngSpec.js

Statements: 100% (69 / 69)      Branches: 100% (0 / 0)      Functions: 100% (23 / 23)      Lines: 100% (69 / 69)     

All files » ./suites/geo/ » LatLngSpec.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 1191 1 1 1 1 1   1 1 1     1 1 1         1 1 1 1 1     1 1 1 1     1 1 1       1 1 1 1   1 1   1 1   1 1   1 1   1 1   1 1   1 1     1 1 1         1 1 1 1       1 1 1 1   1       1 1 1   1     1 1     1 1 1     1 1     1 1     1 1          
describe('LatLng', function() {
	describe('constructor', function() {
		it("sets lat and lng", function() {
			var a = new L.LatLng(25, 74);
			expect(a.lat).to.eql(25);
			expect(a.lng).to.eql(74);
 
			var b = new L.LatLng(-25, -74);
			expect(b.lat).to.eql(-25);
			expect(b.lng).to.eql(-74);
		});
 
		it('throws an error if invalid lat or lng', function () {
			expect(function () {
				var a = new L.LatLng(NaN, NaN);
			}).to.throwError();
		});
	});
 
	describe('#equals', function() {
		it("returns true if compared objects are equal within a certain margin", function() {
			var a = new L.LatLng(10, 20);
			var b = new L.LatLng(10 + 1.0E-10, 20 - 1.0E-10);
			expect(a.equals(b)).to.eql(true);
		});
 
		it("returns false if compared objects are not equal within a certain margin", function() {
			var a = new L.LatLng(10, 20);
			var b = new L.LatLng(10, 23.3);
			expect(a.equals(b)).to.eql(false);
		});
 
		it('returns false if passed non-valid object', function () {
			var a = new L.LatLng(10, 20);
			expect(a.equals(null)).to.eql(false);
		});
	});
 
	describe('#wrap', function () {
		it("wraps longitude to lie between -180 and 180 by default", function() {
			var a = new L.LatLng(0, 190).wrap().lng;
			expect(a).to.eql(-170);
 
			var b = new L.LatLng(0, 360).wrap().lng;
			expect(b).to.eql(0);
 
			var c = new L.LatLng(0, 380).wrap().lng;
			expect(c).to.eql(20);
 
			var d = new L.LatLng(0, -190).wrap().lng;
			expect(d).to.eql(170);
 
			var e = new L.LatLng(0, -360).wrap().lng;
			expect(e).to.eql(0);
 
			var f = new L.LatLng(0, -380).wrap().lng;
			expect(f).to.eql(-20);
 
			var g = new L.LatLng(0, 90).wrap().lng;
			expect(g).to.eql(90);
 
			var h = new L.LatLng(0, 180).wrap().lng;
			expect(h).to.eql(180);
		});
 
		it("wraps longitude within the given range", function() {
			var a = new L.LatLng(0, 190).wrap(-100, 100).lng;
			expect(a).to.eql(-10);
		});
 
	});
 
	describe('#toString', function () {
		it('formats a string', function () {
			var a = new L.LatLng(10.333333333, 20.2222222);
			expect(a.toString(3)).to.eql('LatLng(10.333, 20.222)');
		});
	});
 
	describe('#distanceTo', function () {
		it('calculates distance in meters', function () {
			var a = new L.LatLng(50.5, 30.5);
			var b = new L.LatLng(50, 1);
 
			expect(Math.abs(Math.round(a.distanceTo(b) / 1000) - 2084) < 5).to.eql(true);
		});
	});
 
	describe('L.latLng factory', function () {
		it('returns LatLng instance as is', function () {
			var a = new L.LatLng(50, 30);
 
			expect(L.latLng(a)).to.eql(a);
		});
 
		it('accepts an array of coordinates', function () {
			expect(L.latLng([50, 30])).to.eql(new L.LatLng(50, 30));
		});
 
		it('passes null or undefined as is', function () {
			expect(L.latLng(undefined)).to.eql(undefined);
			expect(L.latLng(null)).to.eql(null);
		});
 
		it('creates a LatLng object from two coordinates', function () {
			expect(L.latLng(50, 30)).to.eql(new L.LatLng(50, 30));
		});
 
		it('accepts an object with lat/lng', function () {
			expect(L.latLng({lat: 50, lng: 30})).to.eql(new L.LatLng(50, 30));
		});
 
		it('accepts an object with lat/lon', function () {
			expect(L.latLng({lat: 50, lon: 30})).to.eql(new L.LatLng(50, 30));
		});
	});
});