--- trunk/thuban/test/test_classgen.py 2003/07/02 12:59:34 1362 +++ trunk/thuban/test/test_classgen.py 2003/07/18 10:18:56 1450 @@ -21,11 +21,11 @@ generate_uniform_distribution, \ generate_quantiles, \ calculate_quantiles, \ - GreyRamp + GreyRamp, 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): @@ -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(GreyRamp, (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()