View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.imaging.color;
18  
19  import static org.hamcrest.CoreMatchers.is;
20  import static org.hamcrest.MatcherAssert.assertThat;
21  import static org.junit.jupiter.api.Assertions.assertEquals;
22  import static org.junit.jupiter.api.Assertions.assertNotEquals;
23  import static org.junit.jupiter.api.Assertions.assertTrue;
24  
25  import org.junit.jupiter.api.BeforeEach;
26  import org.junit.jupiter.api.Test;
27  
28  public class ColorHslTest {
29  
30      private ColorHsl color;
31      private ColorHsl colorCopy;
32  
33      @BeforeEach
34      public void setUp() {
35          color = new ColorHsl(1.0, 2.0, 3.0);
36          colorCopy = new ColorHsl(1.0, 2.0, 3.0);
37      }
38  
39      @Test
40      public void testCreatesColorHslOne() {
41          final ColorHsl colorHsl = ColorHsl.BLUE;
42          final ColorHsl colorHslTwo = new ColorHsl(100.0, 667.226, -687.72287636);
43  
44          assertEquals(667.226, colorHslTwo.s, 0.01);
45          assertEquals(100.0, colorHslTwo.h, 0.01);
46          assertEquals(-687.72287636, colorHslTwo.l, 0.01);
47          assertNotEquals(colorHsl, colorHslTwo);
48      }
49  
50      @Test
51      public void testHashCodeAndEquals() {
52          assertTrue(color.equals(colorCopy) && colorCopy.equals(color));
53          assertThat(color.hashCode(), is(colorCopy.hashCode()));
54      }
55  
56      @Test
57      public void testHAssignment() {
58          assertEquals(1.0, color.h, 0.0);
59      }
60  
61      @Test
62      public void testLAssignment() {
63          assertEquals(3.0, color.l, 0.0);
64      }
65  
66      @Test
67      public void testSAssignment() {
68          assertEquals(2.0, color.s, 0.0);
69      }
70  
71      @Test
72      public void testToString() {
73          assertEquals("{H: 1.0, S: 2.0, L: 3.0}", color.toString());
74      }
75  
76  }