GCC Code Coverage Report


Directory: ./
File: unittest/random_generator.hpp
Date: 2025-01-30 11:01:55
Exec Total Coverage
Lines: 8 8 100.0%
Branches: 8 16 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2021, LAAS-CNRS, University of Edinburgh
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #ifndef CROCODDYL_RANDOM_GENERATOR_HPP_
10 #define CROCODDYL_RANDOM_GENERATOR_HPP_
11
12 #include <functional>
13 #include <random>
14
15 static std::mt19937 rng;
16
17 namespace crocoddyl {
18 namespace unittest {
19
20 template <typename IntType>
21 13 IntType random_int_in_range(IntType first = 0, IntType last = 10) {
22
1/2
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
13 return std::uniform_int_distribution<IntType>(first, last)(rng);
23 }
24
25 template <typename RealType>
26 44 RealType random_real_in_range(RealType first = 0, RealType last = 1) {
27
1/2
✓ Branch 2 taken 44 times.
✗ Branch 3 not taken.
44 return std::uniform_real_distribution<RealType>(first, last)(rng);
28 }
29
30 4452 bool random_boolean() {
31
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 static auto generator = std::bind(std::uniform_int_distribution<>(0, 1),
32
5/10
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4440 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 12 times.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
4464 std::default_random_engine());
33 4452 return generator();
34 }
35
36 } // namespace unittest
37 } // namespace crocoddyl
38
39 #endif // CROCODDYL_RANDOM_GENERATOR_HPP_
40