Skip to content

Commit

Permalink
test: ✅ improve test coverage and import order
Browse files Browse the repository at this point in the history
  • Loading branch information
thkruz committed Jan 13, 2024
1 parent 137c83c commit 188071e
Show file tree
Hide file tree
Showing 115 changed files with 2,168 additions and 530 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
"no-useless-return": "error",
"no-var": "error",
"no-void": "error",
"no-warning-comments": "error",
"no-warning-comments": "warn",
"no-whitespace-before-property": "error",
"nonblock-statement-body-position": "error",
"object-curly-newline": "error",
Expand All @@ -209,7 +209,7 @@
"prefer-spread": "error",
"prefer-template": "error",
"quote-props": "off",
"quotes": ["error", "single"],
"quotes": ["off", "single"],
"radix": "off",
"require-atomic-updates": "error",
"require-await": "error",
Expand Down
30 changes: 20 additions & 10 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
}
},
{
"label": "Test without Building",
"command": "npm run test:nobuild",
"label": "Test for Coverage",
"command": "npm run test:coverage",
"type": "shell",
"args": [],
"isBackground": true,
Expand All @@ -38,15 +38,25 @@
}
},
{
"label": "Open Test Coverage",
"command": "npm run lcov",
"type": "shell",
"args": [],
"isBackground": true,
"problemMatcher": [],
"label": "Open Coverage in Brave",
"type": "process",
"command": "",
"windows": {
"command": "C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe",
"args": ["${workspaceFolder}/coverage/lcov-report/index.html"]
},
"icon": {
"id": "file-code",
"color": "terminal.ansiYellow"
"id": "browser",
"color": "terminal.ansiCyan"
},
"presentation": {
"echo": false,
"reveal": "never",
"focus": false,
"panel": "new",
"showReuseMessage": false,
"clear": true,
"close": true
}
}
],
Expand Down
17 changes: 4 additions & 13 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,13 @@ const jestConfig = {
transform: {
'\\.(js|ts|jsx|tsx)$': 'babel-jest',
},
testPathIgnorePatterns: ['<rootDir>/dist', '<rootDir>/lib', '<rootDir>/scripts', '<rootDir>/coverage'],
transformIgnorePatterns: ['dist', 'scripts', 'coverage'],
testMatch: ['**/?(*.)+(spec|test).?(m)[jt]s?(x)'],
testMatch: ['**/test/**/?(*.)+(spec|test).?(m)[jt]s?(x)'],
moduleFileExtensions: ['js', 'mjs', 'ts'],
// setupFiles: [''],
coverageDirectory: '<rootDir>/coverage',
moduleDirectories: ['node_modules', 'offline'],
modulePathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/coverage/',
'<rootDir>/dist/',
'<rootDir>/scripts/',
'<rootDir>/test/sgp4/sgp4prop',
],
moduleDirectories: ['node_modules'],
modulePathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/test/sgp4/sgp4prop'],
coverageReporters: ['lcov', 'html', 'text'],
coveragePathIgnorePatterns: ['/node_modules/', '/dist/', '/lib/', '/scripts/', '/coverage/'],
coveragePathIgnorePatterns: ['/node_modules/', '/dist/', '/lib/', '/commonjs/', '/test/', '/scripts/', '/coverage/'],
};

export default jestConfig;
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"build": "node ./scripts/cleanup.mjs && npm run js && npm run cjs && node ./scripts/makeMjs.mjs",
"lint": "npx eslint src",
"lint:fix": "npx eslint src --fix",
"test": "npm run build && jest",
"test:nobuild": "jest",
"test": "jest",
"test:coverage": "jest --coverage",
"version": "auto-changelog -p && git add CHANGELOG.md"
},
Expand Down Expand Up @@ -60,4 +59,4 @@
"typescript-transform-paths": "^3.4.6"
},
"homepage": "https://github.com/thkruz/ootk"
}
}
53 changes: 42 additions & 11 deletions src/body/Celestial.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
import { AzEl, Degrees, Kilometers, RaDec, Radians } from '..';
import { RAD2DEG } from '../utils/constants';
import { Sun } from './Sun';
import { Sun, RAD2DEG, AzEl, Degrees, Kilometers, RaDec, Radians } from '..';

/**
* Celestial is a static class that provides methods for calculating the position of celestial objects such
* as the Sun, Moon, and planets in the sky.
*/
export class Celestial {
private constructor() {
// disable constructor
}

static getStarAzEl(date: Date, lat: Degrees, lon: Degrees, ra: Radians, dec: Radians): AzEl<Degrees> {
/**
* Calculates the azimuth and elevation of a celestial object at a given date, latitude,
* longitude, right ascension, and declination.
* @param date - The date for which to calculate the azimuth and elevation.
* @param lat - The latitude of the observer.
* @param lon - The longitude of the observer.
* @param ra - The right ascension of the celestial object.
* @param dec - The declination of the celestial object.
* @returns An object containing the azimuth and elevation in degrees.
*/
static azEl(date: Date, lat: Degrees, lon: Degrees, ra: Radians, dec: Radians): AzEl<Degrees> {
const c: RaDec = {
ra,
dec,
dist: 0 as Kilometers,
};
const azEl = Sun.azEl(date, lat, lon, c);

const el = <Radians>(azEl.el + Celestial.astroRefraction(azEl.el)); // elevation correction for refraction
const el = <Radians>(azEl.el + Celestial.atmosphericRefraction(azEl.el)); // elevation correction for refraction

return {
az: (azEl.az * RAD2DEG) as Degrees,
Expand All @@ -24,11 +36,22 @@ export class Celestial {
}

/**
* get astro refraction
* Atmospheric refraction in astronomy, refers to the bending of light as it passes through the Earth's
* atmosphere. This effect is most noticeable for celestial objects like stars and planets when they are
* close to the horizon. Here's a breakdown of how it works:
*
* Actual Position: Due to this bending of light, the apparent position of a celestial object is slightly
* different from its true position in the sky. When a star or planet is near the horizon, the effect is more
* pronounced because the light path passes through more of the Earth's atmosphere, which increases the amount of
* bending.
*
* A familiar example of atmospheric refraction is observed during sunrise and sunset. The Sun appears to
* be above the horizon when it is actually just below it. This is because the light from the Sun is bent
* upwards as it passes through the atmosphere.
* @param {Radians} h - elevation
* @returns {number} refraction
*/
static astroRefraction(h: Radians): Radians {
static atmosphericRefraction(h: Radians): Radians {
if (h < 0) {
h = <Radians>0;
}
Expand All @@ -37,7 +60,8 @@ export class Celestial {
}

/**
* get declination
* Calculate the declination. Similar to latitude on Earth, declination is another celestial coordinate.
* It measures how far north or south an object is from the celestial equator
* @param {number} l - ecliptic longitude
* @param {number} b - ecliptic latitude
* @returns {number} declination
Expand All @@ -47,7 +71,9 @@ export class Celestial {
}

/**
* get right ascension
* Calculate the right ascension. This is a celestial coordinate used to determine the position of objects
* in the sky. It's analogous to longitude on Earth. Right Ascension indicates how far east an object is
* from the vernal equinox along the celestial equator.
* @param {number} l - ecliptic longitude
* @param {number} b - ecliptic latitude
* @returns {number} right ascension
Expand All @@ -57,7 +83,10 @@ export class Celestial {
}

/**
* get elevation (sometimes called altitude)
* Calculate the elevation. Elevation, or altitude, is the angle between an object in the sky and the
* observer's local horizon. It's commonly expressed in degrees, where 0 degrees is right at the horizon
* and 90 degrees is directly overhead (the zenith), but we are using radians to support trigonometric
* functions like Math.sin() and Math.cos().
* @param {number} H - siderealTime
* @param {Radians} phi - latitude
* @param {Radians} dec - The declination of the sun
Expand All @@ -68,7 +97,9 @@ export class Celestial {
}

/**
* get azimuth
* Calculate the azimuth. This is a compass direction measurement. Azimuth measures the angle along
* the horizon from a specific reference direction (usually true north) to the point where a vertical
* line from the object intersects the horizon.
* @param {number} H - siderealTime
* @param {Radians} phi - latitude
* @param {Radians} dec - The declination of the sun
Expand Down
26 changes: 19 additions & 7 deletions src/body/Earth.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import { AngularDiameterMethod, Kilometers, Radians } from '..';
import { DataHandler } from '../data/DataHandler';
import { Vector3D } from '../operations/Vector3D';
import { EpochUTC } from '../time/EpochUTC';
import { asec2rad, DEG2RAD, RAD2DEG, secondsPerDay, secondsPerSiderealDay, TAU, ttasec2rad } from '../utils/constants';
import { angularDiameter, evalPoly } from '../utils/functions';
import {
earthGravityParam,
angularDiameter,
evalPoly,
asec2rad,
DEG2RAD,
RAD2DEG,
secondsPerDay,
secondsPerSiderealDay,
TAU,
ttasec2rad,
EpochUTC,
Vector3D,
DataHandler,
AngularDiameterMethod,
Kilometers,
Radians,
} from '..';
import { NutationAngles } from './NutationAngles';
import { PrecessionAngles } from './PrecessionAngles';

Expand All @@ -14,7 +26,7 @@ export class Earth {
}

// / Earth gravitational parameter _(km²/s³)_.
static readonly mu: number = 398600.4415;
static readonly mu: number = earthGravityParam;

// / Earth equatorial radius.
static readonly radiusEquator = 6378.1363 as Kilometers;
Expand Down
6 changes: 3 additions & 3 deletions src/body/Moon.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @author Theodore Kruczek.
* @description Orbital Object ToolKit (ootk) is a collection of tools for working
* @description Orbital Object ToolKit Core (ootk-core) is a collection of tools for working
* with satellites and other orbital objects.
*
* Some of the math in this file was originally created by Vladimir Agafonkin.
Expand Down Expand Up @@ -96,7 +96,7 @@ export class Moon {
static radiusEquator = 1738.0;

// / Calculate the Moon's ECI position _(km)_ for a given UTC [epoch].
static eci(epoch: EpochUTC): Vector3D {
static eci(epoch: EpochUTC = EpochUTC.fromDateTime(new Date())): Vector3D {
const jc = epoch.toJulianCenturies();
const dtr = DEG2RAD;
const lamEcl =
Expand Down Expand Up @@ -296,7 +296,7 @@ export class Moon {
// formula 14.1 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998.
const pa = Math.atan2(Math.sin(H), Math.tan(phi) * Math.cos(c.dec) - Math.sin(c.dec) * Math.cos(H));

h = <Radians>(h + Celestial.astroRefraction(h)); // altitude correction for refraction
h = <Radians>(h + Celestial.atmosphericRefraction(h)); // altitude correction for refraction

return {
az: Celestial.azimuth(H, phi, c.dec),
Expand Down
22 changes: 21 additions & 1 deletion src/body/NutationAngles.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
import { Radians } from '..';

// / Earth nutation angles _(rad)_.
/**
* Represents the nutation angles.
*/
export type NutationAngles = {
/**
* The nutation in longitude (Δψ) in radians.
*/
dPsi: Radians;
/**
* The nutation in obliquity (Δε) in radians.
*/
dEps: Radians;
/**
* The mean obliquity of the ecliptic (ε₀) in radians.
*/
mEps: Radians;
/**
* The true obliquity of the ecliptic (ε) in radians.
*/
eps: Radians;
/**
* The equation of the equinoxes (ΔΔt) in radians.
*/
eqEq: Radians;
/**
* The Greenwich Apparent Sidereal Time (GAST) in radians.
*/
gast: Radians;
};
4 changes: 3 additions & 1 deletion src/body/PrecessionAngles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Radians } from '..';

// / Earth precession angles _(rad)_.
/**
* Represents the precession angles in radians.
*/
export type PrecessionAngles = {
zeta: Radians;
theta: Radians;
Expand Down
32 changes: 23 additions & 9 deletions src/body/Sun.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import { AngularDiameterMethod, AzEl, Degrees, Kilometers, Meters, RaDec, Radians, SunTime } from '..';
import { Vector3D } from '../operations/Vector3D';
import { EpochUTC } from '../time/EpochUTC';
import { astronomicalUnit, cKmPerSec, DEG2RAD, MS_PER_DAY, RAD2DEG, TAU } from '../utils/constants';
import { angularDiameter } from '../utils/functions';
import { Celestial } from './Celestial';
import { Earth } from './Earth';
import {
Earth,
Celestial,
angularDiameter,
astronomicalUnit,
cKmPerSec,
DEG2RAD,
MS_PER_DAY,
RAD2DEG,
TAU,
EpochUTC,
Vector3D,
AngularDiameterMethod,
AzEl,
Degrees,
Kilometers,
Meters,
RaDec,
Radians,
SunTime,
} from '..';

/**
* Sun metrics and operations.
Expand Down Expand Up @@ -163,7 +177,7 @@ export class Sun {

/**
* returns set time for the given sun altitude
* @param {number} h - heigh at 0
* @param {number} h - height at 0
* @param {number} lw - rad * -lng
* @param {number} phi - rad * lat;
* @param {number} dec - declination
Expand Down Expand Up @@ -347,7 +361,7 @@ export class Sun {
* @param {Degrees} lon - Degrees longitude
* @returns {number} julian cycle
*/
static julianCyle(date: Date, lon: Degrees): number {
static julianCycle(date: Date, lon: Degrees): number {
const lw = <Radians>(-lon * DEG2RAD);
const d = Sun.date2jSince2000(date);

Expand Down
7 changes: 3 additions & 4 deletions src/coordinate/ClassicalElements.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Earth } from '../body/Earth';
import { Vector3D } from '../operations/Vector3D';
import { EpochUTC } from '../time/EpochUTC';
import { RAD2DEG, sec2min, secondsPerDay, TAU } from '../utils/constants';
import { earthGravityParam, RAD2DEG, sec2min, secondsPerDay, TAU } from '../utils/constants';
import { clamp, matchHalfPlane, newtonNu } from '../utils/functions';
import { EquinoctialElements } from './EquinoctialElements';
import { OrbitRegime } from './OrbitRegime';
Expand Down Expand Up @@ -46,7 +45,7 @@ export class ClassicalElements {
rightAscension,
argPerigee,
trueAnomaly,
mu = Earth.mu,
mu = earthGravityParam,
}: ClassicalElementsParams) {
this.epoch = epoch;
this.semimajorAxis = semimajorAxis;
Expand All @@ -65,7 +64,7 @@ export class ClassicalElements {
* @returns A new instance of ClassicalElements.
* @throws Error if classical elements are undefined for fixed frames.
*/
static fromStateVector(state: StateVector, mu = Earth.mu): ClassicalElements {
static fromStateVector(state: StateVector, mu = earthGravityParam): ClassicalElements {
if (!state.inertial) {
throw new Error('Classical elements are undefined for fixed frames.');
}
Expand Down
Loading

0 comments on commit 188071e

Please sign in to comment.