public void ParseInstruction_Returns_Correct_Jump_When_Jump_Is_Specified(string input, ComputeJumpType expected)
        {
            // arrange
            var parser = new ComputeJumpParser();

            // act
            ComputeJumpType result = parser.ParseComputeJump(input);

            // assert
            Assert.AreEqual(expected, result);
        }
        public void ParseInstruction_Returns_Correct_Jump_When_Jump_Is_Specified(string input, ComputeJumpType expected)
        {
            // arrange
            var parser = new ComputeJumpParser();

            // act
            ComputeJumpType result = parser.ParseComputeJump(input);

            // assert
            Assert.AreEqual(expected, result);
        }
        public void ParseInstruction_Returns_None_When_Jump_Is_Empty()
        {
            // arrange
            string input  = string.Empty;
            var    parser = new ComputeJumpParser();

            // act
            ComputeJumpType result = parser.ParseComputeJump(input);

            // assert
            Assert.AreEqual(ComputeJumpType.None, result);
        }
        public void AssembleInstruction_Returns_Correct_Jump_Bits(ComputeJumpType jumpType, string expected)
        {
            // arrange
            var instruction = new ComputeInstruction(ComputeDestinationType.None, "D&A", jumpType);
            var computeBitsAssembler = Substitute.For<IHackComputeBitsAssembler>();
            computeBitsAssembler.AssembleComputeBits(Arg.Any<string>()).Returns("0000000");
            var assembler = new HackComputeInstructionAssembler(computeBitsAssembler);

            // act
            string[] result = assembler.AssembleInstruction(instruction);
            string line = result[0];

            // assert
            Assert.AreEqual(expected, line);
        }
        public void AssembleInstruction_Returns_Correct_Jump_Bits(ComputeJumpType jumpType, string expected)
        {
            // arrange
            var instruction          = new ComputeInstruction(ComputeDestinationType.None, "D&A", jumpType);
            var computeBitsAssembler = Substitute.For <IHackComputeBitsAssembler>();

            computeBitsAssembler.AssembleComputeBits(Arg.Any <string>()).Returns("0000000");
            var assembler = new HackComputeInstructionAssembler(computeBitsAssembler);

            // act
            string[] result = assembler.AssembleInstruction(instruction);
            string   line   = result[0];

            // assert
            Assert.AreEqual(expected, line);
        }
Esempio n. 6
0
 public ComputeInstruction(ComputeDestinationType destinationType, string computation, ComputeJumpType jumpType = ComputeJumpType.None)
 {
     _destinationType = destinationType;
     _computation     = computation;
     _jumpType        = jumpType;
 }