Skip to content

Commit

Permalink
Fix pretty-printing of zero-nominal bilaterals
Browse files Browse the repository at this point in the history
  • Loading branch information
mawildoer committed May 23, 2024
1 parent b5d38d4 commit 660795b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/atopile/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ def simplify_expressions(entry_addr: address.AddrStr):
assertion.rhs = expressions.Expression.from_numericish(
expressions.simplify_expression(assertion.rhs, simplified_context)
)
pass


def _translator_factory(
Expand Down
4 changes: 2 additions & 2 deletions src/atopile/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ def _f(val: float):
tol, tol_unit = pretty_unit(self.tolerance * self.unit)

if nom == 0:
return f"± {_f(tol)}{unit}"
if unit == tol_unit or nom == 0 or tol == 0:
return f"± {_f(tol)}{tol_unit}"
if unit == tol_unit:
return f"{_f(nom)} ± {_f(tol)} {unit}"
return f"{_f(nom)}{unit} ± {_f(tol)}{tol_unit}"

Expand Down
2 changes: 2 additions & 0 deletions tests/test_expressions/test_ranged_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def test_pretty_str():
assert RangedValue(3, 3, pint.Unit("V"), str_rep=str_rep).pretty_str() == str_rep
assert RangedValue(3, 3, pint.Unit("V")).pretty_str() == "3V"
assert RangedValue(3, 5, pint.Unit("V")).pretty_str() == "3 to 5 V"
assert RangedValue(3, 5, pint.Unit("mV")).pretty_str() == "3 to 5 mV"
assert RangedValue(3, 3.1, pint.Unit("V")).pretty_str() == "3.05V ± 50mV"

# # Test Zeros
Expand All @@ -64,6 +65,7 @@ def test_pretty_str():
assert RangedValue(-50, -48, pint.Unit("V")).pretty_str() == "-49 ± 1 V"
assert RangedValue(-50, -30, pint.Unit("V")).pretty_str() == "-50 to -30 V"
assert RangedValue(-50, 50, pint.Unit("V")).pretty_str() == "± 50V"
assert RangedValue(-50, 50, pint.Unit("mV")).pretty_str() == "± 50mV"

# Make sure combined units compact properly
v = RangedValue(3, 3, pint.Unit("V"))
Expand Down

0 comments on commit 660795b

Please sign in to comment.