This repository has been archived by the owner on May 7, 2020. It is now read-only.
/
UtilTest.java
89 lines (72 loc) · 2.39 KB
/
UtilTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Copyright (c) 2014-2017 by the respective copyright holders.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.smarthome.binding.dmx.internal;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import org.eclipse.smarthome.binding.dmx.internal.Util;
import org.eclipse.smarthome.binding.dmx.internal.multiverse.DmxChannel;
import org.eclipse.smarthome.core.library.types.PercentType;
import org.junit.Test;
/**
* Tests cases Util
*
* @author Jan N. Klug - Initial contribution
*/
public class UtilTest {
@Test
public void coercingOfDmxValues() {
// overrange
int value = Util.toDmxValue(300);
assertThat(value, is(DmxChannel.MAX_VALUE));
// underrange
value = Util.toDmxValue(-1);
assertThat(value, is(DmxChannel.MIN_VALUE));
// inrange
value = Util.toDmxValue(100);
assertThat(value, is(100));
}
@Test
public void conversionString() {
int value = Util.toDmxValue("100");
assertThat(value, is(100));
}
@Test
public void conversionFromPercentType() {
// borders
int value = Util.toDmxValue(new PercentType(100));
assertThat(value, is(255));
value = Util.toDmxValue(new PercentType(0));
assertThat(value, is(0));
// middle
value = Util.toDmxValue(new PercentType(50));
assertThat(value, is(127));
}
@Test
public void conversionToPercentType() {
// borders
PercentType value = Util.toPercentValue(255);
assertThat(value.intValue(), is(100));
value = Util.toPercentValue(0);
assertThat(value.intValue(), is(0));
// middle
value = Util.toPercentValue(127);
assertThat(value.intValue(), is(49));
}
@Test
public void fadeTimeFraction() {
// target already reached
int value = Util.fadeTimeFraction(123, 123, 1000);
assertThat(value, is(0));
// full fade
value = Util.fadeTimeFraction(0, 255, 1000);
assertThat(value, is(1000));
// fraction
value = Util.fadeTimeFraction(100, 155, 2550);
assertThat(value, is(550));
}
}