Skip to content

Commit

Permalink
Organize test code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Ahrenkiel authored and Phil Ahrenkiel committed Jan 4, 2024
1 parent 2b87503 commit d62fa56
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/HPWH.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5403,7 +5403,14 @@ HPWH::Usage HPWH::findUsageFromFirstHourRating() { return Usage::Medium; }

HPWH::Usage HPWH::findUsageFromMaximumGPM_Rating()
{
if (tankVolume_L < L_TO_GAL(1.7))
// Assume flow rate unlimited for heat-exchange models
if (hasHeatExchanger)
{
return Usage::High;
}

// Assume max. flow rate = tankVolume / (1 min)
else if (tankVolume_L < L_TO_GAL(1.7))
{
return Usage::VerySmall;
}
Expand Down
94 changes: 88 additions & 6 deletions test/testCalcUEF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,96 @@ static bool testCalcUEF(const std::string& sModelName, double& UEF)
return hpwh.calcUEF(hpwh.findUsageFromMaximumGPM_Rating(), UEF);
}

int main(int, char**)
int main(int argc, char* argv[])
{
double UEF;
ASSERTTRUE(testCalcUEF("AOSmithHPTS50", UEF));
ASSERTTRUE(cmpd(UEF, 4.4091));
bool validNumArgs = false;
bool runUnitTests = false;

ASSERTTRUE(testCalcUEF("AquaThermAire", UEF));
ASSERTTRUE(cmpd(UEF, 3.5848));
// process command line arguments
std::string sPresetOrFile = "Preset";
std::string sModelName;
if (argc == 1)
{
runUnitTests = true;
}
else if (argc == 2)
{
sModelName = argv[1];
validNumArgs = true;
runUnitTests = false;
}
else if (argc == 3)
{
sPresetOrFile = argv[1];
sModelName = argv[2];
validNumArgs = true;
runUnitTests = false;
}

if (runUnitTests)
{
double UEF;
ASSERTTRUE(testCalcUEF("AOSmithHPTS50", UEF));
ASSERTTRUE(cmpd(UEF, 4.4091));

ASSERTTRUE(testCalcUEF("AquaThermAire", UEF));
ASSERTTRUE(cmpd(UEF, 3.5848));

return 0;
}

if (!validNumArgs) {
cout << "Invalid input:\n\
To run all unit tests, provide ZERO arguments.\n\
To determine the UEF for a particular model spec, provide ONE or TWO arguments:\n\
\t[model spec Type (i.e., Preset (default) or File)]\n\
\t[model spec Name (i.e., Sanden80)]\n";
exit(1);
}

for (auto& c : sPresetOrFile)
{
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
}

HPWH hpwh;
bool validModel = false;
if (sPresetOrFile == "preset")
{
HPWH::MODELS model = mapStringToPreset(sModelName);
if (hpwh.HPWHinit_presets(model) == 0)
{
validModel = true;
}
}
else
{
std::string inputFile = sModelName + ".txt";
if (hpwh.HPWHinit_file(inputFile) == 0)
{
validModel = true;
}
}

if (!validModel)
{
cout << "Invalid input: Model name not found.\n";
exit(1);
}

sPresetOrFile[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(sPresetOrFile[0])));
std::cout << "Spec type: " << sPresetOrFile << "\n";
std::cout << "Model name: " << sModelName << "\n";

double UEF = 0.;
if(hpwh.calcUEF(hpwh.findUsageFromMaximumGPM_Rating(), UEF))
{
std::cout << "UEF: " << UEF << "\n";
}
else
{
std::cout << "Unable to determine UEF.\n";
}

return 0;
}

0 comments on commit d62fa56

Please sign in to comment.