Skip to content

Commit

Permalink
test: ✅ add tests for RIC
Browse files Browse the repository at this point in the history
  • Loading branch information
thkruz committed Jan 15, 2024
1 parent 79c83f4 commit c822f4e
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/coordinate/RIC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions test/coordinate/ClassicalElements.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
83 changes: 83 additions & 0 deletions test/coordinate/RIC.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
69 changes: 69 additions & 0 deletions test/coordinate/__snapshots__/RIC.test.ts.snap
Original file line number Diff line number Diff line change
@@ -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,
},
}
`;

0 comments on commit c822f4e

Please sign in to comment.