@@ -28,6 +28,52 @@ def test_simple_linear():
2828 linear ._repr_html_ ()
2929
3030
31+ black = "#000000ff"
32+ red = "#ff0000ff"
33+ green = "#00ff00ff"
34+ blue = "#0000ffff"
35+
36+
37+ def test_step_color_indexing ():
38+ step = cm .StepColormap (colors = ["black" , "red" , "lime" , "blue" ], index = [1 , 2 , 4 , 5 ])
39+ assert step (0.99 ) == black
40+ assert step (1 ) == black
41+ assert step (1.01 ) == black
42+ assert step (1.99 ) == black
43+ assert step (2 ) == red
44+ assert step (2.01 ) == red
45+ assert step (3.99 ) == red
46+ assert step (4 ) == green
47+ assert step (4.01 ) == green
48+ assert step (4.99 ) == green
49+ assert step (5 ) == blue
50+ assert step (5.01 ) == blue
51+
52+
53+ def test_step_color_indexing_larger_index ():
54+ # add an upper bound to the last color, which doesn't do much but shouldn't fail
55+ step = cm .StepColormap (
56+ colors = ["black" , "red" , "lime" , "blue" ],
57+ index = [1 , 2 , 4 , 5 , 10 ],
58+ )
59+ assert step (4.99 ) == green
60+ assert step (5 ) == blue
61+ assert step (10 ) == blue
62+ assert step (20 ) == blue
63+
64+
65+ def test_linear_color_indexing ():
66+ linear = cm .LinearColormap (
67+ colors = ["black" , "red" , "lime" , "blue" ],
68+ index = [1 , 2 , 4 , 5 ],
69+ )
70+ assert linear (1 ) == black
71+ assert linear (2 ) == red
72+ assert linear (4 ) == green
73+ assert linear (5 ) == blue
74+ assert linear (3 ) == "#7f7f00ff"
75+
76+
3177def test_linear_to_step ():
3278 some_list = [30.6 , 50 , 51 , 52 , 53 , 54 , 55 , 60 , 70 , 100 ]
3379 lc = cm .linear .YlOrRd_06
0 commit comments