GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 77.0% 114 / 0 / 148
Functions: 90.6% 29 / 0 / 32
Branches: 78.0% 103 / 0 / 132

src/utilities/units/IPUnit.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 "IPUnit.hpp"
7 #include "IPUnit_Impl.hpp"
8
9 #include "../core/Assert.hpp"
10
11 namespace openstudio {
12 namespace detail {
13
14 2337 IPUnit_Impl::IPUnit_Impl(const IPExpnt& exponents, int scaleExponent, const std::string& prettyString)
15
2/2
✓ Branch 1 taken 2337 times.
✓ Branch 4 taken 2337 times.
2337 : Unit_Impl(scaleExponent, prettyString, 13, UnitSystem::IP) {
16
1/1
✓ Branch 2 taken 2337 times.
2337 m_units[0].first = "lb_m";
17 2337 m_units[0].second = exponents.m_lbm;
18
1/1
✓ Branch 2 taken 2337 times.
2337 m_units[1].first = "ft";
19 2337 m_units[1].second = exponents.m_ft;
20
1/1
✓ Branch 2 taken 2337 times.
2337 m_units[2].first = "s";
21 2337 m_units[2].second = exponents.m_s;
22
1/1
✓ Branch 2 taken 2337 times.
2337 m_units[3].first = "R";
23 2337 m_units[3].second = exponents.m_R;
24
1/1
✓ Branch 2 taken 2337 times.
2337 m_units[4].first = "A";
25 2337 m_units[4].second = exponents.m_A;
26
1/1
✓ Branch 2 taken 2337 times.
2337 m_units[5].first = "cd";
27 2337 m_units[5].second = exponents.m_cd;
28
1/1
✓ Branch 2 taken 2337 times.
2337 m_units[6].first = "lbmol";
29 2337 m_units[6].second = exponents.m_lbmol;
30
1/1
✓ Branch 2 taken 2337 times.
2337 m_units[7].first = "lb_f";
31 2337 m_units[7].second = exponents.m_lbf;
32
1/1
✓ Branch 2 taken 2337 times.
2337 m_units[8].first = "deg";
33 2337 m_units[8].second = exponents.m_deg;
34
1/1
✓ Branch 2 taken 2337 times.
2337 m_units[9].first = "sr";
35 2337 m_units[9].second = exponents.m_sr;
36
1/1
✓ Branch 2 taken 2337 times.
2337 m_units[10].first = "people";
37 2337 m_units[10].second = exponents.m_people;
38
1/1
✓ Branch 2 taken 2337 times.
2337 m_units[11].first = "cycle";
39 2337 m_units[11].second = exponents.m_cycle;
40
1/1
✓ Branch 2 taken 2337 times.
2337 m_units[12].first = "$";
41 2337 m_units[12].second = exponents.m_dollar;
42 2337 }
43
44 ✗ IPUnit_Impl::IPUnit_Impl(const std::string& scaleAbbreviation, const IPExpnt& exponents, const std::string& prettyString)
45 ✗ : Unit_Impl(scaleAbbreviation, prettyString, 13, UnitSystem::IP) {
46 ✗ m_units[0].first = "lb_m";
47 ✗ m_units[0].second = exponents.m_lbm;
48 ✗ m_units[1].first = "ft";
49 ✗ m_units[1].second = exponents.m_ft;
50 ✗ m_units[2].first = "s";
51 ✗ m_units[2].second = exponents.m_s;
52 ✗ m_units[3].first = "R";
53 ✗ m_units[3].second = exponents.m_R;
54 ✗ m_units[4].first = "A";
55 ✗ m_units[4].second = exponents.m_A;
56 ✗ m_units[5].first = "cd";
57 ✗ m_units[5].second = exponents.m_cd;
58 ✗ m_units[6].first = "lbmol";
59 ✗ m_units[6].second = exponents.m_lbmol;
60 ✗ m_units[7].first = "lb_f";
61 ✗ m_units[7].second = exponents.m_lbf;
62 ✗ m_units[8].first = "deg";
63 ✗ m_units[8].second = exponents.m_deg;
64 ✗ m_units[9].first = "sr";
65 ✗ m_units[9].second = exponents.m_sr;
66 ✗ m_units[10].first = "people";
67 ✗ m_units[10].second = exponents.m_people;
68 ✗ m_units[11].first = "cycle";
69 ✗ m_units[11].second = exponents.m_cycle;
70 ✗ m_units[12].first = "$";
71 ✗ m_units[12].second = exponents.m_dollar;
72 ✗ }
73
74 1394 Unit IPUnit_Impl::clone() const {
75
3/5
✓ Branch 1 taken 1394 times.
✓ Branch 4 taken 1394 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1394 times.
✗ Branch 10 not taken.
1394 OS_ASSERT(system() == UnitSystem::IP);
76
3/5
✓ Branch 1 taken 1394 times.
✓ Branch 4 taken 1394 times.
✓ Branch 7 taken 1394 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
1394 std::shared_ptr<IPUnit_Impl> impl(new IPUnit_Impl(*this));
77
2/2
✓ Branch 2 taken 1394 times.
✓ Branch 5 taken 1394 times.
2788 return IPUnit(impl).cast<Unit>();
78 1394 }
79
80 1053 void IPUnit_Impl::setBaseUnitExponent(const std::string& baseUnit, int exponent) {
81
1/1
✓ Branch 1 taken 1053 times.
1053 auto loc = findBaseUnit(baseUnit);
82
2/2
✓ Branch 2 taken 1052 times.
✓ Branch 3 taken 1 time.
1053 if (loc != m_units.end()) {
83 1052 loc->second = exponent;
84 } else {
85
13/13
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 19 taken 1 time.
✓ Branch 22 taken 1 time.
✓ Branch 25 taken 1 time.
✓ Branch 28 taken 1 time.
✓ Branch 31 taken 1 time.
✓ Branch 34 taken 1 time.
✓ Branch 38 taken 1 time.
✓ Branch 41 taken 1 time.
1 LOG_AND_THROW("Cannot add base units to an instance of IPUnit.");
86 }
87 1052 }
88
89 38 bool IPUnit_Impl::operator==(const Unit& rUnit) const {
90 // compare using lb_m
91
2/2
✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
38 auto wLUnit = clone().cast<IPUnit>();
92
1/1
✓ Branch 1 taken 38 times.
38 wLUnit.lbfToLbm();
93
94
1/1
✓ Branch 1 taken 38 times.
38 Unit wRUnit = rUnit.clone();
95
2/3
✓ Branch 1 taken 38 times.
✓ Branch 3 taken 38 times.
✗ Branch 4 not taken.
76 if (OptionalIPUnit temp = wRUnit.optionalCast<IPUnit>()) {
96
2/2
✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
38 temp->lbfToLbm();
97
98 // loop through and check each exponent
99
3/3
✓ Branch 1 taken 38 times.
✓ Branch 8 taken 484 times.
✓ Branch 9 taken 37 times.
521 for (const std::string& baseUnit : wLUnit.baseUnits()) {
100
4/4
✓ Branch 1 taken 484 times.
✓ Branch 4 taken 484 times.
✓ Branch 6 taken 1 time.
✓ Branch 7 taken 483 times.
484 if (wLUnit.baseUnitExponent(baseUnit) != wRUnit.baseUnitExponent(baseUnit)) {
101 1 return false;
102 }
103 38 }
104
105 37 return true;
106 38 }
107
108 ✗ return (wRUnit == wLUnit);
109 38 }
110
111 2 void IPUnit_Impl::lbmToLbf() {
112
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
2 if (m_units[0].second != 0) {
113 1 m_units[7].second += m_units[0].second;
114 1 m_units[2].second += 2 * m_units[0].second;
115 1 m_units[1].second -= m_units[0].second;
116 1 m_units[0].second = 0;
117 }
118 2 return;
119 }
120
121 79 void IPUnit_Impl::lbfToLbm() {
122
2/2
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 74 times.
79 if (m_units[7].second != 0) {
123 5 m_units[0].second += m_units[7].second;
124 5 m_units[1].second += m_units[7].second;
125 5 m_units[2].second -= 2 * m_units[7].second;
126 5 m_units[7].second = 0;
127 }
128 79 return;
129 }
130
131 } // namespace detail
132
133 2337 IPUnit::IPUnit(const IPExpnt& exponents, int scaleExponent, const std::string& prettyString)
134
4/6
✓ Branch 1 taken 2337 times.
✓ Branch 4 taken 2337 times.
✓ Branch 7 taken 2337 times.
✓ Branch 10 taken 2337 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
2337 : Unit(std::shared_ptr<detail::Unit_Impl>(new detail::IPUnit_Impl(exponents, scaleExponent, prettyString))) {}
135
136 ✗ IPUnit::IPUnit(const std::string& scaleAbbreviation, const IPExpnt& exponents, const std::string& prettyString)
137 ✗ : Unit(std::shared_ptr<detail::Unit_Impl>(new detail::IPUnit_Impl(scaleAbbreviation, exponents, prettyString))) {}
138
139 ✗ double IPUnit::gc() {
140 ✗ return 32.1740485564; // lb_m*ft/lb_f*s^2
141 }
142
143 2 void IPUnit::lbmToLbf() {
144
1/1
✓ Branch 3 taken 2 times.
2 getImpl<detail::IPUnit_Impl>()->lbmToLbf();
145 2 }
146
147 79 void IPUnit::lbfToLbm() {
148
1/1
✓ Branch 3 taken 79 times.
79 getImpl<detail::IPUnit_Impl>()->lbfToLbm();
149 79 }
150
151 /// @cond
152
1/1
✓ Branch 2 taken 1473 times.
1473 IPUnit::IPUnit(std::shared_ptr<detail::IPUnit_Impl> impl) : Unit(std::dynamic_pointer_cast<detail::Unit_Impl>(impl)) {}
153 /// @endcond
154
155 101 IPUnit createIPMass() {
156
2/2
✓ Branch 1 taken 101 times.
✓ Branch 5 taken 101 times.
202 return IPUnit(IPExpnt(1));
157 }
158
159 355 IPUnit createIPLength() {
160
2/2
✓ Branch 1 taken 355 times.
✓ Branch 5 taken 355 times.
710 return IPUnit(IPExpnt(0, 1));
161 }
162
163 105 IPUnit createIPTime() {
164
2/2
✓ Branch 1 taken 105 times.
✓ Branch 5 taken 105 times.
210 return IPUnit(IPExpnt(0, 0, 1));
165 }
166
167 185 IPUnit createIPTemperature() {
168
2/2
✓ Branch 1 taken 185 times.
✓ Branch 5 taken 185 times.
370 return IPUnit(IPExpnt(0, 0, 0, 1));
169 }
170
171 101 IPUnit createIPElectricCurrent() {
172
2/2
✓ Branch 1 taken 101 times.
✓ Branch 5 taken 101 times.
202 return IPUnit(IPExpnt(0, 0, 0, 0, 1));
173 }
174
175 100 IPUnit createIPLuminousIntensity() {
176
2/2
✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
200 return IPUnit(IPExpnt(0, 0, 0, 0, 0, 1));
177 }
178
179 100 IPUnit createIPAmountOfSubstance() {
180
2/2
✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
200 return IPUnit(IPExpnt(0, 0, 0, 0, 0, 0, 1));
181 }
182
183 101 IPUnit createIPAngle() {
184
2/2
✓ Branch 1 taken 101 times.
✓ Branch 5 taken 101 times.
202 return IPUnit(IPExpnt(0, 0, 0, 0, 0, 0, 0, 0, 1));
185 }
186
187 100 IPUnit createIPSolidAngle() {
188
2/2
✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
200 return IPUnit(IPExpnt(0, 0, 0, 0, 0, 0, 0, 0, 0, 1));
189 }
190
191 104 IPUnit createIPPeople() {
192
2/2
✓ Branch 1 taken 104 times.
✓ Branch 5 taken 104 times.
208 return IPUnit(IPExpnt(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1));
193 }
194
195 101 IPUnit createIPCycle() {
196
2/2
✓ Branch 1 taken 101 times.
✓ Branch 5 taken 101 times.
202 return IPUnit(IPExpnt(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1));
197 }
198
199 1 IPUnit createIPCurrency() {
200
2/2
✓ Branch 1 taken 1 time.
✓ Branch 5 taken 1 time.
2 return IPUnit(IPExpnt(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1));
201 }
202
203 105 IPUnit createIPForce() {
204
2/2
✓ Branch 1 taken 105 times.
✓ Branch 5 taken 105 times.
210 return IPUnit(IPExpnt(0, 0, 0, 0, 0, 0, 0, 1)); // lb_f
205 }
206
207 103 IPUnit createIPEnergy() {
208
2/2
✓ Branch 1 taken 103 times.
✓ Branch 5 taken 103 times.
206 return IPUnit(IPExpnt(0, 1, 0, 0, 0, 0, 0, 1)); // ft*lb_f
209 }
210
211 101 IPUnit createIPPower() {
212
2/2
✓ Branch 1 taken 101 times.
✓ Branch 5 taken 101 times.
202 return IPUnit(IPExpnt(0, 1, -1, 0, 0, 0, 0, 1)); // ft*lb_f/s
213 }
214
215 100 IPUnit createIPElectricCharge() {
216
2/2
✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
200 return IPUnit(IPExpnt(0, 0, 1, 0, 1), 0, "C");
217 }
218
219 100 IPUnit createIPLuminousFlux() {
220
2/2
✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
200 return IPUnit(IPExpnt(0, 0, 0, 0, 0, 1, 0, 0, 0, 1), 0, "lm");
221 }
222
223 100 IPUnit createIPIlluminance() {
224
2/2
✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
200 return IPUnit(IPExpnt(0, -2, 0, 0, 0, 1, 0, 0, 0, 1), 0, "fc");
225 }
226
227 100 IPUnit createIPFrequency() {
228
2/2
✓ Branch 1 taken 100 times.
✓ Branch 5 taken 100 times.
200 return IPUnit(IPExpnt(0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 1), 0, "Hz");
229 }
230
231 } // namespace openstudio
232