Rename IProgramStream to IProgram because of code analysis
authorMichael Welch <michaelgwelch@gmail.com>
Thu, 16 Feb 2012 23:41:07 +0000 (17:41 -0600)
committerMichael Welch <michaelgwelch@gmail.com>
Thu, 16 Feb 2012 23:41:07 +0000 (17:41 -0600)
Not supposed to use word Stream in class name unless inheriting from Stream.

src.net/Brainmess/Main.cs
src.net/BrainmessCore/BrainmessCore.csproj
src.net/BrainmessCore/IProgram.cs [moved from src.net/BrainmessCore/IProgramStream.cs with 94% similarity]
src.net/BrainmessCore/Instruction.cs
src.net/BrainmessCore/Interpreter.cs
src.net/BrainmessCore/Program.cs [moved from src.net/BrainmessCore/ProgramStream.cs with 89% similarity]
src.net/BrainmessCoreTests/InstructionTests.cs
src.net/BrainmessCoreTests/InterpreterTests.cs
src.net/BrainmessCoreTests/ProgramStreamTests.cs

index d16bee4..b1249ae 100644 (file)
@@ -10,7 +10,7 @@ namespace Welch.Brainmess
         public static void Main(string[] args)
         {
 
-            var program = new ProgramStream(
+            var program = new Program(
                 @"+++++++++++ number of digits to output
 > #1
 + initial number
@@ -79,14 +79,14 @@ output #12 even if it’s zero
   [>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-
 ]");
             /* 
-                program = new ProgramStream(@",
+                program = new Program(@",
     ------------------------------------------------
     [->++<]
     >
     ++++++++++++++++++++++++++++++++++++++++++++++++.");
         */
 
-            program = new ProgramStream(@"
+            program = new Program(@"
 ++++++++[<+++++++++>-]<.>+++++[<++++++>-]<-.
 +++++++..+++.>++++++++[<<++++>>-]<<.
 >>++++[<------>-]<.>++++[<++++++>-]<.
index ada34a2..408f4d7 100644 (file)
@@ -42,8 +42,8 @@
   <ItemGroup>
     <Compile Include="Instruction.cs" />
     <Compile Include="Interpreter.cs" />
-    <Compile Include="IProgramStream.cs" />
-    <Compile Include="ProgramStream.cs" />
+    <Compile Include="IProgram.cs" />
+    <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Tape.cs" />
     <Compile Include="String.cs" />
similarity index 94%
rename from src.net/BrainmessCore/IProgramStream.cs
rename to src.net/BrainmessCore/IProgram.cs
index e0f24ef..7547a1f 100644 (file)
@@ -1,9 +1,9 @@
 namespace Welch.Brainmess
 {
     /// <summary>
-    /// Defines the members of a ProgramStream object.
+    /// Defines the members of a Program object.
     /// </summary>
-    public interface IProgramStream
+    public interface IProgram
     {
         /// <summary>
         /// Reads the Instruction at the program counter and returns it.
index f0e034d..d887e2e 100644 (file)
@@ -11,13 +11,13 @@ namespace Welch.Brainmess
     /// <summary>
     /// Defines all of the instructions available in Brainmess. Each type of instruction
     /// defines its own behavior given an execution context that consists of a
-    /// <see cref="IProgramStream"/>, <see cref="Tape"/>, <see cref="TextReader"/> (for input),
+    /// <see cref="IProgram"/>, <see cref="Tape"/>, <see cref="TextReader"/> (for input),
     /// and a <see cref="TextWriter"/> ) (for output).
     /// </summary>
     public sealed class Instruction
     {
-        private readonly Action<IProgramStream, Tape, TextReader, TextWriter> _action;
-        private Instruction(Action<IProgramStream, Tape, TextReader, TextWriter> action)
+        private readonly Action<IProgram, Tape, TextReader, TextWriter> _action;
+        private Instruction(Action<IProgram, Tape, TextReader, TextWriter> action)
         {
             _action = action;
         }
@@ -25,7 +25,7 @@ namespace Welch.Brainmess
         /// <summary>
         /// Executes this instruction within the given context.
         /// </summary>
-        public void Execute(IProgramStream program, Tape tape, TextReader input, TextWriter output)
+        public void Execute(IProgram program, Tape tape, TextReader input, TextWriter output)
         {
             _action(program, tape, input, output);
         }
index 490427f..91327c3 100644 (file)
@@ -11,7 +11,7 @@ namespace Welch.Brainmess
         /// <summary>
         /// Creates an interpreter that runs the empty program.
         /// </summary>
-        public Interpreter() : this(new ProgramStream(""))
+        public Interpreter() : this(new Program(""))
         {
             
         }
@@ -22,7 +22,7 @@ namespace Welch.Brainmess
         /// <param name="tape">The tape to use as a memory story. If this is null, a default tape is used.</param>
         /// <param name="input">The input source to use. If this is null then Console.In is used.</param>
         /// <param name="output">The output source to use. If this is null then Console.Out is used.</param>
-        public Interpreter(IProgramStream program, Tape tape = null, TextReader input = null, TextWriter output = null)
+        public Interpreter(IProgram program, Tape tape = null, TextReader input = null, TextWriter output = null)
         {
             _program = program;
             _tape = tape ?? Tape.Default;
@@ -30,7 +30,7 @@ namespace Welch.Brainmess
             _output = output ?? Console.Out;
         }
 
-        private readonly IProgramStream _program;
+        private readonly IProgram _program;
         private readonly Tape _tape;
         private readonly TextWriter _output;
         private readonly TextReader _input;
similarity index 89%
rename from src.net/BrainmessCore/ProgramStream.cs
rename to src.net/BrainmessCore/Program.cs
index 24e6e57..9bcecd1 100644 (file)
@@ -11,7 +11,7 @@ namespace Welch.Brainmess
     /// are tested 3) JumpForward and JumpBackward require they are called only in certain conditions
     /// which the Interpreter guarantees. 
     /// </summary>
-    public class ProgramStream : IProgramStream
+    public class Program : IProgram
     {
         // Mutable State
         int _programCounter; // = 0;
@@ -20,11 +20,11 @@ namespace Welch.Brainmess
         private readonly string _program;
 
         /// <summary>
-        /// Initializes a new instance of the <see cref="Welch.Brainmess.ProgramStream"/> class
+        /// Initializes a new instance of the <see cref="Program"/> class
         /// with the characters from the specified program. The program counter is set to the first
         /// character in the program.
         /// </summary>
-        public ProgramStream(string program)
+        public Program(string program)
         {
             _program = program;
         }
@@ -88,15 +88,15 @@ namespace Welch.Brainmess
         }
 
         /// <summary>
-        /// Returns a new ProgramStream with the program counter initialized to i.
+        /// Returns a new Program with the program counter initialized to i.
         /// </summary>
         /// <param name="programString"> </param>
         /// <param name="initialProgramCounter"> </param>
         /// <returns></returns>
-        public static ProgramStream LoadState(string programString, int initialProgramCounter = 0)
+        public static Program LoadState(string programString, int initialProgramCounter = 0)
         {
             if (initialProgramCounter < 0) throw new ArgumentOutOfRangeException("initialProgramCounter");
-            ProgramStream program = new ProgramStream(programString)
+            Program program = new Program(programString)
                                         {
                                             _programCounter = initialProgramCounter
                                         };
index 194942c..888beb3 100644 (file)
@@ -8,10 +8,10 @@ namespace Welch.Brainmess
     public class InstructionTests
     {
         // this is doing White Box testing. It takes advantage of the fact that the real logic
-        // is done in other classes, Tape, ProgramStream, etc. Most of the instructions are one line
-        // and need only one test. The bulk of the testing is then done on Tape and ProgramStream
+        // is done in other classes, Tape, Program, etc. Most of the instructions are one line
+        // and need only one test. The bulk of the testing is then done on Tape and Program
 
-        private static readonly ProgramStream _nullProgram  = null;
+        private static readonly Program _nullProgram  = null;
         private static readonly TextReader _nullInput = null;
         private static readonly TextWriter _nullOutput = null;
 
@@ -134,7 +134,7 @@ namespace Welch.Brainmess
         {
             // Arrange
             var tape = Tape.Default;
-            var mock = new Mock<IProgramStream>(MockBehavior.Strict);
+            var mock = new Mock<IProgram>(MockBehavior.Strict);
             mock.Setup(program => program.JumpForward());
 
             // Act
@@ -168,7 +168,7 @@ namespace Welch.Brainmess
         {
             // Arrange
             var tape = Tape.LoadState(new[] { 1, 2, 3 }, 1);
-            var mock = new Mock<IProgramStream>(MockBehavior.Strict);
+            var mock = new Mock<IProgram>(MockBehavior.Strict);
             mock.Setup(program => program.JumpBackward());
 
             // Act
index a6bbcb3..64b2dd2 100644 (file)
@@ -18,7 +18,7 @@ namespace Welch.Brainmess
             // Arrange
 
             // Use strict behavior to make sure the interpreter stops after only one call.
-            var mock = new Mock<IProgramStream>(MockBehavior.Strict);
+            var mock = new Mock<IProgram>(MockBehavior.Strict);
             mock.Setup(prog => prog.EndOfProgram).Returns(true);
             var program = mock.Object;
             var interpreter = new Interpreter(program);
@@ -35,7 +35,7 @@ namespace Welch.Brainmess
         public void Run_WithOneInstruction()
         {
             // Arrange
-            var mock = new Mock<IProgramStream>(MockBehavior.Strict);
+            var mock = new Mock<IProgram>(MockBehavior.Strict);
             mock.Setup(prog => prog.EndOfProgram).ReturnsInOrder(false, true);
             mock.Setup(prog => prog.Fetch()).Returns(Instruction.Increment);
             var tape = Tape.Default;
@@ -66,7 +66,7 @@ namespace Welch.Brainmess
 +++.------.--------.<+.
 ";
             const string expectedString = "Hello World!";
-            var programStream = new ProgramStream(program);
+            var programStream = new Program(program);
             var tape = Tape.Default;
             var outputStream = new MemoryStream();
             var output = new StreamWriter(outputStream) {AutoFlush = true};
@@ -88,7 +88,7 @@ namespace Welch.Brainmess
             // Arrange - Create program, tape, input, and output. We'll verify at the end 
             //           that none of them were modified as a result of running the null program.
             var tape = Tape.Default;
-            var program = new ProgramStream("");
+            var program = new Program("");
             var input = new DummyInput(); // fails on Read
             var output = new DummyOutput(); // fails on Write
             var interpreter = new Interpreter(program, tape, input, output);
index 0c42e72..14fb61b 100644 (file)
@@ -16,7 +16,7 @@ namespace Welch.Brainmess
         {
             // Arrange
             //                                               0123456789
-            ProgramStream program = ProgramStream.LoadState("++[     ]   ", 3);
+            Program program = Program.LoadState("++[     ]   ", 3);
 
             // Act
             program.JumpForward();
@@ -31,7 +31,7 @@ namespace Welch.Brainmess
         {
             // Arrange
             //                                               0123456789
-            ProgramStream program = ProgramStream.LoadState("++[     ]   ", 9);
+            Program program = Program.LoadState("++[     ]   ", 9);
 
             // Act
             program.JumpBackward();
@@ -48,7 +48,7 @@ namespace Welch.Brainmess
         {
             // Arrange
             //                                               0123456789
-            ProgramStream program = ProgramStream.LoadState("++[>>.>>>abc]   ", 4);
+            Program program = Program.LoadState("++[>>.>>>abc]   ", 4);
 
             // Act
             var instruction = program.Fetch();
@@ -63,7 +63,7 @@ namespace Welch.Brainmess
             // Arrange
             // Arrange
             //                                               0123456789
-            ProgramStream program = ProgramStream.LoadState("++[>a.>>>abc]   ", 4);
+            Program program = Program.LoadState("++[>a.>>>abc]   ", 4);
 
             // Act
             var instruction = program.Fetch();
@@ -75,7 +75,7 @@ namespace Welch.Brainmess
         [TestMethod]
         public void Fetch_CurrentInstructionIsNoOpAndWeAreAtEndOfProgram_ShouldReturnNoOp()
         {
-            var program = new ProgramStream("a");
+            var program = new Program("a");
 
             // Act
             var instruction = program.Fetch();
@@ -89,7 +89,7 @@ namespace Welch.Brainmess
         {
             try
             {
-                ProgramStream.LoadState("+", -1);
+                Program.LoadState("+", -1);
                 Assert.Fail("Expected ArgumentOutOfRangeException");
             }
             catch (ArgumentOutOfRangeException)
@@ -105,7 +105,7 @@ namespace Welch.Brainmess
         {
             // Arrange
             //                                               0123456789
-            ProgramStream program = ProgramStream.LoadState("++[>>.>>]", 8);
+            Program program = Program.LoadState("++[>>.>>]", 8);
 
             // Act
             var endOfProgram = program.EndOfProgram;
@@ -119,7 +119,7 @@ namespace Welch.Brainmess
         {
             // Arrange
             //                                               0123456789
-            ProgramStream program = ProgramStream.LoadState("++[>>.>>]", 9);
+            Program program = Program.LoadState("++[>>.>>]", 9);
 
             // Act
             var endOfProgram = program.EndOfProgram;