Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/Progmasoft/Catch3/Generator.hpp
diff options
context:
space:
mode:
authorLeitwolf112026-09-24 22:07:03 +0300
committerLeitwolf112026-09-24 22:07:03 +0300
commit9ad804cedf4cc4a85ef89fe097f97a3b44654360 (patch)
treef088e919776b22d19387377bdbec727daa2429c0 /src/Progmasoft/Catch3/Generator.hpp
parent02f8b5593a15cdec8558256e6f40a0c7fb5862d6 (diff)
downloadcatch3-0.1.0.tar.gz
Add Progmasoft Catch3 property testing and build support0.1.0
Introduce deterministic property execution, built-in generators, shrinking, replayable seeds, and a separate Progmasoft-owned header API while preserving Catch2 compatibility targets and the C++14 engine baseline. Add Bazel, Meson, Xmake, and Premake integration and tests alongside the existing CMake build. Replace Linux-only workflow coverage with Windows and macOS jobs and document the Catch2/Catch3 distinction.
Diffstat (limited to 'src/Progmasoft/Catch3/Generator.hpp')
-rw-r--r--src/Progmasoft/Catch3/Generator.hpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/Progmasoft/Catch3/Generator.hpp b/src/Progmasoft/Catch3/Generator.hpp
new file mode 100644
index 00000000..0e48aaa3
--- /dev/null
+++ b/src/Progmasoft/Catch3/Generator.hpp
@@ -0,0 +1,61 @@
+// Copyright (c) 2026 Progmasoft.
+// SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-1.1
+#pragma once
+
+#include <Progmasoft/Catch3/Random.hpp>
+
+#include <functional>
+#include <stdexcept>
+#include <utility>
+#include <vector>
+
+namespace Progmasoft::Catch3 {
+
+ /// A value source paired with an ordered sequence of simpler candidates.
+ ///
+ /// The property runner owns the shrinking policy; generators only describe
+ /// which candidates are valid and which order is most useful for
+ /// minimization.
+ template <typename ValueType>
+ class Generator final {
+ public:
+ using GenerationFunction = std::function<ValueType( Random& )>;
+ using ShrinkingFunction =
+ std::function<std::vector<ValueType>( const ValueType& )>;
+
+ Generator( GenerationFunction generate, ShrinkingFunction shrink ):
+ generate_( std::move( generate ) ), shrink_( std::move( shrink ) ) {
+ if ( !generate_ || !shrink_ ) {
+ throw std::invalid_argument(
+ "a generator requires both callbacks" );
+ }
+ }
+
+ [[nodiscard]] ValueType Generate( Random& random ) const {
+ return generate_( random );
+ }
+
+ [[nodiscard]] std::vector<ValueType>
+ Shrink( const ValueType& value ) const {
+ return shrink_( value );
+ }
+
+ private:
+ GenerationFunction generate_;
+ ShrinkingFunction shrink_;
+ };
+
+ /// Adapts user callables into a reusable generator.
+ template <typename ValueType,
+ typename GenerateFunction,
+ typename ShrinkFunction>
+ [[nodiscard]] Generator<ValueType>
+ MakeGenerator( GenerateFunction&& generate, ShrinkFunction&& shrink ) {
+ return Generator<ValueType>(
+ typename Generator<ValueType>::GenerationFunction(
+ std::forward<GenerateFunction>( generate ) ),
+ typename Generator<ValueType>::ShrinkingFunction(
+ std::forward<ShrinkFunction>( shrink ) ) );
+ }
+
+} // namespace Progmasoft::Catch3