mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 10:47:34 +00:00
LibTest: Change #define-d constants into constexpr and a runtime flag
MAX_GENERATED_VALUES_PER_TEST is now the --randomized_runs flag: $ ./Build/lagom/bin/TestGenerator --randomized_runs 1000 It's sometimes useful to try larger numbers for it instead of the default of 100. MAX_GEN_ATTEMPTS_PER_VALUE is now a constexpr. It's not usually needed to tweak this value; we can recompile with a different value on the rare occasion.
This commit is contained in:
parent
ed60a032a8
commit
4fc1daa69f
4 changed files with 23 additions and 18 deletions
|
@ -7,22 +7,13 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibTest/Macros.h> // intentionally first -- we redefine VERIFY and friends in here
|
||||
#include <LibTest/Randomized/RandomnessSource.h>
|
||||
#include <LibTest/Randomized/Shrink.h>
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/RefCounted.h>
|
||||
|
||||
#ifndef MAX_GENERATED_VALUES_PER_TEST
|
||||
# define MAX_GENERATED_VALUES_PER_TEST 100
|
||||
#endif
|
||||
|
||||
#ifndef MAX_GEN_ATTEMPTS_PER_VALUE
|
||||
# define MAX_GEN_ATTEMPTS_PER_VALUE 15
|
||||
#endif
|
||||
#include <LibTest/Macros.h>
|
||||
#include <LibTest/Randomized/RandomnessSource.h>
|
||||
#include <LibTest/Randomized/Shrink.h>
|
||||
|
||||
namespace Test {
|
||||
|
||||
|
@ -54,8 +45,12 @@ public:
|
|||
static NonnullRefPtr<TestCase> randomized(DeprecatedString const& name, TestFunction&& test_function)
|
||||
{
|
||||
using namespace Randomized;
|
||||
|
||||
constexpr u8 MAX_GEN_ATTEMPTS_PER_VALUE = 15;
|
||||
|
||||
TestFunction test_case_function = [test_function = move(test_function)]() {
|
||||
for (u32 i = 0; i < MAX_GENERATED_VALUES_PER_TEST; ++i) {
|
||||
u64 max_randomized_runs = randomized_runs();
|
||||
for (u64 i = 0; i < max_randomized_runs; ++i) {
|
||||
bool generated_successfully = false;
|
||||
u8 gen_attempt;
|
||||
for (gen_attempt = 0; gen_attempt < MAX_GEN_ATTEMPTS_PER_VALUE && !generated_successfully; ++gen_attempt) {
|
||||
|
@ -100,7 +95,7 @@ public:
|
|||
return;
|
||||
}
|
||||
}
|
||||
// MAX_GENERATED_VALUES_PER_TEST values generated, all passed the test.
|
||||
// All randomized_runs() values generated + passed the test.
|
||||
};
|
||||
return make_ref_counted<TestCase>(name, move(test_case_function), false);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue