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.assertNotNull;
22 import static org.junit.jupiter.api.Assertions.assertNull;
23 import static org.junit.jupiter.api.Assertions.assertThrows;
24 import static org.junit.jupiter.api.Assertions.assertTrue;
25
26 import java.awt.Color;
27
28 import org.junit.jupiter.api.Test;
29
30
31
32
33 public class PaletteEntryForValueTest {
34
35 public PaletteEntryForValueTest() {
36 }
37
38 @Test
39 public void testFaultyConstructors() {
40 assertThrows(IllegalArgumentException.class, () -> new PaletteEntryForValue(0.0f, null), "Constructor failed to detect invalid color");
41 }
42
43
44
45
46 @Test
47 public void testGetARGB() {
48 final Color c0 = new Color(0xff0000ff);
49 PaletteEntryForValue instance = new PaletteEntryForValue(0.0f, c0);
50 int a0 = instance.getArgb(0.0f);
51 int a1 = instance.getArgb(0.5f);
52 final int a2 = instance.getArgb(Float.NaN);
53 assertEquals(0xff0000ff, a0, "Invalid value for target 0.0f");
54 assertEquals(0, a1, "Invalid value for target 0.5f");
55 assertEquals(0, a2, "Invalid value for target NaN");
56 instance = new PaletteEntryForValue(Float.NaN, c0);
57 a0 = instance.getArgb(0.0f);
58 a1 = instance.getArgb(Float.NaN);
59 assertEquals(0, a0, "Invalid value for target 0.0f");
60 assertEquals(0xff0000ff, a1, "Invalid value for target NaN");
61 }
62
63
64
65
66 @Test
67 public void testGetColor() {
68 final Color cTest = new Color(0xff0000ff);
69 PaletteEntryForValue instance = new PaletteEntryForValue(0.0f, cTest);
70 Color c0 = instance.getColor(0.0f);
71 final int a0 = c0.getRGB();
72 assertEquals(0xff0000ff, a0, "Invalid value for 0.0f");
73 c0 = instance.getColor(1f);
74 assertNull(c0, "Non-null return for invalid target 1.0f");
75 c0 = instance.getColor(Float.NaN);
76 assertNull(c0, "Non-null return for invalid target 1.0f");
77 instance = new PaletteEntryForValue(Float.NaN, cTest);
78 c0 = instance.getColor(Float.NaN);
79 assertNotNull(c0, "Invalid return for valid target Float.NaN");
80 c0 = instance.getColor(1.0f);
81 assertNull(c0, "Invalid return for invalid valid target 1.0f");
82
83 }
84
85
86
87
88 @Test
89 public void testIsCovered() {
90 final Color c0 = new Color(0xff0000ff);
91 PaletteEntryForValue instance = new PaletteEntryForValue(0.0f, c0);
92 assertTrue(instance.isCovered(0.0f), "Zero value must be covered");
93 assertFalse(instance.isCovered(1.0f), "Value 1.0 must not be covered");
94 instance = new PaletteEntryForValue(Float.NaN, c0);
95 assertTrue(instance.isCovered(Float.NaN), "NaN value must be covered");
96 assertFalse(instance.isCovered(1.0f), "Value 1.0 must not be covered");
97
98 }
99 }