Skip to content

Commit

Permalink
test: 🩹 fix mock date object being modified
Browse files Browse the repository at this point in the history
  • Loading branch information
thkruz committed Jan 15, 2024
1 parent 0adde7a commit ff1a6ad
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 64 deletions.
2 changes: 1 addition & 1 deletion test/body/Celestial.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Degrees, Radians } from './../../src/types/types';
import { Celestial } from './../../src/body/Celestial';
import { mockExampleDate } from '../lib/mockData';

describe('Celestial', () => {
/*
* Calculates the azimuth and elevation of a celestial object at a given date,
* latitude, longitude, right ascension, and declination.
*/
it('should calculate the azimuth and elevation when given valid inputs', () => {
const mockExampleDate = new Date(1705109326817);
const lat = 37.7749 as Degrees; // latitude of San Francisco
const lon = -122.4194 as Degrees; // longitude of San Francisco
const ra = 1.3963 as Radians; // right ascension of a celestial object
Expand Down
23 changes: 15 additions & 8 deletions test/body/Earth.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Earth, EpochUTC, Vector3D } from '../../src/main';
import { mockExampleDate } from '../lib/mockData';

describe('Earth', () => {
let exampleDate = new Date(1705109326817);

beforeEach(() => {
const mockExampleDate = new Date(1705109326817);

exampleDate = new Date(mockExampleDate.getTime());
});

// can calculate mean motion from semimajor axis
it('should calculate mean motion when given a semimajor axis', () => {
const semimajorAxis = 7000; // km
Expand All @@ -12,7 +19,7 @@ describe('Earth', () => {

// can calculate precession angles from epoch
it('should calculate precession angles when given an epoch', () => {
const epoch = EpochUTC.fromDateTime(mockExampleDate);
const epoch = EpochUTC.fromDateTime(exampleDate);
const precessionAngles = Earth.precession(epoch);

expect(precessionAngles.zeta).toMatchSnapshot();
Expand All @@ -22,7 +29,7 @@ describe('Earth', () => {

// can calculate nutation angles from epoch
it('should calculate nutation angles when given an epoch', () => {
const epoch = EpochUTC.fromDateTime(mockExampleDate);
const epoch = EpochUTC.fromDateTime(exampleDate);
const nutationAngles = Earth.nutation(epoch);

expect(nutationAngles.dPsi).toMatchSnapshot();
Expand Down Expand Up @@ -66,7 +73,7 @@ describe('Earth', () => {
});

// can calculate Earth's diameter from satellite position
it("should calculate Earth's diameter from satellite position", () => {
it('should calculate Earth\'s diameter from satellite position', () => {
const satPos = new Vector3D(1000, 1000, 1000);
const diameter = Earth.diameter(satPos);

Expand All @@ -75,15 +82,15 @@ describe('Earth', () => {

// can handle epoch before 1900 when calculating precession angles
it('should handle epoch before 1900 when calculating precession angles', () => {
const epoch = EpochUTC.fromDateTime(mockExampleDate);
const epoch = EpochUTC.fromDateTime(exampleDate);
const precessionAngles = Earth.precession(epoch);

expect(precessionAngles.zeta).toMatchSnapshot();
});

// can handle epoch after 2150 when calculating precession angles
it('should handle epoch after 2150 when calculating precession angles', () => {
const epoch = EpochUTC.fromDateTime(mockExampleDate);
const epoch = EpochUTC.fromDateTime(exampleDate);
const precessionAngles = Earth.precession(epoch);

expect(precessionAngles.zeta).not.toBeNaN();
Expand All @@ -92,7 +99,7 @@ describe('Earth', () => {

// can handle epoch before 1900 when calculating nutation angles
it('should handle epoch before 1900 when calculating nutation angles', () => {
const epoch = EpochUTC.fromDateTime(mockExampleDate);
const epoch = EpochUTC.fromDateTime(exampleDate);
const nutationAngles = Earth.nutation(epoch);

expect(nutationAngles.dPsi).not.toBeNaN();
Expand All @@ -101,7 +108,7 @@ describe('Earth', () => {

// can handle epoch after 2150 when calculating nutation angles
it('should handle epoch after 2150 when calculating nutation angles', () => {
const epoch = EpochUTC.fromDateTime(mockExampleDate);
const epoch = EpochUTC.fromDateTime(exampleDate);
const nutationAngles = Earth.nutation(epoch);

expect(nutationAngles.dPsi).not.toBeNaN();
Expand Down
3 changes: 2 additions & 1 deletion test/body/Moon.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Degrees, EpochUTC, Moon, Vector3D } from '../../src/main';
import { mockExampleDate } from '../lib/mockData';

describe('Moon', () => {
let exampleDate: Date;

beforeEach(() => {
const mockExampleDate = new Date(1705109326817);

exampleDate = new Date(mockExampleDate.getTime());
});

Expand Down
3 changes: 2 additions & 1 deletion test/body/Sun.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Degrees, EpochUTC, Kilometers, Meters, Sun, Vector3D } from '../../src/main';
import { mockExampleDate } from '../lib/mockData';

describe('Sun', () => {
let exampleDate: Date;

beforeEach(() => {
const mockExampleDate = new Date(1705109326817);

exampleDate = new Date(mockExampleDate.getTime());
});

Expand Down
22 changes: 0 additions & 22 deletions test/body/__snapshots__/Moon.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,6 @@ Object {
}
`;

exports[`Moon should return an object with 'rise', 'set', 'ye', 'alwaysUp', 'alwaysDown', and 'highest' properties 1`] = `
Object {
"alwaysDown": false,
"alwaysUp": false,
"highest": 2024-01-12T21:42:31.618Z,
"rise": 2024-01-12T16:43:59.167Z,
"set": 2024-01-13T02:41:04.069Z,
"ye": null,
}
`;

exports[`Moon should return an object with 'rise', 'set', 'ye', 'alwaysUp', 'alwaysDown', and 'highest' properties 2`] = `
Object {
"alwaysDown": false,
"alwaysUp": false,
"highest": 2024-01-12T21:42:31.618Z,
"rise": 2024-01-12T16:43:59.167Z,
"set": 2024-01-13T02:41:04.069Z,
"ye": null,
}
`;

exports[`Moon should return with 'rise', 'set', 'ye', 'alwaysUp', 'alwaysDown', 'highest' properties 1`] = `
Object {
"alwaysDown": false,
Expand Down
6 changes: 3 additions & 3 deletions test/body/__snapshots__/Sun.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ exports[`Sun should return the number of days since January 1, 2000, for a given

exports[`Sun should return the same apparent position result given the same time and position 1`] = `
Vector3D {
"x": 54242939.78872876,
"y": -125479049.84825934,
"z": -54393990.21165644,
"x": 55101974.26909711,
"y": -125165869.77224815,
"z": -54258234.63367154,
}
`;

Expand Down
9 changes: 6 additions & 3 deletions test/coordinate/ITRF.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { mockExampleDate } from '../lib/mockData';
import { Earth, EpochUTC, ITRF, Kilometers, Vector3D } from './../../src/main';
// Generated by CodiumAI

describe('ITRF', () => {
let epochUtc: EpochUTC;
let exampleDate: Date;
let itrf: ITRF;

beforeEach(() => {
const mockExampleDate = new Date(1705109326817);

exampleDate = new Date(mockExampleDate.getTime());
epochUtc = EpochUTC.fromDateTime(mockExampleDate);
itrf = new ITRF(
epochUtc,
Expand Down Expand Up @@ -191,8 +194,8 @@ describe('ITRF', () => {
it('should handle position at different epochs', () => {
const position = new Vector3D<Kilometers>(1000 as Kilometers, 2000 as Kilometers, 3000 as Kilometers);
const velocity = new Vector3D<Kilometers>(10 as Kilometers, 20 as Kilometers, 30 as Kilometers);
const epoch1 = EpochUTC.fromDateTime(mockExampleDate);
const epoch2 = EpochUTC.fromDateTime(new Date(mockExampleDate.getTime() + 1000));
const epoch1 = EpochUTC.fromDateTime(exampleDate);
const epoch2 = EpochUTC.fromDateTime(new Date(exampleDate.getTime() + 1000));
const itrf1 = new ITRF(epoch1, position, velocity);
const itrf2 = new ITRF(epoch2, position, velocity);

Expand Down
4 changes: 2 additions & 2 deletions test/coordinate/J2000.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Generated by CodiumAI

import { EpochUTC, ClassicalElements, Kilometers, Radians, J2000, Vector3D } from '../../src/main';
import { mockExampleDate } from '../lib/mockData';

describe('J2000', () => {
const epoch = EpochUTC.fromDateTime(mockExampleDate);
const exampleDate = new Date(1705109326817);
const epoch = EpochUTC.fromDateTime(exampleDate);

// can be created from classical elements
it('should create a J2000 coordinate from classical elements', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/coordinate/TEME.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { mockExampleDate } from '../lib/mockData';
import { ClassicalElements, EpochUTC, J2000, Kilometers, Radians, TEME, Vector3D } from './../../src/main';
describe('TEME', () => {
let stateVector: TEME;
Expand Down Expand Up @@ -27,7 +26,8 @@ describe('TEME', () => {

// fromClassicalElements
it('should create a TEME coordinate from classical orbital elements', () => {
const epoch = EpochUTC.fromDateTime(mockExampleDate);
const exampleDate = new Date(1705109326817);
const epoch = EpochUTC.fromDateTime(exampleDate);
const elements = new ClassicalElements({
epoch,
semimajorAxis: 6943.547853722985 as Kilometers,
Expand Down
8 changes: 5 additions & 3 deletions test/coordinate/Tle.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { mockExampleDate } from '../lib/mockData';
import { ClassicalElements, EpochUTC, Kilometers, Radians, Tle, TleLine1, TleLine2 } from '../../src/main';

describe('Tle', () => {
let tle: Tle;
let exampleDate: Date;

beforeEach(() => {
// Sample TLE
const tle1 = '1 56006U 23042W 24012.45049317 .00000296 00000-0 36967-4 0 9992' as TleLine1;
const tle2 = '2 56006 143.0043 13.3620 0001137 267.5965 92.4747 15.02542972 44491' as TleLine2;
const mockExampleDate = new Date(1705109326817);

exampleDate = new Date(mockExampleDate.getTime());
tle = new Tle(tle1, tle2);
});

Expand Down Expand Up @@ -54,7 +56,7 @@ describe('Tle', () => {

// propagate
it('should propagate the TLE', () => {
const epoch = EpochUTC.fromDateTime(mockExampleDate);
const epoch = EpochUTC.fromDateTime(exampleDate);
const propagated = tle.propagate(epoch);

expect(propagated).toMatchSnapshot();
Expand All @@ -67,7 +69,7 @@ describe('Tle', () => {

// fromClassicalElements
it('should create a TLE from classical orbital elements', () => {
const epoch = EpochUTC.fromDateTime(mockExampleDate);
const epoch = EpochUTC.fromDateTime(exampleDate);
const elements = new ClassicalElements({
epoch,
semimajorAxis: 6943.547853722985 as Kilometers,
Expand Down
2 changes: 1 addition & 1 deletion test/lib/mockData.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const mockExampleDate = new Date(1705109326817);
// Empty for now
7 changes: 5 additions & 2 deletions test/objects/GroundObject.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { mockExampleDate } from '../lib/mockData';
import { Degrees, Geodetic, GroundObject, Kilometers, Radians } from '../../src/main';

describe('GroundObject', () => {
let groundObject: GroundObject;
let geodetic: Geodetic;
let exampleDate: Date;

beforeEach(() => {
const mockExampleDate = new Date(1705109326817);

exampleDate = new Date(mockExampleDate.getTime());
groundObject = new GroundObject({
lat: 0 as Degrees,
lon: 0 as Degrees,
Expand Down Expand Up @@ -40,7 +43,7 @@ describe('GroundObject', () => {
});

it('should calculate eci', () => {
expect(groundObject.eci(mockExampleDate)).toMatchSnapshot();
expect(groundObject.eci(exampleDate)).toMatchSnapshot();
});

it('should calculate llaRad', () => {
Expand Down
25 changes: 14 additions & 11 deletions test/objects/Satellite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
TleLine1,
TleLine2,
} from '../../src/main';
import { mockExampleDate } from '../lib/mockData';

const dateObj = new Date(1661400000000);

Expand Down Expand Up @@ -71,13 +70,17 @@ describe('Basic Satellite functionality', () => {
describe('Satellite', () => {
let satellite: Satellite;
let observer: GroundObject;
let exampleDate: Date;

beforeEach(() => {
const satelliteParams: SatelliteParams = {
tle1,
tle2,
};

const mockExampleDate = new Date(1705109326817);

exampleDate = new Date(mockExampleDate.getTime());
satellite = new Satellite(satelliteParams);
observer = new GroundObject(llaObserver);
});
Expand All @@ -88,42 +91,42 @@ describe('Satellite', () => {

// can calculate and return RAE coordinates
it('should calculate and return RAE coordinates', () => {
const rae = satellite.toRae(observer, mockExampleDate);
const rae = satellite.toRae(observer, exampleDate);

expect(rae).toMatchSnapshot();
});

// can calculate and return ECI coordinates
it('should calculate and return ECI coordinates', () => {
const eci = satellite.eci(mockExampleDate);
const eci = satellite.eci(exampleDate);

expect(eci).toMatchSnapshot();
});

// can calculate and return ECF coordinates
it('should calculate and return ECF coordinates correctly', () => {
const ecfCoordinates = satellite.ecf(mockExampleDate);
const ecfCoordinates = satellite.ecf(exampleDate);

expect(ecfCoordinates).toMatchSnapshot();
});

// can calculate and return LLA coordinates
it('should calculate and return LLA coordinates when given a date', () => {
const lla = satellite.lla(mockExampleDate);
const lla = satellite.lla(exampleDate);

expect(lla).toMatchSnapshot();
});

// can calculate and return Geodetic coordinates
it('should calculate and return Geodetic coordinates when given a date', () => {
const geodetic = satellite.toGeodetic(mockExampleDate);
const geodetic = satellite.toGeodetic(exampleDate);

expect(geodetic).toMatchSnapshot();
});

// can calculate and return ITRF coordinates
it('should calculate and return ITRF coordinates when called', () => {
const itrfCoordinates = satellite.toITRF(mockExampleDate);
const itrfCoordinates = satellite.toITRF(exampleDate);

expect(itrfCoordinates).toMatchSnapshot();
});
Expand All @@ -135,22 +138,22 @@ describe('Satellite', () => {
tle2: '2 25544 51.6442 13.1247 0008036 23.6079 336.5377 15.48861704303602' as TleLine2,
});

const ric = satellite.toRIC(referenceSatellite, mockExampleDate);
const ric = satellite.toRIC(referenceSatellite, exampleDate);

expect(ric).toMatchSnapshot();
});

// can calculate and return range to an observer
it('should calculate and return range to an observer', () => {
const range = satellite.range(observer, mockExampleDate);
const range = satellite.range(observer, exampleDate);

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

// can calculate and return azimuth and elevation angles
it('should calculate and return azimuth and elevation angles correctly', () => {
const azimuth = satellite.az(observer, mockExampleDate);
const elevation = satellite.el(observer, mockExampleDate);
const azimuth = satellite.az(observer, exampleDate);
const elevation = satellite.el(observer, exampleDate);

expect(azimuth).toMatchSnapshot();
expect(elevation).toMatchSnapshot();
Expand Down
Loading

0 comments on commit ff1a6ad

Please sign in to comment.