Commit | Line | Data |
---|---|---|
0842b24b DV |
1 | /** |
2 | * @fileoverview Tests input data which uses scientific notation. | |
3 | * This is a regression test for | |
4 | * http://code.google.com/p/dygraphs/issues/detail?id=186 | |
5 | * | |
6 | * @author danvk@google.com (Dan Vanderkam) | |
7 | */ | |
89fdcedb | 8 | describe("scientific-notation", function() { |
0842b24b | 9 | |
89fdcedb | 10 | beforeEach(function() { |
0842b24b | 11 | document.body.innerHTML = "<div id='graph'></div>"; |
89fdcedb | 12 | }); |
0842b24b | 13 | |
89fdcedb DV |
14 | afterEach(function() { |
15 | }); | |
0842b24b DV |
16 | |
17 | function getXValues(g) { | |
18 | var xs = []; | |
19 | for (var i = 0; i < g.numRows(); i++) { | |
20 | xs.push(g.getValue(i, 0)); | |
21 | } | |
22 | return xs; | |
23 | } | |
24 | ||
89fdcedb | 25 | it('testScientificInput', function() { |
0842b24b DV |
26 | var data = "X,Y\n" + |
27 | "1.0e1,-1\n" + | |
28 | "2.0e1,0\n" + | |
29 | "3.0e1,1\n" + | |
30 | "4.0e1,0\n" | |
31 | ; | |
32 | ||
33 | var graph = document.getElementById("graph"); | |
34 | var g = new Dygraph(graph, data, {}); | |
dc910fce | 35 | assertDeepCloseTo([10, 20, 30, 40], getXValues(g), 1e-6); |
89fdcedb | 36 | }); |
0842b24b | 37 | |
89fdcedb | 38 | it('testScientificInputPlus', function() { |
0842b24b DV |
39 | var data = "X,Y\n" + |
40 | "1.0e+1,-1\n" + | |
41 | "2.0e+1,0\n" + | |
42 | "3.0e+1,1\n" + | |
43 | "4.0e+1,0\n" | |
44 | ; | |
45 | ||
46 | var graph = document.getElementById("graph"); | |
47 | var g = new Dygraph(graph, data, {}); | |
dc910fce | 48 | assertDeepCloseTo([10, 20, 30, 40], getXValues(g), 1e-6); |
89fdcedb | 49 | }); |
0842b24b | 50 | |
89fdcedb | 51 | it('testScientificInputMinus', function() { |
0842b24b DV |
52 | var data = "X,Y\n" + |
53 | "1.0e-1,-1\n" + | |
54 | "2.0e-1,0\n" + | |
55 | "3.0e-1,1\n" + | |
56 | "4.0e-1,0\n" | |
57 | ; | |
58 | ||
59 | var graph = document.getElementById("graph"); | |
60 | var g = new Dygraph(graph, data, {}); | |
dc910fce | 61 | assertDeepCloseTo([0.1, 0.2, 0.3, 0.4], getXValues(g), 1e-6); |
89fdcedb | 62 | }); |
0842b24b | 63 | |
89fdcedb | 64 | it('testScientificInputMinusCap', function() { |
0842b24b DV |
65 | var data = "X,Y\n" + |
66 | "1.0E-1,-1\n" + | |
67 | "2.0E-1,0\n" + | |
68 | "3.0E-1,1\n" + | |
69 | "4.0E-1,0\n" | |
70 | ; | |
71 | ||
72 | var graph = document.getElementById("graph"); | |
73 | var g = new Dygraph(graph, data, {}); | |
dc910fce | 74 | assertDeepCloseTo([0.1, 0.2, 0.3, 0.4], getXValues(g), 1e-6); |
89fdcedb DV |
75 | }); |
76 | ||
77 | }); |