11namespace hegel::impl::test_case {
42 TestCase(
const TestCase&) =
delete;
43 TestCase& operator=(
const TestCase&) =
delete;
50 TestCase& operator=(TestCase&&) noexcept;
66 template <typename T> T
draw(const
generators::Generator<T>& gen) const;
83 bool repeatable = false) const;
129 void target(
double score, std::string_view label =
"") const;
150 void repeat(const std::function<
void()>& body) const;
158 void note(std::string_view message) const;
199 template <typename F> auto
spawn(F fn) const;
202 explicit TestCase(std::unique_ptr<impl::test_case::TestCaseData> data);
206 impl::test_case::TestCaseData* data()
const {
return data_.get(); }
210 std::unique_ptr<impl::test_case::TestCaseData> data_;
223 Worker(std::thread thread, std::future<T> future)
224 : thread_(std::move(thread)), future_(std::move(future)) {}
231 if (thread_.joinable()) {
245 if (thread_.joinable()) {
248 return future_.get();
253 std::future<T> future_;
257 using R = std::invoke_result_t<F, TestCase&>;
258 std::packaged_task<R()> task(
259 [fn = std::move(fn), cloned_tc =
clone()]()
mutable {
260 return fn(cloned_tc);
262 std::future<R> future = task.get_future();
263 return Worker<R>(std::thread(std::move(task)), std::move(future));
auto spawn(F fn) const
Run fn on a clone of this test case in a new thread.
Definition test_case.h:256
void repeat(const std::function< void()> &body) const
Run body in an engine-managed loop.
void reject() const
Reject the current test case unconditionally.
void assume(bool condition) const
Reject the current test case if condition is false.
void target(double score, std::string_view label="") const
Record a score for the engine's targeted-search phase to maximize.
TestCase clone() const
Creates a clone of this test case with an independent choice sequence forked from this test case.
TestCase(TestCase &&) noexcept
Move-constructs, transferring ownership of the underlying handle.
void note(std::string_view message) const
Record a message that will be printed on the final replay of a failing test case.
T draw(const generators::Generator< T > &gen) const
Draw a random value from a generator.
Definition core.h:264
Handle to a worker started by TestCase::spawn().
Definition test_case.h:220
T join()
Await the worker and return its result.
Definition test_case.h:244
Worker(Worker &&) noexcept=default
Move-constructs, transferring ownership of the running worker.
The base class of all generators.
Definition core.h:67
Hegel generators.
Definition core.h:17
Main namespace.
Definition config.h:29