Skip to content

Commit

Permalink
use better names
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Dec 22, 2023
1 parent 86b6f82 commit 2c5836b
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ServiceDefinitionArb } from '../reference/service_arb/definition_arb';
import {
CandidDefinitionMemo,
DefinitionConstraints,
RecursiveCandidDefinition
RecursiveCandidName
} from './types';

export type ComplexDefinitionWeights = Partial<{
Expand All @@ -29,7 +29,7 @@ export type ComplexDefinitionWeights = Partial<{
export const COMPLEX_ARB_COUNT = 8;

export function complexCandidDefinitionMemo(
parents: RecursiveCandidDefinition[],
parents: RecursiveCandidName[],
constraints: DefinitionConstraints = {}
): CandidDefinitionMemo {
const weights = constraints.weights ?? {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fc from 'fast-check';
import {
CandidDefinitionArb,
RecursiveCandidDefinition,
RecursiveCandidName,
CandidDefinitionMemo,
DefinitionConstraints
} from './types';
Expand All @@ -21,14 +21,14 @@ import { DEFAULT_DEF_MAX_DEPTH } from '../../config';

export function candidDefinitionArb(
maxDepth: number = DEFAULT_DEF_MAX_DEPTH,
parents: RecursiveCandidDefinition[] = [],
parents: RecursiveCandidName[] = [],
constraints: DefinitionConstraints = {}
): CandidDefinitionArb {
return candidDefinitionMemo(parents, constraints)(maxDepth);
}

export function candidDefinitionMemo(
parents: RecursiveCandidDefinition[],
parents: RecursiveCandidName[],
constraints: DefinitionConstraints = {}
): CandidDefinitionMemo {
return fc.memo((n) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fc from 'fast-check';
import { RecursiveDefinitionArb } from '../recursive/definition_arb';
import { complexCandidDefinitionMemo } from './complex_candid_definition_memo';
import { RecursiveCandidDefinition, CandidDefinitionMemo } from './types';
import { RecursiveCandidName, CandidDefinitionMemo } from './types';

// The number of options below (it's just recursive)
export const REC_ARB_COUNT = 0;
Expand All @@ -11,7 +11,7 @@ export const REC_ARB_COUNT = 0;
// https://github.com/demergent-labs/azle/issues/1525

export function recursiveCandidDefinitionMemo(
parents: RecursiveCandidDefinition[]
parents: RecursiveCandidName[]
): CandidDefinitionMemo {
return fc.memo((n) =>
RecursiveDefinitionArb(complexCandidDefinitionMemo, parents, { n })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ComplexDefinitionWeights } from './complex_candid_definition_memo';

export type CandidDefinitionMemo = (n: number) => CandidDefinitionArb;
export type RecursiveCandidDefinitionMemo = (
parents: RecursiveCandidDefinition[],
parents: RecursiveCandidName[],
constraints?: DefinitionConstraints
) => CandidDefinitionMemo;

Expand Down Expand Up @@ -88,11 +88,11 @@ export type ServiceMethodDefinition = {
};

// Recursive
export type RecursiveCandidDefinition = {
export type RecursiveCandidName = {
candidMeta: CandidMeta;
name: string;
};
export type RecursiveGlobalDefinition = {
export type RecursiveCandidDefinition = {
candidMeta: CandidMeta;
name: string;
innerType: CandidDefinition;
Expand Down
6 changes: 2 additions & 4 deletions property_tests/arbitraries/candid/candid_values_arb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import {
CandidDefinition,
OptCandidDefinition,
RecordCandidDefinition,
RecursiveCandidName,
RecursiveCandidDefinition,
RecursiveGlobalDefinition,
ServiceCandidDefinition,
TupleCandidDefinition,
VariantCandidDefinition,
Expand Down Expand Up @@ -126,9 +126,7 @@ export function CandidValueArb(
}
if (candidType === 'Recursive') {
return RecursivePlaceHolderValuesArb(
candidTypeMeta as
| RecursiveCandidDefinition
| RecursiveGlobalDefinition,
candidTypeMeta as RecursiveCandidName | RecursiveCandidDefinition,
n
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
DefinitionConstraints,
OptCandidDefinition,
RecursiveCandidDefinitionMemo,
RecursiveCandidDefinition
RecursiveCandidName
} from '../../candid_definition_arb/types';

export function OptDefinitionArb(
candidTypeArbForInnerType: RecursiveCandidDefinitionMemo,
parents: RecursiveCandidDefinition[],
parents: RecursiveCandidName[],
constraints: DefinitionConstraints
): fc.Arbitrary<OptCandidDefinition> {
return fc
Expand Down Expand Up @@ -59,7 +59,7 @@ export function OptDefinitionArb(

function possiblyRecursiveArb(
candidArb: RecursiveCandidDefinitionMemo,
parents: RecursiveCandidDefinition[],
parents: RecursiveCandidName[],
constraints: DefinitionConstraints
): fc.Arbitrary<CandidDefinition> {
const n = constraints.n ?? 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
CandidDefinition,
DefinitionConstraints,
RecursiveCandidDefinitionMemo,
RecursiveCandidDefinition,
RecursiveCandidName,
VariantCandidDefinition
} from '../../candid_definition_arb/types';
import { JsFunctionNameArb } from '../../../js_function_name_arb';
Expand All @@ -13,7 +13,7 @@ type Field = [string, CandidDefinition];

export function VariantDefinitionArb(
candidTypeArbForFields: RecursiveCandidDefinitionMemo,
parents: RecursiveCandidDefinition[],
parents: RecursiveCandidName[],
constraints: DefinitionConstraints
): fc.Arbitrary<VariantCandidDefinition> {
return fc
Expand Down Expand Up @@ -58,7 +58,7 @@ export function VariantDefinitionArb(

function VariantFieldsArb(
candidTypeArb: RecursiveCandidDefinitionMemo,
parents: RecursiveCandidDefinition[],
parents: RecursiveCandidName[],
constraints: DefinitionConstraints
): fc.Arbitrary<Field[]> {
// Although no minLength is technically required (according to the
Expand Down Expand Up @@ -98,7 +98,7 @@ function VariantFieldsArb(
function possiblyRecursiveArb(
candidArb: RecursiveCandidDefinitionMemo,
index: number,
parents: RecursiveCandidDefinition[],
parents: RecursiveCandidName[],
constraints: DefinitionConstraints
): fc.Arbitrary<CandidDefinition> {
const n = constraints.n ?? 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
CandidDefinition,
DefinitionConstraints,
RecursiveCandidDefinitionMemo,
RecursiveCandidDefinition,
RecursiveCandidName,
VecCandidDefinition
} from '../../candid_definition_arb/types';

export function VecDefinitionArb(
candidTypeArb: RecursiveCandidDefinitionMemo,
parents: RecursiveCandidDefinition[],
parents: RecursiveCandidName[],
constraints: DefinitionConstraints
): fc.Arbitrary<VecCandidDefinition> {
return fc
Expand Down Expand Up @@ -55,7 +55,7 @@ export function VecDefinitionArb(

function possiblyRecursiveArb(
candidArb: RecursiveCandidDefinitionMemo,
parents: RecursiveCandidDefinition[],
parents: RecursiveCandidName[],
constraints: DefinitionConstraints
): fc.Arbitrary<CandidDefinition> {
const n = constraints.n ?? 0;
Expand Down
14 changes: 7 additions & 7 deletions property_tests/arbitraries/candid/recursive/definition_arb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import {
CandidDefinition,
DefinitionConstraints,
RecursiveCandidDefinitionMemo,
RecursiveCandidDefinition,
RecursiveGlobalDefinition
RecursiveCandidName,
RecursiveCandidDefinition
} from '../candid_definition_arb/types';
import { recursive } from '.';

export function RecursiveDefinitionArb(
candidTypeArbForInnerType: RecursiveCandidDefinitionMemo,
parents: RecursiveCandidDefinition[],
parents: RecursiveCandidName[],
constraints: DefinitionConstraints
): fc.Arbitrary<RecursiveGlobalDefinition> {
): fc.Arbitrary<RecursiveCandidDefinition> {
return UniqueIdentifierArb('typeDeclaration')
.chain((name): fc.Arbitrary<RecursiveCandidDefinition> => {
const recCanDef: RecursiveCandidDefinition = {
.chain((name): fc.Arbitrary<RecursiveCandidName> => {
const recCanDef: RecursiveCandidName = {
candidMeta: {
candidType: 'Recursive',
candidTypeObject: name,
Expand Down Expand Up @@ -57,7 +57,7 @@ export function RecursiveDefinitionArb(

const imports = generateImports(innerType);

const shape: RecursiveGlobalDefinition = {
const shape: RecursiveCandidDefinition = {
candidMeta: {
candidTypeObject,
candidTypeAnnotation,
Expand Down
4 changes: 2 additions & 2 deletions property_tests/arbitraries/candid/recursive/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import fc from 'fast-check';
import { CandidValueAndMeta } from '../candid_value_and_meta_arb';
import { RecursiveGlobalDefinition } from '../candid_definition_arb/types';
import { RecursiveCandidDefinition } from '../candid_definition_arb/types';
import { RecursiveDefinitionArb } from './definition_arb';
import { RecursiveValuesArb } from './values_arb';
import { CandidValueAndMetaArbGenerator } from '../candid_value_and_meta_arb_generator';
import { complexCandidDefinitionMemo } from '../candid_definition_arb/complex_candid_definition_memo';
import { DEFAULT_DEF_MAX_DEPTH } from '../../config';

export const recursive: {
shapes: { [key: string]: RecursiveGlobalDefinition };
shapes: { [key: string]: RecursiveCandidDefinition };
} = {
shapes: {}
};
Expand Down
8 changes: 4 additions & 4 deletions property_tests/arbitraries/candid/recursive/values_arb.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import fc from 'fast-check';
import { Recursive, recursive } from '.';
import {
RecursiveCandidDefinition,
RecursiveGlobalDefinition
RecursiveCandidName,
RecursiveCandidDefinition
} from '../candid_definition_arb/types';
import { CandidValues, CandidValueArb } from '../candid_values_arb';

export function RecursivePlaceHolderValuesArb(
recDefinition: RecursiveCandidDefinition | RecursiveGlobalDefinition,
recDefinition: RecursiveCandidName | RecursiveCandidDefinition,
n: number
): fc.Arbitrary<CandidValues<Recursive>> {
const recShape = recursive.shapes[recDefinition.name];
return RecursiveValuesArb(recShape, n);
}

export function RecursiveValuesArb(
recDefinition: RecursiveGlobalDefinition,
recDefinition: RecursiveCandidDefinition,
n: number
): fc.Arbitrary<CandidValues<Recursive>> {
return CandidValueArb(recDefinition.innerType, n);
Expand Down

0 comments on commit 2c5836b

Please sign in to comment.