Skip to content

Commit

Permalink
Merge pull request #1 from swift-nav/in-range-fixup
Browse files Browse the repository at this point in the history
Implement `inRange` for floating-point types
  • Loading branch information
akleeman authored Aug 16, 2020
2 parents 00594ac + 92fce9f commit f79c84f
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion include/rapidcheck/shrink/Shrink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace rc {
namespace shrink {
namespace detail {

template <typename T>
template <typename T, typename Enable = void>
class TowardsSeq {
public:
using UInt = typename std::make_unsigned<T>::type;
Expand All @@ -36,6 +36,35 @@ class TowardsSeq {
bool m_down;
};

template <typename T>
class TowardsSeq<
T,
typename std::enable_if<std::is_floating_point<T>::value>::type> {
public:
TowardsSeq(T value, T target)
: m_value(value)
, m_target(target) {}

Maybe<T> operator()() {
if (m_value == m_target) {
return Nothing;
}

T new_value = (m_value / 2) + (m_target / 2);

if (new_value == m_value) {
new_value = m_target;
}

m_value = new_value;
return m_value;
}

private:
T m_value;
T m_target;
};

template <typename Container>
class RemoveChunksSeq {
public:
Expand Down

0 comments on commit f79c84f

Please sign in to comment.