forked from CesiumGS/cesium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLagrangePolynomialApproximationSpec.js
46 lines (40 loc) · 2.12 KB
/
LagrangePolynomialApproximationSpec.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
/*global defineSuite*/
defineSuite([
'Core/LagrangePolynomialApproximation'
], function(
LagrangePolynomialApproximation) {
"use strict";
/*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn*/
//The results of these specs were validated against STK Components
//an aerospace SDK available from Analytical Graphics. www.agi.com/components/
var xTable = [0, 60, 120, 180, 240, 300, 360, 420];
var yTable = [
13378137.0000000, 0.000000000, 0,
13374128.3576279, 327475.593690065, 0,
13362104.8328212, 654754.936954423, 0,
13342073.6310691, 981641.896976832, 0,
13314046.7567223, 1307940.576089510, 0,
13278041.0057990, 1633455.429171170, 0,
13234077.9559193, 1957991.380833850, 0,
13182183.9533740, 2281353.942328160, 0
];
var x = 100.0;
it('interpolation produces correct results.', function() {
var result = LagrangePolynomialApproximation.interpolateOrderZero(x, xTable, yTable, 3);
var expectedResult = [13367002.870928623, 545695.7388100647, 0];
expect(result).toEqualEpsilon(expectedResult, 1e-15);
});
it('interpolation produces correct results with a result parameter', function() {
var result = new Array(3);
var returnedResult = LagrangePolynomialApproximation.interpolateOrderZero(x, xTable, yTable, 3, result);
var expectedResult = [13367002.870928623, 545695.7388100647, 0];
expect(result).toBe(returnedResult);
expect(result).toEqualEpsilon(expectedResult, 1e-15);
});
it('getRequiredDataPoints should be 1 more than degree, except for 0, which requires 2', function() {
expect(LagrangePolynomialApproximation.getRequiredDataPoints(0)).toEqual(2);
expect(LagrangePolynomialApproximation.getRequiredDataPoints(1)).toEqual(2);
expect(LagrangePolynomialApproximation.getRequiredDataPoints(2)).toEqual(3);
expect(LagrangePolynomialApproximation.getRequiredDataPoints(3)).toEqual(4);
});
});