Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | List of all members
Utopia::TestTools::BaseInfrastructure< RNGType > Struct Template Reference

A base class for an infrastructure fixture. More...

#include <fixtures.hh>

Inheritance diagram for Utopia::TestTools::BaseInfrastructure< RNGType >:
Inheritance graph
[legend]

Public Types

using RNG = RNGType
 The random number generator type to use.
 
using Config = DataIO::Config
 Make the config type more easily available.
 

Public Member Functions

 BaseInfrastructure (const std::string &config_file_path="")
 Construct the BaseInfrastructure fixture.
 
 ~BaseInfrastructure ()
 Destruct the BaseInfrastructure fixture, tearing down the test logger.
 

Public Attributes

const Config cfg
 The test configuration.
 
std::shared_ptr< spdlog::logger > log
 A logger to use during the test or to pass to entities that need it.
 
std::shared_ptr< RNGrng
 The shared random number generator instance, randomly seeded.
 

Detailed Description

template<class RNGType = Utopia::DefaultRNG>
struct Utopia::TestTools::BaseInfrastructure< RNGType >

A base class for an infrastructure fixture.

If a YAML configuration file is to be loaded, the fixture needs to be derived from and the path to the YAML file needs to be specified

Member Typedef Documentation

◆ Config

template<class RNGType = Utopia::DefaultRNG>
using Utopia::TestTools::BaseInfrastructure< RNGType >::Config = DataIO::Config

Make the config type more easily available.

◆ RNG

template<class RNGType = Utopia::DefaultRNG>
using Utopia::TestTools::BaseInfrastructure< RNGType >::RNG = RNGType

The random number generator type to use.

Constructor & Destructor Documentation

◆ BaseInfrastructure()

template<class RNGType = Utopia::DefaultRNG>
Utopia::TestTools::BaseInfrastructure< RNGType >::BaseInfrastructure ( const std::string &  config_file_path = "")
inline

Construct the BaseInfrastructure fixture.

50 :
51 // Load a configuration file, if a file path was given
53 if (config_file_path.size()) {
54 return YAML::LoadFile(config_file_path);
55 }
56 return Config{};
57 }()),
58
59 // Set up a test logger
60 log([](){
61 auto logger = spdlog::get("test");
62
63 // Create it only if it does not already exist
64 if (not logger) {
65 logger = spdlog::stdout_color_mt("test");
66 }
67
68 // Set level and global logging pattern
69 logger->set_level(spdlog::level::trace);
70 spdlog::set_pattern("[%T.%e] [%^%l%$] [%n] %v");
71 // "[HH:MM:SS.mmm] [level(colored)] [logger] <message>"
72
73 return logger;
74 }()),
75
76 // Set up random number generator (with random seed)
77 rng(std::make_shared<RNG>(std::random_device()()))
78 {
79 log->info("BaseInfrastructure fixture set up.");
80 if (config_file_path.size()) {
81 log->info("Test configuration loaded from: {}", config_file_path);
82 }
83 else {
84 log->info("No test configuration file loaded.");
85 }
86 }
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
DataIO::Config Config
Make the config type more easily available.
Definition fixtures.hh:32
const Config cfg
The test configuration.
Definition fixtures.hh:40
std::shared_ptr< spdlog::logger > log
A logger to use during the test or to pass to entities that need it.
Definition fixtures.hh:43
std::shared_ptr< RNG > rng
The shared random number generator instance, randomly seeded.
Definition fixtures.hh:46

◆ ~BaseInfrastructure()

template<class RNGType = Utopia::DefaultRNG>
Utopia::TestTools::BaseInfrastructure< RNGType >::~BaseInfrastructure ( )
inline

Destruct the BaseInfrastructure fixture, tearing down the test logger.

89 {
90 spdlog::drop("test");
91 }

Member Data Documentation

◆ cfg

template<class RNGType = Utopia::DefaultRNG>
const Config Utopia::TestTools::BaseInfrastructure< RNGType >::cfg

The test configuration.

Note
It will only be loaded if a configuration file path is given during construction of this base class. To specify a file, derive from this fixture and pass the path to the base class constructor.

◆ log

template<class RNGType = Utopia::DefaultRNG>
std::shared_ptr<spdlog::logger> Utopia::TestTools::BaseInfrastructure< RNGType >::log

A logger to use during the test or to pass to entities that need it.

◆ rng

template<class RNGType = Utopia::DefaultRNG>
std::shared_ptr<RNG> Utopia::TestTools::BaseInfrastructure< RNGType >::rng

The shared random number generator instance, randomly seeded.


The documentation for this struct was generated from the following file: