2 * @fileoverview Tests for data formats.
4 * @author konigsberg@google.com (Robert Konigsberg)
6 var FormatsTestCase
= TestCase("formats");
8 FormatsTestCase
.prototype.setUp
= function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
12 FormatsTestCase
.prototype.tearDown
= function() {
15 FormatsTestCase
.prototype.dataString
=
22 FormatsTestCase
.prototype.dataArray
=
28 FormatsTestCase
.prototype.testCsv
= function() {
29 var data
= this.dataString
;
30 var graph
= document
.getElementById("graph");
31 var g
= new Dygraph(graph
, data
, {});
35 FormatsTestCase
.prototype.testArray
= function() {
36 var data
= this.dataArray
;
37 var graph
= document
.getElementById("graph");
38 var g
= new Dygraph(graph
, data
, {});
42 FormatsTestCase
.prototype.testFunctionReturnsCsv
= function() {
43 var string
= this.dataString
;
44 var data
= function() { return string
; };
46 var graph
= document
.getElementById("graph");
47 var g
= new Dygraph(graph
, data
, {});
48 // this.assertData(g);
52 FormatsTestCase
.prototype.testFunctionDefinesArray
= function() {
53 var array
= this.dataArray
;
54 var data
= function() { return array
; }
56 var graph
= document
.getElementById("graph");
57 var g
= new Dygraph(graph
, data
, {});
61 FormatsTestCase
.prototype.testXValueParser
= function() {
69 var graph
= document
.getElementById("graph");
70 var g
= new Dygraph(graph
, data
, {
71 xValueParser
: function(str
) {
72 assertEquals(1, str
.length
);
73 return str
.charCodeAt(0) - "a".charCodeAt(0);
77 assertEquals(3, g
.getValue(0, 0));
78 assertEquals(4, g
.getValue(1, 0));
79 assertEquals(5, g
.getValue(2, 0));
80 assertEquals(6, g
.getValue(3, 0));
83 FormatsTestCase
.prototype.assertData
= function(g
) {
84 var expected
= this.dataArray
;
86 assertEquals(4, g
.numRows());
87 assertEquals(2, g
.numColumns());
89 for (var i
= 0; i
< 4; i
++) {
90 for (var j
= 0; j
< 2; j
++) {
91 assertEquals(expected
[i
][j
], g
.getValue(i
, j
));