Support function() returning other data types.
[dygraphs.git] / auto_tests / tests / formats.js
... / ...
CommitLineData
1/**
2 * @fileoverview Tests for data formats.
3 *
4 * @author konigsberg@google.com (Robert Konigsberg)
5 */
6var FormatsTestCase = TestCase("formats");
7
8FormatsTestCase.prototype.setUp = function() {
9 document.body.innerHTML = "<div id='graph'></div>";
10};
11
12FormatsTestCase.prototype.tearDown = function() {
13};
14
15FormatsTestCase.prototype.dataString =
16 "X,Y\n" +
17 "0,-1\n" +
18 "1,0\n" +
19 "2,1\n" +
20 "3,0\n";
21
22FormatsTestCase.prototype.dataArray =
23 [[0,-1],
24 [1,0],
25 [2,1],
26 [3,0]];
27
28FormatsTestCase.prototype.testCsv = function() {
29 var data = this.dataString;
30 var graph = document.getElementById("graph");
31 var g = new Dygraph(graph, data, {});
32 this.assertData(g);
33};
34
35FormatsTestCase.prototype.testArray = function() {
36 var data = this.dataArray;
37 var graph = document.getElementById("graph");
38 var g = new Dygraph(graph, data, {});
39 this.assertData(g);
40};
41
42FormatsTestCase.prototype.testFunctionReturnsCsv = function() {
43 var string = this.dataString;
44 var data = function() { return string; };
45
46 var graph = document.getElementById("graph");
47 var g = new Dygraph(graph, data, {});
48 // this.assertData(g);
49 console.log("x");
50};
51
52FormatsTestCase.prototype.testFunctionDefinesArray = function() {
53 var array = this.dataArray;
54 var data = function() { return array; }
55
56 var graph = document.getElementById("graph");
57 var g = new Dygraph(graph, data, {});
58 this.assertData(g);
59};
60
61FormatsTestCase.prototype.assertData = function(g) {
62 var expected = this.dataArray;
63
64 assertEquals(4, g.numRows());
65 assertEquals(2, g.numColumns());
66
67 for (var i = 0; i < 4; i++) {
68 for (var j = 0; j < 2; j++) {
69 assertEquals(expected[i][j], g.getValue(i, j));
70 }
71 }
72}