mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-18 08:17:01 +00:00
adding test to electronics/electric_power.py (#12387)
* test electric_power * Update electric_power.py * Update electric_power.py * Update electric_power.py * Update electric_power.py --------- Co-authored-by: Julia <julia.de-jesus-aragao@imt-atlantique.net> Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
This commit is contained in:
parent
2ae9534fc6
commit
1652d05e9e
|
@ -23,20 +23,22 @@ def electric_power(voltage: float, current: float, power: float) -> tuple:
|
||||||
>>> electric_power(voltage=2, current=4, power=2)
|
>>> electric_power(voltage=2, current=4, power=2)
|
||||||
Traceback (most recent call last):
|
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)
|
>>> electric_power(voltage=0, current=0, power=2)
|
||||||
Traceback (most recent call last):
|
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)
|
>>> electric_power(voltage=0, current=2, power=-4)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
ValueError: Power cannot be negative in any electrical/electronics system
|
ValueError: Power cannot be negative in any electrical/electronics system
|
||||||
>>> electric_power(voltage=2.2, current=2.2, power=0)
|
>>> electric_power(voltage=2.2, current=2.2, power=0)
|
||||||
Result(name='power', value=4.84)
|
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:
|
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:
|
elif power < 0:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Power cannot be negative in any electrical/electronics system"
|
"Power cannot be negative in any electrical/electronics system"
|
||||||
|
@ -48,7 +50,7 @@ def electric_power(voltage: float, current: float, power: float) -> tuple:
|
||||||
elif power == 0:
|
elif power == 0:
|
||||||
return Result("power", float(round(abs(voltage * current), 2)))
|
return Result("power", float(round(abs(voltage * current), 2)))
|
||||||
else:
|
else:
|
||||||
raise ValueError("Exactly one argument must be 0")
|
raise AssertionError
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue
Block a user