mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 09:34:57 +09:00
LibTest: Add more numeric generators
Rename unsigned_int generator to number_u32. Add generators: - number_u64 - number_f64 - percentage
This commit is contained in:
parent
dd53f64d2f
commit
d52ffcd830
Notes:
sideshowbarker
2024-07-17 06:40:21 +09:00
Author: https://github.com/Janiczek
Commit: d52ffcd830
Pull-request: https://github.com/SerenityOS/serenity/pull/22506
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/LucasChollet
Reviewed-by: https://github.com/ronak69
15 changed files with 312 additions and 133 deletions
|
@ -72,13 +72,13 @@ RANDOMIZED_TEST_CASE(count_leading_zeroes)
|
|||
{
|
||||
// count_leading_zeroes(0b000...0001000...000)
|
||||
// == count_leading_zeroes(0b000...0001___...___) (where _ is 0 or 1)
|
||||
GEN(e, Gen::unsigned_int(0, 63));
|
||||
GEN(e, Gen::number_u64(0, 63));
|
||||
auto power_of_two = 1ULL << e;
|
||||
|
||||
// We add random one-bits below the leftmost (and only) one-bit.
|
||||
// This shouldn't change the output of count_leading_zeroes because
|
||||
// the function should only care about the most significant one.
|
||||
GEN(below, Gen::unsigned_int(0, power_of_two - 1));
|
||||
GEN(below, Gen::number_u64(0, power_of_two - 1));
|
||||
auto n = power_of_two + below;
|
||||
|
||||
EXPECT_EQ(count_leading_zeroes(n), count_leading_zeroes(power_of_two));
|
||||
|
@ -89,7 +89,7 @@ RANDOMIZED_TEST_CASE(count_required_bits)
|
|||
// count_required_bits(n) == log2(n) + 1
|
||||
|
||||
// log2(0) is -infinity, we don't care about that
|
||||
GEN(n, Gen::unsigned_int(1, NumericLimits<u32>::max()));
|
||||
GEN(n, Gen::number_u32(1, NumericLimits<u32>::max()));
|
||||
|
||||
size_t expected = AK::log2(static_cast<double>(n)) + 1;
|
||||
|
||||
|
@ -99,6 +99,6 @@ RANDOMIZED_TEST_CASE(count_required_bits)
|
|||
RANDOMIZED_TEST_CASE(bit_scan_forward_count_trailing_zeroes)
|
||||
{
|
||||
// Behaviour for 0 differs, so we skip it.
|
||||
GEN(n, Gen::unsigned_int(1, 1 << 31));
|
||||
GEN(n, Gen::number_u32(1, 1 << 31));
|
||||
EXPECT_EQ(bit_scan_forward(n), count_trailing_zeroes(n) + 1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue