Files
Cataclysm-DDA/tests/cata_generators.cpp
dumb-kevin 05ab42807e tests/: wrap TU-local test fixture types in anon namespaces
- addiction_test: wrap addict_effect_totals
- battery_density_test: wrap battery_chemistry_family
- comestible_test: wrap all_stats
- encumbrance_test: wrap add_trait
- invlet_test: fuse inventory_location + invlet_state + test_action enums
- throwing_test: fuse throw_test_data + throw_test_pstats, move operator<< inside anon-ns
- vehicle_test: wrap vehicle_preset, damage_preset, folded_item_damage_preset, fuse rack_activation + rack_preset
- vision_test: wrap vision_test_case
- water_movement_test: fuse 6 swimmer/swim structs into one block
- weakpoint_test: wrap weakpoint_test_data, weakpoint_expectation, weakpoint_report
2026-05-12 10:53:28 +04:00

76 lines
1.9 KiB
C++

#include "cata_generators.h"
#include <memory>
#include <random>
#include "point.h"
#include "rng.h"
namespace
{
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;
};
} // namespace
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 ) );
}