From c822f4e621208062c41540d83fbb54bbf53d7001 Mon Sep 17 00:00:00 2001 From: Theodore Kruczek Date: Sun, 14 Jan 2024 19:17:25 -0500 Subject: [PATCH] test: :white_check_mark: add tests for RIC --- src/coordinate/RIC.ts | 16 ++-- test/coordinate/ClassicalElements.test.ts | 8 +- test/coordinate/RIC.test.ts | 83 +++++++++++++++++++ .../coordinate/__snapshots__/RIC.test.ts.snap | 69 +++++++++++++++ 4 files changed, 166 insertions(+), 10 deletions(-) create mode 100644 test/coordinate/RIC.test.ts create mode 100644 test/coordinate/__snapshots__/RIC.test.ts.snap diff --git a/src/coordinate/RIC.ts b/src/coordinate/RIC.ts index 14d5789..a5546f2 100644 --- a/src/coordinate/RIC.ts +++ b/src/coordinate/RIC.ts @@ -7,6 +7,14 @@ import { RelativeState } from './RelativeState'; * Represents a Radial-Intrack-Crosstrack (RIC) coordinates. */ export class RIC extends RelativeState { + /** + * Gets the name of the RIC coordinate system. + * @returns The name of the RIC coordinate system. + */ + get name(): string { + return 'RIC'; + } + /** * Creates a new RIC (Radial-Intrack-Crosstrack) coordinate from the J2000 * state vectors. @@ -39,14 +47,6 @@ export class RIC extends RelativeState { return RIC.fromJ2000Matrix(state, origin, RelativeState.createMatrix(origin.position, origin.velocity)); } - /** - * Gets the name of the RIC coordinate system. - * @returns The name of the RIC coordinate system. - */ - get name(): string { - return 'RIC'; - } - /** * Transforms the current RIC coordinate to the J2000 coordinate system using * the provided origin and transform matrix diff --git a/test/coordinate/ClassicalElements.test.ts b/test/coordinate/ClassicalElements.test.ts index 2f3603c..49392ad 100644 --- a/test/coordinate/ClassicalElements.test.ts +++ b/test/coordinate/ClassicalElements.test.ts @@ -114,8 +114,12 @@ describe('ClassicalElements', () => { it('should create ClassicalElements from StateVector', () => { const stateVector = new J2000( EpochUTC.fromDateTime(new Date(1705109326817)), - new Vector3D(1538.223335842895, 5102.261204021967, 4432.634965003577), - new Vector3D(-7.341518909379302, 0.6516718453998644, 1.7933882499861993), + new Vector3D(1538.223335842895 as Kilometers, 5102.261204021967 as Kilometers, 4432.634965003577 as Kilometers), + new Vector3D( + -7.341518909379302 as Kilometers, + 0.6516718453998644 as Kilometers, + 1.7933882499861993 as Kilometers, + ), ); const classicalElements = ClassicalElements.fromStateVector(stateVector); diff --git a/test/coordinate/RIC.test.ts b/test/coordinate/RIC.test.ts new file mode 100644 index 0000000..9bba0d9 --- /dev/null +++ b/test/coordinate/RIC.test.ts @@ -0,0 +1,83 @@ +import { EpochUTC, J2000, Kilometers, Matrix, RIC, Vector3D } from './../../src/main'; + +describe('RIC', () => { + let stateVector: J2000; + let origin: J2000; + + beforeEach(() => { + stateVector = new J2000( + EpochUTC.fromDateTime(new Date(1705109326817)), + new Vector3D(1538.223335842895 as Kilometers, 5102.261204021967 as Kilometers, 4432.634965003577 as Kilometers), + new Vector3D( + -7.341518909379302 as Kilometers, + 0.6516718453998644 as Kilometers, + 1.7933882499861993 as Kilometers, + ), + ); + + origin = new J2000( + EpochUTC.fromDateTime(new Date(1705109326817)), + new Vector3D(1540.223335842895 as Kilometers, 5102.251204021967 as Kilometers, 4432.644965003577 as Kilometers), + new Vector3D( + -7.331518909379302 as Kilometers, + 0.6516718453998644 as Kilometers, + 1.7933882499861993 as Kilometers, + ), + ); + }); + + // Create a new RIC coordinate from J2000 state vectors and origin + it('should create a new RIC coordinate from J2000 state vectors and origin', () => { + const transform = new Matrix([ + [1, 0, 0], + [0, 1, 0], + [0, 0, 1], + ]); + + const ric = RIC.fromJ2000Matrix(stateVector, origin, transform); + + expect(ric).toMatchSnapshot(); + }); + + // Create a RIC coordinate system from a J2000 state and origin + it('should create a RIC coordinate system from a J2000 state and origin', () => { + const ric = RIC.fromJ2000(stateVector, origin); + + expect(ric).toMatchSnapshot(); + }); + + /* + * Transform the current RIC coordinate to the J2000 coordinate system using + * the provided origin + */ + it('should transform the current RIC coordinate to the J2000 coordinate system using the provided origin', () => { + const transform = new Matrix([ + [1, 0, 0], + [0, 1, 0], + [0, 0, 1], + ]); + const ric = new RIC(stateVector.position, stateVector.velocity); + const j2000 = ric.toJ2000Matrix(origin, transform); + + expect(j2000).toMatchSnapshot(); + }); + + /* + * Transform the current RIC coordinate to the J2000 coordinate system using + * the provided origin and transform matrix + */ + it('should transform the current RIC coordinate to J2000 using the provided origin and transform matrix', () => { + const ric = new RIC(stateVector.position, stateVector.velocity); + const j2000 = ric.toJ2000(origin); + + expect(j2000).toMatchSnapshot(); + }); + + // Get the name of the RIC coordinate system + it('should get the name of the RIC coordinate system', () => { + const ric = new RIC(stateVector.position, stateVector.velocity); + const name = ric.name; + + expect(name).toMatchSnapshot(); + }); +}); diff --git a/test/coordinate/__snapshots__/RIC.test.ts.snap b/test/coordinate/__snapshots__/RIC.test.ts.snap new file mode 100644 index 0000000..ac93284 --- /dev/null +++ b/test/coordinate/__snapshots__/RIC.test.ts.snap @@ -0,0 +1,69 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`RIC should create a RIC coordinate system from a J2000 state and origin 1`] = ` +RIC { + "position": Vector3D { + "x": -0.4434101992280181, + "y": 1.9338646031157782, + "z": -0.25249770699242563, + }, + "velocity": Vector3D { + "x": -0.002221880767217895, + "y": 0.009676856714746954, + "z": -0.001192346417169753, + }, +} +`; + +exports[`RIC should create a new RIC coordinate from J2000 state vectors and origin 1`] = ` +RIC { + "position": Vector3D { + "x": -2, + "y": 0.010000000000218279, + "z": -0.010000000000218279, + }, + "velocity": Vector3D { + "x": -0.010000000000000675, + "y": 0, + "z": 0, + }, +} +`; + +exports[`RIC should get the name of the RIC coordinate system 1`] = `"RIC"`; + +exports[`RIC should transform the current RIC coordinate to J2000 using the provided origin and transform matrix 1`] = ` +J2000 { + "epoch": EpochUTC { + "posix": 1705109326.817, + }, + "position": Vector3D { + "x": -2526.8631969362687, + "y": 3698.432701341307, + "z": 9867.307227222767, + }, + "velocity": Vector3D { + "x": -9.379496377921184, + "y": -5.899851460084735, + "z": -1.4349469513344795, + }, +} +`; + +exports[`RIC should transform the current RIC coordinate to the J2000 coordinate system using the provided origin 1`] = ` +J2000 { + "epoch": EpochUTC { + "posix": 1705109326.817, + }, + "position": Vector3D { + "x": 3078.44667168579, + "y": 10204.512408043935, + "z": 8865.279930007155, + }, + "velocity": Vector3D { + "x": -14.673037818758605, + "y": 1.303343690799729, + "z": 3.5867764999723986, + }, +} +`;