Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add LoadState method to Program and write some unit tests in ProgramT…
…ests.
- Loading branch information
1 parent
3838a8d
commit 7ad3fd6
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
|