/* * Created by Martin on 15/6/2018. * * Distributed under the Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef TWOBLUECUBES_CATCH_GENERATORS_SPECIFIC_HPP_INCLUDED #define TWOBLUECUBES_CATCH_GENERATORS_SPECIFIC_HPP_INCLUDED #include "catch_context.h" #include "catch_generators.hpp" #include "catch_interfaces_config.h" #include namespace Catch { namespace Generators { template class RandomFloatingGenerator final : public IGenerator { // FIXME: What is the right seed? std::minstd_rand m_rand; std::uniform_real_distribution m_dist; Float m_current_number; public: RandomFloatingGenerator(Float a, Float b): m_rand(getCurrentContext().getConfig()->rngSeed()), m_dist(a, b) { static_cast(next()); } Float const& get() const override { return m_current_number; } bool next() override { m_current_number = m_dist(m_rand); return true; } }; template class RandomIntegerGenerator final : public IGenerator { std::minstd_rand m_rand; std::uniform_int_distribution m_dist; Integer m_current_number; public: RandomIntegerGenerator(Integer a, Integer b): m_rand(getCurrentContext().getConfig()->rngSeed()), m_dist(a, b) { static_cast(next()); } Integer const& get() const override { return m_current_number; } bool next() override { m_current_number = m_dist(m_rand); return true; } }; // TODO: Ideally this would be also constrained against the various char types, // but I don't expect users to run into that in practice. template typename std::enable_if::value && !std::is_same::value, GeneratorWrapper>::type random(T a, T b) { return GeneratorWrapper( pf::make_unique>(a, b) ); } template typename std::enable_if::value, GeneratorWrapper>::type random(T a, T b) { return GeneratorWrapper( pf::make_unique>(a, b) ); } } // namespace Generators } // namespace Catch #endif // TWOBLUECUBES_CATCH_GENERATORS_SPECIFIC_HPP_INCLUDED