-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-40331: Increase test coverage for the statistics module #19608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
ccd8bef
21084c1
49def61
b2b9844
50a843f
bbe16bd
74b047a
1a5c2df
ac8b586
ee55b16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1004,6 +1004,10 @@ def test_nan(self): | |
x = statistics._convert(nan, type(nan)) | ||
self.assertTrue(_nan_equal(x, nan)) | ||
|
||
def test_invalid_input_type(self): | ||
with self.assertRaises(TypeError): | ||
statistics._convert(None, float) | ||
|
||
|
||
class FailNegTest(unittest.TestCase): | ||
"""Test _fail_neg private function.""" | ||
|
@@ -1033,6 +1037,47 @@ def test_error_msg(self): | |
self.assertEqual(errmsg, msg) | ||
|
||
|
||
class FindLteqTest(unittest.TestCase): | ||
# Test _find_lteq private function. | ||
|
||
def test_invalid_input_values(self): | ||
for a, x in [ | ||
([], 1), | ||
([1, 2], 3), | ||
([1, 3], 2) | ||
]: | ||
with self.assertRaises(ValueError): | ||
statistics._find_lteq(a, x) | ||
|
||
def test_locate_successfully(self): | ||
for a, x, expected_i in [ | ||
([1, 1, 1, 2, 3], 1, 0), | ||
([0, 1, 1, 1, 2, 3], 1, 1), | ||
([1, 2, 3, 3, 3], 3, 2) | ||
]: | ||
self.assertEqual(expected_i, statistics._find_lteq(a, x)) | ||
|
||
|
||
class FindRteqTest(unittest.TestCase): | ||
# Test _find_rteq private function. | ||
|
||
def test_raise_value_error(self): | ||
for a, l, x in [ | ||
([1], 2, 1), | ||
([1, 3], 0, 2) | ||
]: | ||
with self.assertRaises(ValueError): | ||
statistics._find_rteq(a, l, x) | ||
|
||
def test_locate_successfully(self): | ||
for a, l, x, expected_i in [ | ||
([1, 1, 1, 2, 3], 0, 1, 2), | ||
([0, 1, 1, 1, 2, 3], 0, 1, 3), | ||
([1, 2, 3, 3, 3], 0, 3, 4) | ||
]: | ||
self.assertEqual(expected_i, statistics._find_rteq(a, l, x)) | ||
|
||
|
||
# === Tests for public functions === | ||
|
||
class UnivariateCommonMixin: | ||
|
@@ -1476,6 +1521,20 @@ def test_negative_error(self): | |
with self.subTest(values=values): | ||
self.assertRaises(exc, self.func, values) | ||
|
||
def test_single_value_unsupported_type(self): | ||
with self.assertRaises(TypeError): | ||
self.func(['3.14']) | ||
|
||
def test_multiple_values_type_error(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be combined with the previous test method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, now they assert the same behavior, with the same way. I will combine them under a test with name |
||
# Test TypeError is raised when given multiple (valid/invalid) values | ||
for data in [ | ||
['1', '2', '3'], # only strings | ||
[1, '2', 3, '4', 5], # mixed strings and valid integers | ||
[2.3, 3.4, 4.5, '5.6'] # only one string and valid floats | ||
]: | ||
with self.assertRaises(TypeError): | ||
self.func(data) | ||
|
||
def test_ints(self): | ||
# Test harmonic mean with ints. | ||
data = [2, 4, 4, 8, 16, 16] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test method could also be renamed, similarly to the previous ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I should have changed this too.