Commit graph

9 commits

Author SHA1 Message Date
Martin Janiczek
70ac6918d1 LibTest: Fix integer overflow in Gen::unsigned_int(u32)
NumericLimits<u32>::max + 1 overflowing to 0 caused us to call
AK::get_random_uniform(0) which doesn't make sense (the argument is an
_exclusive_ bound).
2023-11-18 10:01:29 +01:00
Martin Janiczek
4c068ba921 LibTest: Minimize footprint of Gen::unsigned_int, simplify code
unsigned_int(0) doesn't need to draw bits from RandomnessSource.

An expression for getting INT_MAX for u32 didn't need to be
special-cased over the general formula.

This is a follow-up on a few comments
2023-10-27 12:26:06 -06:00
Martin Janiczek
32909d02b3 LibTest: Add a README documenting the high-level randomized approach 2023-10-26 17:26:52 -06:00
Martin Janiczek
30f73221fd LibTest: Add functions for shrinking a given RandomRun 2023-10-26 17:26:52 -06:00
Martin Janiczek
d534005c8d LibTest: Add the ShrinkCommand abstraction
ShrinkCommands are recipes for how a RandomRun should be shrunk. They
are not related to a specific RandomRun, although we'll take the length
of a specific RandomRun into account when generating the ShrinkCommands.

ShrinkCommands will later be interpreted by the shrink_with_command()
function.
2023-10-26 17:26:52 -06:00
Martin Janiczek
99e2d42a53 LibTest: Add a library of Generators
These functions all plug into RandomnessSource and produce random values
of various types. They are to be used either inside other generator
definitions or inside the GEN(...) macro when used in tests.
2023-10-26 17:26:52 -06:00
Martin Janiczek
7e5a3650fe LibTest: Add the RandomnessSource abstraction
This will be a foundational part of bootstrapping generators: this is
the way they'll get prerecorded values from / record random values into
RandomRuns. (Generators don't get in contact with RandomRuns
themselves, they just interact with the RandomnessSource.)
2023-10-26 17:26:52 -06:00
Martin Janiczek
d4e4189a34 LibTest: Add the RandomRun abstraction
To be used later by generators and during shrinking.

The generators used in randomized tests will record the drawn random
bits into a RandomRun. This is a layer of indirection that will help us
automatically shrink any generated value without any user input. (Having
to provide manually defined shrinkers is a downside to many randomized /
property-based testing libraries like QuickCheck for Haskell.)
2023-10-26 17:26:52 -06:00
Martin Janiczek
5dbcc396da LibTest: Add the Chunk abstraction
A prerequisite for shrinking the failing RandomRuns in randomized tests.
2023-10-26 17:26:52 -06:00