Skip to content

Commit

Permalink
Bump to v2 (#9)
Browse files Browse the repository at this point in the history
* Bumped to API v2.x.x referencing to original [Python based implementation](https://github.com/o-murphy/py-ballisticcalc)
  • Loading branch information
o-murphy authored Sep 9, 2024
1 parent 9c3b066 commit 7a5f9d2
Show file tree
Hide file tree
Showing 21 changed files with 6,570 additions and 5 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Node.js Unittests

on:
pull_request:
branches:
- '*'
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
- run: npm test
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"atmo"
]
}
4 changes: 2 additions & 2 deletions __tests__/trajectory.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {describe, expect, test} from '@jest/globals';
import {Ammo, Atmo, DragModel, Table, Shot, TrajectoryCalc, UNew, Unit, Weapon, Wind, TrajFlag} from "../src/index.js";
import {Ammo, Atmo, DragModel, Table, Shot, TrajectoryCalc, UNew, Unit, Weapon, Wind, TrajFlag, TrajectoryData} from "../src/index.js";

describe("TrajectoryCalc", () => {

Expand Down Expand Up @@ -105,7 +105,7 @@ describe("TrajectoryCalc", () => {
customAssertEqual(data.length, 11, 0.1, "Length")

const test_data = [
[data[0], 0, 2750, 2.463, 2820.6, -2, 0, 0, 0, 0, 880, Unit.MOA],
[data[0], 0, 2750.0, 2.463, 2820.6, -2, 0, 0, 0, 0, 880, Unit.MOA],
[data[1], 100, 2351.2, 2.106, 2061, 0, 0, -0.6, -0.6, 0.118, 550, Unit.MOA],
[data[5], 500, 1169.1, 1.047, 509.8, -87.9, -16.8, -19.5, -3.7, 0.857, 67, Unit.MOA],
[data[10], 1000, 776.4, 0.695, 224.9, -823.9, -78.7, -87.5, -8.4, 2.495, 20, Unit.MOA]
Expand Down
44 changes: 44 additions & 0 deletions __tests__/v2/atmosphere.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Atmo, Temperature, Pressure, Velocity, UNew } from "../../src/v2";

describe('Atmo Class Tests', () => {
let standard: Atmo;
let highICAO: Atmo;
let highISA: Atmo;
let custom: Atmo;

beforeEach(() => {
standard = Atmo.standard({});
highICAO = Atmo.standard({altitude: UNew.Foot(10000)});
highISA = Atmo.standard({altitude: UNew.Meter(1000)});
custom = new Atmo({
pressure: UNew.InHg(31),
temperature: UNew.Fahrenheit(30),
humidity: 0.5
}
);
});

test('Standard atmosphere properties', () => {
expect(standard.temperature.In(Temperature.Fahrenheit)).toBeCloseTo(59.0, 1);
expect(standard.pressure.In(Pressure.hPa)).toBeCloseTo(1013.25, 1);
expect(standard.densityImperial).toBeCloseTo(0.076474, 4);
});

test('High altitude properties (ICAO and ISA)', () => {
// Ref https://www.engineeringtoolbox.com/standard-atmosphere-d_604.html
expect(highICAO.temperature.In(Temperature.Fahrenheit)).toBeCloseTo(23.36, 1);
expect(highICAO.densityRatio).toBeCloseTo(0.7387, 3);
// Ref https://www.engineeringtoolbox.com/international-standard-atmosphere-d_985.html
expect(highISA.pressure.In(Pressure.hPa)).toBeCloseTo(899, 0);
expect(highISA.densityRatio).toBeCloseTo(0.9075, 4);
});

test('Mach calculations', () => {
// Ref https://www.omnicalculator.com/physics/speed-of-sound
expect(Atmo.machF(59)).toBeCloseTo(1116.15, 0);
expect(Atmo.machF(10)).toBeCloseTo(1062.11, 0);
expect(Atmo.machF(99)).toBeCloseTo(1158.39, 0);
expect(Atmo.machC(-20)).toBeCloseTo(318.94, 1);
expect(highISA.mach.In(Velocity.MPS)).toBeCloseTo(336.4, 1);
});
});
Loading

0 comments on commit 7a5f9d2

Please sign in to comment.