Skip to content

Instantly share code, notes, and snippets.

@Hochul822
Last active August 29, 2015 14:26
Show Gist options
  • Save Hochul822/da1fd4d547daba3fa203 to your computer and use it in GitHub Desktop.
Save Hochul822/da1fd4d547daba3fa203 to your computer and use it in GitHub Desktop.
exports.abs = function(number){
return number < 0 ? -number : number;
};
exports.pow = function(x, y){
var value = 1;
for( var i = 0; i < y; i++ ){
value *= x;
}
return value;
};
exports.asyncAbs = function(number, cb){
setTimeout(function(){
cb(null, exports.abs(number));
}, 100);
};
var assert = require('assert');
var math = require('../math');
suite('math test', function(){
test('math.pow test', function(){
assert.deepEqual(4, math.pow(2,2));
assert.deepEqual(1, math.pow(1,2));
});
test('math.abs test', function(){
assert.deepEqual(10, math.abs(-10));
assert.deepEqual(10, math.abs(10));
});
test('math.asyncAbs test', function(done){
math.asyncAbs(-10, function(err, number){
assert.ifError(err);
assert.deepEqual(10, number);
done();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment