Skip to content

Commit

Permalink
test: ✅ increase testing to 90%
Browse files Browse the repository at this point in the history
  • Loading branch information
thkruz committed Jan 15, 2024
1 parent b804ded commit ab08816
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/sgp4/sgp4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ export class Sgp4 {
* vallado 2013, 113, alg 9, ex 2-5
* ---------------------------------------------------------------------------
*/
static rv2coe_(
static rv2coe(
r: Vec3Flat,
v: Vec3Flat,
mus: number,
Expand Down
2 changes: 2 additions & 0 deletions src/utils/jacobian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Vector } from '../operations/Vector';
import { JacobianFunction } from '../types/types';
import { array2d } from './functions';

// TODO: #11 Expand documentation of Jacobian function.

Check warning on line 6 in src/utils/jacobian.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected 'todo' comment: 'TODO: #11 Expand documentation of...'

/**
* Calculates the Jacobian matrix of a given Jacobian function.
* @param f The Jacobian function.
Expand Down
17 changes: 17 additions & 0 deletions test/sgp4/__snapshots__/sgp4-full-cov.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Ensure bstar and ndot account for leading zeros rv2coe 1`] = `
Object {
"a": 36127.16533103146,
"arglat": 999999.1,
"argp": 0.9317417321423879,
"ecc": 0.8328526866648804,
"incl": 1.5336055626394494,
"lonper": 999999.1,
"m": 0.13272880776065465,
"nu": 1.6115535789428714,
"omega": 3.9775750028016947,
"p": 11067.78839665728,
"truelon": 999999.1,
}
`;
9 changes: 8 additions & 1 deletion test/sgp4/sgp4-full-cov.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Sgp4OpsMode } from '../../src/enums/Sgp4OpsMode';
import { EciVec3, Sgp4 } from '../../src/main';
import { EciVec3, Sgp4, Vec3Flat } from '../../src/main';
import { Sgp4GravConstants } from '../../src/sgp4/sgp4';
import { sgp4FullCov } from './sgp4-full-cov';
import { sgp4FullCovFail } from './sgp4-full-cov-fail';
Expand Down Expand Up @@ -138,4 +138,11 @@ describe('Ensure bstar and ndot account for leading zeros', () => {

expect(satrec.nddot).toEqual(-0.00023);
});

test('rv2coe', () => {
const r = [6524.834, 6862.875, 6448.296] as Vec3Flat;
const v = [4.901327, 5.533756, -1.976341] as Vec3Flat;

expect(Sgp4.rv2coe(r, v, 398600.8)).toMatchSnapshot();
});
});
47 changes: 47 additions & 0 deletions test/utils/__snapshots__/functions.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ exports[`functions should be calculate acotch 1`] = `Infinity`;

exports[`functions should be calculate acsch 1`] = `0.8813735870195429`;

exports[`functions should be calculate array2d 1`] = `
Array [
Array [
3,
3,
],
]
`;

exports[`functions should be calculate asech 1`] = `0`;

exports[`functions should be calculate concat 1`] = `
Expand All @@ -25,12 +34,50 @@ exports[`functions should be calculate copySign 3`] = `-1`;

exports[`functions should be calculate copySign 4`] = `-1`;

exports[`functions should be calculate covariance 1`] = `0.6666666666666666`;

exports[`functions should be calculate createVec 1`] = `
Array [
1,
]
`;

exports[`functions should be calculate csch 1`] = `0.8509181282393216`;

exports[`functions should be calculate derivative 1`] = `[Function]`;

exports[`functions should be calculate gamma 1`] = `1`;

exports[`functions should be calculate jacobian 1`] = `
Matrix {
"columns": 3,
"elements": Array [
Array [
1.000000000006551,
0,
0,
],
],
"rows": 1,
}
`;

exports[`functions should be calculate linearInterpolate 1`] = `0.75`;

exports[`functions should be calculate log10 1`] = `2`;

exports[`functions should be calculate mean 1`] = `2`;

exports[`functions should be calculate sech 1`] = `0.6480542736638855`;

exports[`functions should be calculate sign 1`] = `1`;

exports[`functions should be calculate sign 2`] = `-1`;

exports[`functions should be calculate spaceObjType2Str 1`] = `"Debris"`;

exports[`functions should be calculate std 1`] = `0.816496580927726`;

exports[`functions should be calculate wrapAngle 1`] = `1`;

exports[`functions should be calculate wrapAngle 2`] = `-1.2831853071795862`;
Expand Down
82 changes: 81 additions & 1 deletion test/utils/functions.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
import { Radians, acoth, acsch, asech, concat, copySign, csch, log10, sech, wrapAngle } from '../../src/main';
import {
Radians,
SpaceObjectType,
acoth,
acsch,
array2d,
asech,
concat,
copySign,
covariance,
createVec,
csch,
derivative,
gamma,
jacobian,
linearInterpolate,
log10,
mean,
sech,
sign,
spaceObjType2Str,
std,
wrapAngle,
} from '../../src/main';

describe('functions', () => {
it('should be calculate log10', () => {
Expand Down Expand Up @@ -50,4 +73,61 @@ describe('functions', () => {
expect(wrapAngle(-5 as Radians)).toMatchSnapshot();
});

// createVec
it('should be calculate createVec', () => {
const vec = createVec(1, 2, 3);

expect(vec).toMatchSnapshot();
});

// spaceObjType2Str
it('should be calculate spaceObjType2Str', () => {
expect(spaceObjType2Str(SpaceObjectType.DEBRIS)).toMatchSnapshot();
});

// sign
it('should be calculate sign', () => {
expect(sign(1)).toMatchSnapshot();
expect(sign(-1)).toMatchSnapshot();
});

// array2d
it('should be calculate array2d', () => {
expect(array2d(1, 2, 3)).toMatchSnapshot();
});

// gamma
it('should be calculate gamma', () => {
expect(gamma(1)).toMatchSnapshot();
});

// derivative
it('should be calculate derivative', () => {
expect(derivative((x: number) => x * x, 1)).toMatchSnapshot();
});

// covariance
it('should be calculate covariance', () => {
expect(covariance([1, 2, 3], [1, 2, 3])).toMatchSnapshot();
});

// std
it('should be calculate std', () => {
expect(std([1, 2, 3])).toMatchSnapshot();
});

// mean
it('should be calculate mean', () => {
expect(mean([1, 2, 3])).toMatchSnapshot();
});

// linearInterpolate
it('should be calculate linearInterpolate', () => {
expect(linearInterpolate(1, 2, 0.5, 0, 1)).toMatchSnapshot();
});

// jacobian
it('should be calculate jacobian', () => {
expect(jacobian((xs: Float64Array) => xs, 1, new Float64Array([1, 2, 3]))).toMatchSnapshot();
});
});

0 comments on commit ab08816

Please sign in to comment.