Skip to content

Commit

Permalink
pr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Nov 2, 2023
1 parent 046b3ab commit 3fb2e0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions property_tests/arbitraries/candid/constructed/opt_arb.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import fc from 'fast-check';
import { Candid, CandidType, CandidTypeArb } from '../../candid';

type InnerOptArb = ['Some' | 'None', Candid<CandidType>];
type BaseOpt = ['Some' | 'None', Candid<CandidType>];

// This gives us a random Some or None, which means the default depth of all Opts is at least one
const InnerOptArb = (arb: fc.Arbitrary<Candid<CandidType>>) => {
const BaseOptArb = (arb: fc.Arbitrary<Candid<CandidType>>) => {
return fc.constantFrom('Some', 'None').chain((keySample) => {
return arb.map((innerValueSample): InnerOptArb => {
return arb.map((innerValueSample): BaseOpt => {
if (keySample === 'Some') {
return ['Some', innerValueSample];
} else {
Expand All @@ -18,7 +18,7 @@ const InnerOptArb = (arb: fc.Arbitrary<Candid<CandidType>>) => {

// TODO look into making this recursive
// TODO we need to add all constructed and reference types
export const PrimitiveOptArb = InnerOptArb(CandidTypeArb);
export const PrimitiveOptArb = BaseOptArb(CandidTypeArb);

type RecursiveOpt<T> = {
base: T;
Expand All @@ -33,7 +33,7 @@ export const OptArb = fc
base: PrimitiveOptArb,
nextLayer: fc
.option(tie('RecursiveOptArb'), { maxDepth: 10 })
.map((sample) => sample as RecursiveOpt<InnerOptArb>)
.map((sample) => sample as RecursiveOpt<BaseOpt>)
})
}))
.RecursiveOptArb.map((recursiveOptArb): Candid<Opt> => {
Expand All @@ -48,7 +48,7 @@ export const OptArb = fc
};
});

function generateCandidType(recursiveOpt: RecursiveOpt<InnerOptArb>): string {
function generateCandidType(recursiveOpt: RecursiveOpt<BaseOpt>): string {
if (recursiveOpt.nextLayer === null) {
// base case
return `Opt(${recursiveOpt.base[1].src.candidType})`;
Expand All @@ -57,7 +57,7 @@ function generateCandidType(recursiveOpt: RecursiveOpt<InnerOptArb>): string {
}
}

function generateImports(recursiveOpt: RecursiveOpt<InnerOptArb>): Set<string> {
function generateImports(recursiveOpt: RecursiveOpt<BaseOpt>): Set<string> {
if (recursiveOpt.nextLayer === null) {
// base case
return new Set([...recursiveOpt.base[1].src.imports, 'Opt']);
Expand All @@ -66,7 +66,7 @@ function generateImports(recursiveOpt: RecursiveOpt<InnerOptArb>): Set<string> {
}
}

function generateValue(recursiveOpt: RecursiveOpt<InnerOptArb>): Opt {
function generateValue(recursiveOpt: RecursiveOpt<BaseOpt>): Opt {
if (recursiveOpt.nextLayer === null) {
// base case
if (recursiveOpt.base[0] === 'Some') {
Expand All @@ -79,7 +79,7 @@ function generateValue(recursiveOpt: RecursiveOpt<InnerOptArb>): Opt {
}
}

function generateValueLiteral(recursiveOpt: RecursiveOpt<InnerOptArb>): string {
function generateValueLiteral(recursiveOpt: RecursiveOpt<BaseOpt>): string {
if (recursiveOpt.nextLayer === null) {
// base case
if (recursiveOpt.base[0] === 'Some') {
Expand Down Expand Up @@ -118,7 +118,7 @@ function calculateDepthAndValues(value: [any] | []): {
}

function getBaseEquals(
recursiveOpt: RecursiveOpt<InnerOptArb>
recursiveOpt: RecursiveOpt<BaseOpt>
): (a: any, b: any) => boolean {
if (recursiveOpt.nextLayer === null) {
// base case
Expand Down
2 changes: 1 addition & 1 deletion property_tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function runPropTests(testArb: fc.Arbitrary<TestSample>) {

return await runTests(
canister.tests,
process.env.AZLE_PROPTEST_VERBOSE === undefined
process.env.AZLE_PROPTEST_VERBOSE !== 'true'
);
}),
{
Expand Down

0 comments on commit 3fb2e0f

Please sign in to comment.