scozv / algo-js

[obsoleted] has been moved to project Tango:
https://github.com/scozv/tango
GNU General Public License v3.0
2 stars 1 forks source link

unit test through reading input file should be implemented #18

Closed scozv closed 10 years ago

scozv commented 10 years ago

From Algo.js of Google Code on September 21, 2013 21:26:42

See unit test of graph, we place lots of input edges data in q-graph.js. It is better to read input file.

Original issue: http://code.google.com/p/algo-js/issues/detail?id=18

scozv commented 10 years ago

It is not easy or quick to read file from browser.

How about use Node.js environment to read file and run our unit tests. If so, we may use Grunt.js to run some tasks.

I have tested the following pattern successfully in Node.js environment and browser, which is inspired by Require.js, comparing require.js with r.js for Node.

// module file 
var env;
if (typeof window !== 'undefined' && window) {
    env = (window.Sorting = window.Sorting || {});
} else if (typeof process !== 'undefined' && process.versions && !!process.versions.node) {
    env = exports;
} else {
    // or throw new Error('invalid environment');
    env = 'invalid environment';
}
(function(Sorting, undefined){
    Sorting.isSorted = function () {};
})(env);

Applying this, we can require(./fileName.js) in Node.js environment, or run JavaScript in browser.

// application file
var Sorting = require('./sorting.js');
Sorting.isSorted();
scozv commented 10 years ago

Due to the limits of drone.io, a CI service, committing and decompressing big file (> 5M) is time-consuming.

So we have to keep big file at local place.