@@ -200,6 +200,16 @@ def test_percentile_inf_raises(self) -> None:
200200 with pytest .raises (ValueError , match = 'percentile' ):
201201 result .percentile (float ('inf' ))
202202
203+ def test_percentile_neg_inf_raises (self ) -> None :
204+ result = make_result ((1.0 , 2.0 , 3.0 ))
205+ with pytest .raises (ValueError , match = 'percentile' ):
206+ result .percentile (float ('-inf' ))
207+
208+ def test_percentile_zero_float_raises (self ) -> None :
209+ result = make_result ((1.0 , 2.0 , 3.0 ))
210+ with pytest .raises (ValueError , match = 'percentile' ):
211+ result .percentile (0.0 )
212+
203213 def test_percentile_preserves_fsum_mean (self ) -> None :
204214 durations = tuple (0.1 * i for i in range (1 , 11 ))
205215 result = make_result (durations )
@@ -409,3 +419,23 @@ def test_from_json_not_dict_raises(self) -> None:
409419 payload = json .dumps ([1 , 2 , 3 ])
410420 with pytest .raises (ValueError , match = 'JSON must be an object' ):
411421 BenchmarkResult .from_json (payload )
422+
423+ def test_from_json_inf_round_trip (self ) -> None :
424+ # Python's json module handles Infinity via allow_nan=True (default)
425+ result = make_result ((float ('inf' ), 1.0 ))
426+ restored = BenchmarkResult .from_json (result .to_json ())
427+ assert math .isinf (restored .durations [0 ])
428+ assert restored .durations [1 ] == 1.0
429+
430+ def test_from_json_bool_duration_converts_to_float (self ) -> None :
431+ # JSON true/false → Python True/False → float(True)=1.0, float(False)=0.0
432+ payload = json .dumps ({'durations' : [True , False ], 'is_primary' : True })
433+ restored = BenchmarkResult .from_json (payload )
434+ assert restored .durations == (1.0 , 0.0 )
435+
436+ def test_from_json_negative_durations_accepted (self ) -> None :
437+ # negative durations can occur with non-monotonic timers; no validation
438+ payload = json .dumps ({'durations' : [- 0.1 , 0.2 ], 'is_primary' : True })
439+ restored = BenchmarkResult .from_json (payload )
440+ assert restored .mean == pytest .approx (0.05 )
441+ assert restored .best == - 0.1
0 commit comments