/
ProgramTests.cs
60 lines (44 loc) · 1.39 KB
/
ProgramTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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);
}
}
}