Test restructuring. No functional change.

This commit is contained in:
Marc Jansen
2012-06-22 13:07:13 +02:00
parent 965a5a13b2
commit 11aedf710b
2 changed files with 199 additions and 189 deletions
+111 -104
View File
@@ -1,4 +1,4 @@
describe("ol.geom.point", function() { describe("ol.geom.point", function() {
var pNoArgs, var pNoArgs,
pNoZ_arr, pNoZ_arr,
pWithZ_arr, pWithZ_arr,
@@ -7,7 +7,7 @@ describe("ol.geom.point", function() {
pWithZ_obj, pWithZ_obj,
p_obj, p_obj,
proj = "EPSG:4326"; proj = "EPSG:4326";
var instances = { var instances = {
"no arguments passed": ol.geom.point(), "no arguments passed": ol.geom.point(),
"one argument <Array[x,y]> passed": ol.geom.point([21, 4]), "one argument <Array[x,y]> passed": ol.geom.point([21, 4]),
@@ -17,7 +17,7 @@ describe("ol.geom.point", function() {
"one argument <Object{x,y,z}> passed": ol.geom.point({x: 21, y: 4, z: 8}), "one argument <Object{x,y,z}> passed": ol.geom.point({x: 21, y: 4, z: 8}),
"one argument <Object{x,y,z,projection}> passed": ol.geom.point({x: 21, y: 4, z: 8, projection: proj}) "one argument <Object{x,y,z,projection}> passed": ol.geom.point({x: 21, y: 4, z: 8, projection: proj})
}; };
beforeEach(function() { beforeEach(function() {
proj = ol.projection("EPSG:4326"); proj = ol.projection("EPSG:4326");
instances = { instances = {
@@ -37,7 +37,7 @@ describe("ol.geom.point", function() {
pWithZ_obj = instances["one argument <Object{x,y,z}> passed"]; pWithZ_obj = instances["one argument <Object{x,y,z}> passed"];
p_obj = instances["one argument <Object{x,y,z,projection}> passed"]; p_obj = instances["one argument <Object{x,y,z,projection}> passed"];
}); });
afterEach(function() { afterEach(function() {
pNoArgs = null; pNoArgs = null;
pNoZ_arr = pWithZ_arr = p_arr = null; pNoZ_arr = pWithZ_arr = p_arr = null;
@@ -52,111 +52,118 @@ describe("ol.geom.point", function() {
"one argument <Object{x,y,z,projection}> passed": ol.geom.point({x: 21, y: 4, z: 8, projection: proj}) "one argument <Object{x,y,z,projection}> passed": ol.geom.point({x: 21, y: 4, z: 8, projection: proj})
}; };
}); });
for (instancesDesc in instances) { for (instancesDesc in instances) {
if (instances.hasOwnProperty(instancesDesc)) { if (instances.hasOwnProperty(instancesDesc)) {
var instance = instances[instancesDesc]; var instance = instances[instancesDesc];
it("constructs instances (" + instancesDesc + ")", function() { describe("instantiate with " + instancesDesc, function() {
expect(instance).toEqual(jasmine.any(ol.geom.Point));
}); it("constructs instances", 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("constructs instances of ol.geom.Geometry", function() {
expect(instance).toEqual(jasmine.any(ol.geom.Geometry));
it("has coordinate getter/setter methods (" + instancesDesc + ")", function() { });
expect(instance.x).not.toBeUndefined();
expect(instance.y).not.toBeUndefined(); it("has coordinate getter/setter methods", function() {
expect(instance.z).not.toBeUndefined(); expect(instance.x).not.toBeUndefined();
expect(instance.y).not.toBeUndefined();
// always a number expect(instance.z).not.toBeUndefined();
expect( !isNaN( instance.x() ) ).toBe(true);
// setter returns self // always a number
expect(instance.x(47)).toBeA(ol.geom.Point); expect( !isNaN( instance.x() ) ).toBe(true);
// getter returns correct number // setter returns self
expect(instance.x()).toBe(47); expect(instance.x(47)).toBeA(ol.geom.Point);
// getter returns correct number
// always a number expect(instance.x()).toBe(47);
expect( !isNaN( instance.y() ) ).toBe(true);
// setter returns self // always a number
expect(instance.y(74)).toBeA(ol.geom.Point); expect( !isNaN( instance.y() ) ).toBe(true);
// getter returns correct number // setter returns self
expect(instance.y()).toBe(74); expect(instance.y(74)).toBeA(ol.geom.Point);
// getter returns correct number
// always number or undefined expect(instance.y()).toBe(74);
expect(instance.z() === undefined || !isNaN(instance.z()) ).toBe(true);
// setter returns self // always number or undefined
expect(instance.z(0.074)).toBeA(ol.geom.Point); expect(instance.z() === undefined || !isNaN(instance.z()) ).toBe(true);
// getter returns correct number // setter returns self
expect(instance.z()).toBe(0.074); expect(instance.z(0.074)).toBeA(ol.geom.Point);
// getter returns correct number
}); expect(instance.z()).toBe(0.074);
it("has projection getter/setter methods (" + instancesDesc + ")", function() { });
expect(instance.projection).not.toBeUndefined();
it("has projection getter/setter methods", function() {
var getRes = instance.projection(); expect(instance.projection).not.toBeUndefined();
expect(getRes === null || getRes instanceof ol.Projection).toBe(true);
var getRes = instance.projection();
var setRes = instance.projection("EPSG:12345"); expect(getRes === null || getRes instanceof ol.Projection).toBe(true);
expect(setRes instanceof ol.geom.Point).toBe(true);
var setRes = instance.projection("EPSG:12345");
getRes = instance.projection(); expect(setRes instanceof ol.geom.Point).toBe(true);
expect(getRes).toBeA(ol.Projection);
expect(getRes.code()).toEqual("EPSG:12345"); getRes = instance.projection();
expect(getRes).toBeA(ol.Projection);
expect(getRes.code()).toEqual("EPSG:12345");
});
}); });
} }
} }
it("has functional getters (no arguments passed)", function(){ describe('the getters are functional', function(){
expect(pNoArgs.x()).toBe(0); it("works when no arguments passed", function(){
expect(pNoArgs.y()).toBe(0); expect(pNoArgs.x()).toBe(0);
expect(pNoArgs.z()).toBeUndefined(); expect(pNoArgs.y()).toBe(0);
expect(pNoArgs.projection()).toBeNull(); expect(pNoArgs.z()).toBeUndefined();
}); expect(pNoArgs.projection()).toBeNull();
});
it("has functional getters (one argument <Array[x,y]> passed)", function(){
expect(pNoZ_arr.x()).toBe(21); it("works when one argument <Array[x,y]> passed", function(){
expect(pNoZ_arr.y()).toBe(4); expect(pNoZ_arr.x()).toBe(21);
expect(pNoZ_arr.z()).toBeUndefined(); expect(pNoZ_arr.y()).toBe(4);
expect(pNoZ_arr.projection()).toBeNull(); expect(pNoZ_arr.z()).toBeUndefined();
}); expect(pNoZ_arr.projection()).toBeNull();
});
it("has functional getters (one argument <Array[x,y,z]> passed)", function(){
expect(pWithZ_arr.x()).toBe(21); it("works when one argument <Array[x,y,z]> passed", function(){
expect(pWithZ_arr.y()).toBe(4); expect(pWithZ_arr.x()).toBe(21);
expect(pWithZ_arr.z()).toBe(8); expect(pWithZ_arr.y()).toBe(4);
expect(pWithZ_arr.projection()).toBeNull(); expect(pWithZ_arr.z()).toBe(8);
}); expect(pWithZ_arr.projection()).toBeNull();
});
it("has functional getters (one argument <Array[x,y,z,projection]> passed)", function(){
expect(p_arr.x()).toBe(21); it("works when one argument <Array[x,y,z,projection]> passed", function(){
expect(p_arr.y()).toBe(4); expect(p_arr.x()).toBe(21);
expect(p_arr.z()).toBe(8); expect(p_arr.y()).toBe(4);
expect(p_arr.projection()).not.toBeNull(); expect(p_arr.z()).toBe(8);
expect(p_arr.projection()).toBeA(ol.Projection); expect(p_arr.projection()).not.toBeNull();
}); expect(p_arr.projection()).toBeA(ol.Projection);
});
it("has functional getters (one argument <Object{x,y}> passed)", function(){
expect(pNoZ_obj.x()).toBe(21); it("works when one argument <Object{x,y}> passed", function(){
expect(pNoZ_obj.y()).toBe(4); expect(pNoZ_obj.x()).toBe(21);
expect(pNoZ_obj.z()).toBeUndefined(); expect(pNoZ_obj.y()).toBe(4);
expect(pNoZ_obj.projection()).toBeNull(); expect(pNoZ_obj.z()).toBeUndefined();
}); expect(pNoZ_obj.projection()).toBeNull();
});
it("has functional getters (one argument <Object{x,y,z}> passed)", function(){
expect(pWithZ_obj.x()).toBe(21); it("works when one argument <Object{x,y,z}> passed", function(){
expect(pWithZ_obj.y()).toBe(4); expect(pWithZ_obj.x()).toBe(21);
expect(pWithZ_obj.z()).toBe(8); expect(pWithZ_obj.y()).toBe(4);
expect(pWithZ_obj.projection()).toBeNull(); expect(pWithZ_obj.z()).toBe(8);
}); expect(pWithZ_obj.projection()).toBeNull();
});
it("has functional getters (one argument <Object{x,y,z,projection}> passed)", function(){
expect(p_obj.x()).toBe(21); it("works when one argument <Object{x,y,z,projection}> passed", function(){
expect(p_obj.y()).toBe(4); expect(p_obj.x()).toBe(21);
expect(p_obj.z()).toBe(8); expect(p_obj.y()).toBe(4);
expect(p_obj.projection()).not.toBeNull(); expect(p_obj.z()).toBe(8);
expect(p_obj.projection()).toEqual(jasmine.any(ol.Projection)); expect(p_obj.projection()).not.toBeNull();
expect(p_obj.projection()).toEqual(jasmine.any(ol.Projection));
});
}); });
}); });
+88 -85
View File
@@ -1,15 +1,15 @@
describe("ol.geom.Point", function() { describe("ol.geom.Point", function() {
var p2Args, var p2Args,
p3Args, p3Args,
p4Args, p4Args,
proj = "EPSG:4326"; proj = "EPSG:4326";
var instances = { var instances = {
"two arguments <x>,<y> passed": new ol.geom.Point(21, 4), "two arguments <x>,<y> passed": new ol.geom.Point(21, 4),
"three arguments <x>,<y>,<z> passed": new ol.geom.Point(21, 4, 8), "three arguments <x>,<y>,<z> passed": new ol.geom.Point(21, 4, 8),
"four arguments <x>,<y>,<z>,<projection> passed": new ol.geom.Point(21, 4, 8, proj) "four arguments <x>,<y>,<z>,<projection> passed": new ol.geom.Point(21, 4, 8, proj)
}; };
beforeEach(function() { beforeEach(function() {
proj = ol.projection("EPSG:4326"); proj = ol.projection("EPSG:4326");
instances = { instances = {
@@ -21,7 +21,7 @@ describe("ol.geom.Point", function() {
p3Args = instances['three arguments <x>,<y>,<z> passed']; p3Args = instances['three arguments <x>,<y>,<z> passed'];
p4Args = instances['four arguments <x>,<y>,<z>,<projection> passed']; p4Args = instances['four arguments <x>,<y>,<z>,<projection> passed'];
}); });
afterEach(function() { afterEach(function() {
p2Args = p3Args = p4Args = null; p2Args = p3Args = p4Args = null;
instances = { instances = {
@@ -30,94 +30,97 @@ describe("ol.geom.Point", function() {
"four arguments <x>,<y>,<z>,<projection> passed": new ol.geom.Point(21, 4, 8, proj) "four arguments <x>,<y>,<z>,<projection> passed": new ol.geom.Point(21, 4, 8, proj)
}; };
}); });
for (instancesDesc in instances) { for (instancesDesc in instances) {
if (instances.hasOwnProperty(instancesDesc)) { if (instances.hasOwnProperty(instancesDesc)) {
var instance = instances[instancesDesc]; var instance = instances[instancesDesc];
it("constructs instances (" + instancesDesc + ")", function() { describe("instantiate with " + instancesDesc, function() {
expect(instance).toEqual(jasmine.any(ol.geom.Point));
it("constructs instances", function() {
expect(instance).toEqual(jasmine.any(ol.geom.Point));
});
it("constructs instances of ol.geom.Geometry", function() {
expect(instance).toEqual(jasmine.any(ol.geom.Geometry));
});
it("has the coordinate accessor methods", 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", function() {
expect(instance.getProjection).not.toBeUndefined();
expect(instance.setProjection).not.toBeUndefined();
});
}); });
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();
});
} }
} }
describe('the getters are functional', function(){
it("has functional getters (two arguments <x>,<y> passed)", function(){ it("works when two arguments <x>,<y> passed", function(){
expect(p2Args.getX()).toBe(21); expect(p2Args.getX()).toBe(21);
expect(p2Args.getY()).toBe(4); expect(p2Args.getY()).toBe(4);
expect(p2Args.getZ()).toBeUndefined(); expect(p2Args.getZ()).toBeUndefined();
expect(p2Args.getProjection()).toBeNull(); expect(p2Args.getProjection()).toBeNull();
});
it("works when three arguments <x>,<y>,<z> 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("works when four arguments <x>,<y>,<z>,<projection> 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);
});
}); });
it("has functional getters (three arguments <x>,<y>,<z> passed)", function(){ describe("transformation is functional", function(){
expect(p3Args.getX()).toBe(21); it("can be transformed", function(){
expect(p3Args.getY()).toBe(4); // save for later comparison
expect(p3Args.getZ()).not.toBeUndefined(); var old = {
expect(p3Args.getZ()).toBe(8); x: p4Args.getX().toFixed(3),
expect(p3Args.getProjection()).toBeNull(); y: p4Args.getY().toFixed(3)
}); };
// with code only
it("has functional getters (four arguments <x>,<y>,<z>,<projection> passed)", function(){ var transformedPoint = p4Args.transform("EPSG:3857");
expect(p4Args.getX()).toBe(21);
expect(p4Args.getY()).toBe(4); // is it still an instance of ol.geom.Point?
expect(p4Args.getZ()).toBe(8); expect(transformedPoint).toBeA(ol.geom.Point);
expect(p4Args.getProjection()).not.toBeNull(); // coordinates OK?
expect(p4Args.getProjection()).toBeA(ol.Projection); expect(transformedPoint.getX().toFixed(3)).toBe("2337709.306");
}); expect(transformedPoint.getY().toFixed(3)).toBe("445640.110");
it("can be transformed", function(){ // with an ol.Projection
// save for later comparison var retransformedPoint = transformedPoint.transform(new ol.Projection("EPSG:4326"));
var old = { expect(retransformedPoint).toBeA(ol.geom.Point);
x: p4Args.getX().toFixed(3),
y: p4Args.getY().toFixed(3) // coordinates shopulkd be the originally configured
}; expect(retransformedPoint.getX().toFixed(3)).toBe(old.x);
// with code only expect(retransformedPoint.getY().toFixed(3)).toBe(old.y);
var transformedPoint = p4Args.transform("EPSG:3857"); });
// is it still an instance of ol.geom.Point? it("throws an exception when you try to transform without a source projection", function(){
expect(transformedPoint).toBeA(ol.geom.Point); expect(function() {
// coordinates OK? p2Args.transform("EPSG:3857");
expect(transformedPoint.getX().toFixed(3)).toBe("2337709.306"); }).toThrow();
expect(transformedPoint.getY().toFixed(3)).toBe("445640.110");
expect(function() {
// with an ol.Projection p3Args.transform("EPSG:3857");
var retransformedPoint = transformedPoint.transform(new ol.Projection("EPSG:4326")); }).toThrow();
expect(retransformedPoint).toBeA(ol.geom.Point); });
// coordinates shopulkd be the originally configured
expect(retransformedPoint.getX().toFixed(3)).toBe(old.x);
expect(retransformedPoint.getY().toFixed(3)).toBe(old.y);
});
it("throws an exception when you try to transform without a source projection", function(){
expect(function() {
p2Args.transform("EPSG:3857");
}).toThrow();
expect(function() {
p3Args.transform("EPSG:3857");
}).toThrow();
}); });
}); });