--- trunk/thuban/test/test_classgen.py 2003/07/02 12:59:34 1362 +++ trunk/thuban/test/test_classgen.py 2003/07/30 15:43:41 1528 @@ -21,11 +21,11 @@ generate_uniform_distribution, \ generate_quantiles, \ calculate_quantiles, \ - GreyRamp + grey_ramp, CustomRamp, FixedRamp from Thuban.Model.range import Range from Thuban.Model.color import Color -from Thuban.Model.classification import ClassGroupRange +from Thuban.Model.classification import ClassGroupRange, ClassGroupProperties class ClassGenTest(unittest.TestCase): @@ -47,12 +47,12 @@ self.doBoundsTest(clazz) - def doBoundsTest(self, clazz, ramp = GreyRamp): + def doBoundsTest(self, clazz, ramp = grey_ramp): # # check that the properties are right (i.e. the first group # is all white, the last is all black). This assumes that - # the GreyRamp, unless another is provided. + # the grey_ramp, unless another is provided. # if clazz.GetNumGroups() >= 1: groupF = clazz.GetGroup(0) @@ -69,7 +69,7 @@ eq = self.assertEquals gs = generate_singletons - ramp = GreyRamp + ramp = grey_ramp _list = [1, 2, 3, 4] cl = gs(_list, ramp) @@ -101,7 +101,7 @@ eq = self.assertEquals gud = generate_uniform_distribution - ramp = GreyRamp + ramp = grey_ramp cl = gud(0, 99, 10, ramp, True) self.doClassRangeTest(cl, ("[0;10[", "[10;20[", "[20;30[", "[30;40[", @@ -132,7 +132,7 @@ gq = generate_quantiles - ramp = GreyRamp + ramp = grey_ramp adj, cl = gq([1, 2, 3, 4], [.25, .5, .75, 1.0], ramp, Range("[1;4]")) self.failIf(adj) @@ -299,6 +299,53 @@ [.12, .24, .36, .50, .62, .76, .88, 1.0], Range("[1;5]")) eq(result, (1, 0, 24, [(4, .2), (9, .4), (14, .6), (19, .8), (24, 1.0)])) + +class TestCustomRamp(unittest.TestCase): + + def test_color_interpolation(self): + """Test CustomRamp color interpolation""" + start = ClassGroupProperties() + start.SetFill(Color(1, 1, 1)) + start.SetLineColor(Color(0, 0, 0)) + + end = ClassGroupProperties() + end.SetFill(Color(1, 0, 0)) + end.SetLineColor(Color(0, 1, 0)) + + ramp = CustomRamp(start, end) + half = ramp.GetProperties(0.5) + self.assertEquals(half.GetFill(), Color(1, 0.5, 0.5)) + self.assertEquals(half.GetLineColor(), Color(0, 0.5, 0)) + + +class TestFixedRamp(unittest.TestCase): + + def test(self): + """Test FixedRamp""" + eq = self.assertEquals + + for lineColor, lineWidth, fillColor in \ + [(None, None, None), (Color(1, 1, 1), None, None), + (None, 4, None), (None, None, Color(0, 1, 0)), + (Color(1, 1, 1), 4, None), (Color(1, 1, 1), None, Color(0, 1, 0)), + (None, 4, Color(0, 1, 0)), (Color(1, 1, 1), 4, Color(0, 1, 0))]: + + framp = FixedRamp(grey_ramp, (lineColor, lineWidth, fillColor)) + + for i in [0.0, 0.2, 0.4, 0.6, 0.8, 1.0]: + props = framp.GetProperties(i) + grey = Color(1 - i, 1 - i, 1 - i) + if lineColor is not None: + eq(props.GetLineColor(), lineColor) + else: + eq(props.GetLineColor(), grey) + if lineWidth is not None: + eq(props.GetLineWidth(), lineWidth) + if fillColor is not None: + eq(props.GetFill(), fillColor) + else: + eq(props.GetFill(), grey) + if __name__ == "__main__": unittest.main()