@@ -130,12 +130,25 @@ def test_sigfigs(test_group, variables):
130
130
pytest .fail (f"test group is not defined (got: '{ test_group } ')" )
131
131
assert (pbh .sigfigs (test_input ) == correct_sigfigs ), f"input: { test_input } , output: { pbh .sigfigs (test_input )} "
132
132
133
- def test_sigfigs_floatinput_fail ():
133
+ def test_sigfigs_float_input_fail ():
134
134
with pytest .raises (Exception ):
135
135
pbh .sigfigs (float (1 ))
136
136
137
137
138
138
# Test round_sig function
139
+ def test_roundsig_int_returns_int ():
140
+ """Test rounding an int with specified sigfigs"""
141
+ assert isinstance (pbh .round_sig (123 , 2 ), int )
142
+
143
+ def test_roundsig_with_float ():
144
+ """Test rounding an float with specified sigfigs"""
145
+ assert isinstance (pbh .round_sig (123.0 , 2 ), float )
146
+
147
+ def test_roundsig_with_string_fail ():
148
+ """Test rounding a string with specified sigfigs"""
149
+ with pytest .raises (Exception ):
150
+ pbh .round_sig ("123.0" , 2 )
151
+
139
152
@pytest .mark .parametrize ('id, input, sigfigs, expected_result' , [
140
153
('id_positive float' ,3.14159 , 3 , 3.14 ), # Test rounding a positive float to 3 sigfigs
141
154
('id_negative float' ,- 2.71828 , 3 , - 2.72 ), # Test rounding a negative float to 3 sigfigs
@@ -158,11 +171,22 @@ def test_sigfigs_floatinput_fail():
158
171
],
159
172
ids = idfn
160
173
)
161
- def test_roundsig (id , input , sigfigs , expected_result ):
174
+ def test_roundsig_rigorous (id , input , sigfigs , expected_result ):
162
175
assert (pbh .round_sig (input , sigfigs ) == expected_result )
163
176
164
177
165
178
#test num_as_str function
179
+ def test_num_as_str_default_dp ():
180
+ """test default decimal places"""
181
+ assert pbh .num_as_str (3.14159 ) == '3.14'
182
+
183
+ def test_num_as_str_invalid_args_kwargs ():
184
+ with pytest .raises (TypeError ):
185
+ pbh .num_as_str (123.45 , 2 , "args" ) # Function should not accept *args
186
+
187
+ with pytest .raises (TypeError ):
188
+ pbh .num_as_str (123.45 , 2 , digits_after_decimal = 2 ) # Function should not accept **kwargs
189
+
166
190
@pytest .mark .parametrize ('id, input, digits_after_decimal, expected_result' , [
167
191
('id_positive float' ,3.14159 , 2 , '3.14' ), # Test rounding a positive float to 2 digits after decimal
168
192
('id_negative float' ,- 2.71828 , 2 , '-2.72' ), # Test rounding a negative float to 2 digits after decimal
@@ -184,20 +208,9 @@ def test_roundsig(id, input, sigfigs, expected_result):
184
208
],
185
209
ids = idfn
186
210
)
187
- def test_num_as_str (id , input , digits_after_decimal , expected_result ):
211
+ def test_num_as_str_rigorous (id , input , digits_after_decimal , expected_result ):
188
212
assert pbh .num_as_str (input , digits_after_decimal ) == expected_result
189
213
190
- def test_num_as_str_default_dp ():
191
- """test default decimal places"""
192
- assert pbh .num_as_str (3.14159 ) == '3.14'
193
-
194
- def test_num_as_str_invalid_args_kwargs ():
195
- with pytest .raises (TypeError ):
196
- pbh .num_as_str (123.45 , 2 , "args" ) # Function should not accept *args
197
-
198
- with pytest .raises (TypeError ):
199
- pbh .num_as_str (123.45 , 2 , digits_after_decimal = 2 ) # Function should not accept **kwargs
200
-
201
214
202
215
# Test roundp function
203
216
def test_roundp_with_overriden_sigfig_settings ():
@@ -266,7 +279,7 @@ def test_roundp_notation_sci_dp():
266
279
],
267
280
ids = idfn
268
281
)
269
- def test_roundp_rigorous_sigfig (id , input , sigfigs , expected_result ):
282
+ def test_roundp_rigorous (id , input , sigfigs , expected_result ):
270
283
assert pbh .roundp (input , sigfigs = sigfigs ) == expected_result
271
284
272
285
@@ -317,5 +330,5 @@ def test_roundstr_with_decimal_sci_notation_dp():
317
330
],
318
331
ids = idfn
319
332
)
320
- def test_roundstr_rigorous_sigfig (id , input , sigfigs , expected_result ):
333
+ def test_roundstr_rigorous (id , input , sigfigs , expected_result ):
321
334
assert pbh .round_str (input , sigfigs = sigfigs ) == expected_result
0 commit comments