Skip to content

Commit

Permalink
fix Inverted status when Inconsistent
Browse files Browse the repository at this point in the history
  • Loading branch information
icklesteve committed Aug 2, 2019
1 parent 90186c5 commit 8f6d6a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 8 additions & 3 deletions java/src/jmri/Turnout.java
Expand Up @@ -247,14 +247,19 @@ public interface Turnout extends DigitalIO {
public void setTurnoutOperation(@Nullable TurnoutOperation toper);

/**
* return the inverted state of the specified state
* Return the inverted state of the specified state
* Does NOT invert INCONSISTENT
* @param inState the specified state
* @return the inverted state
*/
public static int invertTurnoutState(int inState) {
int result = CLOSED;
if (result == inState) {
int result = UNKNOWN;
if (inState == CLOSED) {
result = THROWN;
} else if (inState == THROWN){
result = CLOSED;
} else if (inState == INCONSISTENT){
result = INCONSISTENT;
}
return result;
}
Expand Down
3 changes: 3 additions & 0 deletions java/test/jmri/TurnoutTest.java
Expand Up @@ -19,12 +19,15 @@ public void testStateConstants() {
Assert.assertTrue("Off and Unknown differ", (Turnout.CLOSED & Turnout.UNKNOWN) == 0);
Assert.assertTrue("Thrown and Inconsistent differ", (Turnout.THROWN & Turnout.INCONSISTENT) == 0);
Assert.assertTrue("Closed and Inconsistent differ", (Turnout.CLOSED & Turnout.INCONSISTENT) == 0);
Assert.assertTrue("Unknown and Inconsistent differ", (Turnout.UNKNOWN & Turnout.INCONSISTENT) == 0);
}

@Test
public void testInvertTurnoutState() {
Assert.assertEquals("Closed state Inverted",Turnout.THROWN,Turnout.invertTurnoutState(Turnout.CLOSED));
Assert.assertEquals("Thrown state Inverted",Turnout.CLOSED,Turnout.invertTurnoutState(Turnout.THROWN));
Assert.assertEquals("Inconsistent state Inverted",Turnout.INCONSISTENT,Turnout.invertTurnoutState(Turnout.INCONSISTENT));
Assert.assertEquals("Unknown state Inverted",Turnout.UNKNOWN,Turnout.invertTurnoutState(Turnout.UNKNOWN));
}

}

0 comments on commit 8f6d6a5

Please sign in to comment.