1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include "cata_generators.h"
#include <algorithm>
#include <memory>
#include "point.h"
#include "rng.h"
class RandomPointGenerator final :
public Catch::Generators::IGenerator<point>
{
public:
RandomPointGenerator( int low, int high ) :
engine( rng_get_engine() ),
dist( low, high ) {
this->next();
}
const point &get() const override {
return current_point;
}
bool next() override {
current_point = point( dist( engine ), dist( engine ) );
return true;
}
protected:
cata_default_random_engine &engine;
std::uniform_int_distribution<> dist;
point current_point;
};
class RandomTripointGenerator final :
public Catch::Generators::IGenerator<tripoint>
{
public:
RandomTripointGenerator( int low, int high, int zlow, int zhigh ) :
engine( rng_get_engine() ),
xy_dist( low, high ),
z_dist( zlow, zhigh ) {
this->next();
}
const tripoint &get() const override {
return current_point;
}
bool next() override {
current_point = tripoint( xy_dist( engine ), xy_dist( engine ), z_dist( engine ) );
return true;
}
protected:
cata_default_random_engine &engine;
std::uniform_int_distribution<> xy_dist;
std::uniform_int_distribution<> z_dist;
tripoint current_point;
};
Catch::Generators::GeneratorWrapper<point> random_points( int low, int high )
{
return Catch::Generators::GeneratorWrapper<point>(
std::make_unique<RandomPointGenerator>( low, high ) );
}
Catch::Generators::GeneratorWrapper<tripoint> random_tripoints(
int low, int high, int zlow, int zhigh )
{
return Catch::Generators::GeneratorWrapper<tripoint>(
std::make_unique<RandomTripointGenerator>( low, high, zlow, zhigh ) );
}
|