Skip to content

Commit

Permalink
add property tests for Ratio module
Browse files Browse the repository at this point in the history
  • Loading branch information
chfanghr committed Oct 30, 2024
1 parent ba07448 commit 75e3411
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/Tests/Ratio-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import fc from "fast-check";
import * as LbRatio from "../Lib/Ratio.js";
import { describe, it } from "node:test";
import * as TestUtils from "./TestUtils.js";

export function fcRational(): fc.Arbitrary<LbRatio.Rational> {
return fc
.tuple(
fc.bigInt(),
fc.bigInt().filter((n) => n !== 0n),
)
.map(([numerator, denominator]) => {
return {
numerator,
denominator,
};
});
}

describe("Ratio tests", () => {
describe("Eq Rational tests", () => {
it(`eq is not neq property based tests`, () => {
fc.assert(
fc.property(fcRational(), fcRational(), (l, r) => {
TestUtils.negationTest(LbRatio.eqRational, l, r);
}),
{ examples: [] },
);
});
});
describe("Json Rational tests", () => {
it(`toJson/fromJson property based tests`, () => {
fc.assert(
fc.property(fcRational(), (data) => {
TestUtils.toJsonFromJsonRoundTrip(LbRatio.jsonRational, data);
}),
{ examples: [] },
);
});
});
describe("IsPlutusData AssocMap tests", () => {
it(`toData/fromData property based tests`, () => {
fc.assert(
fc.property(fcRational(), (data) => {
TestUtils.isPlutusDataRoundTrip(LbRatio.isPlutusDataRational, data);
}),
{ examples: [] },
);
});
});
});

0 comments on commit 75e3411

Please sign in to comment.