From 1f0d53342af1ac99e932e25aba01fe13b4909f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Tue, 25 Sep 2012 00:29:23 +0200 Subject: [PATCH] Jasmine tests for ol.array --- test/ol.html | 1 + test/spec/ol/array.test.js | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 test/spec/ol/array.test.js diff --git a/test/ol.html b/test/ol.html index 7e362c8f88..14a77429b3 100644 --- a/test/ol.html +++ b/test/ol.html @@ -75,6 +75,7 @@ + diff --git a/test/spec/ol/array.test.js b/test/spec/ol/array.test.js new file mode 100644 index 0000000000..850e040f1e --- /dev/null +++ b/test/spec/ol/array.test.js @@ -0,0 +1,48 @@ +goog.require('ol.array'); + +describe('ol.array', function() { + + describe('binaryFindNearest', function() { + it('returns expected value', function() { + var arr = [1000, 500, 100]; + + expect(ol.array.binaryFindNearest(arr, 10000)).toEqual(0); + expect(ol.array.binaryFindNearest(arr, 1000)).toEqual(0); + expect(ol.array.binaryFindNearest(arr, 900)).toEqual(0); + + expect(ol.array.binaryFindNearest(arr, 750)).toEqual(1); + + expect(ol.array.binaryFindNearest(arr, 550)).toEqual(1); + expect(ol.array.binaryFindNearest(arr, 500)).toEqual(1); + expect(ol.array.binaryFindNearest(arr, 450)).toEqual(1); + + expect(ol.array.binaryFindNearest(arr, 300)).toEqual(2); + + expect(ol.array.binaryFindNearest(arr, 200)).toEqual(2); + expect(ol.array.binaryFindNearest(arr, 100)).toEqual(2); + expect(ol.array.binaryFindNearest(arr, 50)).toEqual(2); + }); + }); + + describe('linearFindNearest', function() { + it('returns expected value', function() { + var arr = [1000, 500, 100]; + + expect(ol.array.linearFindNearest(arr, 10000)).toEqual(0); + expect(ol.array.linearFindNearest(arr, 1000)).toEqual(0); + expect(ol.array.linearFindNearest(arr, 900)).toEqual(0); + + expect(ol.array.linearFindNearest(arr, 750)).toEqual(1); + + expect(ol.array.linearFindNearest(arr, 550)).toEqual(1); + expect(ol.array.linearFindNearest(arr, 500)).toEqual(1); + expect(ol.array.linearFindNearest(arr, 450)).toEqual(1); + + expect(ol.array.linearFindNearest(arr, 300)).toEqual(2); + + expect(ol.array.linearFindNearest(arr, 200)).toEqual(2); + expect(ol.array.linearFindNearest(arr, 100)).toEqual(2); + expect(ol.array.linearFindNearest(arr, 50)).toEqual(2); + }); + }); +});