-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.test.ts
More file actions
240 lines (211 loc) · 7.91 KB
/
index.test.ts
File metadata and controls
240 lines (211 loc) · 7.91 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import { describe, it, expect } from "vitest";
import constituents from "../../src/constituents/index.js";
import astro from "../../src/astronomy/index.js";
const sampleTime = new Date("2019-10-04T10:15:40.010Z");
const testAstro = astro(sampleTime);
describe("Base constituent definitions", () => {
it("it prepared constituent SA", () => {
expect(constituents.SA.value(testAstro)).toBeCloseTo(192.826398978, 4);
});
it("it prepared constituent SSA", () => {
expect(constituents.SSA.value(testAstro)).toBeCloseTo(385.652797955, 4);
});
it("it prepared constituent M2", () => {
expect(constituents.M2.value(testAstro)).toBeCloseTo(177.008710124, 4);
});
it("computes IHO nodal corrections for M2", () => {
const correction = constituents.M2.correction(testAstro);
expect(correction.u).toBeCloseTo(-2.085704074, 4);
expect(correction.f).toBeCloseTo(1.00886892009, 4);
});
it("computes IHO nodal corrections for M3", () => {
const correction = constituents.M3.correction(testAstro);
expect(correction.u).toBeCloseTo(-3.128556111, 4);
expect(correction.f).toBeCloseTo(1.01333283333, 4);
});
it("has correct properties for LAMBDA2 (alias of LAM2)", () => {
expect(constituents.LAMBDA2).toBeDefined();
expect(constituents.LAMBDA2.speed).toBeCloseTo(29.455626, 2);
});
it("has correct properties for RHO1 (alias of RHO)", () => {
expect(constituents.RHO1).toBeDefined();
const expectedSpeed = constituents.NU2.speed - constituents.K1.speed;
expect(constituents.RHO1.speed).toBeCloseTo(expectedSpeed, 2);
});
it("has correct properties for EP2 (lunar elliptic semi-diurnal)", () => {
expect(constituents.EP2).toBeDefined();
expect(constituents.EP2.speed).toBeCloseTo(27.4238338, 7);
});
it("has correct properties for MA2 (lunar variational semi-diurnal, mu2)", () => {
expect(constituents.MA2).toBeDefined();
expect(constituents.MA2.speed).toBeCloseTo(28.943036, 6);
});
it("has correct properties for MB2 (lunar elliptic parameter variation)", () => {
expect(constituents.MB2).toBeDefined();
expect(constituents.MB2.speed).toBeCloseTo(29.025173, 6);
});
it("has correct properties for SGM (lunar diurnal variational, sigma1)", () => {
expect(constituents.SGM).toBeDefined();
expect(constituents.SGM.speed).toBeCloseTo(12.9271398);
});
// IHO MSqm is a long-period constituent (not the old compound M2+S2+K1)
it("has correct properties for MSQM (long-period, alias of MSqm)", () => {
expect(constituents.MSQM).toBeDefined();
expect(constituents.MSQM.speed).toBeCloseTo(2.1139287, 6);
});
// IHO MKS2 = M2+K2-S2 (semi-diurnal)
it("has correct properties for MKS2 (semi-diurnal M2+K2-S2)", () => {
expect(constituents.MKS2).toBeDefined();
expect(constituents.MKS2.speed).toBeCloseTo(29.0662415, 2);
});
it("has correct properties for N4 (N2 overtide)", () => {
expect(constituents.N4).toBeDefined();
const expectedSpeed = 2 * constituents.N2.speed;
expect(constituents.N4.speed).toBeCloseTo(expectedSpeed, 2);
});
it("has correct properties for T3 (solar elliptic terdiurnal)", () => {
expect(constituents.T3).toBeDefined();
const expectedSpeed = 1.5 * constituents.T2.speed;
expect(constituents.T3.speed).toBeCloseTo(expectedSpeed, 2);
expect(constituents.T3.members).toEqual([{ constituent: constituents.T2, factor: 1.5 }]);
});
it("has correct properties for R3 (solar elliptic terdiurnal)", () => {
expect(constituents.R3).toBeDefined();
const expectedSpeed = 1.5 * constituents.R2.speed;
expect(constituents.R3.speed).toBeCloseTo(expectedSpeed, 2);
expect(constituents.R3.members).toEqual([{ constituent: constituents.R2, factor: 1.5 }]);
});
it("has correct properties for 3L2 (triple L2)", () => {
expect(constituents["3L2"]).toBeDefined();
const expectedSpeed = 3 * constituents.L2.speed;
expect(constituents["3L2"].speed).toBeCloseTo(expectedSpeed, 2);
});
it("has correct properties for 3N2 (triple N2)", () => {
expect(constituents["3N2"]).toBeDefined();
const expectedSpeed = 3 * constituents.N2.speed;
expect(constituents["3N2"].speed).toBeCloseTo(expectedSpeed, 2);
});
it("has correct properties for S3 (solar terdiurnal)", () => {
expect(constituents.S3).toBeDefined();
expect(constituents.S3.speed).toBeCloseTo(45.0, 2);
});
// Null-XDO compound constituents derive V₀ from structural decomposition
it("derives V₀ for MS4 (M2+S2) from structural members", () => {
const expected = constituents.M2.value(testAstro) + constituents.S2.value(testAstro);
expect(constituents.MS4.value(testAstro)).toBeCloseTo(expected, 4);
});
it("derives V₀ for MN4 (M2+N2) from structural members", () => {
const expected = constituents.M2.value(testAstro) + constituents.N2.value(testAstro);
expect(constituents.MN4.value(testAstro)).toBeCloseTo(expected, 4);
});
it("derives V₀ for 2MK3 (2×M2−K1) from structural members", () => {
// Sign resolution: M(2)×2 + K(1)×1 = 5, target=3 → K flipped to −1
const expected = 2 * constituents.M2.value(testAstro) - constituents.K1.value(testAstro);
expect(constituents["2MK3"].value(testAstro)).toBeCloseTo(expected, 4);
});
it("has correct properties for 2MS6 (quarter-diurnal M2-S2 interaction)", () => {
expect(constituents["2MS6"]).toBeDefined();
expect(constituents["2MS6"].speed).toBeCloseTo(87.9682085, 7);
});
it("has correct properties for 2MK5 (fifth-diurnal M2-K1 interaction)", () => {
expect(constituents["2MK5"]).toBeDefined();
const expectedSpeed = 2 * constituents.M2.speed + constituents.K1.speed;
expect(constituents["2MK5"].speed).toBeCloseTo(expectedSpeed, 2);
});
it("has correct properties for 2MO5 (fifth-diurnal M2-O1 interaction)", () => {
expect(constituents["2MO5"]).toBeDefined();
expect(constituents["2MO5"].speed).toBeCloseTo(71.911244, 6);
});
it("has correct properties for MP1 (solar-lunar diurnal)", () => {
expect(constituents.MP1).toBeDefined();
expect(constituents.MP1.speed).toBeCloseTo(14.0251729, 7);
});
// Long-period compounds with explicit members from data.json
it.each([
{
name: "Sta",
members: [
["K2", 1],
["T2", -1],
],
},
{
name: "MSm",
members: [
["M2", 1],
["nu2", -1],
],
},
{
name: "Mnum",
members: [
["M2", 1],
["nu2", -1],
],
},
{
name: "SM",
members: [
["S2", 1],
["M2", -1],
],
},
{
name: "KOo",
members: [
["K1", 1],
["O1", -1],
],
},
{
name: "MKo",
members: [
["K2", 1],
["M2", -1],
],
},
{
name: "SN",
members: [
["S2", 1],
["N2", -1],
],
},
{
name: "MStm",
members: [
["Mf", 1],
["M2", 1],
["nu2", -1],
],
},
{
name: "2SMN",
members: [
["S2", 2],
["M2", -1],
["N2", -1],
],
},
])("$name has explicit members from data.json", ({ name, members: expected }) => {
const c = constituents[name];
expect(c).toBeDefined();
expect(c.members).not.toBeNull();
expect(c.members).toHaveLength(expected.length);
for (let i = 0; i < expected.length; i++) {
expect(c.members![i].constituent).toBe(constituents[expected[i][0] as string]);
expect(c.members![i].factor).toBe(expected[i][1]);
}
});
it("long-period explicit member speeds match constituent speeds", () => {
const longPeriod = ["Sta", "MSm", "Mnum", "SM", "KOo", "MKo", "SN", "MStm", "2SMN"];
for (const name of longPeriod) {
const c = constituents[name];
let computedSpeed = 0;
for (const { constituent, factor } of c.members!) {
computedSpeed += factor * constituent.speed;
}
expect(Math.abs(computedSpeed - c.speed), `${name} speed`).toBeLessThan(0.0001);
}
});
});