1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.formats.tiff.photometricinterpreters.floatingpoint;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertFalse;
21 import static org.junit.jupiter.api.Assertions.assertThrows;
22 import static org.junit.jupiter.api.Assertions.assertTrue;
23
24 import java.awt.Color;
25
26 import org.junit.jupiter.api.Test;
27
28
29
30
31 public class PaletteEntryForRangeTest {
32
33 public PaletteEntryForRangeTest() {
34 }
35
36
37
38
39 @Test
40 public void testCoversSingleEntry() {
41 final Color c0 = new Color(0xff0000ff);
42 final Color c1 = new Color(0xff00ff00);
43 final PaletteEntryForRange instance = new PaletteEntryForRange(0.0f, 1.0f, c0, c1);
44 assertFalse(instance.coversSingleEntry());
45 }
46
47 @Test
48 public void testFaultyConstructors() {
49 final Color c0 = new Color(0xff0000ff);
50 final Color c1 = new Color(0xff00ff00);
51
52
53 assertThrows(IllegalArgumentException.class, () -> new PaletteEntryForRange(0.0f, 0.0f, c0, c1), "Constructor failed to detect invalid range");
54
55 assertThrows(IllegalArgumentException.class, () -> new PaletteEntryForRange(0.0f, 1.0f, null, c1), "Constructor failed to detect null color");
56
57 assertThrows(IllegalArgumentException.class, () -> new PaletteEntryForRange(0.0f, 1.0f, c0, null), "Constructor failed to detect invalid color");
58
59
60 assertThrows(IllegalArgumentException.class, () -> new PaletteEntryForRange(0.0f, 0.0f, c0), "Constructor failed to detect invalid range");
61
62 assertThrows(IllegalArgumentException.class, () -> new PaletteEntryForRange(0.0f, 1.0f, null), "Constructor failed to detect null color");
63 }
64
65
66
67
68 @Test
69 public void testGetARGB() {
70 final Color c0 = new Color(0xff0000ff);
71 final Color c1 = new Color(0xff00ff00);
72 final PaletteEntryForRange instance = new PaletteEntryForRange(0.0f, 1.0f, c0, c1);
73 final int a0 = instance.getArgb(0.0f);
74 final int a1 = instance.getArgb(0.5f);
75 assertEquals(0xff0000ff, a0, "Invalid value for 0.0f");
76 assertEquals(0xff008080, a1, "Invalid interpolated values");
77 }
78
79
80
81
82 @Test
83 public void testGetColor() {
84 Color c0 = new Color(0xff0000ff);
85 Color c1 = new Color(0xff00ff00);
86 final PaletteEntryForRange instance = new PaletteEntryForRange(0.0f, 1.0f, c0, c1);
87 c0 = instance.getColor(0.0f);
88 c1 = instance.getColor(0.5f);
89 final int a0 = c0.getRGB();
90 final int a1 = c1.getRGB();
91 assertEquals(0xff0000ff, a0, "Invalid value for 0.0f");
92 assertEquals(0xff008080, a1, "Invalid interpolated values");
93
94 }
95
96
97
98
99 @Test
100 public void testGetLowerBound() {
101 final Color c0 = new Color(0xff0000ff);
102 final Color c1 = new Color(0xff00ff00);
103 final PaletteEntryForRange instance = new PaletteEntryForRange(0.0f, 1.0f, c0, c1);
104 assertEquals(0.0f, instance.getLowerBound());
105 }
106
107
108
109
110 @Test
111 public void testGetUpperBound() {
112 final Color c0 = new Color(0xff0000ff);
113 final Color c1 = new Color(0xff00ff00);
114 final PaletteEntryForRange instance = new PaletteEntryForRange(0.0f, 1.0f, c0, c1);
115 assertEquals(1.0f, instance.getUpperBound());
116 }
117
118
119
120
121 @Test
122 public void testIsCovered() {
123 final Color c0 = new Color(0xff0000ff);
124 final Color c1 = new Color(0xff00ff00);
125 final PaletteEntryForRange instance = new PaletteEntryForRange(0.0f, 1.0f, c0, c1);
126 assertTrue(instance.isCovered(0.0f), "Zero value must be covered");
127 assertFalse(instance.isCovered(1.0f), "Value 1.0 must not be covered");
128 }
129 }