mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Merge pull request #3228 from chrismoradi/fix-complex-repr-tests
Fix repr for complex numbers involving NaN
This commit is contained in:
3 files changed
+5
-6
No files matched your search
Vendored
-2
@@ -156,8 +156,6 @@ class CMathTests(unittest.TestCase):
|
||||
self.assertAlmostEqual(cmath.e, e_expected, places=9,
|
||||
msg="cmath.e is {}; should be {}".format(cmath.e, e_expected))
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_infinity_and_nan_constants(self):
|
||||
self.assertEqual(cmath.inf.real, math.inf)
|
||||
self.assertEqual(cmath.inf.imag, 0.0)
|
||||
|
||||
Vendored
-2
@@ -460,8 +460,6 @@ class ComplexTest(unittest.TestCase):
|
||||
for num in nums:
|
||||
self.assertAlmostEqual((num.real**2 + num.imag**2) ** 0.5, abs(num))
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_repr_str(self):
|
||||
def test(v, expected, test_fn=self.assertEqual):
|
||||
test_fn(repr(v), expected)
|
||||
|
||||
@@ -335,10 +335,13 @@ impl PyComplex {
|
||||
#[pymethod(magic)]
|
||||
fn repr(&self) -> String {
|
||||
let Complex64 { re, im } = self.value;
|
||||
// converting to lowercase to format "NaN" as "nan"
|
||||
if re == 0.0 {
|
||||
format!("{}j", im)
|
||||
format!("{}j", im).to_lowercase()
|
||||
} else if im.is_nan() {
|
||||
format!("({}+{:+}j)", re, im).to_lowercase()
|
||||
} else {
|
||||
format!("({}{:+}j)", re, im)
|
||||
format!("({}{:+}j)", re, im).to_lowercase()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user