]> git.basschouten.com Git - openhab-addons.git/blob
82060850794302bb6c15e764b267c2fe2e5c5603
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.avmfritz.internal.dto;
14
15 import static org.hamcrest.CoreMatchers.is;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.junit.jupiter.api.Assertions.assertTrue;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.core.library.types.PercentType;
22
23 /**
24  * Tests for {@link ColorControlModel} methods.
25  *
26  * @author Christoph Weitkamp - Initial contribution
27  */
28 @NonNullByDefault
29 class ColorControlModelTest {
30
31     @Test
32     public void testColorControlModelSaturationConversionIsBijective() {
33         for (int percent = 0; percent <= 100; ++percent) {
34             PercentType percentType = new PercentType(percent);
35             int saturation = ColorControlModel.fromPercent(percentType);
36             assertThat(ColorControlModel.toPercent(saturation).intValue(), is(percent));
37         }
38     }
39
40     @Test
41     public void testColorControlModelPercentConversionRestrictsToLowerBounds() {
42         assertThat(ColorControlModel.toPercent(-1), is(PercentType.ZERO));
43     }
44
45     @Test
46     public void testColorControlModelPercentConversionRestrictsToUpperBounds() {
47         assertThat(ColorControlModel.toPercent(999), is(PercentType.HUNDRED));
48     }
49
50     @Test
51     public void hsbSaturationAlwaysGreaterThanZero() {
52         // a saturation greater than 1 should result in a percentage greater than 1
53         for (int saturation = 1; saturation <= 254; ++saturation) {
54             PercentType percentType = ColorControlModel.toPercent(saturation);
55             assertTrue(ColorControlModel.fromPercent(percentType) > 0);
56         }
57     }
58 }