/[thuban]/branches/WIP-pyshapelib-bramz/test/test_classgen.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/test/test_classgen.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 890 by jonathan, Fri May 9 18:08:31 2003 UTC revision 896 by jonathan, Mon May 12 11:21:14 2003 UTC
# Line 35  class ClassGenTest(unittest.TestCase): Line 35  class ClassGenTest(unittest.TestCase):
35          cq = cg.CalculateQuantiles          cq = cg.CalculateQuantiles
36    
37          result = cq([1, 2, 3, 4], [.25, .5, .75, 1.0], Range("[1;4]"))          result = cq([1, 2, 3, 4], [.25, .5, .75, 1.0], Range("[1;4]"))
38          eq(result, (0, [(0, .25), (1, .5), (2, .75), (3, 1.0)]))          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]"))          result = cq(range(0, 100), [.25, .5, .75, 1.0], Range("[0;100]"))
41          eq(result, (0, [(24, .25), (49, .5), (74, .75), (99, 1.0)]))          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]"))          result = cq(range(0, 100), [.33, .66, 1.0], Range("[0;100]"))
44          eq(result, (0, [(32, .33), (65, .66), (99, 1.0)]))          eq(result, (0, 0, 99, [(32, .33), (65, .66), (99, 1.0)]))
45    
46          # negative input          # negative input
47          result = cq(range(-100, 100), [.33, .66, 1.0], Range("[-100;100]"))          result = cq(range(-100, 100), [.33, .66, 1.0], Range("[-100;100]"))
48          eq(result, (0, [(65, .33), (131, .66), (199, 1.0)]))          eq(result, (0, 0, 199, [(65, .33), (131, .66), (199, 1.0)]))
49    
50          # unequal percentiles          # unequal percentiles
51          result = cq(range(0, 100), [.25, .66, .8, 1.0], Range("[0;100]"))          result = cq(range(0, 100), [.25, .66, .8, 1.0], Range("[0;100]"))
52          eq(result, (0, [(24, .25), (65, .66), (79, .8), (99, 1.0)]))          eq(result, (0, 0, 99, [(24, .25), (65, .66), (79, .8), (99, 1.0)]))
53    
54          # input all the same          # input all the same
55          result = cq([1, 1, 1, 1], [.25, .5, .75, 1.0], Range("[1;4]"))          result = cq([1, 1, 1, 1], [.25, .5, .75, 1.0], Range("[1;4]"))
56          eq(result, (0, [(3, 1.0)]))          eq(result, (1, 0, 3, [(3, 1.0)]))
57    
58          # empty input          # empty input
59          result = cq([], [.25, .5, .75, 1.0], Range("[1;4]"))          result = cq([], [.25, .5, .75, 1.0], Range("[1;4]"))
60          eq(result, (0, []))          eq(result, None)
61    
62          # empty range          # empty range
63          result = cq([1, 2, 3, 4], [.25, .5, .75, 1.0], Range("]0;1["))          result = cq([1, 2, 3, 4], [.25, .5, .75, 1.0], Range("]0;1["))
64          eq(result, (0, []))          eq(result, None)
65    
66          # empty percentiles          # empty percentiles
67          result = cq([1, 2, 3, 4], [], Range("]0;1["))          result = cq([1, 2, 3, 4], [], Range("]0;1["))
68          eq(result, (0, []))          eq(result, None)
69    
70          # single percentile          # single percentile
71          result = cq([1, 2, 3, 4], [.5], Range("[0;4]"))          result = cq([1, 2, 3, 4], [.5], Range("[0;4]"))
72          eq(result, (0, [(1, .5)]))          eq(result, (0, 0, 3, [(1, .5)]))
73    
74          # more percentiles than input          # more percentiles than input
75          result = cq([1], [.5, 1.0], Range("[0;4]"))          result = cq([1], [.5, 1.0], Range("[0;4]"))
76          eq(result, (1, [(0, 1.0)]))          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]"))          result = cq([1], [.1, .2, .3, .4, .5, .6, .7, .8, .9, 1.0], Range("[0;4]"))
79          eq(result, (1, [(0, 1.0)]))          eq(result, (1, 0, 0, [(0, 1.0)]))
80    
81          # range smaller than the input          # range smaller than the input
82          result = cq([1, 2, 3, 4], [.5, 1.0], Range("[2;3]"))          result = cq([1, 2, 3, 4], [.5, 1.0], Range("[2;3]"))
83          eq(result, (0, [(1, .5), (2, 1.0)]))          eq(result, (0, 1, 2, [(1, .5), (2, 1.0)]))
84    
85          # range outside the input          # range outside the input
86          result = cq([5, 6, 7, 8], [.5, 1.0], Range("[2;3]"))          result = cq([5, 6, 7, 8], [.5, 1.0], Range("[2;3]"))
87          eq(result, (0, []))          eq(result, None)
88    
89          result = cq([1, 1, 1, 1, 1, 1], [.25, .5, .75, 1.0], Range("[1;4]"))          result = cq([1, 1, 1, 1, 1, 1], [.25, .5, .75, 1.0], Range("[1;4]"))
90          eq(result, (1, [(5, 1.0)]))          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]"))          result = cq([1, 1, 1, 1, 1, 2, 3], [.25, .5, .75, 1.0], Range("[1;4]"))
93          eq(result, (1, [(4, 0.7142857142857143), # the algorithm generated          eq(result, (1, 0, 6,
94                          (5, 0.8571428571428571), # these values, but they are                 [(4, 0.7142857142857143), # the algorithm generated
95                          (6, 1.0)]))              # right.                  (5, 0.8571428571428571), # these values, but they are
96                    (6, 1.0)]))              # right.
97    
98          # adjusted quantiles          # adjusted quantiles
99          result = cq([1, 1, 1, 1, 1,          result = cq([1, 1, 1, 1, 1,
# Line 101  class ClassGenTest(unittest.TestCase): Line 102  class ClassGenTest(unittest.TestCase):
102                       4, 4, 4, 4, 4,                       4, 4, 4, 4, 4,
103                       5, 5, 5, 5, 5],                       5, 5, 5, 5, 5],
104                      [.12, .24, .36, .50, .62, .76, .88, 1.0], Range("[1;5]"))                      [.12, .24, .36, .50, .62, .76, .88, 1.0], Range("[1;5]"))
105          eq(result, (1, [(4, .2), (9, .4), (14, .6), (19, .8), (24, 1.0)]))          eq(result, (1, 0, 24, [(4, .2), (9, .4), (14, .6), (19, .8), (24, 1.0)]))
106    
107  if __name__ == "__main__":  if __name__ == "__main__":
108      unittest.main()      unittest.main()

Legend:
Removed from v.890  
changed lines
  Added in v.896

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26