Ejemplo n.º 1
0
 def test_odd_ints(self):
     # Test median with an odd number of int data points.
     data = [1, 2, 3, 4, 5, 6, 9]
     assert len(data) % 2 == 1
     assert statistics.median(data) == 4
     assert Math.median(data) == 4
     assert statistics.median(data) == Math.median(data)
Ejemplo n.º 2
0
 def test_even_ints(self):
     # Test median with an even number of int data points.
     data = [1, 2, 3, 4, 5, 6]
     assert len(data) % 2 == 0
     assert statistics.median(data) == 3.5
     assert Math.median(data) == 3.5
     assert statistics.median(data) == Math.median(data)
Ejemplo n.º 3
0
 def test_odd_fractions(self):
     # Test median works with an odd number of Fractions.
     data = [
         Fraction(1, 7),
         Fraction(2, 7),
         Fraction(3, 7),
         Fraction(4, 7),
         Fraction(5, 7)
     ]
     assert len(data) % 2 == 1
     random.shuffle(data)
     assert statistics.median(data) == Fraction(3, 7)
     assert Math.median(data) == Fraction(3, 7)
     assert statistics.median(data) == Math.median(data)
Ejemplo n.º 4
0
 def test_odd_decimals(self):
     # Test median works with an odd number of Decimals.
     data = [
         Decimal("2.5"),
         Decimal("3.1"),
         Decimal("4.2"),
         Decimal("5.7"),
         Decimal("5.8")
     ]
     assert len(data) % 2 == 1
     random.shuffle(data)
     assert statistics.median(data) == Decimal("4.2")
     assert Math.median(data) == Decimal("4.2")
     assert statistics.median(data) == Math.median(data)
Ejemplo n.º 5
0
 def test_even_decimals(self):
     # Test median works with an even number of Decimals.
     data = [
         Decimal('1.2'),
         Decimal('2.5'),
         Decimal('3.1'),
         Decimal('4.2'),
         Decimal('5.7'),
         Decimal('5.8')
     ]
     assert len(data) % 2 == 0
     random.shuffle(data)
     assert statistics.median(data) == Decimal('3.65')
     assert Math.median(data) == Decimal('3.65')
     assert statistics.median(data) == Math.median(data)
Ejemplo n.º 6
0
 def test_odd_decimals(self):
     # Test median works with an odd number of Decimals.
     D = Decimal
     data = [
         Decimal('2.5'),
         Decimal('3.1'),
         Decimal('4.2'),
         Decimal('5.7'),
         Decimal('5.8')
     ]
     assert len(data) % 2 == 1
     random.shuffle(data)
     assert statistics.median(data) == Decimal('4.2')
     assert Math.median(data) == Decimal('4.2')
     assert statistics.median(data) == Math.median(data)
Ejemplo n.º 7
0
 def test_even_fractions(self):
     # Test median works with an even number of Fractions.
     data = [
         Fraction(1, 7),
         Fraction(2, 7),
         Fraction(3, 7),
         Fraction(4, 7),
         Fraction(5, 7),
         Fraction(6, 7),
     ]
     assert len(data) % 2 == 0
     random.shuffle(data)
     assert statistics.median(data) == Fraction(1, 2)
     assert Math.median(data) == Fraction(1, 2)
     assert statistics.median(data) == Math.median(data)