2010-09-13 19:58:28 +08:00
|
|
|
describe('Bounds', function() {
|
2012-09-04 06:22:24 +08:00
|
|
|
var a, b, c;
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2010-09-13 19:58:28 +08:00
|
|
|
beforeEach(function() {
|
|
|
|
a = new L.Bounds(
|
|
|
|
new L.Point(14, 12),
|
|
|
|
new L.Point(30, 40));
|
|
|
|
b = new L.Bounds([
|
2012-09-04 06:22:24 +08:00
|
|
|
new L.Point(20, 12),
|
|
|
|
new L.Point(14, 20),
|
|
|
|
new L.Point(30, 40)
|
|
|
|
]);
|
|
|
|
c = new L.Bounds();
|
2010-09-13 19:58:28 +08:00
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2010-09-13 19:58:28 +08:00
|
|
|
describe('constructor', function() {
|
|
|
|
it('should create bounds with proper min & max on (Point, Point)', function() {
|
|
|
|
expect(a.min).toEqual(new L.Point(14, 12));
|
|
|
|
expect(a.max).toEqual(new L.Point(30, 40));
|
|
|
|
});
|
|
|
|
it('should create bounds with proper min & max on (Point[])', function() {
|
|
|
|
expect(b.min).toEqual(new L.Point(14, 12));
|
|
|
|
expect(b.max).toEqual(new L.Point(30, 40));
|
|
|
|
});
|
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2010-09-13 19:58:28 +08:00
|
|
|
describe('#extend', function() {
|
|
|
|
it('should extend the bounds to contain the given point', function() {
|
|
|
|
a.extend(new L.Point(50, 20));
|
|
|
|
expect(a.min).toEqual(new L.Point(14, 12));
|
|
|
|
expect(a.max).toEqual(new L.Point(50, 40));
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2010-09-13 19:58:28 +08:00
|
|
|
b.extend(new L.Point(25, 50));
|
|
|
|
expect(b.min).toEqual(new L.Point(14, 12));
|
|
|
|
expect(b.max).toEqual(new L.Point(30, 50));
|
|
|
|
});
|
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2010-09-13 19:58:28 +08:00
|
|
|
describe('#getCenter', function() {
|
|
|
|
it('should return the center point', function() {
|
|
|
|
expect(a.getCenter()).toEqual(new L.Point(22, 26));
|
|
|
|
});
|
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2011-07-13 19:13:35 +08:00
|
|
|
describe('#contains', function() {
|
2012-09-04 06:22:24 +08:00
|
|
|
it('should contains other bounds or point', function() {
|
|
|
|
a.extend(new L.Point(50, 10));
|
|
|
|
expect(a.contains(b)).toBeTruthy();
|
|
|
|
expect(b.contains(a)).toBeFalsy();
|
|
|
|
expect(a.contains(new L.Point(24, 25))).toBeTruthy();
|
|
|
|
expect(a.contains(new L.Point(54, 65))).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
2012-09-04 06:22:24 +08:00
|
|
|
describe('#isValid', function() {
|
|
|
|
it('should return true if properly set up', function() {
|
|
|
|
expect(a.isValid()).toBeTruthy();
|
|
|
|
});
|
|
|
|
it('should return false if is invalid', function() {
|
|
|
|
expect(c.isValid()).toBeFalsy();
|
|
|
|
});
|
|
|
|
it('should be valid if extended', function() {
|
|
|
|
c.extend([0, 0]);
|
|
|
|
expect(c.isValid()).toBeTruthy();
|
|
|
|
});
|
2011-07-13 19:13:35 +08:00
|
|
|
});
|
2013-02-05 19:51:27 +08:00
|
|
|
|
|
|
|
describe('#getSize', function () {
|
|
|
|
it('should return the size of the bounds as point', function () {
|
|
|
|
expect(a.getSize()).toEqual(new L.Point(16, 28));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#intersects', function () {
|
|
|
|
it('should return true if bounds intersect', function () {
|
|
|
|
expect(a.intersects(b)).toBe(true);
|
|
|
|
expect(a.intersects(new L.Bounds(new L.Point(100, 100), new L.Point(120, 120)))).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('L.bounds factory', function () {
|
|
|
|
it('should create bounds from array of number arrays', function () {
|
|
|
|
var bounds = L.bounds([[14, 12], [30, 40]]);
|
|
|
|
expect(bounds).toEqual(a);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|