TerrainGen coverage


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

distribution/combined.cpp
Line Branch Exec Source
1 #include "terraingen/distribution/combined.h"
2
3 #include <stdexcept>
4
5 namespace terraingen::detail {
6
7 2223 SfdKind CommonKind(std::span<const SizeFrequencyDistribution* const> distributions,
8 const std::string& what) {
9
2/2
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 2216 times.
2223 if (distributions.empty()) {
10
2/2
✓ Branch 2 taken 7 times.
✓ Branch 5 taken 7 times.
7 throw std::invalid_argument(what + " needs at least one distribution");
11 }
12
2/2
✓ Branch 5 taken 3962 times.
✓ Branch 6 taken 2206 times.
6168 for (const SizeFrequencyDistribution* distribution : distributions) {
13
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3956 times.
3962 if (distribution == nullptr) {
14
2/2
✓ Branch 2 taken 6 times.
✓ Branch 5 taken 6 times.
6 throw std::invalid_argument(what + " cannot hold a null distribution");
15 }
16
2/2
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 3952 times.
3956 if (distribution->Kind() != distributions.front()->Kind()) {
17
2/2
✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
4 throw std::invalid_argument(what + " needs distributions of one kind");
18 }
19 }
20 2206 return distributions.front()->Kind();
21 }
22
23 1888 DiameterRange UsableRange(const SizeFrequencyDistribution& distribution) {
24
2/2
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 1861 times.
1888 return distribution.AllowsExtrapolation() ? DiameterRange{} : distribution.ValidRange();
25 }
26
27 802 void CheckJoin(double below, double above, double start, double tolerance,
28 bool allowDiscontinuities) {
29
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 798 times.
802 if (above > below * (1.0 + tolerance)) {
30
1/1
✓ Branch 1 taken 4 times.
8 throw std::invalid_argument("A cumulative distribution cannot rise at the join at " +
31
3/3
✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
✓ Branch 8 taken 4 times.
12 std::to_string(start) + " m");
32 }
33
4/4
✓ Branch 0 taken 789 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 786 times.
798 if (!allowDiscontinuities && above < below * (1.0 - tolerance)) {
34
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
6 throw std::invalid_argument("The pieces are discontinuous at " + std::to_string(start) +
35
2/2
✓ Branch 2 taken 3 times.
✓ Branch 5 taken 3 times.
9 " m");
36 }
37 795 }
38
39 } // namespace terraingen::detail
40