/[thuban]/trunk/thuban/test/test_classgen.py
ViewVC logotype

Annotation of /trunk/thuban/test/test_classgen.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1110 - (hide annotations)
Fri May 30 09:46:57 2003 UTC (21 years, 9 months ago) by bh
File MIME type: text/x-python
File size: 3387 byte(s)
(ClassGenTest.test): Update to reflect the
changes in classgen.py

1 bh 1110 # Copyright (c) 2002, 2003 by Intevation GmbH
2 jonathan 890 # Authors:
3     # Bernhard Herzog <[email protected]>
4     #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with Thuban for details.
7    
8     """
9     Test the Menu
10     """
11    
12     __version__ = "$Revision$"
13    
14     import unittest
15    
16     import support
17     support.initthuban()
18    
19 bh 1110 from Thuban.Model.classgen import CalculateQuantiles
20 jonathan 890 from Thuban.Model.range import Range
21    
22     class ClassGenTest(unittest.TestCase):
23    
24     def test(self):
25     """Test ClassGenerator methods"""
26    
27     eq = self.assertEquals
28    
29     #
30     # Test CalculateQuantiles
31     #
32    
33 bh 1110 cq = CalculateQuantiles
34 jonathan 890
35     result = cq([1, 2, 3, 4], [.25, .5, .75, 1.0], Range("[1;4]"))
36 jonathan 896 eq(result, (0, 0, 3, [(0, .25), (1, .5), (2, .75), (3, 1.0)]))
37 jonathan 890
38     result = cq(range(0, 100), [.25, .5, .75, 1.0], Range("[0;100]"))
39 jonathan 896 eq(result, (0, 0, 99, [(24, .25), (49, .5), (74, .75), (99, 1.0)]))
40 jonathan 890
41     result = cq(range(0, 100), [.33, .66, 1.0], Range("[0;100]"))
42 jonathan 896 eq(result, (0, 0, 99, [(32, .33), (65, .66), (99, 1.0)]))
43 jonathan 890
44     # negative input
45     result = cq(range(-100, 100), [.33, .66, 1.0], Range("[-100;100]"))
46 jonathan 896 eq(result, (0, 0, 199, [(65, .33), (131, .66), (199, 1.0)]))
47 jonathan 890
48     # unequal percentiles
49     result = cq(range(0, 100), [.25, .66, .8, 1.0], Range("[0;100]"))
50 jonathan 896 eq(result, (0, 0, 99, [(24, .25), (65, .66), (79, .8), (99, 1.0)]))
51 jonathan 890
52     # input all the same
53     result = cq([1, 1, 1, 1], [.25, .5, .75, 1.0], Range("[1;4]"))
54 jonathan 896 eq(result, (1, 0, 3, [(3, 1.0)]))
55 jonathan 890
56     # empty input
57     result = cq([], [.25, .5, .75, 1.0], Range("[1;4]"))
58 jonathan 896 eq(result, None)
59 jonathan 890
60     # empty range
61     result = cq([1, 2, 3, 4], [.25, .5, .75, 1.0], Range("]0;1["))
62 jonathan 896 eq(result, None)
63 jonathan 890
64     # empty percentiles
65     result = cq([1, 2, 3, 4], [], Range("]0;1["))
66 jonathan 896 eq(result, None)
67 jonathan 890
68     # single percentile
69     result = cq([1, 2, 3, 4], [.5], Range("[0;4]"))
70 jonathan 896 eq(result, (0, 0, 3, [(1, .5)]))
71 jonathan 890
72     # more percentiles than input
73     result = cq([1], [.5, 1.0], Range("[0;4]"))
74 jonathan 896 eq(result, (1, 0, 0, [(0, 1.0)]))
75 jonathan 890
76     result = cq([1], [.1, .2, .3, .4, .5, .6, .7, .8, .9, 1.0], Range("[0;4]"))
77 jonathan 896 eq(result, (1, 0, 0, [(0, 1.0)]))
78 jonathan 890
79     # range smaller than the input
80     result = cq([1, 2, 3, 4], [.5, 1.0], Range("[2;3]"))
81 jonathan 896 eq(result, (0, 1, 2, [(1, .5), (2, 1.0)]))
82 jonathan 890
83     # range outside the input
84     result = cq([5, 6, 7, 8], [.5, 1.0], Range("[2;3]"))
85 jonathan 896 eq(result, None)
86 jonathan 890
87     result = cq([1, 1, 1, 1, 1, 1], [.25, .5, .75, 1.0], Range("[1;4]"))
88 jonathan 896 eq(result, (1, 0, 5, [(5, 1.0)]))
89 jonathan 890
90     result = cq([1, 1, 1, 1, 1, 2, 3], [.25, .5, .75, 1.0], Range("[1;4]"))
91 jonathan 896 eq(result, (1, 0, 6,
92     [(4, 0.7142857142857143), # the algorithm generated
93     (5, 0.8571428571428571), # these values, but they are
94     (6, 1.0)])) # right.
95 jonathan 890
96     # adjusted quantiles
97     result = cq([1, 1, 1, 1, 1,
98     2, 2, 2, 2, 2,
99     3, 3, 3, 3, 3,
100     4, 4, 4, 4, 4,
101     5, 5, 5, 5, 5],
102     [.12, .24, .36, .50, .62, .76, .88, 1.0], Range("[1;5]"))
103 jonathan 896 eq(result, (1, 0, 24, [(4, .2), (9, .4), (14, .6), (19, .8), (24, 1.0)]))
104 jonathan 890
105     if __name__ == "__main__":
106     unittest.main()
107    

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26