Skip to content

Commit

Permalink
Add more tests and remove dead code.
Browse files Browse the repository at this point in the history
  • Loading branch information
zuckerruebe committed May 2, 2024
1 parent 8e9607a commit a8d2ca3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
8 changes: 0 additions & 8 deletions src/trnsys_dck_parser/parse/expression/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,9 @@ def _argument_list(self) -> _tp.Sequence[_exp.Expression]:

def _unit_and_output_number(self) -> _tp.Tuple[int, int]:
unit_number = int(self._expect(_petok.Tokens.POSITIVE_INTEGER))
self._check_non_negative(unit_number, "Unit number")

self._expect(_petok.Tokens.COMMA)

output_number = int(self._expect(_petok.Tokens.POSITIVE_INTEGER))
self._check_non_negative(output_number, "Output number")

return unit_number, output_number

def _check_non_negative(self, integer: int, what: str) -> None:
if integer >= 0:
return

self._raise_parsing_error(f"{what} numbers must be non-negative.")
29 changes: 19 additions & 10 deletions test/test_trnsys_dck_parser/test_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def _get_expression_test_cases() -> _tp.Iterable[_ExpressionTestCase]: # pylint
yield _ExpressionTestCase(string, result, benchmark=False)

string = "ABS([33,1])"
result = _pcom.ParseSuccess(
_build.absolute(_mexpr.UnitOutput(33, 1)), 11
)
result = _pcom.ParseSuccess(_build.absolute(_mexpr.UnitOutput(33, 1)), 11)
yield _ExpressionTestCase(string, result, benchmark=False)

string = "[-6,1] "
Expand Down Expand Up @@ -67,6 +65,17 @@ def _get_expression_test_cases() -> _tp.Iterable[_ExpressionTestCase]: # pylint
)
yield _ExpressionTestCase(string, result)

string = "(1+COS(C_tilt))*0.5*tSky + (1-]COS(C_tilt))*0.5*tAmb"
result = _pcom.ParseError(
error_message=(
"Expected number, variable, function call, opening square bracket or opening parenthesis "
'but found closing square bracket ("]")'
),
input_string=string,
error_start=30,
)
yield _ExpressionTestCase(string, result)

string = "((tSky+273.15)**4)*5.67*(10**-8)*3.6"
t_sky = _build.create_variable("tSky")
result = _pcom.ParseSuccess(
Expand Down Expand Up @@ -94,14 +103,14 @@ def _get_expression_test_cases() -> _tp.Iterable[_ExpressionTestCase]: # pylint

string = "x*y**z"
x, y, z = _build.create_variables("x y z")
result = _pcom.ParseSuccess(x * (y ** z), 6)
result = _pcom.ParseSuccess(x * (y**z), 6)
yield _ExpressionTestCase(string, result, benchmark=False)

string = ""
result = _pcom.ParseError(
error_message="Expected number, variable, function call, opening "
"square bracket or opening parenthesis but found "
"end of input",
"square bracket or opening parenthesis but found "
"end of input",
input_string=string,
error_start=0,
)
Expand All @@ -110,8 +119,8 @@ def _get_expression_test_cases() -> _tp.Iterable[_ExpressionTestCase]: # pylint
string = "((tSky+)"
result = _pcom.ParseError(
error_message="Expected number, variable, function call, opening "
"square bracket or opening parenthesis but found "
'closing parenthesis (")")',
"square bracket or opening parenthesis but found "
'closing parenthesis (")")',
input_string=string,
error_start=7,
)
Expand All @@ -128,8 +137,8 @@ def _get_expression_test_cases() -> _tp.Iterable[_ExpressionTestCase]: # pylint
string = "(10**-)"
result = _pcom.ParseError(
error_message="Expected number, variable, function call, opening "
"square bracket or opening parenthesis but found "
'closing parenthesis (")")',
"square bracket or opening parenthesis but found "
'closing parenthesis (")")',
input_string=string,
error_start=6,
)
Expand Down

0 comments on commit a8d2ca3

Please sign in to comment.