Some minor improvements in the unit tests

This commit is contained in:
mossroy 2013-04-01 17:33:31 +02:00
parent 7eadf1c921
commit 03b33afc63
2 changed files with 54 additions and 37 deletions

View File

@ -7,22 +7,16 @@ define(function (require) {
// we can not read directly the files and run the unit tests
// The user has to select them manually, then launch the tests
$('#runTests').on('click', function(e) {
//QUnit.reset(); // should clear the DOM
//QUnit.init(); // resets the qunit test environment
//QUnit.start(); // allows for the new test to be captured.
runTests();
});
var runTests = function() {
module("environment");
// Dummy test to check that qunit is properly configured
test("qunit test", function() {
equal("test", "test");
equal("test", "test", "QUnit is properly configured");
});
module("evopedia");
test("check title and data files are set", function(){
var titleFile = document.getElementById('titleFile').files[0];
var dataFiles = document.getElementById('dataFiles').files;
@ -30,43 +24,66 @@ define(function (require) {
ok(dataFiles && dataFiles[0] && dataFiles[0].size>0,"First data file set and not empty");
});
asyncTest("check getTitlesSartingAtOffset", function(){
// Create a localArchive from selected files, in order to run the following tests
var localArchive = new evopedia.LocalArchive();
localArchive.titleFile = document.getElementById('titleFile').files[0];
localArchive.dataFiles = document.getElementById('dataFiles').files;
localArchive.language = "small";
localArchive.date = "2010-08-14";
module("evopedia");
asyncTest("check getTitlesStartingAtOffset 0", function(){
var callbackFunction = function(titleList) {
ok(titleList.length>0,"At least one title found");
equal(titleList.length, 4, "4 titles found, as requested");
var indexAbraham=-1;
for (var i=0; i<titleList.length; i++) {
if (titleList[i].name == "Abraham") {
indexAbraham=i;
}
}
ok(indexAbraham>-1,"Title 'Abraham' found");
var firstTitleName = titleList[0].name;
var secondTitleName = titleList[1].name;
// These tests do not work for now : the algorithm has to be fixed
// TODO : fix the algorithm, so that these tests can work
//equal(firstTitleName,"Abbasid_Caliphate","First article name is 'Abbasid_Caliphate'");
//equal(secondTitleName,"Abortion","Second article name is 'Abortion'");
start();
};
localArchive.getTitlesStartingAtOffset(0, 4, callbackFunction);
});
var localArchive = new evopedia.LocalArchive();
localArchive.titleFile = document.getElementById('titleFile').files[0];
localArchive.dataFiles = document.getElementById('dataFiles').files;
localArchive.getTitlesStartingAtOffset(0, 2, callbackFunction);
//TODO check findTitlesWithPrefix
// Create a title instance for the Article 'Abraham'
var titleAbraham = new evopedia.Title();
titleAbraham.archive = localArchive;
titleAbraham.articleLength = 10071;
titleAbraham.blockOffset = 127640;
titleAbraham.blockStart = 2364940;
titleAbraham.fileNr = 0;
titleAbraham.name = "Abraham";
titleAbraham.titleOffset = 57;
// TODO check parseTitle for Abraham, and for another one with escape characters
// TODO check getTitleByName
test("check parseTitleFromId", function() {
var titleId = "small|2010-08-14|0|57|Abraham|2364940|127640|10071";
var title = evopedia.Title.parseTitleId(localArchive,titleId);
ok(title,"Title instance created");
deepEqual(title,titleAbraham,"Parsing from titleId gives Abraham title");
});
asyncTest("check readArticle", function(){
var callbackFunction = function(htmlArticle) {
ok(htmlArticle.length>0,"Article not empty");
equal(htmlArticle.substring(0,3),"<h1","Article starts with <h1");
equal(htmlArticle.substring(htmlArticle.length - 7,htmlArticle.length - 1),"</div>","Article ends with </div>");
ok(htmlArticle && htmlArticle.length>0,"Article not empty");
// Remove new lines
htmlArticle = htmlArticle.replace(/[\r\n]/g, " ");
ok(htmlArticle.match("^[ \t]*<h1[^>]*>Abraham</h1>"),"'Abraham' title at the beginning");
ok(htmlArticle.match("</div>[ \t]$"),"</div> at the end");
start();
};
var localArchive = new evopedia.LocalArchive();
localArchive.titleFile = document.getElementById('titleFile').files[0];
localArchive.dataFiles = document.getElementById('dataFiles').files;
var title = new evopedia.Title();
title.archive = localArchive;
title.articleLength = 10071;
title.blockOffset = 127640;
title.blockStart = 2364940;
title.fileNr = 0;
title.name = "Abraham";
title.titleOffset = 57;
localArchive.readArticle(title, callbackFunction);
localArchive.readArticle(titleAbraham, callbackFunction);
});
};
});

View File

@ -405,12 +405,12 @@ define(function(require) {
var title = new Title();
var idParts = titleId.split("|");
title.archive = localArchive;
title.fileNr = idParts[2];
title.titleOffset = idParts[3];
title.fileNr = parseInt(idParts[2],10);
title.titleOffset = parseInt(idParts[3],10);
title.name = idParts[4];
title.blockStart = idParts[5];
title.blockOffset = idParts[6];
title.articleLength = idParts[7];
title.blockStart = parseInt(idParts[5],10);
title.blockOffset = parseInt(idParts[6],10);
title.articleLength = parseInt(idParts[7],10);
return title;
};