Mercurial > hg > numerics
diff tests/test_histogram.py @ 73:8e93d7357c6b
working histogram w tests
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sat, 28 Feb 2015 21:28:17 -0800 |
parents | 07362c531a7e |
children |
line wrap: on
line diff
--- a/tests/test_histogram.py Sat Feb 28 17:05:04 2015 -0800 +++ b/tests/test_histogram.py Sat Feb 28 21:28:17 2015 -0800 @@ -19,12 +19,49 @@ """basic histogram test""" # make some test data - data = [0,0,1,1,2,3,4,5,6,7,8,8,8] + data = [0.1, 0.1, + 1.1, 1.2, + 2, + 3, + 5, + 6, + 7, + 8, 8, 8, 8.1] bins = range(0,10) # make a histogram h = Histogram(bins) + # add some data to it + h.add(*data) + + # now make sure what we did works + + # First, let's check the bins + expected_bins = [(0,1), + (1,2), + (2,3), + (3,4), + (4,5), + (5,6), + (6,7), + (7,8), + (8,9)] + self.assertEqual(h.keys(), expected_bins) + + # now let's check the values + values = h() + self.assertEqual(values[(0,1)], 2) + self.assertEqual(values[(1,2)], 2) + self.assertEqual(values[(2,3)], 1) + self.assertEqual(values[(3,4)], 1) + self.assertEqual(values[(4,5)], 0) + self.assertEqual(values[(5,6)], 1) + self.assertEqual(values[(6,7)], 1) + self.assertEqual(values[(7,8)], 1) + self.assertEqual(values[(8,9)], 4) + + if __name__ == '__main__': unittest.main()