From: Robert Konigsberg Date: Sat, 29 Dec 2012 18:23:02 +0000 (-0500) Subject: Move makeNumbers to Util, and reduce number of makeNumbers calls. X-Git-Tag: v1.0.0~138^2~3 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=71a1930b83cd253c64bdb8dd0ed2d1b804a2d42c;p=dygraphs.git Move makeNumbers to Util, and reduce number of makeNumbers calls. --- diff --git a/auto_tests/tests/Util.js b/auto_tests/tests/Util.js index 7fca030..6469bc6 100644 --- a/auto_tests/tests/Util.js +++ b/auto_tests/tests/Util.js @@ -57,3 +57,14 @@ Util.getLegend = function(parent) { return legend.textContent; } + +/** + * Takes in an array of strings and returns an array of floats. + */ +Util.makeNumbers = function(ary) { + var ret = []; + for (var i = 0; i < ary.length; i++) { + ret.push(parseFloat(ary[i])); + } + return ret; +} diff --git a/auto_tests/tests/axis_labels.js b/auto_tests/tests/axis_labels.js index d4812ea..a198288 100644 --- a/auto_tests/tests/axis_labels.js +++ b/auto_tests/tests/axis_labels.js @@ -12,16 +12,6 @@ AxisLabelsTestCase.prototype.setUp = function() { AxisLabelsTestCase.prototype.tearDown = function() { }; -/** - * Takes in an array of strings and returns an array of floats. - */ -function makeNumbers(ary) { - var ret = []; - for (var i = 0; i < ary.length; i++) { - ret.push(parseFloat(ary[i])); - } - return ret; -} AxisLabelsTestCase.prototype.kCloseFloat = 1.0e-10; @@ -78,18 +68,18 @@ AxisLabelsTestCase.prototype.testSmallRangeNearZero = function() { var graph = document.getElementById("graph"); var g = new Dygraph(graph, data, opts); - assertEqualsDelta(makeNumbers(["-0.1","-0.08","-0.06","-0.04","-0.02","0","0.02","0.04","0.06","0.08"]), - makeNumbers(Util.getYLabels()), this.kCloseFloat); + assertEqualsDelta([-0.1, -0.08, -0.06, -0.04, -0.02, 0, 0.02, 0.04, 0.06, 0.08], + Util.makeNumbers(Util.getYLabels()), this.kCloseFloat); opts.valueRange = [-0.05, 0.05]; g.updateOptions(opts); - // TODO(danvk): why '1.00e-2' and not '0.01'? - assertEquals(makeNumbers(["-0.05","-0.04","-0.03","-0.02","-0.01","0","1.00e-2","0.02","0.03","0.04"]), - makeNumbers(Util.getYLabels())); + assertEquals([-0.05, -0.04, -0.03, -0.02, -0.01, 0, 0.01, 0.02, 0.03, 0.04], + Util.makeNumbers(Util.getYLabels())); opts.valueRange = [-0.01, 0.01]; g.updateOptions(opts); - assertEquals(makeNumbers(["-0.01","-8.00e-3","-6.00e-3","-4.00e-3","-2.00e-3","0","2.00e-3","4.00e-3","6.00e-3","8.00e-3"]), makeNumbers(Util.getYLabels())); + assertEquals([-0.01, -8.00e-3, -6.00e-3, -4.00e-3, -2.00e-3, 0, 2.00e-3, 4.00e-3, 6.00e-3, 8.00e-3], + Util.makeNumbers(Util.getYLabels())); g.setSelection(1); assertEquals('1: Y:0', Util.getLegend());