From d387a311770d32f57a7b086d5bceea56bb1d25f9 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 23 Jan 2013 16:59:08 -0500 Subject: [PATCH] Add tests for new geo utils --- test/spec/util.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/spec/util.js b/test/spec/util.js index c2c645673..24f7e6ca7 100644 --- a/test/spec/util.js +++ b/test/spec/util.js @@ -112,5 +112,26 @@ describe('iD.Util', function() { expect(iD.geo.polygonIntersectsPolygon(outer, inner)).to.be.false; }); }); + + describe("#area", function() { + it('calculates the area of a trapezoid', function() { + var polygon = [[0, 0], [3, 0], [2, 2], [1, 2]]; + expect(iD.geo.area(polygon)).to.eql(4); + }); + }); + + describe('#polygonCentroid', function() { + it('calculates the centroid of a square', function() { + var square = [[0, 0], [0, 2], [2, 2], [2, 0]]; + expect(iD.geo.polygonCentroid(square)).to.eql([1, 1]); + }); + }); + + describe('#pathLength', function() { + it('calculates a simple path length', function() { + var path = [[0, 0], [0, 1], [3, 5]]; + expect(iD.geo.pathLength(path)).to.eql(6); + }); + }); }); });