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 testHAssignment() {
41          assertEquals(1.0, color.H, 0.0);
42      }
43  
44      @Test
45      public void testSAssignment() {
46          assertEquals(2.0, color.S, 0.0);
47      }
48  
49      @Test
50      public void testLAssignment() {
51          assertEquals(3.0, color.L, 0.0);
52      }
53  
54      @Test
55      public void testToString() {
56          assertEquals("{H: 1.0, S: 2.0, L: 3.0}", color.toString());
57      }
58  
59      @Test
60      public void testHashCodeAndEquals() {
61          assertTrue(color.equals(colorCopy) && colorCopy.equals(color));
62          assertThat(color.hashCode(), is(colorCopy.hashCode()));
63      }
64  
65      @Test
66      public void testCreatesColorHslOne() {
67          final ColorHsl colorHsl = ColorHsl.BLUE;
68          final ColorHsl colorHslTwo = new ColorHsl(100.0, 667.226, (-687.72287636));
69  
70          assertEquals(667.226, colorHslTwo.S, 0.01);
71          assertEquals(100.0, colorHslTwo.H, 0.01);
72          assertEquals((-687.72287636), colorHslTwo.L, 0.01);
73          assertNotEquals(colorHsl, colorHslTwo);
74      }
75  
76  }