summaryrefslogtreecommitdiff
path: root/pbt/ts/src/gen.test.ts
blob: eaba36f94ea134edc722266c3727b88fb95cff28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import Prando from 'prando';
import {none} from 'fp-ts/lib/Option.js';
import * as G from './gen.js';
import {test, expect} from 'vitest';

test('can generate and shrink bytes', async () => {
  const prng = new Prando(Math.random() * 1000);
  const gen = new G.BytesGen(prng);
  const bytes: number[][] = [];
  for (let i = 1; i < 10; i++) {
    bytes.push(gen.generate(i));
  }
  console.log('Generated bytes:', bytes);
  const replay = gen.replay();
  for (let i = 1; i < 10; i++) {
    const replayed = replay.generate(i);
    expect(replayed, `Replaying at ${i}`).toEqual(bytes[i - 1]);
  }
});