2 * @fileoverview Tests for data formats.
4 * @author konigsberg@google.com (Robert Konigsberg)
6 describe("formats", function() {
8 beforeEach(function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
12 afterEach(function() {
27 var BASE_OPTS
= {labels
: ['X', 'Y']};
29 it('testCsv', function() {
30 var data
= dataString
;
31 var graph
= document
.getElementById("graph");
32 var g
= new Dygraph(graph
, data
, {});
36 it('testArray', function() {
38 var graph
= document
.getElementById("graph");
39 var g
= new Dygraph(graph
, data
, BASE_OPTS
);
43 it('testFunctionReturnsCsv', function() {
44 var data
= function() { return dataString
; };
46 var graph
= document
.getElementById("graph");
47 var g
= new Dygraph(graph
, data
, {});
51 it('testFunctionDefinesArray', function() {
52 var array
= dataArray
;
53 var data
= function() { return array
; }
55 var graph
= document
.getElementById("graph");
56 var g
= new Dygraph(graph
, data
, BASE_OPTS
);
60 it('testXValueParser', function() {
68 var graph
= document
.getElementById("graph");
69 var g
= new Dygraph(graph
, data
, {
70 xValueParser
: function(str
) {
71 assert
.equal(1, str
.length
);
72 return str
.charCodeAt(0) - "a".charCodeAt(0);
76 assert
.equal(3, g
.getValue(0, 0));
77 assert
.equal(4, g
.getValue(1, 0));
78 assert
.equal(5, g
.getValue(2, 0));
79 assert
.equal(6, g
.getValue(3, 0));
82 var assertData
= function(g
) {
83 var expected
= dataArray
;
85 assert
.equal(4, g
.numRows());
86 assert
.equal(2, g
.numColumns());
88 for (var i
= 0; i
< 4; i
++) {
89 for (var j
= 0; j
< 2; j
++) {
90 assert
.equal(expected
[i
][j
], g
.getValue(i
, j
));