annotate tests/test_histogram.py @ 130:d3ed3a0092d1

remove unused import
author Jeff Hammel <k0scist@gmail.com>
date Mon, 16 Mar 2015 21:14:48 -0700
parents 8e93d7357c6b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
68
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 """
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 unit tests for histograms
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6 """
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 import os
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 import sys
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 import unittest
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 from numerics.histogram import Histogram
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 # globals
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 here = os.path.dirname(os.path.abspath(__file__))
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 class HistogramUnitTest(unittest.TestCase):
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 def test_histogram(self):
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 """basic histogram test"""
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 # make some test data
73
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
22 data = [0.1, 0.1,
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
23 1.1, 1.2,
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
24 2,
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
25 3,
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
26 5,
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
27 6,
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
28 7,
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
29 8, 8, 8, 8.1]
68
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
30 bins = range(0,10)
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
32 # make a histogram
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
33 h = Histogram(bins)
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
34
73
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
35 # add some data to it
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
36 h.add(*data)
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
37
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
38 # now make sure what we did works
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
39
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
40 # First, let's check the bins
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
41 expected_bins = [(0,1),
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
42 (1,2),
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
43 (2,3),
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
44 (3,4),
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
45 (4,5),
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
46 (5,6),
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
47 (6,7),
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
48 (7,8),
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
49 (8,9)]
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
50 self.assertEqual(h.keys(), expected_bins)
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
51
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
52 # now let's check the values
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
53 values = h()
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
54 self.assertEqual(values[(0,1)], 2)
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
55 self.assertEqual(values[(1,2)], 2)
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
56 self.assertEqual(values[(2,3)], 1)
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
57 self.assertEqual(values[(3,4)], 1)
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
58 self.assertEqual(values[(4,5)], 0)
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
59 self.assertEqual(values[(5,6)], 1)
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
60 self.assertEqual(values[(6,7)], 1)
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
61 self.assertEqual(values[(7,8)], 1)
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
62 self.assertEqual(values[(8,9)], 4)
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
63
8e93d7357c6b working histogram w tests
Jeff Hammel <k0scist@gmail.com>
parents: 68
diff changeset
64
68
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
65 if __name__ == '__main__':
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
66 unittest.main()
07362c531a7e stub histogram tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
67