def test_distance_function_same_bin(self): histogram_a = Histogram() histogram_b = Histogram() histogram_a.add(0, 5) histogram_b.add(0, -5) self.assertEqual(distance(histogram_a, histogram_b), 10)
def test_distance_function_different_bin(self): histogram_a = Histogram() histogram_b = Histogram() histogram_a.add(0, 10) histogram_b.add(7, 5) self.assertAlmostEqual(distance(histogram_a, histogram_b), math.sqrt(125), delta=0.01)
def test_histogram_normalization_of_zeros(self): histogram = Histogram() histogram.normalize() self.assertAlmostEqual(histogram.get(0), 0.0, delta=0.01)
def test_histogram_normalize_middle_elem(self): histogram = Histogram() histogram.add(0, 0.0) histogram.add(1, 1.0) histogram.add(2, 2.0) histogram.add(3, 3.0) histogram.add(4, 4.0) histogram.add(5, 5.0) histogram.add(6, 6.0) histogram.add(7, 7.0) histogram.normalize() self.assertAlmostEqual(histogram.get(4), 0.1429, delta=0.01)
def test_histogram_add_middle(self): histogram = Histogram() histogram.add(3, 9.5) self.assertEqual(histogram.get(3), 9.5)
def test_histogram_add_last(self): histogram = Histogram() histogram.add(7, -1.0) self.assertEqual(histogram.get(7), -1.0)
def test_histogram_add_first(self): histogram = Histogram() histogram.add(0, 4.32) self.assertEqual(histogram.get(0), 4.32)