/[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 896 - (hide annotations)
Mon May 12 11:21:14 2003 UTC (21 years, 9 months ago) by jonathan
File MIME type: text/x-python
File size: 3411 byte(s)
Modified Quantile tests to use the new return values.

1 jonathan 890 # Copyright (c) 2002 by Intevation GmbH
2     # 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     from Thuban.Model.classgen import ClassGenerator
20     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     cg = ClassGenerator()
30    
31     #
32     # Test CalculateQuantiles
33     #
34    
35     cq = cg.CalculateQuantiles
36    
37     result = cq([1, 2, 3, 4], [.25, .5, .75, 1.0], Range("[1;4]"))
38 jonathan 896 eq(result, (0, 0, 3, [(0, .25), (1, .5), (2, .75), (3, 1.0)]))
39 jonathan 890
40     result = cq(range(0, 100), [.25, .5, .75, 1.0], Range("[0;100]"))
41 jonathan 896 eq(result, (0, 0, 99, [(24, .25), (49, .5), (74, .75), (99, 1.0)]))
42 jonathan 890
43     result = cq(range(0, 100), [.33, .66, 1.0], Range("[0;100]"))
44 jonathan 896 eq(result, (0, 0, 99, [(32, .33), (65, .66), (99, 1.0)]))
45 jonathan 890
46     # negative input
47     result = cq(range(-100, 100), [.33, .66, 1.0], Range("[-100;100]"))
48 jonathan 896 eq(result, (0, 0, 199, [(65, .33), (131, .66), (199, 1.0)]))
49 jonathan 890
50     # unequal percentiles
51     result = cq(range(0, 100), [.25, .66, .8, 1.0], Range("[0;100]"))
52 jonathan 896 eq(result, (0, 0, 99, [(24, .25), (65, .66), (79, .8), (99, 1.0)]))
53 jonathan 890
54     # input all the same
55     result = cq([1, 1, 1, 1], [.25, .5, .75, 1.0], Range("[1;4]"))
56 jonathan 896 eq(result, (1, 0, 3, [(3, 1.0)]))
57 jonathan 890
58     # empty input
59     result = cq([], [.25, .5, .75, 1.0], Range("[1;4]"))
60 jonathan 896 eq(result, None)
61 jonathan 890
62     # empty range
63     result = cq([1, 2, 3, 4], [.25, .5, .75, 1.0], Range("]0;1["))
64 jonathan 896 eq(result, None)
65 jonathan 890
66     # empty percentiles
67     result = cq([1, 2, 3, 4], [], Range("]0;1["))
68 jonathan 896 eq(result, None)
69 jonathan 890
70     # single percentile
71     result = cq([1, 2, 3, 4], [.5], Range("[0;4]"))
72 jonathan 896 eq(result, (0, 0, 3, [(1, .5)]))
73 jonathan 890
74     # more percentiles than input
75     result = cq([1], [.5, 1.0], Range("[0;4]"))
76 jonathan 896 eq(result, (1, 0, 0, [(0, 1.0)]))
77 jonathan 890
78     result = cq([1], [.1, .2, .3, .4, .5, .6, .7, .8, .9, 1.0], Range("[0;4]"))
79 jonathan 896 eq(result, (1, 0, 0, [(0, 1.0)]))
80 jonathan 890
81     # range smaller than the input
82     result = cq([1, 2, 3, 4], [.5, 1.0], Range("[2;3]"))
83 jonathan 896 eq(result, (0, 1, 2, [(1, .5), (2, 1.0)]))
84 jonathan 890
85     # range outside the input
86     result = cq([5, 6, 7, 8], [.5, 1.0], Range("[2;3]"))
87 jonathan 896 eq(result, None)
88 jonathan 890
89     result = cq([1, 1, 1, 1, 1, 1], [.25, .5, .75, 1.0], Range("[1;4]"))
90 jonathan 896 eq(result, (1, 0, 5, [(5, 1.0)]))
91 jonathan 890
92     result = cq([1, 1, 1, 1, 1, 2, 3], [.25, .5, .75, 1.0], Range("[1;4]"))
93 jonathan 896 eq(result, (1, 0, 6,
94     [(4, 0.7142857142857143), # the algorithm generated
95     (5, 0.8571428571428571), # these values, but they are
96     (6, 1.0)])) # right.
97 jonathan 890
98     # adjusted quantiles
99     result = cq([1, 1, 1, 1, 1,
100     2, 2, 2, 2, 2,
101     3, 3, 3, 3, 3,
102     4, 4, 4, 4, 4,
103     5, 5, 5, 5, 5],
104     [.12, .24, .36, .50, .62, .76, .88, 1.0], Range("[1;5]"))
105 jonathan 896 eq(result, (1, 0, 24, [(4, .2), (9, .4), (14, .6), (19, .8), (24, 1.0)]))
106 jonathan 890
107     if __name__ == "__main__":
108     unittest.main()
109    

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26