Converted "vector" branch unit tests to mocha, expect.js and sinon

This commit is contained in:
Tobias Bieniek
2013-03-13 04:48:08 +01:00
parent 8273d880d5
commit d5d8afc858
23 changed files with 421 additions and 354 deletions

View File

@@ -6,22 +6,22 @@ describe('ol.geom.LineString', function() {
it('creates a linestring from an array', function() {
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
expect(line).toBeA(ol.geom.LineString);
expect(line).toBeA(ol.geom.Geometry);
expect(line).to.be.a(ol.geom.LineString);
expect(line).to.be.a(ol.geom.Geometry);
});
it('throws when given mismatched dimension', function() {
expect(function() {
var line = new ol.geom.LineString([[10, 20], [30, 40, 50]]);
}).toThrow();
}).to.throwException();
});
it('accepts shared vertices', function() {
var vertices = new ol.geom.SharedVertices();
var l1 = new ol.geom.LineString([[10, 20], [30, 40]], vertices);
var l2 = new ol.geom.LineString([[50, 60], [70, 80]], vertices);
expect(l1.getCoordinates()).toEqual([[10, 20], [30, 40]]);
expect(l2.getCoordinates()).toEqual([[50, 60], [70, 80]]);
expect(l1.getCoordinates()).to.eql([[10, 20], [30, 40]]);
expect(l2.getCoordinates()).to.eql([[50, 60], [70, 80]]);
});
});
@@ -30,12 +30,12 @@ describe('ol.geom.LineString', function() {
it('can be 2', function() {
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
expect(line.dimension).toBe(2);
expect(line.dimension).to.be(2);
});
it('can be 3', function() {
var line = new ol.geom.LineString([[10, 20, 30], [40, 50, 60]]);
expect(line.dimension).toBe(3);
expect(line.dimension).to.be(3);
});
});
@@ -45,10 +45,10 @@ describe('ol.geom.LineString', function() {
it('returns the bounding extent', function() {
var line = new ol.geom.LineString([[10, 20], [20, 30], [30, 40]]);
var bounds = line.getBounds();
expect(bounds.minX).toBe(10);
expect(bounds.minY).toBe(20);
expect(bounds.maxX).toBe(30);
expect(bounds.maxY).toBe(40);
expect(bounds.minX).to.be(10);
expect(bounds.minY).to.be(20);
expect(bounds.maxX).to.be(30);
expect(bounds.maxY).to.be(40);
});
});
@@ -57,7 +57,7 @@ describe('ol.geom.LineString', function() {
it('returns an array', function() {
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
expect(line.getCoordinates()).toEqual([[10, 20], [30, 40]]);
expect(line.getCoordinates()).to.eql([[10, 20], [30, 40]]);
});
});
@@ -74,24 +74,24 @@ describe('ol.geom.LineString', function() {
var id1 = l1.getSharedId();
var id2 = l2.getSharedId();
expect(vertices.coordinates).toEqual(
expect(vertices.coordinates).to.eql(
[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]);
expect(vertices.getStart(id1)).toBe(0);
expect(vertices.getCount(id1)).toBe(2);
expect(vertices.get(id1, 0, 0)).toBe(10);
expect(vertices.get(id1, 0, 1)).toBe(20);
expect(vertices.get(id1, 1, 0)).toBe(30);
expect(vertices.get(id1, 1, 1)).toBe(40);
expect(vertices.getStart(id1)).to.be(0);
expect(vertices.getCount(id1)).to.be(2);
expect(vertices.get(id1, 0, 0)).to.be(10);
expect(vertices.get(id1, 0, 1)).to.be(20);
expect(vertices.get(id1, 1, 0)).to.be(30);
expect(vertices.get(id1, 1, 1)).to.be(40);
expect(vertices.getStart(id2)).toBe(4);
expect(vertices.getCount(id2)).toBe(3);
expect(vertices.get(id2, 0, 0)).toBe(50);
expect(vertices.get(id2, 0, 1)).toBe(60);
expect(vertices.get(id2, 1, 0)).toBe(70);
expect(vertices.get(id2, 1, 1)).toBe(80);
expect(vertices.get(id2, 2, 0)).toBe(90);
expect(vertices.get(id2, 2, 1)).toBe(100);
expect(vertices.getStart(id2)).to.be(4);
expect(vertices.getCount(id2)).to.be(3);
expect(vertices.get(id2, 0, 0)).to.be(50);
expect(vertices.get(id2, 0, 1)).to.be(60);
expect(vertices.get(id2, 1, 0)).to.be(70);
expect(vertices.get(id2, 1, 1)).to.be(80);
expect(vertices.get(id2, 2, 0)).to.be(90);
expect(vertices.get(id2, 2, 1)).to.be(100);
});
});