public void AssembleInstruction_Throws_ArgumentOutOfRangeException_When_Address_Is_Greater_Than_15_bits()
        {
            // arrange
            var instruction = new AddressInstruction(65536);
            var assembler   = new HackAddressInstructionAssembler();

            // act
            TestDelegate testDelegate = () => assembler.AssembleInstruction(instruction);

            // assert
            Assert.Throws <ArgumentOutOfRangeException>(testDelegate);
        }
        public void AssembleInstruction_Throws_ArgumentOutOfRangeException_When_Address_Is_Greater_Than_15_bits()
        {
            // arrange
            var instruction = new AddressInstruction(65536);
            var assembler = new HackAddressInstructionAssembler();

            // act
            TestDelegate testDelegate = () => assembler.AssembleInstruction(instruction);

            // assert
            Assert.Throws<ArgumentOutOfRangeException>(testDelegate);
        }
        public void AssembleInstruction_Returns_Single_Line()
        {
            // arrange
            var instruction = new AddressInstruction(1234);
            var assembler   = new HackAddressInstructionAssembler();

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

            // assert
            Assert.AreEqual(1, result.Length);
        }
        public void AssembleInstruction_Returns_Single_Line()
        {
            // arrange
            var instruction = new AddressInstruction(1234);
            var assembler = new HackAddressInstructionAssembler();

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

            // assert
            Assert.AreEqual(1, result.Length);
        }
        public void AssembleInstruction_Returns_Line_Starts_With_Zero()
        {
            // arrange
            var instruction = new AddressInstruction(1234);
            var assembler   = new HackAddressInstructionAssembler();

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

            // assert
            Assert.AreEqual('0', line[0]);
        }
        public void AssembleInstruction_Returns_16_Bit_Line()
        {
            // arrange
            var instruction = new AddressInstruction(1234);
            var assembler   = new HackAddressInstructionAssembler();

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

            // assert
            Assert.AreEqual(16, line.Length);
        }
        public void AssembleInstruction_Returns_Line_Starts_With_Zero()
        {
            // arrange
            var instruction = new AddressInstruction(1234);
            var assembler = new HackAddressInstructionAssembler();

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

            // assert
            Assert.AreEqual('0', line[0]);
        }
        public void AssembleInstruction_Returns_16_Bit_Line()
        {
            // arrange
            var instruction = new AddressInstruction(1234);
            var assembler = new HackAddressInstructionAssembler();

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

            // assert
            Assert.AreEqual(16, line.Length);
        }
        public void AssembleInstruction_Returns_Binary_Representation_Of_Address_Instruction(int address, string expected)
        {
            // arrange
            var instruction = new AddressInstruction(address);
            var assembler   = new HackAddressInstructionAssembler();

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

            // assert
            Assert.AreEqual(1, result.Length);
            Assert.AreEqual(expected.Replace(" ", ""), line);
        }
        public void VisitAddressInstruction_Delegates_To_AddressInstructionAssembler()
        {
            // arrange
            var computeAssembler = Substitute.For<IInstructionAssembler<ComputeInstruction>>();
            var addressAssembler = Substitute.For<IInstructionAssembler<AddressInstruction>>();
            IInstructionVisitor<string[]> visitor = new AssemblyInstructionVisitor(computeAssembler, addressAssembler);
            var instruction = new AddressInstruction(1234);

            // act
            visitor.VisitInstruction(instruction);

            // assert
            addressAssembler.Received().AssembleInstruction(Arg.Is(instruction));
        }
        public void AssembleInstruction_Returns_Binary_Representation_Of_Address_Instruction(int address, string expected)
        {
            // arrange
            var instruction = new AddressInstruction(address);
            var assembler = new HackAddressInstructionAssembler();

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

            // assert
            Assert.AreEqual(1, result.Length);
            Assert.AreEqual(expected.Replace(" ",""), line);
        }
Example #12
0
        [Test] //TODO get rid of these useless tests
        public void VisitAddressInstruction_Delegates_To_AddressInstructionAssembler()
        {
            // arrange
            var computeAssembler = Substitute.For <IInstructionAssembler <ComputeInstruction> >();
            var addressAssembler = Substitute.For <IInstructionAssembler <AddressInstruction> >();
            IInstructionVisitor <string[]> visitor = new AssemblyInstructionVisitor(computeAssembler, addressAssembler);
            var instruction = new AddressInstruction(1234);

            // act
            visitor.VisitInstruction(instruction);

            // assert
            addressAssembler.Received().AssembleInstruction(Arg.Is(instruction));
        }
Example #13
0
 public bool VisitInstruction(AddressInstruction instruction)
 {
     return(false);
 }
Example #14
0
 public string[] VisitInstruction(AddressInstruction instruction)
 {
     return(_addressAssembler.AssembleInstruction(instruction));
 }