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

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

All files » ./suites/geo/ » LatLngBoundsSpec.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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 1371 1   1 19     19     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('LatLngBounds', function() {
	var a, c;
 
	beforeEach(function() {
		a = new L.LatLngBounds(
			new L.LatLng(14, 12),
			new L.LatLng(30, 40));
		c = new L.LatLngBounds();
	});
 
	describe('constructor', function () {
		it('instantiates either passing two latlngs or an array of latlngs', function () {
			var b = new L.LatLngBounds([
				new L.LatLng(14, 12),
				new L.LatLng(30, 40)
			]);
			expect(b).to.eql(a);
			expect(b.getNorthWest()).to.eql(new L.LatLng(30, 12));
		});
	});
 
	describe('#extend', function () {
		it('extends the bounds by a given point', function () {
			a.extend(new L.LatLng(20, 50));
			expect(a.getNorthEast()).to.eql(new L.LatLng(30, 50));
		});
 
		it('extends the bounds by given bounds', function () {
			a.extend([[20, 50], [8, 40]]);
 
			expect(a.getSouthEast()).to.eql(new L.LatLng(8, 50));
		});
	});
 
	describe('#getCenter', function () {
		it('returns the bounds center', function () {
			expect(a.getCenter()).to.eql(new L.LatLng(22, 26));
		});
	});
 
	describe('#pad', function () {
		it('pads the bounds by a given ratio', function () {
			var b = a.pad(0.5);
 
			expect(b).to.eql(L.latLngBounds([[6, -2], [38, 54]]));
		});
	});
 
	describe('#equals', function () {
		it('returns true if bounds equal', function () {
			expect(a.equals([[14, 12], [30, 40]])).to.eql(true);
			expect(a.equals([[14, 13], [30, 40]])).to.eql(false);
			expect(a.equals(null)).to.eql(false);
		});
	});
 
	describe('#isValid', function() {
		it('returns true if properly set up', function() {
			expect(a.isValid()).to.be.ok();
		});
		it('returns false if is invalid', function() {
			expect(c.isValid()).to.not.be.ok();
		});
		it('returns true if extended', function() {
			c.extend([0, 0]);
			expect(c.isValid()).to.be.ok();
		});
	});
 
	describe('#getWest', function () {
		it('returns a proper bbox west value', function() {
			expect(a.getWest()).to.eql(12);
		});
	});
 
	describe('#getSouth', function () {
		it('returns a proper bbox south value', function() {
			expect(a.getSouth()).to.eql(14);
		});
 
	});
 
	describe('#getEast', function () {
		it('returns a proper bbox east value', function() {
			expect(a.getEast()).to.eql(40);
		});
 
	});
 
	describe('#getNorth', function () {
		it('returns a proper bbox north value', function() {
			expect(a.getNorth()).to.eql(30);
		});
 
	});
 
	describe('#toBBoxString', function () {
		it('returns a proper left,bottom,right,top bbox', function() {
			expect(a.toBBoxString()).to.eql("12,14,40,30");
		});
 
	});
 
	describe('#getNorthWest', function () {
		it('returns a proper north-west LatLng', function() {
			expect(a.getNorthWest()).to.eql(new L.LatLng(a.getNorth(), a.getWest()));
		});
 
	});
 
	describe('#getSouthEast', function () {
		it('returns a proper south-east LatLng', function() {
			expect(a.getSouthEast()).to.eql(new L.LatLng(a.getSouth(), a.getEast()));
		});
	});
 
	describe('#contains', function () {
		it('returns true if contains latlng point', function () {
			expect(a.contains([16, 20])).to.eql(true);
			expect(L.latLngBounds(a).contains([5, 20])).to.eql(false);
		});
 
		it('returns true if contains bounds', function () {
			expect(a.contains([[16, 20], [20, 40]])).to.eql(true);
			expect(a.contains([[16, 50], [8, 40]])).to.eql(false);
		});
	});
 
	describe('#intersects', function () {
		it('returns true if intersects the given bounds', function () {
			expect(a.intersects([[16, 20], [50, 60]])).to.eql(true);
			expect(a.contains([[40, 50], [50, 60]])).to.eql(false);
		});
	});
 
});