GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 78.7% 37 / 0 / 47
Functions: 71.4% 5 / 0 / 7
Branches: 83.6% 56 / 0 / 67

src/alfalfa/AlfalfaOutputVariable.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 "AlfalfaOutputVariable.hpp"
7
8 #include "../utilities/idd/IddObject.hpp"
9 #include "../utilities/idd/IddEnums.hpp"
10
11 #include <utilities/idd/OS_EnergyManagementSystem_OutputVariable_FieldEnums.hxx>
12 #include <utilities/idd/OS_Output_Variable_FieldEnums.hxx>
13 #include <utilities/idd/EnergyManagementSystem_OutputVariable_FieldEnums.hxx>
14 #include <utilities/idd/Output_Variable_FieldEnums.hxx>
15 #include <utilities/idd/IddEnums.hxx>
16
17 #include <fmt/format.h>
18
19 namespace openstudio {
20 namespace alfalfa {
21 9 AlfalfaOutputVariable::AlfalfaOutputVariable(const std::string& variable_key, const std::string& variable_name)
22
2/2
✓ Branch 2 taken 9 times.
✓ Branch 5 taken 9 times.
9 : m_variable_key(variable_key), m_variable_name(variable_name) {
23
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
9 if (variable_key.empty()) {
24 ✗ throw std::runtime_error("Error creating OutputVariable: variable_key must be non-empty");
25
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
9 } else if (variable_name.empty()) {
26 ✗ throw std::runtime_error("Error creating OutputVariable: variable_name must be non-empty");
27
2/3
✓ Branch 1 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
9 } else if (variable_key == "*") {
28 ✗ throw std::runtime_error("Error creating OutputVariable: Key must not be wildcard '*'");
29 }
30 9 }
31
32 24 AlfalfaOutputVariable::AlfalfaOutputVariable(const openstudio::IdfObject& output_variable) {
33
2/2
✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
24 const openstudio::IddObjectType idd_type = output_variable.iddObject().type();
34
35
3/3
✓ Branch 1 taken 24 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 18 times.
24 if (idd_type == IddObjectType::OS_Output_Variable) {
36
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 m_variable_key = output_variable.getString(OS_Output_VariableFields::KeyValue).value_or("");
37
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 m_variable_name = output_variable.getString(OS_Output_VariableFields::VariableName).value_or("");
38
3/3
✓ Branch 1 taken 18 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 12 times.
18 } else if (idd_type == IddObjectType::Output_Variable) {
39
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 m_variable_key = output_variable.getString(Output_VariableFields::KeyValue).value_or("");
40
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 m_variable_name = output_variable.getString(Output_VariableFields::VariableName).value_or("");
41
3/3
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 6 times.
12 } else if (idd_type == IddObjectType::OS_EnergyManagementSystem_OutputVariable) {
42
1/1
✓ Branch 1 taken 6 times.
6 m_variable_key = "EMS";
43
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 m_variable_name = output_variable.getString(OS_EnergyManagementSystem_OutputVariableFields::EMSVariableName).value_or("");
44
2/3
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 } else if (idd_type == IddObjectType::EnergyManagementSystem_OutputVariable) {
45
1/1
✓ Branch 1 taken 6 times.
6 m_variable_key = "EMS";
46
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 m_variable_name = output_variable.getString(EnergyManagementSystem_OutputVariableFields::EMSVariableName).value_or("");
47 } else {
48 ✗ throw std::runtime_error(fmt::format("Error creating OutputVariable: {} is not a supported object type", idd_type.valueDescription()));
49 }
50
51
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 20 times.
24 if (m_variable_key.empty()) {
52
1/1
✓ Branch 2 taken 4 times.
4 throw std::runtime_error("Error creating OutputVariable: Object is missing a variable key");
53 }
54
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 16 times.
20 if (m_variable_name.empty()) {
55
1/1
✓ Branch 2 taken 4 times.
4 throw std::runtime_error("Error creating OutputVariable: Object is missing a variable name");
56 }
57
2/3
✓ Branch 1 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
16 if (m_variable_key == "*") {
58 ✗ throw std::runtime_error("Error creating OutputVariable: Key must not be wildcard '*'");
59 }
60 40 }
61
62 1 std::string AlfalfaOutputVariable::deriveName() const {
63
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
2 return "Output Variable for " + m_variable_key + ":" + m_variable_name;
64 }
65
66 38 Json::Value AlfalfaOutputVariable::toJSON() const {
67 38 Json::Value parameters;
68
69
2/2
✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
38 parameters["variable_key"] = m_variable_key;
70
2/2
✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
38 parameters["variable_name"] = m_variable_name;
71
72 38 return parameters;
73 ✗ }
74
75 ✗ std::string AlfalfaOutputVariable::variableKey() const {
76 ✗ return m_variable_key;
77 }
78
79 ✗ std::string AlfalfaOutputVariable::variableName() const {
80 ✗ return m_variable_name;
81 }
82
83 23 bool AlfalfaOutputVariable::acceptsObjectType(const IddObjectType& idd_type) {
84
2/2
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 4 times.
42 return idd_type.value() == IddObjectType::OS_Output_Variable || idd_type.value() == IddObjectType::Output_Variable
85
2/2
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 4 times.
15 || idd_type.value() == IddObjectType::EnergyManagementSystem_OutputVariable
86
4/4
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 4 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 7 times.
42 || idd_type.value() == IddObjectType::OS_EnergyManagementSystem_OutputVariable;
87 }
88
89 } // namespace alfalfa
90 } // namespace openstudio
91