-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding string representation for State
Now, you can do `print(state)` in python and get all the computed values
- Loading branch information
Showing
4 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,32 @@ | ||
import fprops as fp | ||
import pytest | ||
import math | ||
import re | ||
|
||
|
||
def test_air_valid(): | ||
air = fp.Air() | ||
state = air.p_T(101325, 300) | ||
assert state.p == 101325 | ||
assert state.T == 300 | ||
assert math.isclose(state.rho, 1.1769510785919943, abs_tol=1e-14) | ||
|
||
|
||
def test_air_repr(capfd): | ||
air = fp.Air() | ||
state = air.p_T(101325, 300) | ||
print(state) | ||
out, err = capfd.readouterr() | ||
lines = out.splitlines() | ||
assert re.match("rho = [0-9.e-]+ kg/m\\^3", lines[0]) | ||
assert re.match("p = [0-9.e-]+ Pa", lines[1]) | ||
assert re.match("T = [0-9.e-]+ K", lines[2]) | ||
assert re.match("e = [0-9.e-]+ J/kg", lines[3]) | ||
assert re.match("v = [0-9.e-]+ m\\^3/kg", lines[4]) | ||
assert re.match("cp = [0-9.e-]+ J/\\(kg-K\\)", lines[5]) | ||
assert re.match("cv = [0-9.e-]+ J/\\(kg-K\\)", lines[6]) | ||
assert re.match("s = [0-9.e-]+ J/\\(kg-K\\)", lines[7]) | ||
assert re.match("h = [0-9.e-]+ J/kg", lines[8]) | ||
assert re.match("c = [0-9.e-]+ m/s", lines[9]) | ||
assert re.match("mu = [0-9.e-]+ Pa-s", lines[10]) | ||
assert re.match("k = [0-9.e-]+ W/\\(m-K\\)", lines[11]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "fprops/State.h" | ||
#include "fmt/printf.h" | ||
|
||
namespace fprops { | ||
|
||
std::string | ||
State::to_string() const | ||
{ | ||
std::string str; | ||
str += fmt::format("rho = {} kg/m^3\n", this->rho); | ||
str += fmt::format("p = {} Pa\n", this->p); | ||
str += fmt::format("T = {} K\n", this->T); | ||
str += fmt::format("e = {} J/kg\n", this->u); | ||
str += fmt::format("v = {} m^3/kg\n", this->v); | ||
str += fmt::format("cp = {} J/(kg-K)\n", this->cp); | ||
str += fmt::format("cv = {} J/(kg-K)\n", this->cv); | ||
str += fmt::format("s = {} J/(kg-K)\n", this->s); | ||
str += fmt::format("h = {} J/kg\n", this->h); | ||
str += fmt::format("c = {} m/s\n", this->w); | ||
str += fmt::format("mu = {} Pa-s\n", this->mu); | ||
str += fmt::format("k = {} W/(m-K)\n", this->k); | ||
return str; | ||
} | ||
|
||
} // namespace fprops |