Skip to content

Commit c66ced0

Browse files
committed
test: ✅ handled input validation for values less than 0
1 parent 812ae42 commit c66ced0

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

physics/boyles_law.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def check_validity(values: dict[str, float]) -> None:
5858
...
5959
ValueError: Invalid input k is not a valid variable
6060
61+
>>> check_validity({'v1':2,'v2':4,'p1':-6})
62+
Traceback (most recent call last):
63+
...
64+
ValueError: Invalid input p1 must be greater than 0
65+
6166
>>> check_validity({'v1':2,'v2':4,'p1':6})
6267
6368
"""
@@ -69,6 +74,9 @@ def check_validity(values: dict[str, float]) -> None:
6974
if value not in valid_variables:
7075
msg = f"Invalid input {value} is not a valid variable"
7176
raise ValueError(msg)
77+
if values[value] <= 0:
78+
msg = f"Invalid input {value} must be greater than 0"
79+
raise ValueError(msg)
7280
return
7381

7482

@@ -92,6 +100,11 @@ def find_target_variable(values: dict[str, float]) -> str:
92100
...
93101
ValueError: Invalid input k is not a valid variable
94102
103+
>>> find_target_variable({'v1':1,'v2':-2,'p2':4})
104+
Traceback (most recent call last):
105+
...
106+
ValueError: Invalid input v2 must be greater than 0
107+
95108
"""
96109
check_validity(values)
97110
for variable in valid_variables:
@@ -123,6 +136,11 @@ def boyles_law(values: dict[str, float]) -> dict[str, str]:
123136
...
124137
ValueError: Invalid input k is not a valid variable
125138
139+
>>> boyles_law({'p1':2,'v2':1, 'v1':-6})
140+
Traceback (most recent call last):
141+
...
142+
ValueError: Invalid input v1 must be greater than 0
143+
126144
>>> boyles_law({'p1':100,'v2':150, 'v1':120})
127145
{'p2': '80.0 Pa'}
128146

0 commit comments

Comments
 (0)