Clean-up and simplify median_grouped(). Vastly improve its docstring. (#92324)

This commit is contained in:
Raymond Hettinger 2022-05-05 03:01:07 -05:00 committed by GitHub
parent b885b8f4be
commit 5212cbc261
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 91 deletions

View file

@ -1040,50 +1040,6 @@ class FailNegTest(unittest.TestCase):
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.subTest(a=a, x=x):
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)
]:
with self.subTest(a=a, x=x):
self.assertEqual(expected_i, statistics._find_lteq(a, x))
class FindRteqTest(unittest.TestCase):
# Test _find_rteq private function.
def test_invalid_input_values(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)
]:
with self.subTest(a=a, l=l, x=x):
self.assertEqual(expected_i, statistics._find_rteq(a, l, x))
# === Tests for public functions ===
class UnivariateCommonMixin: