From 4dd3e695a463e3e88626eb7b486a2ce1e63b06b9 Mon Sep 17 00:00:00 2001 From: Marc Jansen Date: Fri, 22 Jun 2012 17:25:03 +0200 Subject: [PATCH] Test the getCentroid/centroid Method of linestrings --- test/spec/api/geom/linestring.test.js | 20 ++++++++++++++++++++ test/spec/ol/geom/LineString.test.js | 19 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/test/spec/api/geom/linestring.test.js b/test/spec/api/geom/linestring.test.js index 3a4101bc6d..2b401de42b 100644 --- a/test/spec/api/geom/linestring.test.js +++ b/test/spec/api/geom/linestring.test.js @@ -216,6 +216,26 @@ describe("ol.geom.linestring", function() { expect(ls.vertices().length).toBe(0); }); }); + + describe("the centroid method is functional", function(){ + it("returns an instance of ol.geom.Point", function(){ + expect(ls.centroid()).toBeA(ol.geom.Point); + }); + + it("has the expected coordinates", function(){ + + ls = ol.geom.linestring([ + ol.geom.point([0.5, 1]), + ol.geom.point([1, 1.5]), + ol.geom.point([1.5, 1]), + ol.geom.point([1, 0.5]) + ]); + + var c = ls.centroid(); + + expect(c.x() + ',' + c.y()).toBe('1,1'); + }); + }); }); diff --git a/test/spec/ol/geom/LineString.test.js b/test/spec/ol/geom/LineString.test.js index 4160958b71..5ddf06f43f 100644 --- a/test/spec/ol/geom/LineString.test.js +++ b/test/spec/ol/geom/LineString.test.js @@ -109,4 +109,23 @@ describe("ol.geom.LineString", function() { expect( vertices[1].getX() + ',' + vertices[1].getY()).toBe( '10,20' ); expect( vertices[2].getX() + ',' + vertices[2].getY()).toBe( '30,40' ); }); + + describe("the getCentroid method is functional", function(){ + it("returns an instance of ol.geom.Point", function(){ + expect(ls.getCentroid()).toBeA(ol.geom.Point); + }); + + it("has the expected coordinates", function(){ + + ls.setVertices([ + new ol.geom.Point(0.5, 1), + new ol.geom.Point(1, 1.5), + new ol.geom.Point(1.5, 1), + new ol.geom.Point(1, 0.5) + ]); + var c = ls.getCentroid(); + + expect(c.getX() + ',' + c.getY()).toBe('1,1'); + }); + }); });