GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 91.0% 91 / 0 / 100
Functions: 90.0% 27 / 0 / 30
Branches: 100.0% 62 / 0 / 62

src/alfalfa/AlfalfaPoint.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 "AlfalfaPoint.hpp"
7 #include "AlfalfaPoint_Impl.hpp"
8 #include "AlfalfaComponent.hpp"
9
10 #include <boost/regex.hpp>
11 #include <fmt/format.h>
12
13 #include <memory>
14 #include <string_view>
15 #include <algorithm>
16
17 namespace openstudio {
18 namespace alfalfa {
19
20 namespace detail {
21
22 81 AlfalfaPoint_Impl::AlfalfaPoint_Impl(const std::string& display_name) {
23
1/1
✓ Branch 1 taken 80 times.
81 setDisplayName(display_name);
24 85 }
25
26 109 Json::Value AlfalfaPoint_Impl::toJSON() const {
27 109 Json::Value point;
28
29
3/3
✓ Branch 1 taken 109 times.
✓ Branch 4 taken 109 times.
✓ Branch 7 taken 109 times.
109 point["id"] = id();
30
3/3
✓ Branch 1 taken 109 times.
✓ Branch 4 taken 109 times.
✓ Branch 7 taken 109 times.
109 point["name"] = displayName();
31
3/3
✓ Branch 1 taken 109 times.
✓ Branch 3 taken 48 times.
✓ Branch 4 taken 61 times.
218 if (auto input_ = input()) {
32
5/5
✓ Branch 1 taken 48 times.
✓ Branch 4 taken 48 times.
✓ Branch 7 taken 48 times.
✓ Branch 10 taken 48 times.
✓ Branch 13 taken 48 times.
48 point["input"]["type"] = input_->typeName();
33
4/4
✓ Branch 1 taken 48 times.
✓ Branch 4 taken 48 times.
✓ Branch 7 taken 48 times.
✓ Branch 10 taken 48 times.
48 point["input"]["parameters"] = input_->toJSON();
34 109 }
35
36
3/3
✓ Branch 1 taken 109 times.
✓ Branch 3 taken 106 times.
✓ Branch 4 taken 3 times.
218 if (auto output_ = output()) {
37
5/5
✓ Branch 1 taken 106 times.
✓ Branch 4 taken 106 times.
✓ Branch 7 taken 106 times.
✓ Branch 10 taken 106 times.
✓ Branch 13 taken 106 times.
106 point["output"]["type"] = output_->typeName();
38
4/4
✓ Branch 1 taken 106 times.
✓ Branch 4 taken 106 times.
✓ Branch 7 taken 106 times.
✓ Branch 10 taken 106 times.
106 point["output"]["parameters"] = output_->toJSON();
39 109 }
40
41
3/3
✓ Branch 1 taken 109 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 107 times.
218 if (auto units_ = units()) {
42
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 point["units"] = *units_;
43 109 }
44
45
3/3
✓ Branch 1 taken 109 times.
✓ Branch 4 taken 109 times.
✓ Branch 7 taken 109 times.
109 point["optional"] = isOptional();
46
47 109 return point;
48 ✗ }
49
50 40 void AlfalfaPoint_Impl::setInput(const AlfalfaComponent& component) {
51
2/2
✓ Branch 1 taken 37 times.
✓ Branch 2 taken 3 times.
40 if (component.canInput()) {
52 37 m_input = component;
53 } else {
54
2/2
✓ Branch 2 taken 3 times.
✓ Branch 6 taken 3 times.
6 throw std::runtime_error(fmt::format("Component of type: {} cannot be used as an input.", component.typeName()));
55 }
56 37 }
57
58 124 boost::optional<AlfalfaComponent> AlfalfaPoint_Impl::input() const {
59 124 return m_input;
60 }
61
62 79 void AlfalfaPoint_Impl::setOutput(const AlfalfaComponent& component) {
63
2/2
✓ Branch 1 taken 78 times.
✓ Branch 2 taken 1 time.
79 if (component.canOutput()) {
64 78 m_output = component;
65 } else {
66
2/2
✓ Branch 2 taken 1 time.
✓ Branch 6 taken 1 time.
2 throw std::runtime_error(fmt::format("Component of type: {} cannot be used as an output.", component.typeName()));
67 }
68 78 }
69
70 127 boost::optional<AlfalfaComponent> AlfalfaPoint_Impl::output() const {
71 127 return m_output;
72 }
73
74 1 void AlfalfaPoint_Impl::setUnits(const std::string& units) {
75 1 m_units = units;
76 1 }
77
78 110 boost::optional<std::string> AlfalfaPoint_Impl::units() const {
79 110 return m_units;
80 }
81
82 2 void AlfalfaPoint_Impl::setId(const std::string& id) {
83
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
2 if (id.empty()) {
84
1/1
✓ Branch 2 taken 1 time.
1 throw std::runtime_error("Id must have non-zero length");
85 }
86
1/1
✓ Branch 1 taken 1 time.
1 m_id = toIdString(id);
87 1 }
88
89 114 std::string AlfalfaPoint_Impl::id() const {
90
2/2
✓ Branch 1 taken 110 times.
✓ Branch 2 taken 4 times.
114 if (m_id.empty()) {
91
2/2
✓ Branch 1 taken 110 times.
✓ Branch 4 taken 110 times.
110 return toIdString(displayName());
92 }
93 4 return m_id;
94 }
95
96 83 void AlfalfaPoint_Impl::setDisplayName(const std::string& display_name) {
97
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 82 times.
83 if (display_name.empty()) {
98
1/1
✓ Branch 2 taken 1 time.
1 throw std::runtime_error("Display name must have non-zero length");
99 }
100 82 m_display_name = display_name;
101 82 }
102
103 223 std::string AlfalfaPoint_Impl::displayName() const {
104 223 return m_display_name;
105 }
106
107 ✗ void AlfalfaPoint_Impl::setOptional(bool optional) {
108 ✗ m_optional = optional;
109 ✗ }
110
111 109 bool AlfalfaPoint_Impl::isOptional() const {
112 109 return m_optional;
113 }
114
115 111 std::string AlfalfaPoint_Impl::toIdString(const std::string& str) {
116 111 std::string id_string = str;
117 111 std::replace(id_string.begin(), id_string.end(), ' ', '_');
118 111 return id_string;
119 }
120 } // namespace detail
121
122 81 AlfalfaPoint::AlfalfaPoint(const std::string& display_name) : m_impl(std::make_shared<detail::AlfalfaPoint_Impl>(display_name)) {}
123
124 40 void AlfalfaPoint::setInput(const AlfalfaComponent& component) {
125 40 m_impl->setInput(component);
126 37 }
127
128 15 boost::optional<AlfalfaComponent> AlfalfaPoint::input() const {
129 15 return m_impl->input();
130 }
131
132 79 void AlfalfaPoint::setOutput(const AlfalfaComponent& component) {
133 79 m_impl->setOutput(component);
134 78 }
135
136 18 boost::optional<AlfalfaComponent> AlfalfaPoint::output() const {
137 18 return m_impl->output();
138 }
139
140 1 void AlfalfaPoint::setUnits(const std::string& units) {
141 1 m_impl->setUnits(units);
142 1 }
143
144 1 boost::optional<std::string> AlfalfaPoint::units() const {
145 1 return m_impl->units();
146 }
147
148 5 std::string AlfalfaPoint::id() const {
149 5 return m_impl->id();
150 }
151
152 2 void AlfalfaPoint::setId(const std::string& id) {
153 2 m_impl->setId(id);
154 1 }
155
156 4 std::string AlfalfaPoint::displayName() const {
157 4 return m_impl->displayName();
158 }
159
160 2 void AlfalfaPoint::setDisplayName(const std::string& display_name) {
161 2 m_impl->setDisplayName(display_name);
162 2 }
163
164 ✗ bool AlfalfaPoint::isOptional() const {
165 ✗ return m_impl->isOptional();
166 }
167
168 ✗ void AlfalfaPoint::setOptional(bool optional) {
169 ✗ m_impl->setOptional(optional);
170 ✗ }
171
172 109 Json::Value AlfalfaPoint::toJSON() const {
173 109 return m_impl->toJSON();
174 }
175
176 22 bool AlfalfaPoint::operator==(const AlfalfaPoint& rhs) const {
177
3/3
✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
✓ Branch 7 taken 22 times.
22 return toJSON() == rhs.toJSON();
178 }
179 } // namespace alfalfa
180 } // namespace openstudio
181