def test_plot_histogram(self): xs = [0, 1, 3, 4, 5] ys = [0, 1, 3, 4, 5] plot_histogram(Pmf(dict(zip(xs, ys)))) filename = '../resources/test_plot_histogram_method' save_format(filename) self.assertTrue(do_file_exist(filename + '.eps')) os.remove(filename + '.eps')
def relative_mean_difference(pmf, mu=None): test_obj_instance(pmf, Pmf) if mu is None: mu = mean(pmf) diff = Pmf() for v1, p1 in pmf.items(): for v2, p2 in pmf.items(): diff.increment(abs(v1 - v2), p1 * p2) return mean(diff) / mu
def test_make_transform(self): dct = {1: 2, 2: 2, 3: 3, 4: 1, 5: 4} old_pmf = Pmf(dct) new_pmf, options = make_transform(old_pmf) self.assertEqual(old_pmf, new_pmf) self.assertEqual(options, {'xscale': 'linear', 'yscale': 'linear'})
def test_make_cdf_from_pmf(self): dct = {1: 2, 2: 2, 3: 3, 4: 1, 5: 4} self.assertEqual(len(make_cdf_from_pmf(Pmf(dct))), 5)
def test_make_mixture_pmfs(self): dct = {1: 2, 2: 2, 3: 3, 4: 1, 5: 4} pmfs = {Pmf(dct): 0.1, Pmf(dct): 0.2, Pmf(dct): 0.3, Pmf(dct): 0.4} self.assertEqual(len(make_mixture_pmfs(pmfs)), 5)
def test_random(self): pmf = Pmf(d={0: 10}) self.assertEqual(pmf.random(), 0)
def setUp(self): self.pmf = Pmf(d={0: 4.0, 1: 8.0, 2: 12.0, 3: 16.0})
def test_fit_line_pmf(self): pmf = Pmf(dict(zip(self.xs, self.ys))) self.assertEqual(self.least_squares.fit_line_pmf(), pmf)