[model/dataset][m]: introduce Model module containing basic Dataset and TabularData objects (plus tests).

* NB: current Dataset is basic one running off local data.
This commit is contained in:
rgrp
2011-11-03 09:00:42 +00:00
parent abe387a65e
commit c144dda731
3 changed files with 88 additions and 1 deletions

39
test/dataset.test.js Normal file
View File

@@ -0,0 +1,39 @@
(function ($) {
module("Dataset");
test('new Dataset', function () {
var metadata = {
title: 'My Test Dataset'
, name: '1-my-test-dataset'
, id: 1
};
var indata = {
headers: ['x', 'y', 'z']
, rows: [
{x: 1, y: 2, z: 3}
, {x: 2, y: 4, z: 6}
, {x: 3, y: 6, z: 9}
, {x: 4, y: 8, z: 12}
, {x: 5, y: 10, z: 15}
, {x: 6, y: 12, z: 18}
]
};
var dataset = new RECLINE.Model.Dataset(metadata, indata);
equal(dataset.get('name'), metadata.name);
expect(6);
setTimeout(2);
dataset.getTabularData().then(function(tabularData) {
equal(tabularData.get('headers'), indata.headers);
equal(tabularData.getLength(), 6);
tabularData.getRows(4, 2).then(function(rows) {
equal(rows[0], indata.rows[2]);
});
tabularData.getRows().then(function(rows) {
equal(rows.length, Math.min(10, indata.rows.length));
equal(rows[0], indata.rows[0]);
});
});
});
})(this.jQuery);

View File

@@ -3,9 +3,14 @@
<html>
<head>
<title>Qunit Tests</title>
<script src="../src/deps-min.js"></script>
<link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen" />
<script src="../src/deps-min.js"></script>
<script src="../vendor/backbone/0.5.1/backbone.js"></script>
<script type="text/javascript" src="qunit/qunit.js"></script>
<script type="text/javascript" src="../src/dataset.js"></script>
<script type="text/javascript" src="dataset.test.js"></script>
</head>
<body>
<h1 id="qunit-header">Qunit Tests</h1>