-
Notifications
You must be signed in to change notification settings - Fork 130
/
test.js
45 lines (32 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
41
42
43
44
45
var kriging = require('./kriging');
function generateTestData(n){
var x = [];
var y = [];
var t = [];
// create a fake dataset where t is 100 when lat is east
for (var i = 0; i < n; i++){
x[i] = (-180)+Math.random()*360;
y[i] = (-90)+Math.random()*180;
t[i] = (x[i] > 0) ? 100 : 0;
}
return [t,x,y];
}
describe('kriging', function(){
this.timeout(50 * 1000);
it('makes a basic prediction', function(done){
var data = generateTestData(100);
var variogram = kriging.train(data[0],data[1],data[2],"exponential", 0, 10);
if (!variogram) return done("variogram is null");
if (kriging.predict(180, 0, variogram) < 50) done("unexpected result (<50)");
if (kriging.predict(-180, 0, variogram) > 50) done("unexpected result (>50)");
done();
});
it('handles 1000 points', function(done){
var data = generateTestData(1000);
var variogram = kriging.train(data[0],data[1],data[2],"exponential", 0, 10);
if (!variogram) return done("variogram is null");
if (kriging.predict(180, 0, variogram) < 50) done("unexpected result (<50)");
if (kriging.predict(-180, 0, variogram) > 50) done("unexpected result (>50)");
done();
});
});