include/simdb/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
7 / 8
87.5%
Branches:
8 / 8
100.0%
Functions:
1 / 1
100.0%

utils/Random.hpp
Line Branch Exec Source
1 #pragma once
2
3 #include <random>
4 #include <type_traits>
5 #include <vector>
6
7 namespace simdb::utils {
8
9 /// Generate a random vector of numbers. Used primarily by unit tests.
10 5 template <typename T> inline std::vector<T> generateRandomData(size_t size, T min = T(0), T max = T(100))
11 {
12 static_assert(std::is_arithmetic<T>::value, "T must be an arithmetic type");
13
14
1/1
✓ Branch 4 → 5 taken 5 times.
5 std::vector<T> data(size);
15
3/3
✓ Branch 6 → 7 taken 5 times.
✓ Branch 7 → 8 taken 5 times.
✓ Branch 8 → 9 taken 5 times.
5 std::mt19937 gen(std::random_device{}());
16
17 if constexpr (std::is_integral<T>::value)
18 {
19
1/1
✓ Branch 10 → 11 taken 5 times.
5 std::uniform_int_distribution<T> dis(min, max);
20
2/2
✓ Branch 17 → 13 taken 5000 times.
✓ Branch 17 → 18 taken 5 times.
5005 for (auto& value : data)
21 {
22
1/1
✓ Branch 14 → 15 taken 5000 times.
5000 value = dis(gen);
23 }
24 } else if constexpr (std::is_floating_point<T>::value)
25 {
26 std::uniform_real_distribution<T> dis(min, max);
27 for (auto& value : data)
28 {
29 value = dis(gen);
30 }
31 }
32
33 5 return data;
34 ✗ }
35
36 } // namespace simdb::utils
37