| 1 | /** |
| 2 | * @fileoverview Tests for data formats. |
| 3 | * |
| 4 | * @author konigsberg@google.com (Robert Konigsberg) |
| 5 | */ |
| 6 | var FormatsTestCase = TestCase("formats"); |
| 7 | |
| 8 | FormatsTestCase.prototype.setUp = function() { |
| 9 | document.body.innerHTML = "<div id='graph'></div>"; |
| 10 | }; |
| 11 | |
| 12 | FormatsTestCase.prototype.tearDown = function() { |
| 13 | }; |
| 14 | |
| 15 | FormatsTestCase.prototype.dataString = |
| 16 | "X,Y\n" + |
| 17 | "0,-1\n" + |
| 18 | "1,0\n" + |
| 19 | "2,1\n" + |
| 20 | "3,0\n"; |
| 21 | |
| 22 | FormatsTestCase.prototype.dataArray = |
| 23 | [[0,-1], |
| 24 | [1,0], |
| 25 | [2,1], |
| 26 | [3,0]]; |
| 27 | |
| 28 | FormatsTestCase.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 | |
| 35 | FormatsTestCase.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 | |
| 42 | FormatsTestCase.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 | |
| 52 | FormatsTestCase.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 | |
| 61 | FormatsTestCase.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 | } |