Skip to content
Prev Previous commit
Next Next commit
Add test for the result type being a float.
  • Loading branch information
rhettinger committed Mar 13, 2023
commit 5fe1be5898a0e649be8bb4c8127c05ef5d642b30
12 changes: 11 additions & 1 deletion Lib/test/test_statistics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test suite for statistics module, including helper NumericTestCase and
x = """Test suite for statistics module, including helper NumericTestCase and
Copy link
Copy Markdown

@alexanderGerbik alexanderGerbik Mar 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a typo or some kind of black magic?

approx_equal function.

"""
Expand Down Expand Up @@ -2610,6 +2610,16 @@ def test_proportional(self):
self.assertAlmostEqual(slope, 20 + 1/150)
self.assertEqual(intercept, 0.0)

def test_float_output(self):
x = [Fraction(2, 3), Fraction(3, 4)]
y = [Fraction(4, 5), Fraction(5, 6)]
slope, intercept = statistics.linear_regression(x, y)
self.assertTrue(isinstance(slope, float))
self.assertTrue(isinstance(intercept, float))
slope, intercept = statistics.linear_regression(x, y, proportional=True)
self.assertTrue(isinstance(slope, float))
self.assertTrue(isinstance(intercept, float))

class TestNormalDist:

# General note on precision: The pdf(), cdf(), and overlap() methods
Expand Down