thejohnfreeman / autocheck

Header-only C++17 library for property-based testing.
ISC License
125 stars 17 forks source link

double/ float generator #2

Closed djwatson closed 11 years ago

djwatson commented 11 years ago

Doesn't look like it has a generator for double or float yet? Probably just needs something like

template <typename Double>                                                                                                                                                                                                          
class generator<                                                                                                                                                                                                                    
Double,                                                                                                                                                                                                                           
  typename std::enable_if<                                                                                                                                                                                                          
    is_one_of<Double, double, float>::value                                                                                                                                                                                         
  >::type                                                                                                                                                                                                                           
>                                                                                                                                                                                                                                   
{                                                                                                                                                                                                                                   
public:                                                                                                                                                                                                                           
  typedef Double result_type;                                                                                                                                                                                                     

  result_type operator() (size_t size) {                                                                                                                                                                                          
    /* Distribution is non-static. */                                                                                                                                                                                             
    std::uniform_real_distribution<Double> dist(0, size);                                                                                                                                                                         
    auto rv = dist(rng());                                                                                                                                                                                                        
    return rv;                                                                                                                                                                                                                    
  }                                                                                                                                                                                                                               

};

thejohnfreeman commented 11 years ago

Thanks!