GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 73.3% 33 / 0 / 45
Functions: 62.5% 5 / 0 / 8
Branches: 79.2% 42 / 0 / 53

src/alfalfa/AlfalfaActuator.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 "AlfalfaActuator.hpp"
7
8 #include "../utilities/idd/IddObject.hpp"
9 #include "../utilities/idd/IddEnums.hpp"
10 #include "../utilities/idf/IdfObject.hpp"
11
12 #include <utilities/idd/OS_EnergyManagementSystem_Actuator_FieldEnums.hxx>
13 #include <utilities/idd/EnergyManagementSystem_Actuator_FieldEnums.hxx>
14 #include <utilities/idd/IddEnums.hxx>
15
16 #include <fmt/format.h>
17 #include <json/value.h>
18
19 #include <string>
20
21 namespace openstudio {
22 namespace alfalfa {
23 11 AlfalfaActuator::AlfalfaActuator(const std::string& component_name, const std::string& component_type, const std::string& control_type)
24
3/3
✓ Branch 2 taken 11 times.
✓ Branch 5 taken 11 times.
✓ Branch 8 taken 11 times.
11 : m_component_name(component_name), m_component_type(component_type), m_control_type(control_type) {
25
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
11 if (component_name.empty()) {
26 ✗ throw std::runtime_error("Error creating AlfalfaActuator: component_name must be non-empty");
27
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
11 } else if (component_type.empty()) {
28 ✗ throw std::runtime_error("Error creating AlfalfaActuator: component_type must be non-empty");
29
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
11 } else if (control_type.empty()) {
30 ✗ throw std::runtime_error("Error creating AlfalfaActuator: control_type must be non-empty");
31 }
32 11 }
33
34 12 AlfalfaActuator::AlfalfaActuator(const IdfObject& actuator) {
35
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 const IddObjectType idd_type = actuator.iddObject().type();
36
37
3/3
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 6 times.
12 if (idd_type == IddObjectType::OS_EnergyManagementSystem_Actuator) {
38
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 m_component_name = actuator.getString(OS_EnergyManagementSystem_ActuatorFields::ActuatedComponentName).value_or("");
39
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 m_component_type = actuator.getString(OS_EnergyManagementSystem_ActuatorFields::ActuatedComponentType).value_or("");
40
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 m_control_type = actuator.getString(OS_EnergyManagementSystem_ActuatorFields::ActuatedComponentControlType).value_or("");
41
2/3
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 } else if (idd_type == IddObjectType::EnergyManagementSystem_Actuator) {
42
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 m_component_name = actuator.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentUniqueName).value_or("");
43
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 m_component_type = actuator.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentType).value_or("");
44
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 m_control_type = actuator.getString(EnergyManagementSystem_ActuatorFields::ActuatedComponentControlType).value_or("");
45 } else {
46 ✗ throw std::runtime_error(fmt::format("Error creating AlfalfaActuator: {} is not a supported object type", idd_type.valueDescription()));
47 }
48
49
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 10 times.
12 if (m_component_name.empty()) {
50
1/1
✓ Branch 2 taken 2 times.
2 throw std::runtime_error("Error creating AlfalfaActuator: Object is missing a component name");
51 }
52
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 8 times.
10 if (m_component_type.empty()) {
53
1/1
✓ Branch 2 taken 2 times.
2 throw std::runtime_error("Error creating AlfalfaActuator: Object is missing a component type");
54 }
55
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 if (m_control_type.empty()) {
56 ✗ throw std::runtime_error("Error creating AlfalfaActuator: Object is missing a control type");
57 }
58 24 }
59
60 1 std::string AlfalfaActuator::deriveName() const {
61 2 return fmt::format("Actuator for {}:{}:{}", m_component_name, m_component_type, m_control_type);
62 }
63
64 54 Json::Value AlfalfaActuator::toJSON() const {
65 54 Json::Value parameters;
66
2/2
✓ Branch 1 taken 54 times.
✓ Branch 4 taken 54 times.
54 parameters["component_name"] = m_component_name;
67
2/2
✓ Branch 1 taken 54 times.
✓ Branch 4 taken 54 times.
54 parameters["component_type"] = m_component_type;
68
2/2
✓ Branch 1 taken 54 times.
✓ Branch 4 taken 54 times.
54 parameters["control_type"] = m_control_type;
69
70 54 return parameters;
71 ✗ }
72
73 ✗ std::string AlfalfaActuator::componentName() const {
74 ✗ return m_component_name;
75 }
76
77 ✗ std::string AlfalfaActuator::componentType() const {
78 ✗ return m_component_type;
79 }
80
81 ✗ std::string AlfalfaActuator::controlType() const {
82 ✗ return m_control_type;
83 }
84
85 39 bool AlfalfaActuator::acceptsObjectType(const IddObjectType& idd_type) {
86 39 return idd_type.value() == IddObjectType::OS_EnergyManagementSystem_Actuator
87
4/4
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 4 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 31 times.
39 || idd_type.value() == IddObjectType::EnergyManagementSystem_Actuator;
88 }
89 } // namespace alfalfa
90 } // namespace openstudio
91