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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 896 - (show 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 # 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 eq(result, (0, 0, 3, [(0, .25), (1, .5), (2, .75), (3, 1.0)]))
39
40 result = cq(range(0, 100), [.25, .5, .75, 1.0], Range("[0;100]"))
41 eq(result, (0, 0, 99, [(24, .25), (49, .5), (74, .75), (99, 1.0)]))
42
43 result = cq(range(0, 100), [.33, .66, 1.0], Range("[0;100]"))
44 eq(result, (0, 0, 99, [(32, .33), (65, .66), (99, 1.0)]))
45
46 # negative input
47 result = cq(range(-100, 100), [.33, .66, 1.0], Range("[-100;100]"))
48 eq(result, (0, 0, 199, [(65, .33), (131, .66), (199, 1.0)]))
49
50 # unequal percentiles
51 result = cq(range(0, 100), [.25, .66, .8, 1.0], Range("[0;100]"))
52 eq(result, (0, 0, 99, [(24, .25), (65, .66), (79, .8), (99, 1.0)]))
53
54 # input all the same
55 result = cq([1, 1, 1, 1], [.25, .5, .75, 1.0], Range("[1;4]"))
56 eq(result, (1, 0, 3, [(3, 1.0)]))
57
58 # empty input
59 result = cq([], [.25, .5, .75, 1.0], Range("[1;4]"))
60 eq(result, None)
61
62 # empty range
63 result = cq([1, 2, 3, 4], [.25, .5, .75, 1.0], Range("]0;1["))
64 eq(result, None)
65
66 # empty percentiles
67 result = cq([1, 2, 3, 4], [], Range("]0;1["))
68 eq(result, None)
69
70 # single percentile
71 result = cq([1, 2, 3, 4], [.5], Range("[0;4]"))
72 eq(result, (0, 0, 3, [(1, .5)]))
73
74 # more percentiles than input
75 result = cq([1], [.5, 1.0], Range("[0;4]"))
76 eq(result, (1, 0, 0, [(0, 1.0)]))
77
78 result = cq([1], [.1, .2, .3, .4, .5, .6, .7, .8, .9, 1.0], Range("[0;4]"))
79 eq(result, (1, 0, 0, [(0, 1.0)]))
80
81 # range smaller than the input
82 result = cq([1, 2, 3, 4], [.5, 1.0], Range("[2;3]"))
83 eq(result, (0, 1, 2, [(1, .5), (2, 1.0)]))
84
85 # range outside the input
86 result = cq([5, 6, 7, 8], [.5, 1.0], Range("[2;3]"))
87 eq(result, None)
88
89 result = cq([1, 1, 1, 1, 1, 1], [.25, .5, .75, 1.0], Range("[1;4]"))
90 eq(result, (1, 0, 5, [(5, 1.0)]))
91
92 result = cq([1, 1, 1, 1, 1, 2, 3], [.25, .5, .75, 1.0], Range("[1;4]"))
93 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
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 eq(result, (1, 0, 24, [(4, .2), (9, .4), (14, .6), (19, .8), (24, 1.0)]))
106
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