Merge branch 'PR723'
[dygraphs.git] / auto_tests / tests / scientific_notation.js
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 */
8
9 import Dygraph from '../../src/dygraph';
10 import {assertDeepCloseTo} from './custom_asserts';
11
12 describe("scientific-notation", function() {
13
14 cleanupAfterEach();
15
16 function getXValues(g) {
17 var xs = [];
18 for (var i = 0; i < g.numRows(); i++) {
19 xs.push(g.getValue(i, 0));
20 }
21 return xs;
22 }
23
24 it('testScientificInput', function() {
25 var data = "X,Y\n" +
26 "1.0e1,-1\n" +
27 "2.0e1,0\n" +
28 "3.0e1,1\n" +
29 "4.0e1,0\n"
30 ;
31
32 var graph = document.getElementById("graph");
33 var g = new Dygraph(graph, data, {});
34 assertDeepCloseTo([10, 20, 30, 40], getXValues(g), 1e-6);
35 });
36
37 it('testScientificInputPlus', function() {
38 var data = "X,Y\n" +
39 "1.0e+1,-1\n" +
40 "2.0e+1,0\n" +
41 "3.0e+1,1\n" +
42 "4.0e+1,0\n"
43 ;
44
45 var graph = document.getElementById("graph");
46 var g = new Dygraph(graph, data, {});
47 assertDeepCloseTo([10, 20, 30, 40], getXValues(g), 1e-6);
48 });
49
50 it('testScientificInputMinus', function() {
51 var data = "X,Y\n" +
52 "1.0e-1,-1\n" +
53 "2.0e-1,0\n" +
54 "3.0e-1,1\n" +
55 "4.0e-1,0\n"
56 ;
57
58 var graph = document.getElementById("graph");
59 var g = new Dygraph(graph, data, {});
60 assertDeepCloseTo([0.1, 0.2, 0.3, 0.4], getXValues(g), 1e-6);
61 });
62
63 it('testScientificInputMinusCap', function() {
64 var data = "X,Y\n" +
65 "1.0E-1,-1\n" +
66 "2.0E-1,0\n" +
67 "3.0E-1,1\n" +
68 "4.0E-1,0\n"
69 ;
70
71 var graph = document.getElementById("graph");
72 var g = new Dygraph(graph, data, {});
73 assertDeepCloseTo([0.1, 0.2, 0.3, 0.4], getXValues(g), 1e-6);
74 });
75
76 });