Skip to content

Instantly share code, notes, and snippets.

@wirelessr
Created May 10, 2022 08:30
Show Gist options
  • Save wirelessr/cb7e073d15342843dcadf97be89a2f51 to your computer and use it in GitHub Desktop.
Save wirelessr/cb7e073d15342843dcadf97be89a2f51 to your computer and use it in GitHub Desktop.
fast-check examples
describe("fast-check test", () => {
before(async () => {
// generate 10 random records
});
it("#1", async () => {
const result = await getMoney(100);
expect(result.length).to.be.equal(10);
});
it("#2", async () => {
await fc.assert(
fc.asyncProperty(fc.integer(), async (i) => {
const result = await getMoney(i);
return result.length <= 10 && result.length >= 0;
})
);
});
it("#3", async () => {
await fc.assert(
fc.asyncProperty(fc.integer({ min: 0, max: 10 }), async (i) => {
const result = await getMoney(i);
return result.length === i;
})
);
});
it("#4", async () => {
await fc.assert(
fc.asyncProperty(fc.integer(), async (i) => {
const result = await getMoney(i);
if (result.length > 1) {
let prev = parseFloat(result[0]);
for (let i = 1; i < result.length; i++) {
const curr = parseFloat(result[i]);
if (curr < prev) {
return false;
}
prev = curr;
}
}
return true;
})
);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment