Skip to content

Commit

Permalink
Refactor arbitraries
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Apr 28, 2024
1 parent 764a9bd commit a86511b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 36 deletions.
36 changes: 36 additions & 0 deletions test/arbitrary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { fc } from "@fast-check/vitest";
import {
GRS_80,
WGS_72,
WGS_84,
WGS_84_SPHERE,
type Ellipsoid,
} from "../src/ellipsoid.js";
import type { Matrix3x3 } from "../src/matrix.js";
import type { Vector3, Vector4 } from "../src/vector.js";

Expand Down Expand Up @@ -49,6 +56,35 @@ export function arbitrary3dUnitVector(): fc.Arbitrary<Vector3> {
});
}

export function arbitraryEllipsoid(): fc.Arbitrary<Ellipsoid> {
return fc.oneof(
fc.constant(WGS_84),
fc.constant(WGS_84_SPHERE),
fc.constant(WGS_72),
fc.constant(GRS_80),
);
}

export function arbitraryEllipsoidDepth({
a,
f,
}: Ellipsoid): fc.Arbitrary<number> {
// semi-minor axis
const b = a * (1 - f);

return fc.double({ min: -b, max: b, noNaN: true });
}

export function arbitraryEllipsoidECEFVector({
a,
f,
}: Ellipsoid): fc.Arbitrary<Vector3> {
// semi-minor axis
const b = a * (1 - f);

return arbitrary3dVector({ min: a - b, max: a + b, noNaN: true });
}

export function arbitraryLatLon(): fc.Arbitrary<[number, number]> {
return fc.tuple(
fc.double({
Expand Down
29 changes: 9 additions & 20 deletions test/vitest/n_EB_E2p_EB_E.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { fc, it } from "@fast-check/vitest";
import { afterAll, beforeAll, describe, expect } from "vitest";
import { GRS_80, WGS_72, WGS_84, WGS_84_SPHERE } from "../../src/ellipsoid.js";
import { n_EB_E2p_EB_E } from "../../src/index.js";
import {
arbitrary3dRotationMatrix,
arbitrary3dUnitVector,
arbitraryEllipsoid,
arbitraryEllipsoidDepth,
} from "../arbitrary.js";
import {
NvectorTestClient,
Expand All @@ -27,25 +28,13 @@ describe("n_EB_E2p_EB_E()", () => {
it.prop(
[
arbitrary3dUnitVector(),
fc
.oneof(
fc.constant(WGS_84),
fc.constant(WGS_84_SPHERE),
fc.constant(WGS_72),
fc.constant(GRS_80),
)
.chain(({ a, f }) => {
// semi-minor axis
const b = a * (1 - f);

return fc.tuple(
fc.option(fc.double({ min: -b, max: b, noNaN: true }), {
nil: undefined,
}),
fc.option(fc.constant(a), { nil: undefined }),
fc.option(fc.constant(f), { nil: undefined }),
);
}),
arbitraryEllipsoid().chain((ellipsoid) => {
return fc.tuple(
arbitraryEllipsoidDepth(ellipsoid),
fc.option(fc.constant(ellipsoid.a), { nil: undefined }),
fc.option(fc.constant(ellipsoid.f), { nil: undefined }),
);
}),
fc.option(arbitrary3dRotationMatrix(), { nil: undefined }),
],
{ interruptAfterTimeLimit: TEST_DURATION, numRuns: Infinity },
Expand Down
27 changes: 11 additions & 16 deletions test/vitest/p_EB_E2n_EB_E.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { fc, it } from "@fast-check/vitest";
import { afterAll, beforeAll, describe, expect } from "vitest";
import { GRS_80, WGS_72, WGS_84, WGS_84_SPHERE } from "../../src/ellipsoid.js";
import { WGS_84 } from "../../src/ellipsoid.js";
import { p_EB_E2n_EB_E } from "../../src/index.js";
import { ROTATION_MATRIX_e, rotate } from "../../src/rotation.js";
import { arbitrary3dRotationMatrix, arbitrary3dVector } from "../arbitrary.js";
import {
arbitrary3dRotationMatrix,
arbitraryEllipsoid,
arbitraryEllipsoidECEFVector,
} from "../arbitrary.js";
import {
NvectorTestClient,
createNvectorTestClient,
Expand All @@ -24,21 +28,12 @@ describe("p_EB_E2n_EB_E()", () => {

it.prop(
[
fc
.oneof(
fc.constant(WGS_84),
fc.constant(WGS_84_SPHERE),
fc.constant(WGS_72),
fc.constant(GRS_80),
)
.chain(({ a, f }) => {
// semi-minor axis
const b = a * (1 - f);

arbitraryEllipsoid()
.chain((ellipsoid) => {
return fc.tuple(
arbitrary3dVector({ min: a - b, max: a + b, noNaN: true }),
fc.option(fc.constant(a), { nil: undefined }),
fc.option(fc.constant(f), { nil: undefined }),
arbitraryEllipsoidECEFVector(ellipsoid),
fc.option(fc.constant(ellipsoid.a), { nil: undefined }),
fc.option(fc.constant(ellipsoid.f), { nil: undefined }),
fc.option(arbitrary3dRotationMatrix(), { nil: undefined }),
);
})
Expand Down

0 comments on commit a86511b

Please sign in to comment.