Skip to content

Commit

Permalink
fix: ✅ fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thkruz committed Jan 11, 2024
1 parent b5b506a commit d4ddcf3
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 190 deletions.
1 change: 0 additions & 1 deletion src/ootk-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,3 @@ export * from './transforms';
export * from './types/types';
export * from './utils/constants';
export * from './utils/functions';
export { Utils } from './utils/utils';
37 changes: 35 additions & 2 deletions src/utils/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ export function sign(value: number) {
return value >= 0 ? 1 : -1;
}

const spaceObjTypeStrMap = {
const spaceObjTypeStrMap_ = {
[SpaceObjectType.UNKNOWN]: 'Unknown',
[SpaceObjectType.PAYLOAD]: 'Payload',
[SpaceObjectType.ROCKET_BODY]: 'Rocket Body',
Expand Down Expand Up @@ -657,9 +657,24 @@ const spaceObjTypeStrMap = {
[SpaceObjectType.FRAGMENT]: 'Fragment',
};

/**
* Converts a SpaceObjectType to a string representation.
* @param spaceObjType - The SpaceObjectType to convert.
* @returns The string representation of the SpaceObjectType.
*/
export const spaceObjType2Str = (spaceObjType: SpaceObjectType): string =>
spaceObjTypeStrMap[spaceObjType] || 'Unknown';
spaceObjTypeStrMap_[spaceObjType] || 'Unknown';

/**
* Calculates the Doppler factor for a given location, position, and velocity.
* The Doppler factor is a measure of the change in frequency or wavelength of a wave
* as observed by an observer moving relative to the source of the wave.
*
* @param location - The location vector of the observer.
* @param position - The position vector of the source.
* @param velocity - The velocity vector of the source.
* @returns The calculated Doppler factor.
*/
export const dopplerFactor = (location: EciVec3, position: EciVec3, velocity: EciVec3): number => {
const mfactor = 7.292115e-5;
const c = 299792.458; // Speed of light in km/s
Expand Down Expand Up @@ -690,3 +705,21 @@ export const dopplerFactor = (location: EciVec3, position: EciVec3, velocity: Ec

return dopplerFactor;
};

/**
* Creates an array of numbers from start to stop (inclusive) with the specified step.
*
* @param start The starting number.
* @param stop The ending number.
* @param step The step value.
* @returns An array of numbers.
*/
export function createVec(start: number, stop: number, step: number): number[] {
const array = [];

for (let i = start; i <= stop; i += step) {
array.push(i);
}

return array;
}
17 changes: 0 additions & 17 deletions src/utils/utils.ts

This file was deleted.

132 changes: 0 additions & 132 deletions test/tle/tle.json

This file was deleted.

65 changes: 34 additions & 31 deletions test/tle/tle.test.js → test/tle/tle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,65 @@
*/

import { Tle } from '../../lib/ootk-core';
import tleData from './tle.json';
import { tleData } from './tleData';

describe('Valid TLEs', () => {
tleData.forEach((testCase) => {
describe(`TLE ${testCase.satNum}: Line 1 Parsing`, () => {
it('should parse the line number', () => {
expect(Tle.getLineNumber(testCase.line1)).toBe(testCase.linenum1);
expect(Tle.getLineNumber(testCase.line2)).toBe(testCase.linenum2);
expect(Tle.lineNumber(testCase.line1)).toBe(testCase.linenum1);
expect(Tle.lineNumber(testCase.line2)).toBe(testCase.linenum2);
});

it('should parse satellite number', () => {
expect(Tle.getSatNum(testCase.line1)).toBe(testCase.satNum);
expect(Tle.getSatNum(testCase.line2)).toBe(testCase.satNum2);
expect(Tle.satNum(testCase.line1)).toBe(testCase.satNum);
expect(Tle.satNum(testCase.line2)).toBe(testCase.satNum2);
});

it('should parse satellite number as a raw string', () => {
expect(Tle.getRawSatNum(testCase.line1)).toBe(testCase.satNumRaw);
expect(Tle.getRawSatNum(testCase.line2)).toBe(testCase.satNumRaw2);
expect(Tle.rawSatNum(testCase.line1)).toBe(testCase.satNumRaw);
expect(Tle.rawSatNum(testCase.line2)).toBe(testCase.satNumRaw2);
});

it('should parse satellite classification', () => {
expect(Tle.getClassification(testCase.line1)).toBe(testCase.classification);
expect(Tle.classification(testCase.line1)).toBe(testCase.classification);
});

it('should parse International Designator', () => {
expect(Tle.getIntlDesYear(testCase.line1)).toBe(testCase.intlDesYear);
expect(Tle.getIntlDesLaunchNum(testCase.line1)).toBe(testCase.intlDesLaunchNum);
expect(Tle.getIntlDesLaunchPiece(testCase.line1)).toBe(testCase.intlDesLaunchPiece);
expect(Tle.getIntlDes(testCase.line1)).toBe(testCase.intlDes);
expect(Tle.intlDesYear(testCase.line1)).toBe(testCase.intlDesYear);
expect(Tle.intlDesLaunchNum(testCase.line1)).toBe(testCase.intlDesLaunchNum);
expect(Tle.intlDesLaunchPiece(testCase.line1)).toBe(testCase.intlDesLaunchPiece);
expect(Tle.intlDes(testCase.line1)).toBe(testCase.intlDes);
});

it('should parse epoch', () => {
expect(Tle.getEpochYear(testCase.line1)).toBe(testCase.epochYear);
expect(Tle.getEpochYearFull(testCase.line1)).toBe(testCase.epochYearFull);
expect(Tle.getEpochDay(testCase.line1)).toBe(testCase.epochDay);
expect(Tle.epochYear(testCase.line1)).toBe(testCase.epochYear);
expect(Tle.epochYearFull(testCase.line1)).toBe(testCase.epochYearFull);
expect(Tle.epochDay(testCase.line1)).toBe(testCase.epochDay);
});

it('should parse first derivative', () => {
expect(Tle.getMeanMoDev1(testCase.line1)).toBe(testCase.meanMoDev1);
expect(Tle.meanMoDev1(testCase.line1)).toBe(testCase.meanMoDev1);
});

it('should parse second derivative', () => {
expect(Tle.getMeanMoDev2(testCase.line1)).toBe(testCase.meanMoDev2);
expect(Tle.meanMoDev2(testCase.line1)).toBe(testCase.meanMoDev2);
});

it('should parse bstar', () => {
expect(Tle.getBstar(testCase.line1)).toBe(testCase.bstar);
expect(Tle.bstar(testCase.line1)).toBe(testCase.bstar);
});

it('should parse ephemerisType', () => {
expect(Tle.getEphemerisType(testCase.line1)).toBe(testCase.ephemerisType);
expect(Tle.ephemerisType(testCase.line1)).toBe(testCase.ephemerisType);
});

it('should parse element number', () => {
expect(Tle.getElsetNum(testCase.line1)).toBe(testCase.elsetNum);
expect(Tle.elsetNum(testCase.line1)).toBe(testCase.elsetNum);
});

it('should parse checksum', () => {
expect(Tle.getChecksum(testCase.line1)).toBe(testCase.checksum1);
expect(Tle.checksum(testCase.line1)).toBe(testCase.checksum1);
});

it('should parse all of line 1', () => {
Expand Down Expand Up @@ -92,35 +92,35 @@ describe('Valid TLEs', () => {

describe(`TLE ${testCase.satNum}: Line 2 Parsing`, () => {
it('should parse satellite inclination', () => {
expect(Tle.getInclination(testCase.line2)).toBe(testCase.inclination);
expect(Tle.inclination(testCase.line2)).toBe(testCase.inclination);
});

it('should parse right ascension of ascending node', () => {
expect(Tle.getRaan(testCase.line2)).toBe(testCase.raan);
expect(Tle.rightAscension(testCase.line2)).toBe(testCase.raan);
});

it('should parse eccentricity', () => {
expect(Tle.getEccentricity(testCase.line2)).toBe(testCase.eccentricity);
expect(Tle.eccentricity(testCase.line2)).toBe(testCase.eccentricity);
});

it('should parse argument of perigee', () => {
expect(Tle.getArgOfPerigee(testCase.line2)).toBe(testCase.argOfPerigee);
expect(Tle.argOfPerigee(testCase.line2)).toBe(testCase.argOfPerigee);
});

it('should parse mean anomaly', () => {
expect(Tle.getMeanAnomaly(testCase.line2)).toBe(testCase.meanAnomaly);
expect(Tle.meanAnomaly(testCase.line2)).toBe(testCase.meanAnomaly);
});

it('should parse mean motion', () => {
expect(Tle.getMeanMotion(testCase.line2)).toBe(testCase.meanMotion);
expect(Tle.meanMotion(testCase.line2)).toBe(testCase.meanMotion);
});

it('should parse revolution number', () => {
expect(Tle.getRevNum(testCase.line2)).toBe(testCase.revNum);
expect(Tle.revNum(testCase.line2)).toBe(testCase.revNum);
});

it('should parse checksum', () => {
expect(Tle.getChecksum(testCase.line2)).toBe(testCase.checksum2);
expect(Tle.checksum(testCase.line2)).toBe(testCase.checksum2);
});

it('should parse all of line 2', () => {
Expand All @@ -136,11 +136,12 @@ describe('Valid TLEs', () => {
meanMotion: testCase.meanMotion,
revNum: testCase.revNum,
checksum2: testCase.checksum2,
period: testCase.period,
});
});
describe('TLE Parsing', () => {
it('should parse a TLE for main orbital data', () => {
const tle = Tle.parseTle(testCase.line1, testCase.line2);
const tle = Tle.parse(testCase.line1, testCase.line2);

expect(tle).toEqual({
satNum: testCase.satNum,
Expand All @@ -156,11 +157,12 @@ describe('Valid TLEs', () => {
argOfPerigee: testCase.argOfPerigee,
meanAnomaly: testCase.meanAnomaly,
meanMotion: testCase.meanMotion,
period: testCase.period,
});
});

it('should parse a TLE for all data', () => {
const tle = Tle.parseTleFull(testCase.line1, testCase.line2);
const tle = Tle.parseAll(testCase.line1, testCase.line2);

expect(tle).toEqual({
lineNumber1: testCase.linenum1,
Expand Down Expand Up @@ -189,6 +191,7 @@ describe('Valid TLEs', () => {
revNum: testCase.revNum,
checksum1: testCase.checksum1,
checksum2: testCase.checksum2,
period: testCase.period,
});
});
});
Expand Down
Loading

0 comments on commit d4ddcf3

Please sign in to comment.