GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 67.3% 70 / 0 / 104
Functions: 83.3% 20 / 0 / 24
Branches: 57.3% 59 / 0 / 103

src/utilities/units/WhUnit.cpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #include "WhUnit.hpp"
7 #include "WhUnit_Impl.hpp"
8
9 #include "../core/Assert.hpp"
10
11 namespace openstudio {
12 namespace detail {
13
14 10584 WhUnit_Impl::WhUnit_Impl(const WhExpnt& exponents, int scaleExponent, const std::string& prettyString)
15
2/2
✓ Branch 1 taken 10584 times.
✓ Branch 4 taken 10584 times.
10584 : Unit_Impl(scaleExponent, prettyString, 12, UnitSystem::Wh) {
16
1/1
✓ Branch 2 taken 10584 times.
10584 m_units[0].first = "W";
17 10584 m_units[0].second = exponents.m_W;
18
1/1
✓ Branch 2 taken 10584 times.
10584 m_units[1].first = "h";
19 10584 m_units[1].second = exponents.m_h;
20
1/1
✓ Branch 2 taken 10584 times.
10584 m_units[2].first = "m";
21 10584 m_units[2].second = exponents.m_m;
22
1/1
✓ Branch 2 taken 10584 times.
10584 m_units[3].first = "K";
23 10584 m_units[3].second = exponents.m_K;
24
1/1
✓ Branch 2 taken 10584 times.
10584 m_units[4].first = "A";
25 10584 m_units[4].second = exponents.m_A;
26
1/1
✓ Branch 2 taken 10584 times.
10584 m_units[5].first = "cd";
27 10584 m_units[5].second = exponents.m_cd;
28
1/1
✓ Branch 2 taken 10584 times.
10584 m_units[6].first = "mol";
29 10584 m_units[6].second = exponents.m_mol;
30
1/1
✓ Branch 2 taken 10584 times.
10584 m_units[7].first = "rad";
31 10584 m_units[7].second = exponents.m_rad;
32
1/1
✓ Branch 2 taken 10584 times.
10584 m_units[8].first = "sr";
33 10584 m_units[8].second = exponents.m_sr;
34
1/1
✓ Branch 2 taken 10584 times.
10584 m_units[9].first = "people";
35 10584 m_units[9].second = exponents.m_people;
36
1/1
✓ Branch 2 taken 10584 times.
10584 m_units[10].first = "cycle";
37 10584 m_units[10].second = exponents.m_cycle;
38
1/1
✓ Branch 2 taken 10584 times.
10584 m_units[11].first = "$";
39 10584 m_units[11].second = exponents.m_dollar;
40 10584 }
41
42 ✗ WhUnit_Impl::WhUnit_Impl(const std::string& scaleAbbreviation, const WhExpnt& exponents, const std::string& prettyString)
43 ✗ : Unit_Impl(scaleAbbreviation, prettyString, 12, UnitSystem::Wh) {
44 ✗ m_units[0].first = "W";
45 ✗ m_units[0].second = exponents.m_W;
46 ✗ m_units[1].first = "h";
47 ✗ m_units[1].second = exponents.m_h;
48 ✗ m_units[2].first = "m";
49 ✗ m_units[2].second = exponents.m_m;
50 ✗ m_units[3].first = "K";
51 ✗ m_units[3].second = exponents.m_K;
52 ✗ m_units[4].first = "A";
53 ✗ m_units[4].second = exponents.m_A;
54 ✗ m_units[5].first = "cd";
55 ✗ m_units[5].second = exponents.m_cd;
56 ✗ m_units[6].first = "mol";
57 ✗ m_units[6].second = exponents.m_mol;
58 ✗ m_units[7].first = "rad";
59 ✗ m_units[7].second = exponents.m_rad;
60 ✗ m_units[8].first = "sr";
61 ✗ m_units[8].second = exponents.m_sr;
62 ✗ m_units[9].first = "people";
63 ✗ m_units[9].second = exponents.m_people;
64 ✗ m_units[10].first = "cycle";
65 ✗ m_units[10].second = exponents.m_cycle;
66 ✗ m_units[11].first = "$";
67 ✗ m_units[11].second = exponents.m_dollar;
68 ✗ }
69
70 27180 Unit WhUnit_Impl::clone() const {
71
3/5
✓ Branch 1 taken 27180 times.
✓ Branch 4 taken 27180 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 27180 times.
✗ Branch 10 not taken.
27180 OS_ASSERT(system() == UnitSystem::Wh);
72
3/5
✓ Branch 1 taken 27180 times.
✓ Branch 4 taken 27180 times.
✓ Branch 7 taken 27180 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
27180 std::shared_ptr<WhUnit_Impl> impl(new WhUnit_Impl(*this));
73
2/2
✓ Branch 2 taken 27180 times.
✓ Branch 5 taken 27180 times.
54360 return WhUnit(impl).cast<Unit>();
74 27180 }
75
76 124474 void WhUnit_Impl::setBaseUnitExponent(const std::string& baseUnit, int exponent) {
77
1/1
✓ Branch 1 taken 124474 times.
124474 auto loc = findBaseUnit(baseUnit);
78
1/2
✓ Branch 2 taken 124474 times.
✗ Branch 3 not taken.
124474 if (loc != m_units.end()) {
79 124474 loc->second = exponent;
80 } else {
81 ✗ LOG_AND_THROW("Cannot add base units to an instance of WhUnit.");
82 }
83 124474 }
84
85 } // namespace detail
86
87 10584 WhUnit::WhUnit(const WhExpnt& exponents, int scaleExponent, const std::string& prettyString)
88
4/6
✓ Branch 1 taken 10584 times.
✓ Branch 4 taken 10584 times.
✓ Branch 7 taken 10584 times.
✓ Branch 10 taken 10584 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
10584 : Unit(std::shared_ptr<detail::Unit_Impl>(new detail::WhUnit_Impl(exponents, scaleExponent, prettyString))) {}
89
90 ✗ WhUnit::WhUnit(const std::string& scaleAbbreviation, const WhExpnt& exponents, const std::string& prettyString)
91 ✗ : Unit(std::shared_ptr<detail::Unit_Impl>(new detail::WhUnit_Impl(scaleAbbreviation, exponents, prettyString))) {}
92
93 /// @cond
94
1/1
✓ Branch 2 taken 27180 times.
27180 WhUnit::WhUnit(std::shared_ptr<detail::WhUnit_Impl> impl) : Unit(std::dynamic_pointer_cast<detail::Unit_Impl>(impl)) {}
95 /// @endcond
96
97 130 WhUnit createWhPower() {
98
2/2
✓ Branch 1 taken 130 times.
✓ Branch 5 taken 130 times.
260 return WhUnit(WhExpnt(1));
99 }
100
101 117 WhUnit createWhTime() {
102
2/2
✓ Branch 1 taken 117 times.
✓ Branch 5 taken 117 times.
234 return WhUnit(WhExpnt(0, 1));
103 }
104
105 106 WhUnit createWhLength() {
106
2/2
✓ Branch 1 taken 106 times.
✓ Branch 5 taken 106 times.
212 return WhUnit(WhExpnt(0, 0, 1));
107 }
108
109 101 WhUnit createWhTemperature() {
110
2/2
✓ Branch 1 taken 101 times.
✓ Branch 5 taken 101 times.
202 return WhUnit(WhExpnt(0, 0, 0, 1));
111 }
112
113 100 WhUnit createWhElectricCurrent() {
114
2/2
✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
200 return WhUnit(WhExpnt(0, 0, 0, 0, 1));
115 }
116
117 100 WhUnit createWhLuminousIntensity() {
118
2/2
✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
200 return WhUnit(WhExpnt(0, 0, 0, 0, 0, 1));
119 }
120
121 102 WhUnit createWhAmountOfSubstance() {
122
2/2
✓ Branch 1 taken 102 times.
✓ Branch 5 taken 102 times.
204 return WhUnit(WhExpnt(0, 0, 0, 0, 0, 0, 1));
123 }
124
125 100 WhUnit createWhAngle() {
126
2/2
✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
200 return WhUnit(WhExpnt(0, 0, 0, 0, 0, 0, 0, 1));
127 }
128
129 100 WhUnit createWhSolidAngle() {
130
2/2
✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
200 return WhUnit(WhExpnt(0, 0, 0, 0, 0, 0, 0, 0, 1));
131 }
132
133 102 WhUnit createWhPeople() {
134
2/2
✓ Branch 1 taken 102 times.
✓ Branch 5 taken 102 times.
204 return WhUnit(WhExpnt(0, 0, 0, 0, 0, 0, 0, 0, 0, 1));
135 }
136
137 100 WhUnit createWhCycle() {
138
2/2
✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
200 return WhUnit(WhExpnt(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1));
139 }
140
141 ✗ WhUnit createWhCurrency() {
142 ✗ return WhUnit(WhExpnt(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1));
143 }
144
145 112 WhUnit createWhEnergy() {
146
2/2
✓ Branch 1 taken 112 times.
✓ Branch 5 taken 112 times.
224 return WhUnit(WhExpnt(1, 1), 0, "Wh");
147 }
148
149 100 WhUnit createWhElectricalPotential() {
150
2/2
✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
200 return WhUnit(WhExpnt(1, 0, 0, 0, -1), 0, "V");
151 }
152
153 ✗ WhUnit createWhElectricResistance() {
154 ✗ return WhUnit(WhExpnt(1, 0, 0, 0, -2), 0, "ohm");
155 }
156
157 100 WhUnit createWhLuminousFlux() {
158
2/2
✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
200 return WhUnit(WhExpnt(0, 0, 0, 0, 0, 1, 0, 0, 1), 0, "lm");
159 }
160
161 100 WhUnit createWhIlluminance() {
162
2/2
✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
200 return WhUnit(WhExpnt(0, 0, -2, 0, 0, 1, 0, 0, 1), 0, "lux");
163 }
164
165 } // namespace openstudio
166