Skip to content

Instantly share code, notes, and snippets.

@tyhdefu
Created March 22, 2023 11:06
Show Gist options
  • Save tyhdefu/12a547b00c362f7d1d688dd6754e82d5 to your computer and use it in GitHub Desktop.
Save tyhdefu/12a547b00c362f7d1d688dd6754e82d5 to your computer and use it in GitHub Desktop.
public class TestAndGate {
private IC<?> create(PinSet3ISO pinSet) {
return new AndGateImpl(pinSet);
}
public void testAndGate(Boolean in1, Boolean in2, Boolean in3, Boolean expected) {
Dummy3ISO dummyPinSet = new Dummy3ISO();
dummyPinSet.FRONT_INPUT.setState(in1);
dummyPinSet.LEFT_INPUT.setState(in2);
dummyPinSet.RIGHT_INPUT.setState(in3);
IC<?> ic = create(dummyPinSet);
ic.trigger();
Assertions.assertEquals(expected, dummyPinSet.OUTPUT.getState(), "expected " + Arrays.asList(in1, in2, in3) + " to give output " + expected + " but got: " + dummyPinSet.OUTPUT.getState());
}
@Test
public void testNoPins() {
testAndGate(null, null, null, true);
}
@Test
public void testOnePinOn() {
testAndGate(true, null, null, true);
testAndGate(null, true, null, true);
testAndGate(null, null, true, true);
}
@Test
public void testTwoPinsOn() {
testAndGate(true, true, null, true);
testAndGate(true, null, true, true);
testAndGate(null, true, true, true);
}
@Test
public void testThreePinsOn() {
testAndGate(true, true, true, true);
}
@Test
public void testAllPinsOff() {
testAndGate(false, false, false, false);
}
@Test
public void testOnePinOff() {
testAndGate(false, null, null, false);
testAndGate(null, false, null, false);
testAndGate(null, null, false, false);
}
@Test
public void testTwoMixed() {
testAndGate(true, false, null, false);
testAndGate(false, true, null, false);
testAndGate(null, true, false, false);
testAndGate(null, false, true, false);
}
@Test
public void testThreeMixed() {
testAndGate(false, true, true, false);
testAndGate(true, false, true, false);
testAndGate(true, true, false, false);
testAndGate(true, false, false, false);
testAndGate(false, true, false, false);
testAndGate(false, true, false, false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment