Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
module.exports = {
assert : {
equal : function(one, two){
return one === two
}
},
run : function(){

},
test : {}
};
module.exports = require('./lib');
1 change: 1 addition & 0 deletions lib/data_structures/linkedList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
20 changes: 20 additions & 0 deletions lib/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var fs = require('fs');

module.exports = {
getHTML: function(url, callback) {

setTimeout(function() {
callback('<html><body>Hello World</body></html>');
}, 10);
},

getFile: function(filename, callback) {

fs.readFile( __dirname + '/' + filename, function (err, data) {
if (err) {
throw err;
}
callback(data.toString());
});
}
};
7 changes: 7 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var myLib = require('./mylib')
, linkedList = require('./data_structures/linkedList');

module.exports = {
myLib: myLib,
LinkedList: linkedList
};
42 changes: 42 additions & 0 deletions lib/mylib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var helper = require('./helper');

module.exports = {
assert:{
equal: function(a,b){
return a === b;
}

},
test:{

},
run: function(){

},

getBodyContent: function(url, callback) {

var secondCB = function(html) {

var bodyContent = html.substring(html.indexOf('<body>')+6, html.indexOf('</body>'));

callback(bodyContent);
};

helper.getHTML(url, secondCB);
},

getFileContent: function(filename,callback){

helper.getFile(filename, function(data){
callback(data);
});
},

fib: function(num) {

if(num <= 2) return 1;

return this.fib(num-1) + this.fib(num-2);
}
};
1 change: 1 addition & 0 deletions lib/testFile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
25 changes: 25 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var syncWait = function(milliseconds) {
var now = new Date().getTime();

var stop = now + milliseconds;

while(stop > new Date().getTime()) {
console.log('waiting...');
}

console.log('done!');
};


console.log('1');
var myFunction = function(callback) {
console.log('2');
setTimeout(callback, 1);
console.log('3');
syncWait(1000);
};

myFunction(function() {
console.log('4');
});
console.log('5');
82 changes: 82 additions & 0 deletions test/object_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
var assert = require('chai').assert;
var myLib = require('../index.js').myLib;

describe('MyLib', function() {
it('should be an object', function () {
assert.equal(typeof(myLib), 'object');
});

it('should have a property called assert that is an object', function() {
assert.equal(typeof(myLib.assert), 'object');
});

it('should have a property called test that is an object', function() {
assert.equal(typeof(myLib.test), 'object');
});

it('should have a property called run that is a function', function() {
assert.equal(typeof(myLib.run), 'function');
});

describe('assert', function() {
it('should have a property called equal that is a function', function() {
assert.equal(typeof(myLib.assert.equal), 'function');
});

describe('equal', function() {
it('should take two parameters and return whether they are equal or not', function() {
assert.equal(true, myLib.assert.equal(5, 5));
});

it('should take two parameters and return whether they are exactly equal or not', function() {
assert.equal(false, myLib.assert.equal(5, '5'));
});
});
});

describe('getBodyContent', function() {

it('should be a function', function() {
assert.equal(typeof(myLib.getBodyContent), 'function');
});

it('should get the HTML of a URL and only return the contents of the <body> tag', function(done) {

var firstCB = function(bodyContent) {
assert.equal('Hello World', bodyContent);
done();
};

myLib.getBodyContent('https://www.google.com/', firstCB);
});
});

describe('getFileContent', function() {

it('should be a function', function() {
assert.equal(typeof(myLib.getFileContent), 'function');
});

it('should get the contents of a file and return it', function(done) {

myLib.getFileContent('testFile.txt', function(content) {
assert.equal('Hello World!', content);
done();
});
});
});

describe('fib', function() {

it('should return the fibonacci number for the provided number', function() {
assert.equal(1, myLib.fib(1));
assert.equal(1, myLib.fib(2));
assert.equal(2, myLib.fib(3));
assert.equal(3, myLib.fib(4));
assert.equal(5, myLib.fib(5));
assert.equal(8, myLib.fib(6));
assert.equal(610, myLib.fib(15));

});
});
});
36 changes: 0 additions & 36 deletions test/test.js

This file was deleted.