./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
22 / 22
100.0%
Branches:
16 / 16
100.0%
Functions:
6 / 6
100.0%

src/util/checks.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 #include "util/checks.h"
4
5 #include <stdexcept>
6 #include <string>
7
8 namespace terraingen {
9
10 namespace {
11
12 113 [[noreturn]] void Fail(std::string_view what, std::string_view requirement) {
13
5/5
✓ Branch 2 taken 113 times.
✓ Branch 5 taken 113 times.
✓ Branch 8 taken 113 times.
✓ Branch 11 taken 113 times.
✓ Branch 14 taken 113 times.
565 throw std::invalid_argument(std::string(what) + " must be " + std::string(requirement));
14 }
15
16 } // namespace
17
18 12693733 void RequirePositive(double value, std::string_view what) {
19
2/2
✓ Branch 0 taken 12693711 times.
✓ Branch 1 taken 22 times.
12693733 if (!IsPositive(value)) {
20 84 Fail(what, "positive and finite");
21 }
22 12693649 }
23
24 4194830 void RequireNonNegative(double value, std::string_view what) {
25
2/2
✓ Branch 0 taken 4194825 times.
✓ Branch 1 taken 5 times.
4194830 if (!IsNonNegative(value)) {
26 22 Fail(what, "finite and not negative");
27 }
28 4194808 }
29
30 833 void RequireFinite(double value, std::string_view what) {
31
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 827 times.
833 if (!std::isfinite(value)) {
32 6 Fail(what, "finite");
33 }
34 827 }
35
36 2 void RequireUnitInterval(double value, std::string_view what) {
37
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
2 if (!IsInUnitInterval(value)) {
38 1 Fail(what, "in [0, 1]");
39 }
40 1 }
41
42 3922206 void RequireDiameter(double diameter) {
43
2/2
✓ Branch 0 taken 3922202 times.
✓ Branch 1 taken 4 times.
3922206 if (!IsPositive(diameter)) {
44
1/1
✓ Branch 2 taken 14 times.
14 throw std::domain_error("Diameter must be positive and finite");
45 }
46 3922192 }
47
48 } // namespace terraingen
49