3bbcf27e696d6fec5ba09f7c93489de0eafd9ce5
[jalview.git] / test / jalview / util / ColorUtilsTest.java
1 package jalview.util;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNull;
5
6 import java.awt.Color;
7
8 import org.junit.Test;
9
10 public class ColorUtilsTest
11 {
12
13   Color paleColour = new Color(97, 203, 111); // pale green
14
15   Color midColour = new Color(135, 57, 41); // mid red
16
17   Color darkColour = new Color(11, 30, 50); // dark blue
18
19   @Test
20   public void testDarkerThan()
21   {
22     assertEquals("Wrong darker shade", new Color(32, 69, 37),
23             ColorUtils.darkerThan(paleColour));
24     assertEquals("Wrong darker shade", new Color(45, 18, 13),
25             ColorUtils.darkerThan(midColour));
26     assertEquals("Wrong darker shade", new Color(2, 9, 16),
27             ColorUtils.darkerThan(darkColour));
28     assertNull(ColorUtils.darkerThan(null));
29   }
30
31   @Test
32   public void testBrighterThan()
33   {
34     assertEquals("Wrong brighter shade", new Color(255, 255, 255), // white
35             ColorUtils.brighterThan(paleColour));
36     assertEquals("Wrong brighter shade", new Color(255, 164, 117),
37             ColorUtils.brighterThan(midColour));
38     assertEquals("Wrong brighter shade", new Color(30, 85, 144),
39             ColorUtils.brighterThan(darkColour));
40     assertNull(ColorUtils.brighterThan(null));
41   }
42
43   /**
44    * @see http://www.rtapo.com/notes/named_colors.html
45    */
46   @Test
47   public void testToTkCode()
48   {
49     assertEquals("#fffafa", ColorUtils.toTkCode(new Color(255, 250, 250))); // snow
50     assertEquals("#e6e6fa", ColorUtils.toTkCode(new Color(230, 230, 250))); // lavender
51     assertEquals("#dda0dd", ColorUtils.toTkCode(new Color(221, 160, 221))); // plum
52     assertEquals("#800080", ColorUtils.toTkCode(new Color(128, 0, 128))); // purple
53     assertEquals("#00ff00", ColorUtils.toTkCode(new Color(0, 255, 0))); // lime
54   }
55 }