Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make spoiler functions to be reusable #257

Closed
samchon opened this issue Oct 22, 2022 · 1 comment
Closed

Make spoiler functions to be reusable #257

samchon opened this issue Oct 22, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@samchon
Copy link
Owner

samchon commented Oct 22, 2022

My test automation program has lots of DTO structures and spoiled cases. However, spoiler cases are hard-coded into each test functions and its makes hard to utilize them. In this case, TypeBox author (@sinclairzx81) came here to benchmark each library and suffered from duplicated code implementations by such environment.

Therefore, make spoiler functions to reusable by declaring spoiler functions on each DTO structures like below:

export type ObjectSimple = ObjectSimple.IBox3D;
export namespace ObjectSimple {
    export interface IBox3D {
        scale: IPoint3D;
        position: IPoint3D;
        rotate: IPoint3D;
        pivot: IPoint3D;
    }
    export interface IPoint3D {
        x: number;
        y: number;
        z: number;
    }

    export function generate(): ObjectSimple {
        const point = (): IPoint3D => ({
            x: RandomGenerator.integer(),
            y: RandomGenerator.integer(),
            z: RandomGenerator.integer(),
        });
        return {
            scale: point(),
            position: point(),
            rotate: point(),
            pivot: point(),
        };
    }

    export const SPOILERS: Spoiler<ObjectSimple>[] = [
        (input) => {
            input.scale.x = "number" as any;
            return ["$input.scale.x"];
        },
        (input) => {
            input.position = [] as any;
            return [
                "$input.position.x",
                "$input.position.y",
                "$input.position.z",
            ];
        },
        (input) => {
            input.rotate = undefined!;
            return ["$input.rotate"];
        },
        (input) => {
            input.pivot = null!;
            return ["$input.pivot"];
        },
    ];
}
@samchon samchon added the enhancement New feature or request label Oct 22, 2022
@samchon samchon self-assigned this Oct 22, 2022
@samchon samchon changed the title Make spoiler functions to reusable Make spoiler functions to be reusable Oct 22, 2022
samchon added a commit that referenced this issue Oct 22, 2022
@samchon
Copy link
Owner Author

samchon commented Oct 22, 2022

Benchmark result:

is

image

assertType

image

validate

image

samchon added a commit that referenced this issue Oct 22, 2022
samchon added a commit that referenced this issue Oct 23, 2022
Developing #257 - spoiler functions are reusable
samchon added a commit that referenced this issue Oct 23, 2022
samchon added a commit that referenced this issue Oct 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant