public void TeletypeWithPositionForwardsReads() { _mockTeletype = new Mock <ITeletype>(); _mockTeletype.Setup(mt => mt.Width).Returns(80); _sut = new TeletypeWithPosition(_mockTeletype.Object); _mockTeletype.Setup(mt => mt.Read()).Returns("RUN"); _sut.Write(">"); Assert.AreNotEqual(1, _sut.Position()); var result = _sut.Read(); Assert.AreEqual("RUN", result); Assert.AreEqual(1, _sut.Position()); }
/// <summary> /// Executes the Pos function. /// </summary> /// <param name="parameters">Parameters to the function</param> /// <returns>Current horizontal position</returns> public Accumulator Execute(IList <Accumulator> parameters) { if (parameters.Count != 1) { throw new Exceptions.SyntaxErrorException(); } return(new Accumulator((double)_teletypeWithPosition.Position())); }
public void TeletypeWithPositionForwardsWrites() { _mockTeletype = new Mock <ITeletype>(); _mockTeletype.Setup(mt => mt.Width).Returns(80); _sut = new TeletypeWithPosition(_mockTeletype.Object); _sut.Write("HELLO"); _mockTeletype.Verify(mt => mt.Write("HELLO"), Times.Once); Assert.AreEqual(6, _sut.Position()); }
public void TeletypeWithPositionWritesEnvironmentNewLine() { _mockTeletype = new Mock <ITeletype>(); _mockTeletype.Setup(mt => mt.Width).Returns(80); _sut = new TeletypeWithPosition(_mockTeletype.Object); _sut.NewLine(); _mockTeletype.Verify(mt => mt.Write(Environment.NewLine), Times.Once); Assert.AreEqual(1, _sut.Position()); }
public void TeletypeWithPositionCommasInCorrectPlace( int beforeSpaceCount, string output, int expectedBefore, int expectedAfter) { _mockTeletype = new Mock <ITeletype>(); _mockTeletype.Setup(mt => mt.Width).Returns(80); _sut = new TeletypeWithPosition(_mockTeletype.Object); _sut.Space((short)beforeSpaceCount); var actualBefore = _sut.Position(); _sut.Write(output); _sut.NextComma(); var actualAfter = _sut.Position(); Assert.AreEqual(expectedBefore, actualBefore); Assert.AreEqual(expectedAfter, actualAfter); }