Mercurial > hg > numerics
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 72:06094870fdd7 | 73:8e93d7357c6b |
|---|---|
| 17 | 17 |
| 18 def test_histogram(self): | 18 def test_histogram(self): |
| 19 """basic histogram test""" | 19 """basic histogram test""" |
| 20 | 20 |
| 21 # make some test data | 21 # make some test data |
| 22 data = [0,0,1,1,2,3,4,5,6,7,8,8,8] | 22 data = [0.1, 0.1, |
| 23 1.1, 1.2, | |
| 24 2, | |
| 25 3, | |
| 26 5, | |
| 27 6, | |
| 28 7, | |
| 29 8, 8, 8, 8.1] | |
| 23 bins = range(0,10) | 30 bins = range(0,10) |
| 24 | 31 |
| 25 # make a histogram | 32 # make a histogram |
| 26 h = Histogram(bins) | 33 h = Histogram(bins) |
| 27 | 34 |
| 35 # add some data to it | |
| 36 h.add(*data) | |
| 37 | |
| 38 # now make sure what we did works | |
| 39 | |
| 40 # First, let's check the bins | |
| 41 expected_bins = [(0,1), | |
| 42 (1,2), | |
| 43 (2,3), | |
| 44 (3,4), | |
| 45 (4,5), | |
| 46 (5,6), | |
| 47 (6,7), | |
| 48 (7,8), | |
| 49 (8,9)] | |
| 50 self.assertEqual(h.keys(), expected_bins) | |
| 51 | |
| 52 # now let's check the values | |
| 53 values = h() | |
| 54 self.assertEqual(values[(0,1)], 2) | |
| 55 self.assertEqual(values[(1,2)], 2) | |
| 56 self.assertEqual(values[(2,3)], 1) | |
| 57 self.assertEqual(values[(3,4)], 1) | |
| 58 self.assertEqual(values[(4,5)], 0) | |
| 59 self.assertEqual(values[(5,6)], 1) | |
| 60 self.assertEqual(values[(6,7)], 1) | |
| 61 self.assertEqual(values[(7,8)], 1) | |
| 62 self.assertEqual(values[(8,9)], 4) | |
| 63 | |
| 64 | |
| 28 if __name__ == '__main__': | 65 if __name__ == '__main__': |
| 29 unittest.main() | 66 unittest.main() |
| 30 | 67 |
