Skip to content

Commit

Permalink
Add LoadState method to Program and write some unit tests in ProgramT…
Browse files Browse the repository at this point in the history
…ests.
  • Loading branch information
michaelgwelch committed Mar 23, 2012
1 parent 3838a8d commit 7ad3fd6
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions csharp/BrainmessShort/BrainmessShort.csproj
Expand Up @@ -65,6 +65,7 @@
<Compile Include="StringExtensions.cs" />
<Compile Include="StringExtensionsTests.cs" />
<Compile Include="Program.cs" />
<Compile Include="ProgramTests.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
Expand Down
7 changes: 7 additions & 0 deletions csharp/BrainmessShort/Program.cs
Expand Up @@ -13,6 +13,13 @@ public Program(string program)
pc = 0;
}

public static Program LoadState(string programString, int pc)
{
Program program = new Program(programString);
program.pc = pc;
return program;
}

public bool EndOfProgram
{
get
Expand Down
60 changes: 60 additions & 0 deletions csharp/BrainmessShort/ProgramTests.cs
@@ -0,0 +1,60 @@
using System;
using NUnit.Framework;
namespace BrainmessShort
{
[TestFixture]
public class ProgramStreamTests
{
// White box testing. Each method only needs one test because there are no alternative paths.
// The "hard" testing is done for StringExtensions.FindMatch


[Test]
public void JumpForward()
{
// Arrange
// 0123456789
Program program = Program.LoadState("++[ ] ", 3);

// Act
program.JumpForward();

// Assert
Assert.AreEqual(9, program.ProgramCounter);

}

[Test]
public void JumpBackward()
{
// Arrange
// 0123456789
Program program = Program.LoadState("++[ ] ", 9);

// Act
program.JumpBackward();

// Assert
Assert.AreEqual(2, program.ProgramCounter);
}

[Test]
public void Fetch__ShouldReturnNextInstruction()
{
// Arrange
// 0123456789
Program program = Program.LoadState("++[>>.>>>abc] ", 4);

// Act
var instruction = program.Fetch();

// Assert
Assert.AreEqual('>', instruction);
}

}

}



0 comments on commit 7ad3fd6

Please sign in to comment.