fix fmean/fsum ValueError and test_inv_cdf

This commit is contained in:
bearney74
2023-03-16 11:18:47 -05:00
committed by GitHub
parent bbd8fb2342
commit 123559478e
2 changed files with 5 additions and 9 deletions

View File

@@ -1950,8 +1950,6 @@ class TestFMean(unittest.TestCase):
with self.assertRaises(TypeError):
fmean([10, 20, 60], 70) # too many arguments
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_special_values(self):
# Rules for special values are inherited from math.fsum()
fmean = statistics.fmean
@@ -2913,12 +2911,7 @@ class TestNormalDistPython(unittest.TestCase, TestNormalDist):
def tearDown(self):
sys.modules['statistics'] = statistics
# TODO: RUSTPYTHON, ValueError: math domain error
@unittest.expectedFailure
def test_inv_cdf(self): # TODO: RUSTPYTHON, remove when this passes
super().test_inv_cdf() # TODO: RUSTPYTHON, remove when this passes
@unittest.skipUnless(c_statistics, 'requires _statistics')
class TestNormalDistC(unittest.TestCase, TestNormalDist):

View File

@@ -211,6 +211,9 @@ mod math {
#[pyfunction]
fn sqrt(value: ArgIntoFloat, vm: &VirtualMachine) -> PyResult<f64> {
let value = *value;
if value.is_nan() {
return Ok(value);
}
if value.is_sign_negative() {
return Err(vm.new_value_error("math domain error".to_owned()));
}
@@ -664,7 +667,7 @@ mod math {
}
if special_sum != 0.0 {
return if inf_sum.is_nan() {
Err(vm.new_overflow_error("-inf + inf in fsum".to_owned()))
Err(vm.new_value_error("-inf + inf in fsum".to_owned()))
} else {
Ok(special_sum)
};