def test_biased(biased_data): summary = Summary() for sample in biased_data: summary.add(sample) assert summary.mean == approx(74.085) assert summary.median == approx(32.0) top_3 = summary.mode[:3] assert top_3 == [(500, 97), (42, 42), (41, 41)]
class GIVEN_data_WHEN_1k_samples_THEN_mean_median(unittest.TestCase): def setUp(self): self.summary = Summary() self.data = list(range(1001)) random.shuffle(self.data) def runTest(self): for sample in self.data: self.summary.add(sample) self.assertEqual(500, self.summary.mean) self.assertEqual(500, self.summary.median)
class GIVEN_Summary_WHEN_1k_samples_THEN_mode(unittest.TestCase): def setUp(self): self.summary = Summary() self.data = [500] * 97 # Build 903 elements: each value of n occurs n times. for i in range(1, 43): self.data += [i] * i random.shuffle(self.data) for sample in self.data: self.summary.add(sample) def test_mode(self): top_3 = self.summary.mode[:3] self.assertListEqual([(500, 97), (42, 42), (41, 41)], top_3)
def test_flat(flat_data): summary = Summary() for sample in flat_data: summary.add(sample) assert summary.mean == 500 assert summary.median == 500
def summary_object(flat_data): summary = Summary() for sample in flat_data: summary.add(sample) return summary