Version: SMASH-3.1
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 crit=CollisionCriterion::Geometric)
 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...
 

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 180 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  "σ " +
70  std::to_string(smashon_mass) + " " + std::to_string(smashon_width) +
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

◆ 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  return p;
110 }

◆ 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 115 of file setup.h.

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

◆ 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 124 of file setup.h.

125  {
126  ParticleData p{ParticleType::find(0x661), id};
127  p.set_4position(position);
128  p.set_4momentum(momentum);
129  return p;
130 }

◆ 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 138 of file setup.h.

139  {
140  ParticleData p{ParticleType::find(0x661), id};
141  p.set_4position(position);
142  p.set_4momentum(momentum);
143  return p;
144 }

◆ 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 149 of file setup.h.

149  {
150  auto random_value = random::make_uniform_distribution(-15.0, +15.0);
151  ParticleData p{ParticleType::find(0x661), id};
152  p.set_4position(
153  {random_value(), random_value(), random_value(), random_value()});
154  p.set_4momentum(smashon_mass,
155  {random_value(), random_value(), random_value()});
156  return p;
157 }
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 162 of file setup.h.

162  {
163  return ExperimentBase::create(c, ".");
164 }

◆ 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 170 of file setup.h.

170  {
171  ParticleList list;
172  list.reserve(n);
173  for (auto i = n; i; --i) {
174  list.emplace_back(generator());
175  }
176  return list;
177 }
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 187 of file setup.h.

187  {
188  ParticlesPtr p = std::make_unique<Particles>();
189  for (auto i = n; i; --i) {
190  p->insert(generator());
191  }
192  return p;
193 }
std::unique_ptr< Particles > ParticlesPtr
A type alias for a unique_ptr of Particles.
Definition: setup.h:180

◆ 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 199 of file setup.h.

200  {
201  ParticlesPtr p = std::make_unique<Particles>();
202  for (const auto &data : init) {
203  p->insert(data);
204  }
205  return p;
206 }

◆ all_reactions_included()

ReactionsBitSet smash::Test::all_reactions_included ( )
inline

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

Definition at line 209 of file setup.h.

209  {
210  return ReactionsBitSet().set();
211 }
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 214 of file setup.h.

214  {
215  return MultiParticleReactionsBitSet().reset();
216 }
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  crit = CollisionCriterion::Geometric 
)
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 225 of file setup.h.

227  {
228  return ExperimentParameters{
229  std::make_unique<UniformClock>(0., dt, 300.0), // labclock
230  std::make_unique<UniformClock>(0., 1., 300.0), // outputclock
231  1, // ensembles
232  testparticles, // testparticles
233  DerivativesMode::CovariantGaussian, // derivatives mode
234  RestFrameDensityDerivativesMode::Off, // rest frame derivatives mode
235  FieldDerivativesMode::ChainRule, // field derivatives mode
236  SmearingMode::CovariantGaussian, // smearing mode
237  1.0, // Gaussian smearing width
238  4.0, // Gaussian smearing cut-off
239  0.333333, // discrete smearing weight
240  2.0, // triangular smearing range
241  crit,
242  true, // two_to_one
245  false, // strings switch
246  1.0,
248  0., // low energy sigma_NN cut-off
249  false, // potential_affect_threshold
250  -1.0, // box_length
251  200.0, // max. cross section
252  2.5, // fixed min. cell length
253  1.0, // cross section scaling
254  false, // in thermodynamics outputs spectators are included
255  false, // do weak decays
256  true, // decay initial particles
257  std::nullopt // use monash tune, not known
258  };
259 }
@ NoAnnihilation
No Annihilation.
MultiParticleReactionsBitSet no_multiparticle_reactions()
returns BitSet for multi-particle reactions, where everything is off
Definition: setup.h:214
ReactionsBitSet all_reactions_included()
returns BitSet of 2->2 reactions, where everything is on
Definition: setup.h:209

◆ 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.

Definition at line 267 of file setup.h.

274  {
275  StringTransitionParameters default_transition_params{};
276  return {elastic_parameter,
277  0., // low_snn_cut
278  1., // scale_xs
279  0., // additional_el_xs
280  200., // maximum_cross_section
282  nnbar_treatment,
283  included_2to2,
285  1, // testparticles
286  true, // two_to_one
287  false, // allow_first_collisions_within_nucleus
288  strings_switch,
289  use_AQM,
290  strings_with_probability,
291  true, // only_warn_for_high_prob
292  default_transition_params,
293  xs_strategy,
295 }
@ Geometric
Geometric criterion.
@ None
No pseudo-resonance is created.

◆ 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 298 of file setup.h.

299  {
300  return EventInfo{impact_parameter, 0.0, 0.0, 0.0, 0.0, 0.0, 1, 1,
301  empty_event, false};
302 }

◆ 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 305 of file setup.h.

305  {
306  return std::make_unique<StringProcess>(
307  1.0, // String_Tension
308  1.0, // String_Formation_Time
309  0.5, // Gluon_Beta
310  0.001, // Gluon_Pmin
311  2.0, // Quark_Alpha
312  7.0, // Quark_Beta
313  0.16, // Strange_Supp
314  0.036, // Diquark_Supp
315  0.42, // Sigma_Perp
316  0.2, // StringZ_A_Leading
317  2.0, // StringZ_B_Leading
318  2.0, // StringZ_A
319  0.55, // StringZ_B
320  0.5, // String_Sigma_T
321  1.0, // Form_Time_Factor
322  false, // Mass_Dependent_Formation_Times
323  1. / 3., // Prob_proton_to_d_uu
324  true, // Separate_Fragment_Baryon
325  0.15, // Popcorn_Rate
326  false); // Use_Monash_Tune
327 }

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.