aboutsummaryrefslogtreecommitdiffstats
path: root/extlib/leaflet/spec/suites/geo
diff options
context:
space:
mode:
Diffstat (limited to 'extlib/leaflet/spec/suites/geo')
-rw-r--r--extlib/leaflet/spec/suites/geo/LatLngBoundsSpec.js1
-rw-r--r--extlib/leaflet/spec/suites/geo/LatLngSpec.js70
-rw-r--r--extlib/leaflet/spec/suites/geo/ProjectionSpec.js42
3 files changed, 113 insertions, 0 deletions
diff --git a/extlib/leaflet/spec/suites/geo/LatLngBoundsSpec.js b/extlib/leaflet/spec/suites/geo/LatLngBoundsSpec.js
new file mode 100644
index 00000000..be9bf12b
--- /dev/null
+++ b/extlib/leaflet/spec/suites/geo/LatLngBoundsSpec.js
@@ -0,0 +1 @@
+describe('LatLngBounds', noSpecs); \ No newline at end of file
diff --git a/extlib/leaflet/spec/suites/geo/LatLngSpec.js b/extlib/leaflet/spec/suites/geo/LatLngSpec.js
new file mode 100644
index 00000000..a7498e71
--- /dev/null
+++ b/extlib/leaflet/spec/suites/geo/LatLngSpec.js
@@ -0,0 +1,70 @@
+describe('LatLng', function() {
+ describe('constructor', function() {
+ it("should set lat and lng", function() {
+ var a = new L.LatLng(25, 74);
+ expect(a.lat).toEqual(25);
+ expect(a.lng).toEqual(74);
+
+ var a = new L.LatLng(-25, -74);
+ expect(a.lat).toEqual(-25);
+ expect(a.lng).toEqual(-74);
+ });
+
+ it("should clamp latitude to lie between -90 and 90", function() {
+ var a = new L.LatLng(150, 0).lat;
+ expect(a).toEqual(90);
+
+ var b = new L.LatLng(-230, 0).lat;
+ expect(b).toEqual(-90);
+ });
+
+ it("should clamp longtitude to lie between -180 and 180", function() {
+ var a = new L.LatLng(0, 190).lng;
+ expect(a).toEqual(-170);
+
+ var b = new L.LatLng(0, 360).lng;
+ expect(b).toEqual(0);
+
+ var c = new L.LatLng(0, 380).lng;
+ expect(c).toEqual(20);
+
+ var d = new L.LatLng(0, -190).lng;
+ expect(d).toEqual(170);
+
+ var e = new L.LatLng(0, -360).lng;
+ expect(e).toEqual(0);
+
+ var f = new L.LatLng(0, -380).lng;
+ expect(f).toEqual(-20);
+ });
+
+ it("should not clamp latitude and longtitude if unbounded flag set to true", function() {
+ var a = new L.LatLng(150, 0, true).lat;
+ expect(a).toEqual(150);
+
+ var b = new L.LatLng(-230, 0, true).lat;
+ expect(b).toEqual(-230);
+
+ var c = new L.LatLng(0, 250, true).lng;
+ expect(c).toEqual(250);
+
+ var d = new L.LatLng(0, -190, true).lng;
+ expect(d).toEqual(-190);
+ });
+ });
+
+ describe('#equals', function() {
+ it("should return 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)).toBe(true);
+ });
+
+ it("should return 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)).toBe(false);
+ });
+ });
+});
+
diff --git a/extlib/leaflet/spec/suites/geo/ProjectionSpec.js b/extlib/leaflet/spec/suites/geo/ProjectionSpec.js
new file mode 100644
index 00000000..6b9c7b61
--- /dev/null
+++ b/extlib/leaflet/spec/suites/geo/ProjectionSpec.js
@@ -0,0 +1,42 @@
+describe("Projection.Mercator", function() {
+ var p = L.Projection.Mercator;
+
+ beforeEach(function() {
+ function almostEqual(a, b, p) {
+ return Math.abs(a - b) <= (p || 1.0E-12);
+ };
+ this.addMatchers({
+ toAlmostEqual: function(expected, margin) {
+ var p1 = this.actual,
+ p2 = expected;
+ return almostEqual(p1.x, p2.x, margin) && almostEqual(p1.y, p2.y, margin);
+ }
+ });
+ });
+
+
+ describe("#project", function() {
+ it("should do projection properly", function() {
+ //edge cases
+ expect(p.project(new L.LatLng(0, 0))).toAlmostEqual(new L.Point(0, 0));
+ expect(p.project(new L.LatLng(90, 180))).toAlmostEqual(new L.Point(-Math.PI, Math.PI));
+ expect(p.project(new L.LatLng(-90, -180))).toAlmostEqual(new L.Point(-Math.PI, -Math.PI));
+
+ expect(p.project(new L.LatLng(50, 30))).toAlmostEqual(new L.Point(0.523598775598, 1.010683188683));
+ });
+ });
+
+ describe("#unproject", function() {
+ it("should do unprojection properly", function() {
+ function pr(point) {
+ return p.project(p.unproject(point));
+ }
+
+ expect(pr(new L.Point(0, 0))).toAlmostEqual(new L.Point(0, 0));
+ expect(pr(new L.Point(-Math.PI, Math.PI))).toAlmostEqual(new L.Point(-Math.PI, Math.PI));
+ expect(pr(new L.Point(-Math.PI, -Math.PI))).toAlmostEqual(new L.Point(-Math.PI, -Math.PI));
+
+ expect(pr(new L.Point(0.523598775598, 1.010683188683))).toAlmostEqual(new L.Point(0.523598775598, 1.010683188683));
+ });
+ });
+}); \ No newline at end of file