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