public void TestCharacters(char character, string expected) { //arrange var center = new StubPinInterface(1); var upperLeft = new StubPinInterface(2); var top = new StubPinInterface(3); var upperRight = new StubPinInterface(4); var lowerLeft = new StubPinInterface(5); var bottom = new StubPinInterface(6); var lowerRight = new StubPinInterface(7); var decimalPoint = new StubPinInterface(8); var display = new SevenSegmentDisplay(center, upperLeft, top, upperRight, lowerLeft, bottom, lowerRight, decimalPoint); //act display.Show(character); //assert Assert.Equal(expected[1] == '*' ? PowerValue.On : PowerValue.Off, top.Power); Assert.Equal(expected[3] == '*' ? PowerValue.On : PowerValue.Off, upperLeft.Power); Assert.Equal(expected[5] == '*' ? PowerValue.On : PowerValue.Off, upperRight.Power); Assert.Equal(expected[7] == '*' ? PowerValue.On : PowerValue.Off, center.Power); Assert.Equal(expected[9] == '*' ? PowerValue.On : PowerValue.Off, lowerLeft.Power); Assert.Equal(expected[11] == '*' ? PowerValue.On : PowerValue.Off, lowerRight.Power); Assert.Equal(expected[13] == '*' ? PowerValue.On : PowerValue.Off, bottom.Power); if (expected.Length > 15) { Assert.Equal(expected[15] == '*' ? PowerValue.On : PowerValue.Off, decimalPoint.Power); } }
public void TurnCounterclockwiseForSetsDirection() { //arrange var enabled = new StubPinInterface(1); var clockwise = new StubPinInterface(2); var counterclockwise = new StubPinInterface(3); var motor = new Motor(enabled, clockwise, counterclockwise); //act motor.TurnCounterclockwiseFor(TimeSpan.Zero); //assert Assert.Equal(Motor.Rotation.Counterclockwise, motor.Direction); }
public void RunForStopsWhenDone() { //arrange var enabled = new StubPinInterface(1); var clockwise = new StubPinInterface(2); var counterclockwise = new StubPinInterface(3); var motor = new Motor(enabled, clockwise, counterclockwise); //act motor.RunFor(TimeSpan.Zero); //assert Assert.Equal(PowerValue.Off, clockwise.Power); Assert.Equal(PowerValue.Off, counterclockwise.Power); }
public void OnDecreasePerformsActionWhenSet() { //arrange var increasePin = new StubPinInterface(1); var decreasePin = new StubPinInterface(2); var dial = new RotaryEncoder(increasePin, decreasePin); var called = false; dial.OnDecrease(() => called = true); //act decreasePin.Spike(); //assert Assert.True(called); }
public void TestBlue() { //arrange var red = new StubPinInterface(1); var green = new StubPinInterface(2); var blue = new StubPinInterface(3); var led = new RGBLED(red, green, blue); //act led.TurnBlue(); //assert Assert.Equal(PowerValue.Off, red.Power); Assert.Equal(PowerValue.Off, green.Power); Assert.Equal(PowerValue.On, blue.Power); }
public void CoastKeepsInputsOn() { //arrange var enabled = new StubPinInterface(1); var clockwise = new StubPinInterface(2); var counterclockwise = new StubPinInterface(3); var motor = new Motor(enabled, clockwise, counterclockwise); motor.Start(); //act motor.Coast(); //assert Assert.Equal(PowerValue.Off, enabled.Power); Assert.Equal(PowerValue.On, clockwise.Power); Assert.Equal(PowerValue.Off, counterclockwise.Power); }
public void StopTurnsOffAllPins() { //arrange var enabled = new StubPinInterface(1); var clockwise = new StubPinInterface(2); var counterclockwise = new StubPinInterface(3); var motor = new Motor(enabled, clockwise, counterclockwise); motor.Start(); //act motor.Stop(); //assert Assert.Equal(PowerValue.Off, enabled.Power); Assert.Equal(PowerValue.Off, clockwise.Power); Assert.Equal(PowerValue.Off, counterclockwise.Power); }
public void StartWhenCounterclockwiseSetsInputsCorrectly() { //arrange var enabled = new StubPinInterface(1); var clockwise = new StubPinInterface(2); var counterclockwise = new StubPinInterface(3); var motor = new Motor(enabled, clockwise, counterclockwise) { Direction = Motor.Rotation.Counterclockwise }; //act motor.Start(); //assert Assert.Equal(PowerValue.On, enabled.Power); Assert.Equal(PowerValue.Off, clockwise.Power); Assert.Equal(PowerValue.On, counterclockwise.Power); }
public void PinsAreMappedCorrectly() { //arrange var newPin = Substitute.For <Func <byte, IPinInterface> >(); newPin.Invoke(Arg.Any <byte>()).Returns(p => new StubPinInterface(p.Arg <byte>())); var board = new BroadcomBoard(newPin); var pins = new StubPinInterface[28]; //act for (var x = 0; x < 28; x++) { pins[x] = (StubPinInterface)board.GetType().GetProperty($"GPIO{x}").GetValue(board); } //assert for (var x = 0; x < 28; x++) { Assert.Equal(x, pins[x].Pin); } }