From ab0881663e1b42830c715359c12a59228116acf6 Mon Sep 17 00:00:00 2001 From: Theodore Kruczek Date: Mon, 15 Jan 2024 12:26:21 -0500 Subject: [PATCH] test: :white_check_mark: increase testing to 90% --- src/sgp4/sgp4.ts | 2 +- src/utils/jacobian.ts | 2 + .../__snapshots__/sgp4-full-cov.test.ts.snap | 17 ++++ test/sgp4/sgp4-full-cov.test.ts | 9 +- .../__snapshots__/functions.test.ts.snap | 47 +++++++++++ test/utils/functions.test.ts | 82 ++++++++++++++++++- 6 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 test/sgp4/__snapshots__/sgp4-full-cov.test.ts.snap diff --git a/src/sgp4/sgp4.ts b/src/sgp4/sgp4.ts index 5163170..6d42a15 100644 --- a/src/sgp4/sgp4.ts +++ b/src/sgp4/sgp4.ts @@ -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, diff --git a/src/utils/jacobian.ts b/src/utils/jacobian.ts index 83f8bb1..3ba4ad9 100644 --- a/src/utils/jacobian.ts +++ b/src/utils/jacobian.ts @@ -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. + /** * Calculates the Jacobian matrix of a given Jacobian function. * @param f The Jacobian function. diff --git a/test/sgp4/__snapshots__/sgp4-full-cov.test.ts.snap b/test/sgp4/__snapshots__/sgp4-full-cov.test.ts.snap new file mode 100644 index 0000000..9d61a57 --- /dev/null +++ b/test/sgp4/__snapshots__/sgp4-full-cov.test.ts.snap @@ -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, +} +`; diff --git a/test/sgp4/sgp4-full-cov.test.ts b/test/sgp4/sgp4-full-cov.test.ts index 5980e90..d77c240 100644 --- a/test/sgp4/sgp4-full-cov.test.ts +++ b/test/sgp4/sgp4-full-cov.test.ts @@ -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'; @@ -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(); + }); }); diff --git a/test/utils/__snapshots__/functions.test.ts.snap b/test/utils/__snapshots__/functions.test.ts.snap index e2dc6c5..c8d1faa 100644 --- a/test/utils/__snapshots__/functions.test.ts.snap +++ b/test/utils/__snapshots__/functions.test.ts.snap @@ -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`] = ` @@ -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`; diff --git a/test/utils/functions.test.ts b/test/utils/functions.test.ts index 7728b65..4436130 100644 --- a/test/utils/functions.test.ts +++ b/test/utils/functions.test.ts @@ -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', () => { @@ -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(); + }); });