-
Notifications
You must be signed in to change notification settings - Fork 45
/
test.js
40 lines (33 loc) · 1.26 KB
/
test.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
var req = require('request');
var colors = require('colors');
// Start server
require('./app.js')
var newtonUrl = 'http://localhost:3000/';
function request(route, callback){
req(newtonUrl + route, function (error, response, body) {
var value = JSON.parse(body).result;
callback(value);
});
}
function assert(expected, route, name){
expected = JSON.stringify(expected);
request(route, function(result){
result = JSON.stringify(result);
if(expected !== result){
console.log(`Warning: ${name} did not pass test!`.yellow);
console.log(`Expected: ${expected}\nReceived: ${result}`.red);
} else {
console.log(`Test: ${name} passed test`.green);
}
});
}
// Assert that our functions give the proper output
// TODO: give functions more than one test case at a time
assert('2 x', 'simplify/x+x', 'Simplify');
assert('x (x + 2)', 'factor/x^2 + 2x', 'Factor');
assert('2 x + 2', 'derive/x^2 + 2x', 'Derive');
assert('1/3 x^3 + x^2', 'integrate/x^2 + 2x','Integrate');
assert([-2, 0], 'zeroes/x^2 + 2x', 'Zeroes');
assert('12 x + -16', 'tangent/2|x^3', 'Tangent');
assert('60', 'area/2:4|x^3', 'Area Under Curve');
assert('3', 'log/2|8', 'Logarithm');