TerrainGen coverage


terraingen/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
6 / 6
100.0%
Branches:
12 / 12
100.0%
Functions:
3 / 3
100.0%

util/checks.h
Line Branch Exec Source
1 /// @file
2 /// @brief Predicates and argument checks for numeric parameters.
3 #pragma once
4
5 #include <cmath>
6 #include <string_view>
7
8 namespace terraingen {
9
10 /// Whether a value is finite and greater than zero.
11 99359305 inline bool IsPositive(double value) {
12
4/4
✓ Branch 1 taken 99359275 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 99359083 times.
✓ Branch 4 taken 192 times.
99359305 return std::isfinite(value) && value > 0.0;
13 }
14
15 /// Whether a value is finite and not negative.
16 19927997 inline bool IsNonNegative(double value) {
17
4/4
✓ Branch 1 taken 19927986 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 19927932 times.
✓ Branch 4 taken 54 times.
19927997 return std::isfinite(value) && value >= 0.0;
18 }
19
20 /// Whether a value lies in [0, 1]; false for NaN.
21 1012949 inline bool IsInUnitInterval(double value) {
22
4/4
✓ Branch 0 taken 1012944 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 1012923 times.
✓ Branch 3 taken 21 times.
1012949 return value >= 0.0 && value <= 1.0;
23 }
24
25 /// Checks that a value is positive and finite.
26 /// @param what The value's name, which starts the error message.
27 /// @throws std::invalid_argument "<what> must be positive and finite" otherwise.
28 void RequirePositive(double value, std::string_view what);
29
30 /// Checks that a value is finite and not negative.
31 /// @param what The value's name, which starts the error message.
32 /// @throws std::invalid_argument "<what> must be finite and not negative" otherwise.
33 void RequireNonNegative(double value, std::string_view what);
34
35 /// Checks that a value is finite.
36 /// @param what The value's name, which starts the error message.
37 /// @throws std::invalid_argument "<what> must be finite" for an infinite or NaN `value`.
38 void RequireFinite(double value, std::string_view what);
39
40 /// Checks that a value lies in [0, 1].
41 /// @param what The value's name, which starts the error message.
42 /// @throws std::invalid_argument "<what> must be in [0, 1]" otherwise.
43 void RequireUnitInterval(double value, std::string_view what);
44
45 } // namespace terraingen
46