-
Notifications
You must be signed in to change notification settings - Fork 192
/
Copy pathrunner.js
65 lines (53 loc) · 1.3 KB
/
runner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* Module dependencies.
*/
var should = require('../');
function test(name, fn){
try {
fn();
} catch (err) {
console.log(' \x1b[31m%s', name);
console.log(' %s\x1b[0m', err.stack);
return;
}
console.log(' √ \x1b[32m%s\x1b[0m', name);
}
function Point(x, y) {
this.x = x;
this.y = y;
this.sub = function(other){
return new Point(
this.x - other.x
, this.y - other.y);
}
}
console.log();
test('new Point(x, y)', function(){
var point = new Point(50, 100);
point.should.be.an.instanceof(Point);
point.should.have.property('x', 50);
point.should.have.property('y', 100);
});
test('Point#sub()', function(){
var a = new Point(50, 100)
, b = new Point(20, 50);
a.sub(b).should.be.an.instanceof(Point);
a.sub(b).should.not.equal(a);
a.sub(b).should.not.equal(b);
a.sub(b).should.have.property('x', 30);
a.sub(b).should.have.property('y', 50);
});
test('Point#add()', function(){
var point = new Point(50, 100);
point.should.have.not.property('add');
});
test('Math#sin()', function(){
Math.sin(12).should.be.approximately(-0.5365, 1e-3);
});
test('Math#cos()', function(){
Math.cos(0).should.not.be.approximately(10, 1e-3);
});
test('Math#log()', function(){
Math.log(10).should.be.approximately(2.3, 1e-1);
});
console.log();