diff --git a/test/index.html b/test/index.html index e43d5bc22a..b271f302c1 100644 --- a/test/index.html +++ b/test/index.html @@ -17,6 +17,7 @@ + diff --git a/test/spec/api/geom/point.test.js b/test/spec/api/geom/point.test.js new file mode 100644 index 0000000000..70736921e1 --- /dev/null +++ b/test/spec/api/geom/point.test.js @@ -0,0 +1,134 @@ +describe("ol.geom.point", function() { + var pNoArgs, + pNoZ_arr, + pWithZ_arr, + p_arr, + pNoZ_obj, + pWithZ_obj, + p_obj, + proj = "EPSG:4326"; + + var instances = { + "no arguments passed": ol.geom.point(), + "one argument passed": ol.geom.point([21, 4]), + "one argument passed": ol.geom.point([21, 4, 8]), + "one argument passed": ol.geom.point([21, 4, 8, proj]), + "one argument passed": ol.geom.point({x: 21, y: 4}), + "one argument passed": ol.geom.point({x: 21, y: 4, z: 8}), + "one argument passed": ol.geom.point({x: 21, y: 4, z: 8, projection: proj}) + }; + + beforeEach(function() { + proj = ol.projection("EPSG:4326"); + instances = { + "no arguments passed": ol.geom.point(), + "one argument passed": ol.geom.point([21, 4]), + "one argument passed": ol.geom.point([21, 4, 8]), + "one argument passed": ol.geom.point([21, 4, 8, proj]), + "one argument passed": ol.geom.point({x: 21, y: 4}), + "one argument passed": ol.geom.point({x: 21, y: 4, z: 8}), + "one argument passed": ol.geom.point({x: 21, y: 4, z: 8, projection: proj}) + }; + pNoArgs = instances["no arguments passed"]; + pNoZ_arr = instances["one argument passed"]; + pWithZ_arr = instances["one argument passed"]; + p_arr = instances["one argument passed"]; + pNoZ_obj = instances["one argument passed"]; + pWithZ_obj = instances["one argument passed"]; + p_obj = instances["one argument passed"]; + }); + + afterEach(function() { + pNoArgs = null; + pNoZ_arr = pWithZ_arr = p_arr = null; + PNoZ_obj = pWithZ_obj = p_obj = null; + instances = { + "no arguments passed": ol.geom.point(), + "one argument passed": ol.geom.point([21, 4]), + "one argument passed": ol.geom.point([21, 4, 8]), + "one argument passed": ol.geom.point([21, 4, 8, proj]), + "one argument passed": ol.geom.point({x: 21, y: 4}), + "one argument passed": ol.geom.point({x: 21, y: 4, z: 8}), + "one argument passed": ol.geom.point({x: 21, y: 4, z: 8, projection: proj}) + }; + }); + + for (instancesDesc in instances) { + if (instances.hasOwnProperty(instancesDesc)) { + var instance = instances[instancesDesc]; + + it("constructs instances (" + instancesDesc + ")", function() { + expect(instance).toEqual(jasmine.any(ol.geom.Point)); + }); + + it("constructs instances of ol.geom.Geometry (" + instancesDesc + ")", function() { + expect(instance).toEqual(jasmine.any(ol.geom.Geometry)); + }); + + it("has the coordinate accessor methods (" + instancesDesc + ")", function() { + expect(instance.getX).not.toBeUndefined(); + expect(instance.getY).not.toBeUndefined(); + expect(instance.getZ).not.toBeUndefined(); + expect(instance.setX).not.toBeUndefined(); + expect(instance.setY).not.toBeUndefined(); + expect(instance.setZ).not.toBeUndefined(); + }); + + it("has the projection accessor methods (" + instancesDesc + ")", function() { + expect(instance.getProjection).not.toBeUndefined(); + expect(instance.setProjection).not.toBeUndefined(); + }); + } + } + + it("has functional getters (no arguments passed)", function(){ + expect(pNoArgs.getX()).toBe(0); + expect(pNoArgs.getY()).toBe(0); + expect(pNoArgs.getZ()).toBeUndefined(); + expect(pNoArgs.getProjection()).toBeNull(); + }); + + it("has functional getters (one argument passed)", function(){ + expect(pNoZ_arr.getX()).toBe(21); + expect(pNoZ_arr.getY()).toBe(4); + expect(pNoZ_arr.getZ()).toBeUndefined(); + expect(pNoZ_arr.getProjection()).toBeNull(); + }); + + it("has functional getters (one argument passed)", function(){ + expect(pWithZ_arr.getX()).toBe(21); + expect(pWithZ_arr.getY()).toBe(4); + expect(pWithZ_arr.getZ()).toBe(8); + expect(pWithZ_arr.getProjection()).toBeNull(); + }); + + it("has functional getters (one argument passed)", function(){ + expect(p_arr.getX()).toBe(21); + expect(p_arr.getY()).toBe(4); + expect(p_arr.getZ()).toBe(8); + expect(p_arr.getProjection()).not.toBeNull(); + expect(p_arr.getProjection()).toEqual(jasmine.any(ol.Projection)); + }); + + it("has functional getters (one argument passed)", function(){ + expect(pNoZ_obj.getX()).toBe(21); + expect(pNoZ_obj.getY()).toBe(4); + expect(pNoZ_obj.getZ()).toBeUndefined(); + expect(pNoZ_obj.getProjection()).toBeNull(); + }); + + it("has functional getters (one argument passed)", function(){ + expect(pWithZ_obj.getX()).toBe(21); + expect(pWithZ_obj.getY()).toBe(4); + expect(pWithZ_obj.getZ()).toBe(8); + expect(pWithZ_obj.getProjection()).toBeNull(); + }); + + it("has functional getters (one argument passed)", function(){ + expect(p_obj.getX()).toBe(21); + expect(p_obj.getY()).toBe(4); + expect(p_obj.getZ()).toBe(8); + expect(p_obj.getProjection()).not.toBeNull(); + expect(p_obj.getProjection()).toEqual(jasmine.any(ol.Projection)); + }); +}); diff --git a/test/spec/ol/geom/Point.test.js b/test/spec/ol/geom/Point.test.js index 0af7941f76..65103b2469 100644 --- a/test/spec/ol/geom/Point.test.js +++ b/test/spec/ol/geom/Point.test.js @@ -1,44 +1,34 @@ describe("ol.geom.Point", function() { - var pNoArgs, - pNoZ_arr, - pWithZ_arr, + var p2Args, + p3Args, + p4Args, p_arr, - pNoZ_obj, - pWithZ_obj, - p_obj, proj = "EPSG:4326"; var instances = { - "no arguments passed": ol.geom.point(), - "one argument [x,y] passed": ol.geom.point([21, 4]), - "one argument [x,y,z] passed": ol.geom.point([21, 4, 8]), - "one argument [x,y,z,projection] passed": ol.geom.point([21, 4, 8, proj]), - "one argument {x,y} passed": ol.geom.point([21, 4]), - "one argument {x,y,z} passed": ol.geom.point([21, 4, 8]), - "one argument {x,y,z,projection} passed": ol.geom.point([21, 4, 8, proj]) + "two arguments , passed": new ol.geom.Point(21, 4), + "three arguments ,, passed": new ol.geom.Point(21, 4, 8), + "four arguments ,,, passed": new ol.geom.Point(21, 4, 8, proj) }; beforeEach(function() { proj = ol.projection("EPSG:4326"); instances = { - "no arguments passed": ol.geom.point(), - "one argument [x,y] passed": ol.geom.point([21, 4]), - "one argument [x,y,z] passed": ol.geom.point([21, 4, 8]), - "one argument [x,y,z,projection] passed": ol.geom.point([21, 4, 8, proj]) + "two arguments , passed": new ol.geom.Point(21, 4), + "three arguments ,, passed": new ol.geom.Point(21, 4, 8), + "four arguments ,,, passed": new ol.geom.Point(21, 4, 8, proj) }; - pNoArgs = instances['no arguments passed']; - pNoZ = instances['one argument [x,y] passed']; - pWithZ = instances['one argument [x,y,z] passed']; - p = instances['one argument [x,y,z,projection] passed']; + p2Args = instances['two arguments , passed']; + p3Args = instances['three arguments ,, passed']; + p4Args = instances['four arguments ,,, passed']; }); afterEach(function() { - pNoArgs = pNoZ = pWithZ = p = null; + p2Args = p3Args = p4Args = null; instances = { - "no arguments passed": ol.geom.point(), - "one argument [x,y] passed": ol.geom.point([21, 4]), - "one argument [x,y,z] passed": ol.geom.point([21, 4, 8]), - "one argument [x,y,z,projection] passed": ol.geom.point([21, 4, 8, proj]) + "two arguments , passed": new ol.geom.Point(21, 4), + "three arguments ,, passed": new ol.geom.Point(21, 4, 8), + "four arguments ,,, passed": new ol.geom.Point(21, 4, 8, proj) }; }); @@ -70,32 +60,27 @@ describe("ol.geom.Point", function() { } } - it("has functional getters (no arguments passed)", function(){ - expect(pNoArgs.getX()).toBe(0); - expect(pNoArgs.getY()).toBe(0); - expect(pNoArgs.getZ()).toBeUndefined(); - expect(pNoArgs.getProjection()).toBeNull(); + it("has functional getters (two arguments , passed)", function(){ + + expect(p2Args.getX()).toBe(21); + expect(p2Args.getY()).toBe(4); + expect(p2Args.getZ()).toBeUndefined(); + expect(p2Args.getProjection()).toBeNull(); }); - it("has functional getters (one argument [x,y] passed)", function(){ - expect(pNoZ.getX()).toBe(21); - expect(pNoZ.getY()).toBe(4); - expect(pNoZ.getZ()).toBeUndefined(); - expect(pNoZ.getProjection()).toBeNull(); + it("has functional getters (three arguments ,, passed)", function(){ + expect(p3Args.getX()).toBe(21); + expect(p3Args.getY()).toBe(4); + expect(p3Args.getZ()).not.toBeUndefined(); + expect(p3Args.getZ()).toBe(8); + expect(p3Args.getProjection()).toBeNull(); }); - it("has functional getters (one argument [x,y,z] passed)", function(){ - expect(pWithZ.getX()).toBe(21); - expect(pWithZ.getY()).toBe(4); - expect(pWithZ.getZ()).toBe(8); - expect(pWithZ.getProjection()).toBeNull(); - }); - - it("has functional getters (one argument [x,y,z,projection] passed)", function(){ - expect(p.getX()).toBe(21); - expect(p.getY()).toBe(4); - expect(p.getZ()).toBe(8); - expect(p.getProjection()).not.toBeNull(); - expect(p.getProjection()).toEqual(jasmine.any(ol.Projection)); + it("has functional getters (four arguments ,,, passed)", function(){ + expect(p4Args.getX()).toBe(21); + expect(p4Args.getY()).toBe(4); + expect(p4Args.getZ()).toBe(8); + expect(p4Args.getProjection()).not.toBeNull(); + expect(p4Args.getProjection()).toBeA(ol.Projection); }); });