Skip to content

adding test to electronics/electric_power.py #9943 #12387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions electronics/electric_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,22 @@ def electric_power(voltage: float, current: float, power: float) -> tuple:
>>> electric_power(voltage=2, current=4, power=2)
Traceback (most recent call last):
...
ValueError: Only one argument must be 0
ValueError: Exactly one argument must be 0
>>> electric_power(voltage=0, current=0, power=2)
Traceback (most recent call last):
...
ValueError: Only one argument must be 0
ValueError: Exactly one argument must be 0
>>> electric_power(voltage=0, current=2, power=-4)
Traceback (most recent call last):
...
ValueError: Power cannot be negative in any electrical/electronics system
>>> electric_power(voltage=2.2, current=2.2, power=0)
Result(name='power', value=4.84)
>>> electric_power(current=0, power=6, voltage=2)
Result(name='current', value=3.0)
"""
if (voltage, current, power).count(0) != 1:
raise ValueError("Only one argument must be 0")
raise ValueError("Exactly one argument must be 0")
elif power < 0:
raise ValueError(
"Power cannot be negative in any electrical/electronics system"
Expand All @@ -48,7 +50,7 @@ def electric_power(voltage: float, current: float, power: float) -> tuple:
elif power == 0:
return Result("power", float(round(abs(voltage * current), 2)))
else:
raise ValueError("Exactly one argument must be 0")
raise AssertionError


if __name__ == "__main__":
Expand Down
Loading