diff --git a/src/coordinate/Geodetic.ts b/src/coordinate/Geodetic.ts index 6511967..10cdf22 100644 --- a/src/coordinate/Geodetic.ts +++ b/src/coordinate/Geodetic.ts @@ -45,14 +45,10 @@ export class Geodetic { constructor(latitude: Radians, longitude: Radians, altitude: Kilometers) { if (Math.abs(latitude) > Math.PI / 2) { - // eslint-disable-next-line no-console - console.warn(longitude * RAD2DEG); throw new RangeError('Latitude must be between -90° and 90° in Radians.'); } if (Math.abs(longitude) > Math.PI) { - // eslint-disable-next-line no-console - console.warn(longitude * RAD2DEG); throw new RangeError('Longitude must be between -180° and 180° in Radians.'); } diff --git a/test/body/Celestial.test.ts b/test/body/Celestial.test.ts index fa0f255..3b29f30 100644 --- a/test/body/Celestial.test.ts +++ b/test/body/Celestial.test.ts @@ -1,6 +1,6 @@ import { Degrees, Radians } from './../../src/types/types'; import { Celestial } from './../../src/body/Celestial'; -import { exampleDate } from '../lib/mockData'; +import { mockExampleDate } from '../lib/mockData'; describe('Celestial', () => { /* @@ -13,7 +13,7 @@ describe('Celestial', () => { const ra = 1.3963 as Radians; // right ascension of a celestial object const dec = 0.7854 as Radians; // declination of a celestial object - const azEl = Celestial.azEl(exampleDate, lat, lon, ra, dec); + const azEl = Celestial.azEl(mockExampleDate, lat, lon, ra, dec); expect(azEl).toMatchSnapshot(); }); diff --git a/test/body/Earth.test.ts b/test/body/Earth.test.ts index d0d6de4..dd87561 100644 --- a/test/body/Earth.test.ts +++ b/test/body/Earth.test.ts @@ -1,5 +1,5 @@ import { Earth, EpochUTC, Vector3D } from '../../src/main'; -import { exampleDate } from '../lib/mockData'; +import { mockExampleDate } from '../lib/mockData'; describe('Earth', () => { // can calculate mean motion from semimajor axis @@ -12,7 +12,7 @@ describe('Earth', () => { // can calculate precession angles from epoch it('should calculate precession angles when given an epoch', () => { - const epoch = EpochUTC.fromDateTime(exampleDate); + const epoch = EpochUTC.fromDateTime(mockExampleDate); const precessionAngles = Earth.precession(epoch); expect(precessionAngles.zeta).toMatchSnapshot(); @@ -22,7 +22,7 @@ describe('Earth', () => { // can calculate nutation angles from epoch it('should calculate nutation angles when given an epoch', () => { - const epoch = EpochUTC.fromDateTime(exampleDate); + const epoch = EpochUTC.fromDateTime(mockExampleDate); const nutationAngles = Earth.nutation(epoch); expect(nutationAngles.dPsi).toMatchSnapshot(); @@ -75,7 +75,7 @@ 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(exampleDate); + const epoch = EpochUTC.fromDateTime(mockExampleDate); const precessionAngles = Earth.precession(epoch); expect(precessionAngles.zeta).toMatchSnapshot(); @@ -83,7 +83,7 @@ describe('Earth', () => { // can handle epoch after 2150 when calculating precession angles it('should handle epoch after 2150 when calculating precession angles', () => { - const epoch = EpochUTC.fromDateTime(exampleDate); + const epoch = EpochUTC.fromDateTime(mockExampleDate); const precessionAngles = Earth.precession(epoch); expect(precessionAngles.zeta).not.toBeNaN(); @@ -92,7 +92,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(exampleDate); + const epoch = EpochUTC.fromDateTime(mockExampleDate); const nutationAngles = Earth.nutation(epoch); expect(nutationAngles.dPsi).not.toBeNaN(); @@ -101,7 +101,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(exampleDate); + const epoch = EpochUTC.fromDateTime(mockExampleDate); const nutationAngles = Earth.nutation(epoch); expect(nutationAngles.dPsi).not.toBeNaN(); diff --git a/test/body/Moon.test.ts b/test/body/Moon.test.ts index ac15527..45aa683 100644 --- a/test/body/Moon.test.ts +++ b/test/body/Moon.test.ts @@ -1,7 +1,13 @@ import { Degrees, EpochUTC, Moon, Vector3D } from '../../src/main'; -import { exampleDate } from '../lib/mockData'; +import { mockExampleDate } from '../lib/mockData'; describe('Moon', () => { + let exampleDate: Date; + + beforeEach(() => { + exampleDate = new Date(mockExampleDate.getTime()); + }); + // The static property 'mu' should be accessible and have a value of 4902.799. it('should have a static property "mu" with value 4902.799', () => { expect(Moon.mu).toBe(4902.799); @@ -99,7 +105,7 @@ describe('Moon', () => { * 'Degrees' parameters and return an object with 'az', 'el', 'rng', and * 'parallacticAngle' properties. */ - it("should return an object with 'az', 'el', 'rng', and 'parallacticAngle' properties", () => { + it('should return an object with \'az\', \'el\', \'rng\', and \'parallacticAngle\' properties', () => { const date = new Date(1635724800000); // November 1, 2021 const lat = 37.7749 as Degrees; // San Francisco latitude const lon = -122.4194 as Degrees; // San Francisco longitude @@ -113,7 +119,7 @@ describe('Moon', () => { * 'Degrees', 'Degrees', and 'boolean' parameters and return an object with * 'rise', 'set', 'ye', 'alwaysUp', 'alwaysDown', and 'highest' properties. */ - it("should return an object with 'rise', 'set', 'ye', 'alwaysUp', 'alwaysDown', and 'highest' properties", () => { + it('should return with \'rise\', \'set\', \'ye\', \'alwaysUp\', \'alwaysDown\', \'highest\' properties', () => { const date = exampleDate; const lat = 37.7749 as Degrees; // San Francisco latitude const lon = -122.4194 as Degrees; // San Francisco longitude @@ -128,7 +134,7 @@ describe('Moon', () => { * 'Degrees' parameters and return an object with 'az', 'el', 'rng', and * 'parallacticAngle' properties. */ - it("should return an object with 'az', 'el', 'rng', and 'parallacticAngle' properties", () => { + it('should return an object with \'az\', \'el\', \'rng\', and \'parallacticAngle\' properties', () => { const date = new Date(exampleDate); // November 1, 2021 const lat = 37.7749 as Degrees; // San Francisco latitude const lon = -122.4194 as Degrees; // San Francisco longitude @@ -142,7 +148,7 @@ describe('Moon', () => { * 'Degrees', 'Degrees', and 'boolean' parameters and return an object with * 'rise', 'set', 'ye', 'alwaysUp', 'alwaysDown', and 'highest' properties. */ - it("should return an object with 'rise', 'set', 'ye', 'alwaysUp', 'alwaysDown', and 'highest' properties", () => { + it('should return with \'rise\', \'set\', \'ye\', \'alwaysUp\', \'alwaysDown\', and \'highest\' properties', () => { const date = exampleDate; const lat = 37.7749 as Degrees; // San Francisco latitude const lon = -122.4194 as Degrees; // San Francisco longitude @@ -156,7 +162,7 @@ describe('Moon', () => { * The private method 'moonCoords' should be callable with a 'number' * parameter and return a 'RaDec' object. */ - it("should call the private method 'moonCoords' with a number parameter and return a RaDec object", () => { + it('should call the private method \'moonCoords\' with a number parameter and return a RaDec object', () => { const d = 123456789; const result = Moon.moonCoords(d); diff --git a/test/body/Sun.test.ts b/test/body/Sun.test.ts index c18fc73..ec909fd 100644 --- a/test/body/Sun.test.ts +++ b/test/body/Sun.test.ts @@ -1,7 +1,13 @@ -import { Degrees, EpochUTC, Meters, Sun, Vector3D } from '../../src/main'; -import { exampleDate } from '../lib/mockData'; +import { Degrees, EpochUTC, Kilometers, Meters, Sun, Vector3D } from '../../src/main'; +import { mockExampleDate } from '../lib/mockData'; describe('Sun', () => { + let exampleDate: Date; + + beforeEach(() => { + exampleDate = new Date(mockExampleDate.getTime()); + }); + /* * The 'azEl' method should return the azimuth and elevation of the sun given * a date, latitude, and longitude. @@ -29,8 +35,8 @@ describe('Sun', () => { * the observer's position and the sun's position. */ it('should return the angular diameter of the sun given the observers position and the suns position', () => { - const obsPos = new Vector3D(0, 0, 0); - const sunPos = new Vector3D(1, 1, 1); + const obsPos = new Vector3D(0 as Kilometers, 0 as Kilometers, 0 as Kilometers); + const sunPos = new Vector3D(1 as Kilometers, 1 as Kilometers, 1 as Kilometers); const result = Sun.diameter(obsPos, sunPos); expect(result).toMatchSnapshot(); @@ -41,8 +47,8 @@ describe('Sun', () => { * if a satellite is in the shadow of the earth. */ it('should return the angles necessary to determine if a satellite is in the shadow of the earth', () => { - const satPos = new Vector3D(0, 0, 0); - const sunPos = new Vector3D(1, 1, 1); + const satPos = new Vector3D(0 as Kilometers, 0 as Kilometers, 0 as Kilometers); + const sunPos = new Vector3D(1 as Kilometers, 1 as Kilometers, 1 as Kilometers); const result = Sun.eclipseAngles(satPos, sunPos); expect(result).toMatchSnapshot(); @@ -83,8 +89,8 @@ describe('Sun', () => { * the same as the sun's position. */ it('should handle cases where the observers position is the same as the suns position', () => { - const obsPos = new Vector3D(1, 1, 1); - const sunPos = new Vector3D(1, 1, 1); + const obsPos = new Vector3D(1 as Kilometers, 1 as Kilometers, 1 as Kilometers); + const sunPos = new Vector3D(1 as Kilometers, 1 as Kilometers, 1 as Kilometers); const result = Sun.diameter(obsPos, sunPos); expect(result).toMatchSnapshot(); @@ -95,8 +101,8 @@ describe('Sun', () => { * directly above or below the earth. */ it('should handle cases where the satellite is directly above or below the earth', () => { - const satPos = new Vector3D(0, 0, 0); - const sunPos = new Vector3D(0, 0, 1); + const satPos = new Vector3D(0 as Kilometers, 0 as Kilometers, 0 as Kilometers); + const sunPos = new Vector3D(0 as Kilometers, 0 as Kilometers, 1 as Kilometers); const result = Sun.eclipseAngles(satPos, sunPos); expect(result).toMatchSnapshot(); @@ -171,7 +177,10 @@ describe('Sun', () => { }); it('should return the same shadow result given the same time and position', () => { - const result = Sun.shadow(EpochUTC.fromDateTime(exampleDate), new Vector3D(8000, 0, 0)); + const result = Sun.shadow( + EpochUTC.fromDateTime(exampleDate), + new Vector3D(8000 as Kilometers, 0 as Kilometers, 0 as Kilometers), + ); expect(result).toMatchSnapshot(); }); @@ -192,7 +201,10 @@ describe('Sun', () => { // lightingRatio it('should return the same lighting ratio result given the same positions', () => { - const result = Sun.lightingRatio(new Vector3D(8000, 0, 0), new Vector3D(1000000, 0, 0)); + const result = Sun.lightingRatio( + new Vector3D(8000 as Kilometers, 0 as Kilometers, 0 as Kilometers), + new Vector3D(1000000 as Kilometers, 0 as Kilometers, 0 as Kilometers), + ); expect(result).toMatchSnapshot(); }); diff --git a/test/body/__snapshots__/Moon.test.ts.snap b/test/body/__snapshots__/Moon.test.ts.snap index 89204d7..ac41586 100644 --- a/test/body/__snapshots__/Moon.test.ts.snap +++ b/test/body/__snapshots__/Moon.test.ts.snap @@ -98,3 +98,25 @@ Object { "ye": null, } `; + +exports[`Moon should return with 'rise', 'set', 'ye', 'alwaysUp', 'alwaysDown', '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 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, +} +`; diff --git a/test/coordinate/ITRF.test.ts b/test/coordinate/ITRF.test.ts index a44ce4f..faf1d64 100644 --- a/test/coordinate/ITRF.test.ts +++ b/test/coordinate/ITRF.test.ts @@ -1,4 +1,4 @@ -import { exampleDate } from '../lib/mockData'; +import { mockExampleDate } from '../lib/mockData'; import { Earth, EpochUTC, ITRF, Kilometers, Vector3D } from './../../src/main'; // Generated by CodiumAI @@ -7,7 +7,7 @@ describe('ITRF', () => { let itrf: ITRF; beforeEach(() => { - epochUtc = EpochUTC.fromDateTime(exampleDate); + epochUtc = EpochUTC.fromDateTime(mockExampleDate); itrf = new ITRF( epochUtc, new Vector3D(1000 as Kilometers, 2000 as Kilometers, 3000 as Kilometers), @@ -191,8 +191,8 @@ describe('ITRF', () => { it('should handle position at different epochs', () => { const position = new Vector3D(1000 as Kilometers, 2000 as Kilometers, 3000 as Kilometers); const velocity = new Vector3D(10 as Kilometers, 20 as Kilometers, 30 as Kilometers); - const epoch1 = EpochUTC.fromDateTime(exampleDate); - const epoch2 = EpochUTC.fromDateTime(new Date(exampleDate.getTime() + 1000)); + const epoch1 = EpochUTC.fromDateTime(mockExampleDate); + const epoch2 = EpochUTC.fromDateTime(new Date(mockExampleDate.getTime() + 1000)); const itrf1 = new ITRF(epoch1, position, velocity); const itrf2 = new ITRF(epoch2, position, velocity); diff --git a/test/coordinate/J2000.test.ts b/test/coordinate/J2000.test.ts index 11e21d0..7c72dd2 100644 --- a/test/coordinate/J2000.test.ts +++ b/test/coordinate/J2000.test.ts @@ -1,10 +1,10 @@ // Generated by CodiumAI import { EpochUTC, ClassicalElements, Kilometers, Radians, J2000, Vector3D } from '../../src/main'; -import { exampleDate } from '../lib/mockData'; +import { mockExampleDate } from '../lib/mockData'; describe('J2000', () => { - const epoch = EpochUTC.fromDateTime(exampleDate); + const epoch = EpochUTC.fromDateTime(mockExampleDate); // can be created from classical elements it('should create a J2000 coordinate from classical elements', () => { diff --git a/test/coordinate/TEME.test.ts b/test/coordinate/TEME.test.ts index 12a53dd..d7a199d 100644 --- a/test/coordinate/TEME.test.ts +++ b/test/coordinate/TEME.test.ts @@ -1,4 +1,4 @@ -import { exampleDate } from '../lib/mockData'; +import { mockExampleDate } from '../lib/mockData'; import { ClassicalElements, EpochUTC, J2000, Kilometers, Radians, TEME, Vector3D } from './../../src/main'; describe('TEME', () => { let stateVector: TEME; @@ -27,7 +27,7 @@ describe('TEME', () => { // fromClassicalElements it('should create a TEME coordinate from classical orbital elements', () => { - const epoch = EpochUTC.fromDateTime(exampleDate); + const epoch = EpochUTC.fromDateTime(mockExampleDate); const elements = new ClassicalElements({ epoch, semimajorAxis: 6943.547853722985 as Kilometers, diff --git a/test/coordinate/Tle.test.ts b/test/coordinate/Tle.test.ts index 40b16ca..258cc81 100644 --- a/test/coordinate/Tle.test.ts +++ b/test/coordinate/Tle.test.ts @@ -1,4 +1,4 @@ -import { exampleDate } from '../lib/mockData'; +import { mockExampleDate } from '../lib/mockData'; import { ClassicalElements, EpochUTC, Kilometers, Radians, Tle, TleLine1, TleLine2 } from '../../src/main'; describe('Tle', () => { @@ -54,7 +54,7 @@ describe('Tle', () => { // propagate it('should propagate the TLE', () => { - const epoch = EpochUTC.fromDateTime(exampleDate); + const epoch = EpochUTC.fromDateTime(mockExampleDate); const propagated = tle.propagate(epoch); expect(propagated).toMatchSnapshot(); @@ -67,7 +67,7 @@ describe('Tle', () => { // fromClassicalElements it('should create a TLE from classical orbital elements', () => { - const epoch = EpochUTC.fromDateTime(exampleDate); + const epoch = EpochUTC.fromDateTime(mockExampleDate); const elements = new ClassicalElements({ epoch, semimajorAxis: 6943.547853722985 as Kilometers, diff --git a/test/lib/mockData.ts b/test/lib/mockData.ts index 9e84ae5..48b9bc2 100644 --- a/test/lib/mockData.ts +++ b/test/lib/mockData.ts @@ -1 +1 @@ -export const exampleDate = new Date(1705109326817); +export const mockExampleDate = new Date(1705109326817); diff --git a/test/objects/GroundObject.test.ts b/test/objects/GroundObject.test.ts index b7011b2..4284c91 100644 --- a/test/objects/GroundObject.test.ts +++ b/test/objects/GroundObject.test.ts @@ -1,4 +1,4 @@ -import { exampleDate } from '../lib/mockData'; +import { mockExampleDate } from '../lib/mockData'; import { Degrees, Geodetic, GroundObject, Kilometers, Radians } from '../../src/main'; describe('GroundObject', () => { @@ -40,7 +40,7 @@ describe('GroundObject', () => { }); it('should calculate eci', () => { - expect(groundObject.eci(exampleDate)).toMatchSnapshot(); + expect(groundObject.eci(mockExampleDate)).toMatchSnapshot(); }); it('should calculate llaRad', () => { diff --git a/test/objects/Satellite.test.ts b/test/objects/Satellite.test.ts index fc1e350..3d7c853 100644 --- a/test/objects/Satellite.test.ts +++ b/test/objects/Satellite.test.ts @@ -8,7 +8,7 @@ import { TleLine1, TleLine2, } from '../../src/main'; -import { exampleDate } from '../lib/mockData'; +import { mockExampleDate } from '../lib/mockData'; const dateObj = new Date(1661400000000); @@ -88,42 +88,42 @@ describe('Satellite', () => { // can calculate and return RAE coordinates it('should calculate and return RAE coordinates', () => { - const rae = satellite.toRae(observer, exampleDate); + const rae = satellite.toRae(observer, mockExampleDate); expect(rae).toMatchSnapshot(); }); // can calculate and return ECI coordinates it('should calculate and return ECI coordinates', () => { - const eci = satellite.eci(exampleDate); + const eci = satellite.eci(mockExampleDate); expect(eci).toMatchSnapshot(); }); // can calculate and return ECF coordinates it('should calculate and return ECF coordinates correctly', () => { - const ecfCoordinates = satellite.ecf(exampleDate); + const ecfCoordinates = satellite.ecf(mockExampleDate); expect(ecfCoordinates).toMatchSnapshot(); }); // can calculate and return LLA coordinates it('should calculate and return LLA coordinates when given a date', () => { - const lla = satellite.lla(exampleDate); + const lla = satellite.lla(mockExampleDate); expect(lla).toMatchSnapshot(); }); // can calculate and return Geodetic coordinates it('should calculate and return Geodetic coordinates when given a date', () => { - const geodetic = satellite.toGeodetic(exampleDate); + const geodetic = satellite.toGeodetic(mockExampleDate); expect(geodetic).toMatchSnapshot(); }); // can calculate and return ITRF coordinates it('should calculate and return ITRF coordinates when called', () => { - const itrfCoordinates = satellite.toITRF(exampleDate); + const itrfCoordinates = satellite.toITRF(mockExampleDate); expect(itrfCoordinates).toMatchSnapshot(); }); @@ -135,22 +135,22 @@ describe('Satellite', () => { tle2: '2 25544 51.6442 13.1247 0008036 23.6079 336.5377 15.48861704303602' as TleLine2, }); - const ric = satellite.toRIC(referenceSatellite, exampleDate); + const ric = satellite.toRIC(referenceSatellite, mockExampleDate); 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, exampleDate); + const range = satellite.range(observer, mockExampleDate); 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, exampleDate); - const elevation = satellite.el(observer, exampleDate); + const azimuth = satellite.az(observer, mockExampleDate); + const elevation = satellite.el(observer, mockExampleDate); expect(azimuth).toMatchSnapshot(); expect(elevation).toMatchSnapshot(); diff --git a/test/objects/sun-moon.test.ts b/test/objects/sun-moon.test.ts index 13a608f..e525a13 100644 --- a/test/objects/sun-moon.test.ts +++ b/test/objects/sun-moon.test.ts @@ -31,9 +31,6 @@ describe('Sun and Moon', () => { }); test('getMoonIllumination returns fraction and angle of moons illuminated limb and phase', () => { - // eslint-disable-next-line no-console - console.log('dateObj', dateObj); - const moonIllum = Moon.getMoonIllumination(dateObj); expect(moonIllum).toMatchSnapshot(); diff --git a/test/transforms/transforms.test.ts b/test/transforms/transforms.test.ts index 11cdb7d..b8c08d8 100644 --- a/test/transforms/transforms.test.ts +++ b/test/transforms/transforms.test.ts @@ -1,4 +1,4 @@ -import { exampleDate } from '../lib/mockData'; +import { mockExampleDate } from '../lib/mockData'; import { RadarSensor, azel2uv, @@ -220,7 +220,7 @@ describe('Rae2Ecf', () => { lat: 0 as Radians, alt: 0 as Kilometers, }; - const { gmst } = calcGmst(exampleDate); + const { gmst } = calcGmst(mockExampleDate); const eciCoordinates = lla2eci(lla, gmst); expect(eciCoordinates).toMatchSnapshot(); @@ -256,7 +256,7 @@ describe('Rae2Ecf', () => { minRng: 0 as Kilometers, maxRng: 0 as Kilometers, }) as RadarSensor; - const { gmst } = calcGmst(exampleDate); + const { gmst } = calcGmst(mockExampleDate); const eciCoordinates = rae2eci(rae, sensor, gmst); @@ -348,7 +348,7 @@ describe('Rae2Ecf', () => { maxRng: 0 as Kilometers, }) as RadarSensor; - const raeCoordinates = eci2rae(exampleDate, eci, sensor); + const raeCoordinates = eci2rae(mockExampleDate, eci, sensor); expect(raeCoordinates).toMatchSnapshot(); });