Version: SMASH-3.3
Unit Test Macros and Functions

Classes

struct  smash::Test::Position
 A FourVector that is marked as a position vector. More...
 
struct  smash::Test::Momentum
 A FourVector that is marked as a momentum vector. More...
 

Macros

#define TEST(function_name)
 Defines a test function. More...
 
#define TEST_CATCH(function_name, ExceptionType)
 Same as above, but expects the code to throw an exception of type ExceptionType. More...
 
#define TEST_TYPES(T, test_name, typelist)
 Define a test function template, with type parameter T, which is specialized for all types in the typelist. More...
 
#define VERIFY(condition)
 Verifies that condition is true. More...
 
#define COMPARE(test_value, reference)
 Verifies that test_value is equal to reference. More...
 
#define COMPARE_ABSOLUTE_ERROR(test_value, reference, allowed_difference)
 Verifies that the difference between test_value and reference is smaller than allowed_difference. More...
 
#define COMPARE_RELATIVE_ERROR(test_value, reference, allowed_relative_difference)
 Verifies that the difference between test_value and reference is smaller than allowed_relative_difference * reference. More...
 
#define FUZZY_COMPARE(test_value, reference)
 Verifies that test_value is equal to reference within a pre-defined distance in units of least precision (ulp). More...
 
#define FAIL()
 Call this to fail a test. More...
 

Typedefs

using smash::Test::ParticlesPtr = std::unique_ptr< Particles >
 A type alias for a unique_ptr of Particles. More...
 

Functions

void smash::Test::create_actual_particletypes ()
 Creates the ParticleType list containing the actual particles that SMASH uses. More...
 
void smash::Test::create_actual_decaymodes ()
 Creates the DecayModes list containing the actual decay modes that SMASH uses. More...
 
void smash::Test::create_smashon_particletypes ()
 Creates a ParticleType list containing only the smashon test particle. More...
 
void smash::Test::create_stable_smashon_particletypes ()
 Creates a ParticleType list containing only the smashon test particle with width 0 (stable). More...
 
ParticleData smash::Test::smashon (int id=-1)
 Create a particle with 0 position and momentum vectors and optionally a given id. More...
 
ParticleData smash::Test::smashon (const Position &position, int id=-1)
 Create a particle with 0 momentum vector, the given position, and optionally a given id. More...
 
ParticleData smash::Test::smashon (const Momentum &momentum, int id=-1)
 Create a particle with 0 position vector, the given momentum, and optionally a given id. More...
 
ParticleData smash::Test::smashon (const Position &position, const Momentum &momentum, int id=-1)
 Create a particle with the given position and momentum vectors, and optionally a given id. More...
 
ParticleData smash::Test::smashon (const Momentum &momentum, const Position &position, int id=-1)
 Create a particle with the given position and momentum vectors, and optionally a given id. More...
 
ParticleData smash::Test::smashon_random (int id=-1)
 Create a particle with random position and momentum vectors and optionally a given id. More...
 
std::unique_ptr< ExperimentBasesmash::Test::experiment (Configuration c)
 Create an experiment given an input configuration. More...
 
template<typename G >
ParticleList smash::Test::create_particle_list (std::size_t n, G &&generator)
 Generate a list of particles from the given generator function. More...
 
template<typename G >
ParticlesPtr smash::Test::create_particles (int n, G &&generator)
 Creates a Particles object and fills it with n particles generated by the generator function. More...
 
ParticlesPtr smash::Test::create_particles (const std::initializer_list< ParticleData > &init)
 Creates a Particles object and fills it with the particles passed as initializer_list to this function. More...
 
ReactionsBitSet smash::Test::all_reactions_included ()
 returns BitSet of 2->2 reactions, where everything is on More...
 
MultiParticleReactionsBitSet smash::Test::no_multiparticle_reactions ()
 returns BitSet for multi-particle reactions, where everything is off More...
 
ExperimentParameters smash::Test::default_parameters (int testparticles=1, double dt=0.1, CollisionCriterion criterion=CollisionCriterion::Geometric, bool strings=false, NNbarTreatment nnbar_treatment=NNbarTreatment::NoAnnihilation, ReactionsBitSet included_2to2=all_reactions_included())
 Creates a standard ExperimentParameters object which works for almost all testing purposes. More...
 
ScatterActionsFinderParameters smash::Test::default_finder_parameters (double elastic_parameter=10, NNbarTreatment nnbar_treatment=NNbarTreatment::NoAnnihilation, ReactionsBitSet included_2to2=all_reactions_included(), bool strings_switch=true, bool use_AQM=false, bool strings_with_probability=false, TotalCrossSectionStrategy xs_strategy=TotalCrossSectionStrategy::BottomUp)
 Creates a standard ScatterActionsFinderParameters object which works for almost all testing purposes. More...
 
EventInfo smash::Test::default_event_info (double impact_parameter=0.0, bool empty_event=false)
 Creates default EventInfo object for testing purposes. More...
 
std::unique_ptr< StringProcesssmash::Test::default_string_process_interface ()
 Creates a default StringProcessInterface object for testing. More...
 
InitialConditionParameters smash::Test::default_dynamic_IC_parameters ()
 Creates default parameters for dynamic IC. More...
 

Variables

static constexpr double smash::Test::smashon_mass = 0.123
 The mass of the smashon particle. More...
 
static constexpr double smash::Test::smashon_width = 1.2
 The decay width of the smashon particle. More...
 
static constexpr const char smash::Test::smashon_pdg_string [] = "661"
 The PDG code of the smashon particle. More...
 

Macro Definition Documentation

◆ TEST

#define TEST (   function_name)

Defines a test function.

Consider this to expand to void function_name(). The function_name will also be the name that appears in the output after PASS/FAIL.

Definition at line 234 of file unittest.h.

◆ TEST_CATCH

#define TEST_CATCH (   function_name,
  ExceptionType 
)

Same as above, but expects the code to throw an exception of type ExceptionType.

If the code does not throw (or throws a different exception), the test is considered failed.

Definition at line 243 of file unittest.h.

◆ TEST_TYPES

#define TEST_TYPES (   T,
  test_name,
  typelist 
)

Define a test function template, with type parameter T, which is specialized for all types in the typelist.

Definition at line 249 of file unittest.h.

◆ VERIFY

#define VERIFY (   condition)

Verifies that condition is true.

Definition at line 254 of file unittest.h.

◆ COMPARE

#define COMPARE (   test_value,
  reference 
)

Verifies that test_value is equal to reference.

Definition at line 259 of file unittest.h.

◆ COMPARE_ABSOLUTE_ERROR

#define COMPARE_ABSOLUTE_ERROR (   test_value,
  reference,
  allowed_difference 
)

Verifies that the difference between test_value and reference is smaller than allowed_difference.

If the test fails the output will show the actual difference between test_value and reference. If this value is positive test_value is too large. If it is negative test_value is too small.

Definition at line 269 of file unittest.h.

◆ COMPARE_RELATIVE_ERROR

#define COMPARE_RELATIVE_ERROR (   test_value,
  reference,
  allowed_relative_difference 
)

Verifies that the difference between test_value and reference is smaller than allowed_relative_difference * reference.

If the test fails the output will show the actual difference between test_value and reference. If this value is positive test_value is too large. If it is negative test_value is too small.

The following example tests that a is no more than 1% different from b:

#define COMPARE_ABSOLUTE_ERROR(test_value, reference, allowed_difference)
Verifies that the difference between test_value and reference is smaller than allowed_difference.
Definition: unittest.h:269
Note
This test macro still works even if reference is set to 0. It will then compare the difference against allowed_relative_difference * <smallest positive normalized value of reference type>.

Definition at line 288 of file unittest.h.

◆ FUZZY_COMPARE

#define FUZZY_COMPARE (   test_value,
  reference 
)

Verifies that test_value is equal to reference within a pre-defined distance in units of least precision (ulp).

If the test fails it will print the distance in ulp between test_value and reference as well as the maximum allowed distance. Often this difference is not visible in the value because the conversion of a double/float to a string needs to round the value to a sensible length.

The allowed distance can be modified by calling:

vir::test::setFuzzyness<float>(4);
vir::test::setFuzzyness<double>(7);

ulp

Unit of least precision is a unit that is derived from the the least significant bit in the mantissa of a floating-point value. Consider a single-precision number (23 mantissa bits) with exponent \(e\). Then 1 ulp is \(2^{e-23}\). Thus, \(\log_2(u)\) signifies the the number incorrect mantissa bits (with \(u\) the distance in ulp).

If test_value and reference have a different exponent the meaning of ulp depends on the variable you look at. The FUZZY_COMPARE code always uses reference to determine the magnitude of 1 ulp.

Example: The value 1. is 0x3f800000 in binary. The value 1.00000011920928955078125 with binary representation 0x3f800001 therefore has a distance of 1 ulp. A positive distance means the test_value is larger than the reference. A negative distance means the test_value is smaller than the reference.

  • FUZZY_COMPARE(1.00000011920928955078125, 1.) will show a distance of 1
  • FUZZY_COMPARE(1., 1.00000011920928955078125) will show a distance of -1

The value 0.999999940395355224609375 with binary representation 0x3f7fffff has a smaller exponent than 1.:

  • FUZZY_COMPARE(0.999999940395355224609375, 1.) will show a distance of -0.5
  • FUZZY_COMPARE(1., 0.999999940395355224609375) will show a distance of 1

Comparing to 0

Distance to 0 is implemented as comparing to std::numeric_limits<T>::min() instead and adding 1 to the resulting distance.

Definition at line 337 of file unittest.h.

◆ FAIL

#define FAIL ( )

Call this to fail a test.

Definition at line 342 of file unittest.h.

Typedef Documentation

◆ ParticlesPtr

using smash::Test::ParticlesPtr = typedef std::unique_ptr<Particles>

A type alias for a unique_ptr of Particles.

Definition at line 187 of file setup.h.

Function Documentation

◆ create_actual_particletypes()

void smash::Test::create_actual_particletypes ( )
inline

Creates the ParticleType list containing the actual particles that SMASH uses.

Definition at line 36 of file setup.h.

36  {
37 #ifndef DOXYGEN
39 #include <particles.txt.h>
40 #endif
41  ParticleType::create_type_list(data);
42 }

◆ create_actual_decaymodes()

void smash::Test::create_actual_decaymodes ( )
inline

Creates the DecayModes list containing the actual decay modes that SMASH uses.

Definition at line 48 of file setup.h.

48  {
49 #ifndef DOXYGEN
51 #include <decaymodes.txt.h>
52 #endif
53  DecayModes::load_decaymodes(data);
54 }

◆ create_smashon_particletypes()

void smash::Test::create_smashon_particletypes ( )
inline

Creates a ParticleType list containing only the smashon test particle.

Definition at line 66 of file setup.h.

66  {
67  ParticleType::create_type_list(
68  "# NAME MASS[GEV] WIDTH[GEV] PARITY PDG\n"
69  "σ " +
71  " + 661\n");
72 }
static constexpr double smashon_mass
The mass of the smashon particle.
Definition: setup.h:57
static constexpr double smashon_width
The decay width of the smashon particle.
Definition: setup.h:59
std::string to_string(ThermodynamicQuantity quantity)
Convert a ThermodynamicQuantity enum value to its corresponding string.
Definition: stringify.cc:26

◆ create_stable_smashon_particletypes()

void smash::Test::create_stable_smashon_particletypes ( )
inline

Creates a ParticleType list containing only the smashon test particle with width 0 (stable).

Definition at line 78 of file setup.h.

78  {
79  ParticleType::create_type_list(
80  "# NAME MASS[GEV] WIDTH[GEV] PARITY PDG\n"
81  "σ " +
82  std::to_string(smashon_mass) + " 0.0 + 661\n");
83 }

◆ smashon() [1/5]

ParticleData smash::Test::smashon ( int  id = -1)
inline

Create a particle with 0 position and momentum vectors and optionally a given id.

Definition at line 98 of file setup.h.

98  {
99  ParticleData p{ParticleType::find(0x661), id};
100  return p;
101 }
constexpr int p
Proton.

◆ smashon() [2/5]

ParticleData smash::Test::smashon ( const Position position,
int  id = -1 
)
inline

Create a particle with 0 momentum vector, the given position, and optionally a given id.

Definition at line 106 of file setup.h.

106  {
107  ParticleData p{ParticleType::find(0x661), id};
108  p.set_4position(position);
109  p.set_formation_time(position[0]);
110  return p;
111 }

◆ smashon() [3/5]

ParticleData smash::Test::smashon ( const Momentum momentum,
int  id = -1 
)
inline

Create a particle with 0 position vector, the given momentum, and optionally a given id.

Definition at line 116 of file setup.h.

116  {
117  ParticleData p{ParticleType::find(0x661), id};
118  p.set_4momentum(momentum);
119  return p;
120 }

◆ smashon() [4/5]

ParticleData smash::Test::smashon ( const Position position,
const Momentum momentum,
int  id = -1 
)
inline

Create a particle with the given position and momentum vectors, and optionally a given id.

Definition at line 125 of file setup.h.

126  {
127  ParticleData p{ParticleType::find(0x661), id};
128  p.set_4position(position);
129  p.set_4momentum(momentum);
130  p.set_formation_time(position[0]);
131  p.set_unpolarized_spin_vector();
132  return p;
133 }

◆ smashon() [5/5]

ParticleData smash::Test::smashon ( const Momentum momentum,
const Position position,
int  id = -1 
)
inline

Create a particle with the given position and momentum vectors, and optionally a given id.

Convenience overload of the above to allow arbitrary order of momentum and position.

Definition at line 141 of file setup.h.

142  {
143  ParticleData p{ParticleType::find(0x661), id};
144  p.set_4position(position);
145  p.set_4momentum(momentum);
146  p.set_formation_time(position[0]);
147  p.set_unpolarized_spin_vector();
148  return p;
149 }

◆ smashon_random()

ParticleData smash::Test::smashon_random ( int  id = -1)
inline

Create a particle with random position and momentum vectors and optionally a given id.

Definition at line 154 of file setup.h.

154  {
155  auto random_value = random::make_uniform_distribution(-15.0, +15.0);
156  ParticleData p{ParticleType::find(0x661), id};
157  auto random_time = random_value();
158  p.set_formation_time(random_time);
159  p.set_4position(
160  {random_time, random_value(), random_value(), random_value()});
161  p.set_4momentum(smashon_mass,
162  {random_value(), random_value(), random_value()});
163  return p;
164 }
uniform_dist< T > make_uniform_distribution(T min, T max)
Definition: random.h:135

◆ experiment()

std::unique_ptr<ExperimentBase> smash::Test::experiment ( Configuration  c)
inline

Create an experiment given an input configuration.

Definition at line 169 of file setup.h.

169  {
170  return ExperimentBase::create(c, ".");
171 }

◆ create_particle_list()

template<typename G >
ParticleList smash::Test::create_particle_list ( std::size_t  n,
G &&  generator 
)
inline

Generate a list of particles from the given generator function.

Definition at line 177 of file setup.h.

177  {
178  ParticleList list;
179  list.reserve(n);
180  for (auto i = n; i; --i) {
181  list.emplace_back(generator());
182  }
183  return list;
184 }
constexpr int n
Neutron.

◆ create_particles() [1/2]

template<typename G >
ParticlesPtr smash::Test::create_particles ( int  n,
G &&  generator 
)
inline

Creates a Particles object and fills it with n particles generated by the generator function.

Definition at line 194 of file setup.h.

194  {
195  ParticlesPtr p = std::make_unique<Particles>();
196  for (auto i = n; i; --i) {
197  p->insert(generator());
198  }
199  return p;
200 }
std::unique_ptr< Particles > ParticlesPtr
A type alias for a unique_ptr of Particles.
Definition: setup.h:187

◆ create_particles() [2/2]

ParticlesPtr smash::Test::create_particles ( const std::initializer_list< ParticleData > &  init)
inline

Creates a Particles object and fills it with the particles passed as initializer_list to this function.

Definition at line 206 of file setup.h.

207  {
208  ParticlesPtr p = std::make_unique<Particles>();
209  for (const auto &data : init) {
210  p->insert(data);
211  }
212  return p;
213 }

◆ all_reactions_included()

ReactionsBitSet smash::Test::all_reactions_included ( )
inline

returns BitSet of 2->2 reactions, where everything is on

Definition at line 216 of file setup.h.

216  {
217  return ReactionsBitSet().set();
218 }
std::bitset< 10 > ReactionsBitSet
Container for the 2 to 2 reactions in the code.

◆ no_multiparticle_reactions()

MultiParticleReactionsBitSet smash::Test::no_multiparticle_reactions ( )
inline

returns BitSet for multi-particle reactions, where everything is off

Definition at line 221 of file setup.h.

221  {
222  return MultiParticleReactionsBitSet().reset();
223 }
std::bitset< 4 > MultiParticleReactionsBitSet
Container for the n to m reactions in the code.

◆ default_parameters()

ExperimentParameters smash::Test::default_parameters ( int  testparticles = 1,
double  dt = 0.1,
CollisionCriterion  criterion = CollisionCriterion::Geometric,
bool  strings = false,
NNbarTreatment  nnbar_treatment = NNbarTreatment::NoAnnihilation,
ReactionsBitSet  included_2to2 = all_reactions_included() 
)
inline

Creates a standard ExperimentParameters object which works for almost all testing purposes.

If needed you can set the testparticles parameter to a different value than 1.

Definition at line 232 of file setup.h.

237  {
238  return ExperimentParameters{
239  std::make_unique<UniformClock>(0., dt, 300.0), // labclock
240  std::make_unique<UniformClock>(0., 1., 300.0), // outputclock
241  1, // ensembles
242  testparticles, // testparticles
243  DerivativesMode::CovariantGaussian, // derivatives mode
244  RestFrameDensityDerivativesMode::Off, // rest frame derivatives mode
245  FieldDerivativesMode::ChainRule, // field derivatives mode
246  SmearingMode::CovariantGaussian, // smearing mode
247  1.0, // Gaussian smearing width
248  4.0, // Gaussian smearing cut-off
249  0.333333, // discrete smearing weight
250  2.0, // triangular smearing range
251  criterion, // collision criterion
252  true, // two_to_one
253  included_2to2,
255  strings,
256  1.0,
257  nnbar_treatment,
258  0., // low energy sigma_NN cut-off
259  false, // potential_affect_threshold
260  -1.0, // box_length
261  200.0, // max. cross section
262  2.5, // fixed min. cell length
263  1.0, // cross section scaling
264  false, // in thermodynamics outputs spectators are included
265  false, // do weak decays
266  true, // decay initial particles
267  SpinInteractionType::Off, // no spin interactions
268  std::nullopt // use monash tune, not known
269  };
270 }
@ Off
No spin interactions.
MultiParticleReactionsBitSet no_multiparticle_reactions()
returns BitSet for multi-particle reactions, where everything is off
Definition: setup.h:221

◆ default_finder_parameters()

ScatterActionsFinderParameters smash::Test::default_finder_parameters ( double  elastic_parameter = 10,
NNbarTreatment  nnbar_treatment = NNbarTreatment::NoAnnihilation,
ReactionsBitSet  included_2to2 = all_reactions_included(),
bool  strings_switch = true,
bool  use_AQM = false,
bool  strings_with_probability = false,
TotalCrossSectionStrategy  xs_strategy = TotalCrossSectionStrategy::BottomUp 
)
inline

Creates a standard ScatterActionsFinderParameters object which works for almost all testing purposes.

The selected arguments are changed between different tests, which requires setting the key by hand. This is not directly possible for enums, so one must do it case by case.

Definition at line 280 of file setup.h.

287  {
288  Configuration config{
289  R"(
290  Collision_Term:
291  Only_Warn_For_High_Probability: true
292  Pseudoresonance: None
293  )"};
294  config.set_value(InputKeys::collTerm_elasticCrossSection, elastic_parameter);
295  config.set_value(InputKeys::collTerm_useAQM, use_AQM);
296  config.set_value(InputKeys::collTerm_stringsWithProbability,
297  strings_with_probability);
298 
299  if (xs_strategy == TotalCrossSectionStrategy::BottomUp) {
300  config.merge_yaml(InputKeys::collTerm_totXsStrategy.as_yaml("BottomUp"));
301  } else if (xs_strategy == TotalCrossSectionStrategy::TopDown) {
302  config.merge_yaml(InputKeys::collTerm_totXsStrategy.as_yaml("TopDown"));
303  } else if (xs_strategy == TotalCrossSectionStrategy::TopDownMeasured) {
304  config.merge_yaml(
305  InputKeys::collTerm_totXsStrategy.as_yaml("TopDownMeasured"));
306  }
307  return ScatterActionsFinderParameters(
@ TopDownMeasured
Mix the two above, using the parametrizations only for measured processes, and summing up partials fo...
@ TopDown
Use parametrizations based on existing data, rescaling with AQM for unmeasured processes.
@ BottomUp
Sum the existing partial contributions.

◆ default_event_info()

EventInfo smash::Test::default_event_info ( double  impact_parameter = 0.0,
bool  empty_event = false 
)
inline

Creates default EventInfo object for testing purposes.

Definition at line 310 of file setup.h.

315  {

◆ default_string_process_interface()

std::unique_ptr<StringProcess> smash::Test::default_string_process_interface ( )
inline

Creates a default StringProcessInterface object for testing.

Definition at line 317 of file setup.h.

321  {
322  return std::make_unique<StringProcess>(
323  1.0, // String_Tension
324  1.0, // String_Formation_Time
325  0.5, // Gluon_Beta
326  0.001, // Gluon_Pmin
327  2.0, // Quark_Alpha
328  7.0, // Quark_Beta
329  0.16, // Strange_Supp
330  0.036, // Diquark_Supp
331  0.42, // Sigma_Perp
332  0.2, // StringZ_A_Leading
333  2.0, // StringZ_B_Leading
334  2.0, // StringZ_A
335  0.55, // StringZ_B
336  0.5, // String_Sigma_T
337  1.0, // Form_Time_Factor
338  false, // Mass_Dependent_Formation_Times
339  1. / 3., // Prob_proton_to_d_uu

◆ default_dynamic_IC_parameters()

InitialConditionParameters smash::Test::default_dynamic_IC_parameters ( )
inline

Creates default parameters for dynamic IC.

Definition at line 342 of file setup.h.

346  {
347  InitialConditionParameters parameters{};
348  parameters.type = FluidizationType::Dynamic;
349  parameters.fluidizable_processes = FluidizableProcessesBitSet{}.set();
350  parameters.energy_density_threshold = 0.5;
351  parameters.min_time = 0;
352  parameters.max_time = 100;
353  parameters.num_fluid_cells = 50;
354  parameters.formation_time_fraction = 1;
@ Dynamic
Dynamic fluidization based on local densities.
std::bitset< 5 > FluidizableProcessesBitSet

Variable Documentation

◆ smashon_mass

constexpr double smash::Test::smashon_mass = 0.123
staticconstexpr

The mass of the smashon particle.

Definition at line 57 of file setup.h.

◆ smashon_width

constexpr double smash::Test::smashon_width = 1.2
staticconstexpr

The decay width of the smashon particle.

Definition at line 59 of file setup.h.

◆ smashon_pdg_string

constexpr const char smash::Test::smashon_pdg_string[] = "661"
staticconstexpr

The PDG code of the smashon particle.

Definition at line 61 of file setup.h.