]> git.basschouten.com Git - openhab-addons.git/blob
300559628672b6ec8d62d4002f073812c9adff88
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.dmx.internal.multiverse;
14
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17
18 import java.util.List;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22
23 /**
24  * Tests cases for BaseChannel
25  *
26  * @author Jan N. Klug - Initial contribution
27  */
28 @NonNullByDefault
29 public class BaseChannelTest {
30
31     @Test
32     public void creatingBaseChannelFromIntegers() {
33         // overrange
34         BaseDmxChannel channel = new BaseDmxChannel(0, 600);
35         assertThat(channel.getChannelId(), is(BaseDmxChannel.MAX_CHANNEL_ID));
36
37         // underrange
38         channel = new BaseDmxChannel(0, -1);
39         assertThat(channel.getChannelId(), is(BaseDmxChannel.MIN_CHANNEL_ID));
40
41         // inrange & universe
42         channel = new BaseDmxChannel(5, 100);
43         assertThat(channel.getChannelId(), is(100));
44         assertThat(channel.getUniverseId(), is(5));
45
46         // set universe
47         channel.setUniverseId(1);
48         assertThat(channel.getUniverseId(), is(1));
49     }
50
51     @Test
52     public void creatingBaseChannelfromBaseChannel() {
53         BaseDmxChannel baseChannel = new BaseDmxChannel(5, 100);
54         BaseDmxChannel copyChannel = new BaseDmxChannel(baseChannel);
55
56         assertThat(copyChannel.getChannelId(), is(100));
57         assertThat(copyChannel.getUniverseId(), is(5));
58     }
59
60     @Test
61     public void comparingChannels() {
62         BaseDmxChannel channel1 = new BaseDmxChannel(5, 100);
63         BaseDmxChannel channel2 = new BaseDmxChannel(7, 140);
64
65         assertThat(channel1.compareTo(channel2), is(-1));
66         assertThat(channel2.compareTo(channel1), is(1));
67         assertThat(channel1.compareTo(channel1), is(0));
68     }
69
70     @Test
71     public void stringConversion() {
72         // to string
73         BaseDmxChannel baseChannel = new BaseDmxChannel(5, 100);
74         assertThat(baseChannel.toString(), is(equalTo("5:100")));
75
76         // single channel from string with universe
77         String parseString = new String("2:100");
78         List<BaseDmxChannel> channelList = BaseDmxChannel.fromString(parseString, 0);
79         assertThat(channelList.size(), is(1));
80         assertThat(channelList.get(0).toString(), is(equalTo("2:100")));
81
82         // single channel from string without universe
83         parseString = new String("100");
84         channelList = BaseDmxChannel.fromString(parseString, 2);
85         assertThat(channelList.size(), is(1));
86         assertThat(channelList.get(0).toString(), is(equalTo("2:100")));
87
88         // two channels with channel width
89         parseString = new String("100/2");
90         channelList = BaseDmxChannel.fromString(parseString, 2);
91         assertThat(channelList.size(), is(2));
92         assertThat(channelList.get(0).toString(), is(equalTo("2:100")));
93         assertThat(channelList.get(1).toString(), is(equalTo("2:101")));
94
95         // to channels with comma
96         parseString = new String("100,102");
97         channelList = BaseDmxChannel.fromString(parseString, 2);
98         assertThat(channelList.size(), is(2));
99         assertThat(channelList.get(0).toString(), is(equalTo("2:100")));
100         assertThat(channelList.get(1).toString(), is(equalTo("2:102")));
101
102         // complex string
103         parseString = new String("257,100/3,426");
104         channelList = BaseDmxChannel.fromString(parseString, 2);
105         assertThat(channelList.size(), is(5));
106         assertThat(channelList.get(0).toString(), is(equalTo("2:257")));
107         assertThat(channelList.get(1).toString(), is(equalTo("2:100")));
108         assertThat(channelList.get(2).toString(), is(equalTo("2:101")));
109         assertThat(channelList.get(3).toString(), is(equalTo("2:102")));
110         assertThat(channelList.get(4).toString(), is(equalTo("2:426")));
111     }
112 }