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 ColorCmyTest {
29  
30      private ColorCmy color;
31      private ColorCmy colorCopy;
32  
33      @BeforeEach
34      public void setUp() {
35          color = new ColorCmy(1.0, 2.0, 3.0);
36          colorCopy = new ColorCmy(1.0, 2.0, 3.0);
37      }
38  
39      @Test
40      public void testCAssignment() {
41          assertEquals(1.0, color.c, 0.0);
42      }
43  
44      @Test
45      public void testCreatesColorCmy() {
46          final ColorCmy colorCmy = new ColorCmy(0.0, -1668.733868772, -1568.733868772);
47          final ColorCmy colorCmyTwo = ColorCmy.YELLOW;
48  
49          assertNotEquals(colorCmy, colorCmyTwo);
50          assertEquals(-1568.733868772, colorCmy.y, 0.01);
51          assertEquals(-1668.733868772, colorCmy.m, 0.01);
52      }
53  
54      @Test
55      public void testEquals() {
56          assertTrue(color.equals(colorCopy) && colorCopy.equals(color));
57          assertThat(color.hashCode(), is(colorCopy.hashCode()));
58      }
59  
60      @Test
61      public void testMAssignment() {
62          assertEquals(2.0, color.m, 0.0);
63      }
64  
65      @Test
66      public void testToString() {
67          assertEquals("{C: 1.0, M: 2.0, Y: 3.0}", color.toString());
68      }
69  
70      @Test
71      public void testYAssignment() {
72          assertEquals(3.0, color.y, 0.0);
73      }
74  
75  }