-
|
We're using Fast-check to run property tests against our Effect Schema but Fast-check is struggling to generate values that match the schema for BigDecimal values. Our code looks like this: const schema = Schema.Struct({
money: Schema.BigDecimal.pipe(Schema.betweenBigDecimal($`0`, $`100_000_000`))
}
const arbitrary = Arbitrary.make(schema)
FastCheck.asyncProperty(arbitrary, async (generated) => {
console.log({money: BigDecimal.unsafeToNumber(generated.money).toString() });
}When we log out the generated values, they are all very small decimals (all less than 100 I believe). It feels like they are the wrong order of magnitude (schema defines it as between 0 and 100,000,000). e.g.: I asked this on the fast-check repo and they said it was to do with how the Effect library maps BigDecimal to an Arbitrary. Thread here |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
|
I can't reproduce it, I'm seeing large values here import { Arbitrary, BigDecimal, FastCheck, Schema } from "effect"
const schema = Schema.Struct({
money: Schema.BigDecimal.pipe(Schema.betweenBigDecimal(
BigDecimal.fromBigInt(0n),
BigDecimal.fromBigInt(100000000n)
))
})
const arbitrary = Arbitrary.make(schema)
console.log(FastCheck.sample(arbitrary, 100).map((x) => BigDecimal.unsafeToNumber(x.money).toString()))
/*
[
'65000', '1200', '15', '3.5e-11', '26000000', '2100',
'2.2', '0.67', '7.7e-14', '7.2e-7', '7200', '0.0000059',
'1.8e-13', '0.0000062', '5800', '580', '2.5e-13', '5e-14',
'1700', '3700', '2.3e-16', '4.1e-17', '140', '38',
'2.3e-7', '49000000', '5e-16', '480000', '4e-11', '600',
'4.1e-17', '5.1e-16', '4300', '0.6', '550', '3e-8',
'310000', '4.8', '6.9e-12', '610', '0.74', '0',
'6.3e-9', '0.0074', '4.4e-12', '7.7e-17', '0.042', '0.00051',
'4.1e-15', '7.5e-11', '3.4', '0.043', '27000000', '1.1e-16',
'1600000', '3000000', '7.6e-12', '60000', '760000', '0.0013',
'0', '1.7e-12', '1.8e-7', '0.00068', '620000', '0.002',
'0.57', '0.4', '36000', '4.2e-10', '2e-18', '0.33',
'30', '5.8e-9', '5600', '3500', '2e-14', '0.000076',
'6e-16', '410', '7e-11', '58', '6.6e-9', '100000000',
'0.032', '1e-9', '3.5e-11', '0.003', '450', '0.19',
'0.59', '0.0067', '0.004', '0.00035', '0.008', '110',
'5000', '0.009', '1.3e-16', '37'
]
*/ |
Beta Was this translation helpful? Give feedback.
-
|
Thanks, version 3.19.9 of Effect works. |
Beta Was this translation helpful? Give feedback.
That's because I was being dumb, and while trying to reproduce the issue I accidentally changed the way values were being generated.
So the code responsible is here:
effect/packages/effect/src/Schema.ts
Line 7890 in fb53370
Here
fc.integer({ min: 0, max: 18 })generates the scale.I guess we could tweak that, maybe to
fc.integer({ min: -18, max: 18 })?