Skip to content

Commit

Permalink
feat: random int
Browse files Browse the repository at this point in the history
  • Loading branch information
ItMaga committed Nov 29, 2023
1 parent d5975e4 commit 25aecdb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/generators/NumberGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import type BaseGenerator from './BaseGenerator';

export default class NumberGenerator<T extends z.ZodNumber> implements BaseGenerator<T> {
public generate(schema: T) {
let number: z.infer<T> = 1;
let number: z.infer<T> = this.randomInt();

if (schema._def.checks && schema._def.checks.length > 0) {
for (const check of schema._def.checks) {
switch (check.kind) {
case 'int':
case 'finite':
number = 1;
number = this.randomInt();
break;
case 'min':
number = check.value + 1;
Expand All @@ -27,4 +27,8 @@ export default class NumberGenerator<T extends z.ZodNumber> implements BaseGener

return number;
}

private randomInt() {
return Math.floor(Math.random() * 1000);
}
}

0 comments on commit 25aecdb

Please sign in to comment.