First state of a geom package.

This commit is contained in:
Marc Jansen
2012-06-19 18:21:21 +02:00
parent 712070c1f0
commit 450f8f7b74
10 changed files with 384 additions and 1 deletions
+56
View File
@@ -0,0 +1,56 @@
describe("ol.geom.Geometry", function() {
var g;
beforeEach(function() {
g = ol.geom.geometry();
});
afterEach(function() {
g = null;
});
it("constructs instances", function() {
expect(g).toEqual(jasmine.any(ol.geom.Geometry));
console.log(g);
console.log(g.foo);
console.log(g.foo());
});
it("can set bounds", function() {
var oldBounds = g.bounds();
expect(oldBounds).toBeUndefined();
var b = ol.bounds([0,1,2,3]);
g.bounds(b);
var gotBounds = g.bounds();
expect(gotBounds).not.toBeUndefined();
});
it("can get bounds", function() {
var b = ol.bounds([0,1,2,3]);
g.bounds(b);
var gotBounds = g.bounds();
expect(gotBounds).toEqual(jasmine.any(ol.Bounds));
});
it("sets and gets the correct bounds", function() {
var b = ol.bounds([0,1,2,3]);
g.bounds(b);
var gotBounds = g.bounds();
expect(gotBounds.getMinX()).toEqual(0);
expect(gotBounds.getMinY()).toEqual(1);
expect(gotBounds.getMaxX()).toEqual(2);
expect(gotBounds.getMaxY()).toEqual(3);
});
//
});
+73
View File
@@ -0,0 +1,73 @@
describe("ol.geom.Point", function() {
var pNoArgs,
pNoZ,
p;
var instances = {
"no arguments passed": ol.geom.point(),
"only two arguments [x,y] passed": ol.geom.point([21, 4]),
"all arguments passed": ol.geom.point([21, 4, 8])
};
beforeEach(function() {
instances = {
"no arguments passed": ol.geom.point(),
"only two arguments [x,y] passed": ol.geom.point([21, 4]),
"all arguments passed": ol.geom.point([21, 4, 8])
};
pNoArgs = instances['no arguments passed'];
pNoZ = instances['only two arguments [x,y] passed'];
p = instances['all arguments passed'];
});
afterEach(function() {
pNoArgs = pNoZ = p = null;
instances = {
"no arguments passed": pNoArgs,
"only two arguments [x,y] passed": pNoZ,
"all arguments passed": p
};
});
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 mixin 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 functional getters (no arguments passed)", function(){
expect(pNoArgs.getX()).toBe(0);
expect(pNoArgs.getY()).toBe(0);
expect(pNoArgs.getZ()).toBeUndefined();
});
it("has functional getters (only two arguments [x,y] passed)", function(){
expect(pNoZ.getX()).toBe(21);
expect(pNoZ.getY()).toBe(4);
expect(pNoZ.getZ()).toBeUndefined();
});
it("has functional getters (all arguments passed)", function(){
expect(p.getX()).toBe(21);
expect(p.getY()).toBe(4);
expect(p.getZ()).toBe(8);
});
});