yzt
2023-05-26 2f70f6727314edd84d8ec2bfe3ce832803f1ea77
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { Cartesian3 } from "../../Source/Cesium.js";
import { Math as CesiumMath } from "../../Source/Cesium.js";
import { TridiagonalSystemSolver } from "../../Source/Cesium.js";
 
describe("Core/TridiagonalSystemSolver", function () {
  it("solve throws exception without lower diagonal", function () {
    expect(function () {
      TridiagonalSystemSolver.solve();
    }).toThrowDeveloperError();
  });
 
  it("solve throws exception without diagonal", function () {
    expect(function () {
      TridiagonalSystemSolver.solve([]);
    }).toThrowDeveloperError();
  });
 
  it("solve throws exception without upper diagonal", function () {
    expect(function () {
      TridiagonalSystemSolver.solve([], []);
    }).toThrowDeveloperError();
  });
 
  it("solve throws exception without rhs vector", function () {
    expect(function () {
      TridiagonalSystemSolver.solve([], [], []);
    }).toThrowDeveloperError();
  });
 
  it("solve throws exception when rhs vector length is not equal to diagonal length", function () {
    expect(function () {
      TridiagonalSystemSolver.solve([], [], [], [1]);
    }).toThrowDeveloperError();
  });
 
  it("solve throws exception when lower diagonal length is not equal to upper diagonal length", function () {
    expect(function () {
      TridiagonalSystemSolver.solve([1], [1], [], [1]);
    }).toThrowDeveloperError();
  });
 
  it("solve throws exception when lower/upper diagonal length is not one less than diagonal length", function () {
    expect(function () {
      TridiagonalSystemSolver.solve([1], [1], [1], [1]);
    }).toThrowDeveloperError();
  });
 
  it("solve three unknowns", function () {
    var l = [1.0, 1.0];
    var d = [-2.175, -2.15, -2.125];
    var u = [1.0, 1.0];
    var r = [
      new Cartesian3(-1.625),
      new Cartesian3(0.5),
      new Cartesian3(1.625),
    ];
 
    var expected = [
      new Cartesian3(0.552),
      new Cartesian3(-0.4244),
      new Cartesian3(-0.9644),
    ];
    var actual = TridiagonalSystemSolver.solve(l, d, u, r);
 
    expect(actual.length).toEqual(expected.length);
    expect(actual[0]).toEqualEpsilon(expected[0], CesiumMath.EPSILON4);
    expect(actual[1]).toEqualEpsilon(expected[1], CesiumMath.EPSILON4);
    expect(actual[2]).toEqualEpsilon(expected[2], CesiumMath.EPSILON4);
  });
 
  it("solve nine unknowns", function () {
    var l = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0];
    var d = [
      -2.0304,
      -2.0288,
      -2.0272,
      -2.0256,
      -2.024,
      -2.0224,
      -2.0208,
      -2.0192,
      -2.0176,
    ];
    var u = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0];
    var r = [
      new Cartesian3(-1.952),
      new Cartesian3(0.056),
      new Cartesian3(0.064),
      new Cartesian3(0.072),
      new Cartesian3(0.08),
      new Cartesian3(0.088),
      new Cartesian3(0.096),
      new Cartesian3(0.104),
      new Cartesian3(1.112),
    ];
 
    var expected = [
      new Cartesian3(1.3513),
      new Cartesian3(0.7918),
      new Cartesian3(0.311),
      new Cartesian3(-0.0974),
      new Cartesian3(-0.4362),
      new Cartesian3(-0.7055),
      new Cartesian3(-0.9025),
      new Cartesian3(-1.0224),
      new Cartesian3(-1.0579),
    ];
    var actual = TridiagonalSystemSolver.solve(l, d, u, r);
 
    expect(actual.length).toEqual(expected.length);
    expect(actual[0]).toEqualEpsilon(expected[0], CesiumMath.EPSILON4);
    expect(actual[1]).toEqualEpsilon(expected[1], CesiumMath.EPSILON4);
    expect(actual[2]).toEqualEpsilon(expected[2], CesiumMath.EPSILON4);
    expect(actual[3]).toEqualEpsilon(expected[3], CesiumMath.EPSILON4);
    expect(actual[4]).toEqualEpsilon(expected[4], CesiumMath.EPSILON4);
    expect(actual[5]).toEqualEpsilon(expected[5], CesiumMath.EPSILON4);
    expect(actual[6]).toEqualEpsilon(expected[6], CesiumMath.EPSILON4);
    expect(actual[7]).toEqualEpsilon(expected[7], CesiumMath.EPSILON4);
    expect(actual[8]).toEqualEpsilon(expected[8], CesiumMath.EPSILON4);
  });
});