21 |
generate_uniform_distribution, \ |
generate_uniform_distribution, \ |
22 |
generate_quantiles, \ |
generate_quantiles, \ |
23 |
calculate_quantiles, \ |
calculate_quantiles, \ |
24 |
GreyRamp, CustomRamp, FixedRamp |
grey_ramp, CustomRamp, FixedRamp |
25 |
from Thuban.Model.range import Range |
from Thuban.Model.range import Range |
26 |
from Thuban.Model.color import Color |
from Thuban.Model.color import Color |
27 |
|
|
47 |
|
|
48 |
self.doBoundsTest(clazz) |
self.doBoundsTest(clazz) |
49 |
|
|
50 |
def doBoundsTest(self, clazz, ramp = GreyRamp): |
def doBoundsTest(self, clazz, ramp = grey_ramp): |
51 |
|
|
52 |
# |
# |
53 |
# check that the properties are right (i.e. the first group |
# check that the properties are right (i.e. the first group |
54 |
# is all white, the last is all black). This assumes that |
# is all white, the last is all black). This assumes that |
55 |
# the GreyRamp, unless another is provided. |
# the grey_ramp, unless another is provided. |
56 |
# |
# |
57 |
if clazz.GetNumGroups() >= 1: |
if clazz.GetNumGroups() >= 1: |
58 |
groupF = clazz.GetGroup(0) |
groupF = clazz.GetGroup(0) |
69 |
|
|
70 |
eq = self.assertEquals |
eq = self.assertEquals |
71 |
gs = generate_singletons |
gs = generate_singletons |
72 |
ramp = GreyRamp |
ramp = grey_ramp |
73 |
|
|
74 |
_list = [1, 2, 3, 4] |
_list = [1, 2, 3, 4] |
75 |
cl = gs(_list, ramp) |
cl = gs(_list, ramp) |
101 |
|
|
102 |
eq = self.assertEquals |
eq = self.assertEquals |
103 |
gud = generate_uniform_distribution |
gud = generate_uniform_distribution |
104 |
ramp = GreyRamp |
ramp = grey_ramp |
105 |
|
|
106 |
cl = gud(0, 99, 10, ramp, True) |
cl = gud(0, 99, 10, ramp, True) |
107 |
self.doClassRangeTest(cl, ("[0;10[", "[10;20[", "[20;30[", "[30;40[", |
self.doClassRangeTest(cl, ("[0;10[", "[10;20[", "[20;30[", "[30;40[", |
132 |
|
|
133 |
gq = generate_quantiles |
gq = generate_quantiles |
134 |
|
|
135 |
ramp = GreyRamp |
ramp = grey_ramp |
136 |
|
|
137 |
adj, cl = gq([1, 2, 3, 4], [.25, .5, .75, 1.0], ramp, Range("[1;4]")) |
adj, cl = gq([1, 2, 3, 4], [.25, .5, .75, 1.0], ramp, Range("[1;4]")) |
138 |
self.failIf(adj) |
self.failIf(adj) |
317 |
self.assertEquals(half.GetFill(), Color(1, 0.5, 0.5)) |
self.assertEquals(half.GetFill(), Color(1, 0.5, 0.5)) |
318 |
self.assertEquals(half.GetLineColor(), Color(0, 0.5, 0)) |
self.assertEquals(half.GetLineColor(), Color(0, 0.5, 0)) |
319 |
|
|
320 |
|
|
321 |
class TestFixedRamp(unittest.TestCase): |
class TestFixedRamp(unittest.TestCase): |
322 |
|
|
323 |
def test(self): |
def test(self): |
324 |
|
"""Test FixedRamp""" |
325 |
eq = self.assertEquals |
eq = self.assertEquals |
326 |
|
|
327 |
for lineColor, lineWidth, fillColor in \ |
for lineColor, lineWidth, fillColor in \ |
330 |
(Color(1, 1, 1), 4, None), (Color(1, 1, 1), None, Color(0, 1, 0)), |
(Color(1, 1, 1), 4, None), (Color(1, 1, 1), None, Color(0, 1, 0)), |
331 |
(None, 4, Color(0, 1, 0)), (Color(1, 1, 1), 4, Color(0, 1, 0))]: |
(None, 4, Color(0, 1, 0)), (Color(1, 1, 1), 4, Color(0, 1, 0))]: |
332 |
|
|
333 |
framp = FixedRamp(GreyRamp, (lineColor, lineWidth, fillColor)) |
framp = FixedRamp(grey_ramp, (lineColor, lineWidth, fillColor)) |
334 |
|
|
335 |
for i in [0.0, 0.2, 0.4, 0.6, 0.8, 1.0]: |
for i in [0.0, 0.2, 0.4, 0.6, 0.8, 1.0]: |
336 |
props = framp.GetProperties(i) |
props = framp.GetProperties(i) |
337 |
if lineColor: eq(props.GetLineColor(), lineColor) |
grey = Color(1 - i, 1 - i, 1 - i) |
338 |
if lineWidth: eq(props.GetLineWidth(), lineWidth) |
if lineColor is not None: |
339 |
if fillColor: eq(props.GetFill(), fillColor) |
eq(props.GetLineColor(), lineColor) |
340 |
|
else: |
341 |
|
eq(props.GetLineColor(), grey) |
342 |
|
if lineWidth is not None: |
343 |
|
eq(props.GetLineWidth(), lineWidth) |
344 |
|
if fillColor is not None: |
345 |
|
eq(props.GetFill(), fillColor) |
346 |
|
else: |
347 |
|
eq(props.GetFill(), grey) |
348 |
|
|
349 |
if __name__ == "__main__": |
if __name__ == "__main__": |
350 |
unittest.main() |
unittest.main() |