This repository has been archived by the owner on May 7, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Improve DMX binding (#4455)
* refactor Channel to DmxChannel to avoid confusion * make FadeAction complete on infinite hold, add tests for FadeAction Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
- Loading branch information
Showing
19 changed files
with
342 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
...ing.dmx.test/src/test/java/org/eclipse/smarthome/binding/dmx/internal/FadeActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/** | ||
* 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.action.ActionState; | ||
import org.eclipse.smarthome.binding.dmx.internal.action.FadeAction; | ||
import org.eclipse.smarthome.binding.dmx.internal.multiverse.DmxChannel; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Tests cases FadeAction | ||
* | ||
* @author Jan N. Klug - Initial contribution | ||
*/ | ||
public class FadeActionTest { | ||
|
||
private static final int testValue = 200; | ||
private static final int testFadeTime = 1000; | ||
private static final int testHoldTime = 1000; | ||
|
||
@Test | ||
public void checkWithFadingWithoutHold() { | ||
FadeAction fadeAction = new FadeAction(testFadeTime, testValue, 0); | ||
DmxChannel testChannel = new DmxChannel(0, 1); | ||
testChannel.setValue(0); | ||
|
||
long startTime = System.currentTimeMillis(); | ||
|
||
assertThat(fadeAction.getState(), is(ActionState.WAITING)); | ||
assertThat(fadeAction.getNewValue(testChannel, startTime), is(0)); | ||
assertThat(fadeAction.getState(), is(ActionState.RUNNING)); | ||
assertThat(fadeAction.getNewValue(testChannel, startTime + testFadeTime / 2), is(256 * testValue / 2)); | ||
assertThat(fadeAction.getNewValue(testChannel, startTime + 1000), is(256 * testValue)); | ||
assertThat(fadeAction.getState(), is(ActionState.COMPLETED)); | ||
|
||
fadeAction.reset(); | ||
assertThat(fadeAction.getState(), is(ActionState.WAITING)); | ||
} | ||
|
||
@Test | ||
public void checkWithFadingWithHold() { | ||
FadeAction fadeAction = new FadeAction(testFadeTime, testValue, testHoldTime); | ||
DmxChannel testChannel = new DmxChannel(0, 1); | ||
testChannel.setValue(0); | ||
|
||
long startTime = System.currentTimeMillis(); | ||
|
||
assertThat(fadeAction.getState(), is(ActionState.WAITING)); | ||
assertThat(fadeAction.getNewValue(testChannel, startTime), is(0)); | ||
assertThat(fadeAction.getState(), is(ActionState.RUNNING)); | ||
assertThat(fadeAction.getNewValue(testChannel, startTime + testFadeTime / 2), is(256 * testValue / 2)); | ||
assertThat(fadeAction.getNewValue(testChannel, startTime + testFadeTime), is(256 * testValue)); | ||
assertThat(fadeAction.getState(), is(ActionState.RUNNING)); | ||
assertThat(fadeAction.getNewValue(testChannel, startTime + testFadeTime + testHoldTime / 2), | ||
is(256 * testValue)); | ||
assertThat(fadeAction.getState(), is(ActionState.RUNNING)); | ||
assertThat(fadeAction.getNewValue(testChannel, startTime + testFadeTime + testHoldTime), is(256 * testValue)); | ||
assertThat(fadeAction.getState(), is(ActionState.COMPLETED)); | ||
|
||
fadeAction.reset(); | ||
assertThat(fadeAction.getState(), is(ActionState.WAITING)); | ||
} | ||
|
||
@Test | ||
public void checkWithFadingWithInfiniteHold() { | ||
FadeAction fadeAction = new FadeAction(testFadeTime, testValue, -1); | ||
DmxChannel testChannel = new DmxChannel(0, 1); | ||
testChannel.setValue(0); | ||
|
||
long startTime = System.currentTimeMillis(); | ||
|
||
assertThat(fadeAction.getState(), is(ActionState.WAITING)); | ||
assertThat(fadeAction.getNewValue(testChannel, startTime), is(0)); | ||
assertThat(fadeAction.getState(), is(ActionState.RUNNING)); | ||
assertThat(fadeAction.getNewValue(testChannel, startTime + testFadeTime / 2), is(256 * testValue / 2)); | ||
assertThat(fadeAction.getNewValue(testChannel, startTime + testFadeTime), is(256 * testValue)); | ||
assertThat(fadeAction.getState(), is(ActionState.COMPLETEDFINAL)); | ||
|
||
fadeAction.reset(); | ||
assertThat(fadeAction.getState(), is(ActionState.WAITING)); | ||
} | ||
|
||
@Test | ||
public void checkWithoutFadingWithHold() { | ||
FadeAction fadeAction = new FadeAction(0, testValue, testHoldTime); | ||
DmxChannel testChannel = new DmxChannel(0, 1); | ||
testChannel.setValue(0); | ||
|
||
long startTime = System.currentTimeMillis(); | ||
|
||
assertThat(fadeAction.getState(), is(ActionState.WAITING)); | ||
assertThat(fadeAction.getNewValue(testChannel, startTime), is(256 * testValue)); | ||
assertThat(fadeAction.getState(), is(ActionState.RUNNING)); | ||
assertThat(fadeAction.getNewValue(testChannel, startTime + testHoldTime / 2), is(256 * testValue)); | ||
assertThat(fadeAction.getState(), is(ActionState.RUNNING)); | ||
assertThat(fadeAction.getNewValue(testChannel, startTime + testHoldTime), is(256 * testValue)); | ||
assertThat(fadeAction.getState(), is(ActionState.COMPLETED)); | ||
|
||
fadeAction.reset(); | ||
assertThat(fadeAction.getState(), is(ActionState.WAITING)); | ||
} | ||
|
||
@Test | ||
public void checkWithoutFadingWithoutHold() { | ||
FadeAction fadeAction = new FadeAction(0, testValue, 0); | ||
DmxChannel testChannel = new DmxChannel(0, 1); | ||
testChannel.setValue(0); | ||
|
||
long startTime = System.currentTimeMillis(); | ||
|
||
assertThat(fadeAction.getState(), is(ActionState.WAITING)); | ||
assertThat(fadeAction.getNewValue(testChannel, startTime), is(256 * testValue)); | ||
assertThat(fadeAction.getState(), is(ActionState.COMPLETED)); | ||
|
||
fadeAction.reset(); | ||
assertThat(fadeAction.getState(), is(ActionState.WAITING)); | ||
} | ||
|
||
@Test | ||
public void checkWithoutFadingWithInfiniteHold() { | ||
FadeAction fadeAction = new FadeAction(0, testValue, -1); | ||
DmxChannel testChannel = new DmxChannel(0, 1); | ||
testChannel.setValue(0); | ||
|
||
long startTime = System.currentTimeMillis(); | ||
|
||
assertThat(fadeAction.getState(), is(ActionState.WAITING)); | ||
assertThat(fadeAction.getNewValue(testChannel, startTime), is(256 * testValue)); | ||
assertThat(fadeAction.getState(), is(ActionState.COMPLETEDFINAL)); | ||
|
||
fadeAction.reset(); | ||
assertThat(fadeAction.getState(), is(ActionState.WAITING)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.