Skip to content

Commit

Permalink
test: ✅ add tests for RelativeState
Browse files Browse the repository at this point in the history
  • Loading branch information
thkruz committed Jan 15, 2024
1 parent c822f4e commit d2533d7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/coordinate/RelativeState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export abstract class RelativeState {
* Calculates the range of the relative state.
* @returns The range in kilometers.
*/
range(): Kilometers {
return this.position.magnitude() as Kilometers;
get range(): Kilometers {
return this.position.magnitude();
}

/**
Expand All @@ -79,7 +79,7 @@ export abstract class RelativeState {
*
* @returns The range rate in Kilometers per second.
*/
rangeRate(): number {
return this.position.dot(this.velocity) / this.range();
get rangeRate(): number {
return this.position.dot(this.velocity) / this.range;
}
}
24 changes: 24 additions & 0 deletions test/coordinate/RIC.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,28 @@ describe('RIC', () => {

expect(name).toMatchSnapshot();
});

// toString
it('should return a string representation of the RIC coordinate', () => {
const ric = new RIC(stateVector.position, stateVector.velocity);
const string = ric.toString();

expect(string).toMatchSnapshot();
});

// range
it('should return the range of the RIC coordinate', () => {
const ric = new RIC(stateVector.position, stateVector.velocity);
const range = ric.range;

expect(range).toMatchSnapshot();
});

// rangeRate
it('should return the range rate of the RIC coordinate', () => {
const ric = new RIC(stateVector.position, stateVector.velocity);
const rangeRate = ric.rangeRate;

expect(rangeRate).toMatchSnapshot();
});
});
10 changes: 10 additions & 0 deletions test/coordinate/__snapshots__/RIC.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ RIC {

exports[`RIC should get the name of the RIC coordinate system 1`] = `"RIC"`;

exports[`RIC should return a string representation of the RIC coordinate 1`] = `
"[RIC]
Position: [1538.223336, 5102.261204, 4432.634965] km
Velocity: [-7.341518909, 0.651671845, 1.793388250] km/s"
`;

exports[`RIC should return the range of the RIC coordinate 1`] = `6931.627020979389`;

exports[`RIC should return the range rate of the RIC coordinate 1`] = `-0.002663194316531782`;

exports[`RIC should transform the current RIC coordinate to J2000 using the provided origin and transform matrix 1`] = `
J2000 {
"epoch": EpochUTC {
Expand Down

0 comments on commit d2533d7

Please sign in to comment.