From: Dan Vanderkam Date: Sun, 29 Mar 2015 03:15:31 +0000 (-0400) Subject: tests for more parsing formats X-Git-Tag: v2.0.0~66^2~2 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=a907c94dfb7693a6e721c78012bdf36719da0b19;p=dygraphs.git tests for more parsing formats --- diff --git a/auto_tests/tests/parser.js b/auto_tests/tests/parser.js index 55df841..e74cbef 100644 --- a/auto_tests/tests/parser.js +++ b/auto_tests/tests/parser.js @@ -50,9 +50,22 @@ it('testParseDosNewlines', function() { "3,0\r" ; - var graph = document.getElementById("graph"); - var g = new Dygraph(graph, data, opts); + var g = new Dygraph('graph', data, opts); + assert.equal(0, g.getValue(0, 0)); + assert.equal(-1, g.getValue(0, 1)); + assert.equal(1, g.getValue(1, 0)); + assert.equal(0, g.getValue(1, 1)); + assert.deepEqual(['X', 'Y'], g.getLabels()); +}); + +it('should parse tab-delimited data', function() { + var data = "X\tY\n" + + "0\t-1\n" + + "1\t0\n" + + "2\t1\n" + + "3\t0\n"; + var g = new Dygraph('graph', data); assert.equal(0, g.getValue(0, 0)); assert.equal(-1, g.getValue(0, 1)); assert.equal(1, g.getValue(1, 0)); @@ -60,5 +73,60 @@ it('testParseDosNewlines', function() { assert.deepEqual(['X', 'Y'], g.getLabels()); }); +it('should parse fractions', function() { + var data = "X,Y\n" + + "0,1/4\n" + + "1,2/4\n" + + "2,3/4\n" + + "3,4/4\n"; + var g = new Dygraph('graph', data, {fractions:true}); + + assert.equal(0, g.getValue(0, 0)); + assert.deepEqual([1, 4], g.getValue(0, 1)); + assert.equal(1, g.getValue(1, 0)); + assert.deepEqual([2, 4], g.getValue(1, 1)); + assert.deepEqual(['X', 'Y'], g.getLabels()); +}); + +it('should parse error bars', function() { + var data = "X,Y\n" + + "0,1,4\n" + + "1,2,4\n" + + "2,3,4\n" + + "3,4,4\n"; + var g = new Dygraph('graph', data, {errorBars:true}); + + assert.equal(0, g.getValue(0, 0)); + assert.deepEqual([1, 4], g.getValue(0, 1)); + assert.equal(1, g.getValue(1, 0)); + assert.deepEqual([2, 4], g.getValue(1, 1)); + assert.deepEqual(['X', 'Y'], g.getLabels()); +}); + +it('should parse custom bars', function() { + var data = "X,Y1,Y2\n" + + "1,10;20;30,20;5;25\n" + + "2,10;25;35,20;10;25\n"; + var g = new Dygraph('graph', data, {customBars:true}); + + assert.equal(1, g.getValue(0, 0)); + assert.deepEqual([10, 20, 30], g.getValue(0, 1)); + assert.deepEqual([20, 5, 25], g.getValue(0, 2)); + assert.equal(2, g.getValue(1, 0)); + assert.deepEqual([10, 25, 35], g.getValue(1, 1)); + assert.deepEqual([20, 10, 25], g.getValue(1, 2)); + assert.deepEqual(['X', 'Y1', 'Y2'], g.getLabels()); +}); + +/* +it('should warn on unsorted input', function() { +}); + +it('should warn on different length columns', function() { +}); + +it('should detect double-labeled data', function() { +}); +*/ });