2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.avmfritz.internal.dto;
15 import static org.hamcrest.CoreMatchers.is;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.junit.jupiter.api.Assertions.assertTrue;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.core.library.types.PercentType;
24 * Tests for {@link ColorControlModel} methods.
26 * @author Christoph Weitkamp - Initial contribution
29 class ColorControlModelTest {
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));
41 public void testColorControlModelPercentConversionRestrictsToLowerBounds() {
42 assertThat(ColorControlModel.toPercent(-1), is(PercentType.ZERO));
46 public void testColorControlModelPercentConversionRestrictsToUpperBounds() {
47 assertThat(ColorControlModel.toPercent(999), is(PercentType.HUNDRED));
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);