Write some more instruction tests for java impl
authorMichael Welch <michaelgwelch@gmail.com>
Wed, 14 Mar 2012 01:56:19 +0000 (20:56 -0500)
committerMichael Welch <michaelgwelch@gmail.com>
Wed, 14 Mar 2012 01:56:19 +0000 (20:56 -0500)
java/test/welch/brainmess/InstructionTests.java

index 0e72844..3d0df52 100644 (file)
@@ -3,27 +3,28 @@ package welch.brainmess;
 
 import org.junit.Test;
 import org.jmock.*;
+import static org.junit.Assert.assertEquals;
 
 public class InstructionTests {
+       
+       private final Mockery mockery = new Mockery();
+       private final ExecutionContext executionContext = mockery.mock(ExecutionContext.class);
+
 
        @Test
        public void moveForward_Execute() {
 
                // Arrange
-               Mockery mock = new Mockery();
-               final ExecutionContext context = mock.mock(ExecutionContext.class);
-               
-               
-               mock.checking(new Expectations() {{
-                       oneOf(context).moveForward();
+               mockery.checking(new Expectations() {{
+                       oneOf(executionContext).moveForward();
                }});
                
                
                // Act
-               Instruction.MOVE_FORWARD.execute(context);
+               Instruction.MOVE_FORWARD.execute(executionContext);
                
                // Assert
-               mock.assertIsSatisfied();
+               mockery.assertIsSatisfied();
        }
 
 
@@ -31,36 +32,231 @@ public class InstructionTests {
        public void moveBackward_Execute() {
 
                // Arrange
-               Mockery mock = new Mockery();
-               final ExecutionContext context = mock.mock(ExecutionContext.class);
+               mockery.checking(new Expectations() {{
+                       oneOf(executionContext).moveBackward();
+               }});
                
                
-               mock.checking(new Expectations() {{
-                       oneOf(context).moveBackward();
+               // Act
+               Instruction.MOVE_BACKWARD.execute(executionContext);
+               
+               // Assert
+               mockery.assertIsSatisfied();
+       }
+       
+       @Test
+       public void testAndJumpForward_Execute() {
+               // Arrange
+               mockery.checking(new Expectations() {{
+                       oneOf(executionContext).testAndJumpForward();
+               }});
+               
+               // Act
+               Instruction.TEST_AND_JUMP_FORWARD.execute(executionContext);
+               
+               // Assert
+               mockery.assertIsSatisfied();
+       }
+       
+       @Test
+       public void testAndJumpBackward_Execute() {
+               // Arrange
+               mockery.checking(new Expectations() {{ 
+                       oneOf(executionContext).testAndJumpBackward();
                }});
                
+               // Act
+               Instruction.TEST_AND_JUMP_BACKWARD.execute(executionContext);
+               
+               // Assert
+               mockery.assertIsSatisfied();
+       }
+       
+       @Test
+       public void increment_Execute() {
+               // Arrange
+               mockery.checking(new Expectations() {{ 
+                       oneOf(executionContext).increment();
+               }});
                
                // Act
-               Instruction.MOVE_BACKWARD.execute(context);
+               Instruction.INCREMENT.execute(executionContext);
                
                // Assert
-               mock.assertIsSatisfied();
+               mockery.assertIsSatisfied();
        }
        
        @Test
-       public void testAndJumpForward_Execute() {
+       public void decrement_Execute() {
+               // Arrange
+               mockery.checking(new Expectations() {{ 
+                       oneOf(executionContext).decrement();
+               }});
+               
+               // Act
+               Instruction.DECREMENT.execute(executionContext);
+               
+               // Assert
+               mockery.assertIsSatisfied();
+       }
+       
+       @Test
+       public void input_Execute() {
                // Arrange
-               Mockery mock = new Mockery();
-               final ExecutionContext context = mock.mock(ExecutionContext.class);
+               mockery.checking(new Expectations() {{ 
+                       oneOf(executionContext).input();
+               }});
+               
+               // Act
+               Instruction.INPUT.execute(executionContext);
                
-               mock.checking(new Expectations() {{
-                       oneOf(context).testAndJumpForward();
+               // Assert
+               mockery.assertIsSatisfied();
+       }
+       
+       @Test
+       public void output_Execute() {
+               // Arrange
+               mockery.checking(new Expectations(){{ 
+                       oneOf(executionContext).ouput();
                }});
                
                // Act
-               Instruction.TEST_AND_JUMP_FORWARD.execute(context);
+               Instruction.OUTPUT.execute(executionContext);
+               
+               // Assert
+               mockery.assertIsSatisfied();
+       }
+       
+       @Test
+       public void noOperation_Execute() {
+               // Arrange 
+               
+               
+               // Act
+               Instruction.NO_OPERATION.execute(executionContext);
+               
+               // Assert
+               mockery.assertIsSatisfied();
+       }
+       
+
+       @Test
+       public void parseMoveForwardChar() {
+               // Arrange
+               Instruction expected = Instruction.MOVE_FORWARD;
+               
+               // Act
+               Instruction actual = Instruction.parseInstruction('>');
+               
+               // Assert
+               assertEquals(expected, actual);
+       }
+       
+       @Test
+       public void parseMoveBackward() {
+               // Arrange
+               Instruction expected = Instruction.MOVE_BACKWARD;
+               
+               // Act
+               Instruction actual = Instruction.parseInstruction('<');
+               
+               // Assert
+               assertEquals(expected, actual);
+       }
+       
+       @Test
+       public void parseIncrement() {
+               // Arrange
+               Instruction expected = Instruction.INCREMENT;
+               
+               // Act
+               Instruction actual = Instruction.parseInstruction('+');
+               
+               // Assert
+               assertEquals(expected, actual);
+       }
+       
+       @Test
+       public void parseDecrement() {
+               // Arrange
+               Instruction expected = Instruction.DECREMENT;
+               
+               // Act
+               Instruction actual = Instruction.parseInstruction('-');
+               
+               // Assert
+               assertEquals(expected, actual);
+       }
+       
+       @Test
+       public void parseInput() {
+               // Arrange
+               Instruction expected = Instruction.INPUT;
+               
+               // Act
+               Instruction actual = Instruction.parseInstruction(',');
+               
+               // Assert
+               assertEquals(expected, actual);
+       }
+       
+       @Test
+       public void parseOutput() {
+               // Arrange
+               Instruction expected = Instruction.OUTPUT;
+               
+               // Act
+               Instruction actual = Instruction.parseInstruction('.');
+               
+               // Assert
+               assertEquals(expected, actual);
+       }
+       
+       @Test
+       public void parseTestAndJumpForward() {
+               // Arrange
+               Instruction expected = Instruction.TEST_AND_JUMP_FORWARD;
+               
+               // Act
+               Instruction actual = Instruction.parseInstruction('[');
+               
+               // Assert
+               assertEquals(expected, actual);
+       }
+       
+       @Test
+       public void parseTestAndJumpBackward() {
+               // Arrange
+               Instruction expected = Instruction.TEST_AND_JUMP_BACKWARD;
+               
+               // Act
+               Instruction actual = Instruction.parseInstruction(']');
                
                // Assert
-               mock.assertIsSatisfied();
+               assertEquals(expected, actual);
        }
+       
+       @Test
+       public void parseNoOperation() {
+               // Arrange
+               Instruction expected = Instruction.NO_OPERATION;
+               
+               // Act
+               Instruction actual = Instruction.parseInstruction('H');
+               
+               // Assert
+               assertEquals(expected, actual);
+       }
+       
+       @Test
+       public void toStringMoveForward() {
+               assertEquals("MOVE_FORWARD", Instruction.MOVE_FORWARD.toString());
+       }
+       
+       @Test
+       public void hashCodeTest() {
+               Instruction.MOVE_BACKWARD.hashCode();
+       }
+
 }