Skip to content

Commit

Permalink
pr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Oct 23, 2023
1 parent eba5eed commit 9eb8c99
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ jobs:
"examples/update",
"examples/vanilla_js",
"property_tests/tests/blob",
"property_tests/tests/bool",
"property_tests/tests/int",
"property_tests/tests/int8",
"property_tests/tests/int16",
Expand Down
3 changes: 3 additions & 0 deletions property_tests/arbitraries/candid/primitive/bool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import fc from 'fast-check';

export const BoolArb = fc.boolean();
Empty file.
11 changes: 5 additions & 6 deletions property_tests/tests/bool/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@ import { getCanisterId } from '../../../../test';
import { createUniquePrimitiveArb } from '../../../arbitraries/unique_primitive_arb';
import { JsFunctionNameArb } from '../../../arbitraries/js_function_name_arb';
import { runPropTests } from '../../..';
import { BoolArb } from '../../../arbitraries/candid/primitive/bool';

const BoolTestArb = fc
.tuple(createUniquePrimitiveArb(JsFunctionNameArb), fc.array(fc.boolean()))
.tuple(createUniquePrimitiveArb(JsFunctionNameArb), fc.array(BoolArb))
.map(([functionName, bools]) => {
const paramCandidTypes = bools.map(() => 'bool').join(', ');
const returnCandidType = 'bool';
const paramNames = bools.map((_, index) => `param${index}`);

const paramsAreNumbers = paramNames
const paramsAreBooleans = paramNames
.map((paramName) => {
return `if (typeof ${paramName} !== 'boolean') throw new Error('${paramName} must be a boolean');`;
})
.join('\n');

const paramsAnd = paramNames.reduce((acc, paramName) => {
const returnStatement = paramNames.reduce((acc, paramName) => {
return `${acc} && ${paramName}`;
}, 'true');

const returnStatement = `${paramsAnd}`;

const expectedResult = bools.reduce((acc, bool) => acc && bool, true);

const paramSamples = bools;
Expand All @@ -43,7 +42,7 @@ const BoolTestArb = fc
body: `
${paramsCorrectlyOrdered}
${paramsAreNumbers}
${paramsAreBooleans}
return ${returnStatement};
`,
Expand Down

0 comments on commit 9eb8c99

Please sign in to comment.