21 |
generate_uniform_distribution, \ |
generate_uniform_distribution, \ |
22 |
generate_quantiles, \ |
generate_quantiles, \ |
23 |
calculate_quantiles, \ |
calculate_quantiles, \ |
24 |
GreyRamp |
GreyRamp, CustomRamp |
25 |
from Thuban.Model.range import Range |
from Thuban.Model.range import Range |
26 |
|
from Thuban.Model.color import Color |
27 |
|
|
28 |
from Thuban.Model.classification import ClassGroupRange |
from Thuban.Model.classification import ClassGroupRange, ClassGroupProperties |
29 |
|
|
30 |
class ClassGenTest(unittest.TestCase): |
class ClassGenTest(unittest.TestCase): |
31 |
|
|
32 |
def doClassRangeTest(self, clazz, ranges): |
def doClassRangeTest(self, clazz, ranges): |
33 |
self.assertEquals(clazz.GetNumGroups(), len(ranges)) |
self.assertEquals(clazz.GetNumGroups(), len(ranges)) |
34 |
for i in range(len(ranges)): |
for i in range(clazz.GetNumGroups()): |
35 |
group = clazz.GetGroup(i) |
group = clazz.GetGroup(i) |
36 |
r1 = str(Range(ranges[i])) |
r1 = str(Range(ranges[i])) |
37 |
r2 = group.GetRange() |
r2 = group.GetRange() |
38 |
self.assertEquals(r1, r2) |
self.assertEquals(r1, r2) |
39 |
|
|
40 |
|
self.doBoundsTest(clazz) |
41 |
|
|
42 |
def doClassSingleTest(self, clazz, _list): |
def doClassSingleTest(self, clazz, _list): |
43 |
self.assertEquals(clazz.GetNumGroups(), len(_list)) |
self.assertEquals(clazz.GetNumGroups(), len(_list)) |
44 |
for i in range(len(_list)): |
for i in range(clazz.GetNumGroups()): |
45 |
group = clazz.GetGroup(i) |
group = clazz.GetGroup(i) |
46 |
self.assertEquals(group.GetValue(), _list[i]) |
self.assertEquals(group.GetValue(), _list[i]) |
47 |
|
|
48 |
|
self.doBoundsTest(clazz) |
49 |
|
|
50 |
|
def doBoundsTest(self, clazz, ramp = GreyRamp): |
51 |
|
|
52 |
|
# |
53 |
|
# check that the properties are right (i.e. the first group |
54 |
|
# is all white, the last is all black). This assumes that |
55 |
|
# the GreyRamp, unless another is provided. |
56 |
|
# |
57 |
|
if clazz.GetNumGroups() >= 1: |
58 |
|
groupF = clazz.GetGroup(0) |
59 |
|
first = ramp.GetProperties(0) |
60 |
|
self.assertEquals(groupF.GetProperties(), first) |
61 |
|
|
62 |
|
if clazz.GetNumGroups() >= 2: |
63 |
|
groupL = clazz.GetGroup(clazz.GetNumGroups() - 1) |
64 |
|
last = ramp.GetProperties(1) |
65 |
|
self.assertEquals(groupL.GetProperties(), last) |
66 |
|
|
67 |
def test_generate_singletons(self): |
def test_generate_singletons(self): |
68 |
"""Test generate_singletons""" |
"""Test generate_singletons""" |
299 |
[.12, .24, .36, .50, .62, .76, .88, 1.0], Range("[1;5]")) |
[.12, .24, .36, .50, .62, .76, .88, 1.0], Range("[1;5]")) |
300 |
eq(result, (1, 0, 24, [(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)])) |
301 |
|
|
302 |
|
|
303 |
|
class TestCustomRamp(unittest.TestCase): |
304 |
|
|
305 |
|
def test_color_interpolation(self): |
306 |
|
"""Test CustomRamp color interpolation""" |
307 |
|
start = ClassGroupProperties() |
308 |
|
start.SetFill(Color(1, 1, 1)) |
309 |
|
start.SetLineColor(Color(0, 0, 0)) |
310 |
|
|
311 |
|
end = ClassGroupProperties() |
312 |
|
end.SetFill(Color(1, 0, 0)) |
313 |
|
end.SetLineColor(Color(0, 1, 0)) |
314 |
|
|
315 |
|
ramp = CustomRamp(start, end) |
316 |
|
half = ramp.GetProperties(0.5) |
317 |
|
self.assertEquals(half.GetFill(), Color(1, 0.5, 0.5)) |
318 |
|
self.assertEquals(half.GetLineColor(), Color(0, 0.5, 0)) |
319 |
|
|
320 |
|
|
321 |
if __name__ == "__main__": |
if __name__ == "__main__": |
322 |
unittest.main() |
unittest.main() |
323 |
|
|