public void VisitComputeInstruction_Delegates_To_ComputeInstructionAssembler() { // arrange var computeAssembler = Substitute.For<IInstructionAssembler<ComputeInstruction>>(); var addressAssembler = Substitute.For<IInstructionAssembler<AddressInstruction>>(); IInstructionVisitor<string[]> visitor = new AssemblyInstructionVisitor(computeAssembler, addressAssembler); var instruction = new ComputeInstruction(ComputeDestinationType.Memory, "A-D", ComputeJumpType.JMP); // act visitor.VisitInstruction(instruction); // assert computeAssembler.Received().AssembleInstruction(Arg.Is(instruction)); }
public void VisitComputeInstruction_Delegates_To_ComputeInstructionAssembler() { // arrange var computeAssembler = Substitute.For <IInstructionAssembler <ComputeInstruction> >(); var addressAssembler = Substitute.For <IInstructionAssembler <AddressInstruction> >(); IInstructionVisitor <string[]> visitor = new AssemblyInstructionVisitor(computeAssembler, addressAssembler); var instruction = new ComputeInstruction(ComputeDestinationType.Memory, "A-D", ComputeJumpType.JMP); // act visitor.VisitInstruction(instruction); // assert computeAssembler.Received().AssembleInstruction(Arg.Is(instruction)); }
public void AssembleInstruction_Returns_Single_Line() { // arrange var instruction = new ComputeInstruction(ComputeDestinationType.None, "D+1", ComputeJumpType.None); var computeBitsAssembler = Substitute.For <IHackComputeBitsAssembler>(); computeBitsAssembler.AssembleComputeBits(Arg.Any <string>()).Returns("0000000"); var assembler = new HackComputeInstructionAssembler(computeBitsAssembler); // act string[] result = assembler.AssembleInstruction(instruction); // assert Assert.AreEqual(1, result.Length); }
public void AssembleInstruction_Returns_Line_Starts_With_Three_Digits() { // arrange var instruction = new ComputeInstruction(ComputeDestinationType.None, "D+1", ComputeJumpType.None); 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("111", line.Substring(0, 3)); }
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_16_Bit_Line() { // arrange var instruction = new ComputeInstruction(ComputeDestinationType.None, "D+1", ComputeJumpType.None); 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(16, line.Length); }
public void AssembleInstruction_Returns_Correct_Dest_Bits(ComputeDestinationType destinationType, string expected) { // arrange var instruction = new ComputeInstruction(destinationType, "D&A", ComputeJumpType.None); 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_Line_Starts_With_Three_Digits() { // arrange var instruction = new ComputeInstruction(ComputeDestinationType.None, "D+1", ComputeJumpType.None); 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("111", line.Substring(0, 3)); }
public bool VisitInstruction(ComputeInstruction instruction) { return(false); }
public string[] VisitInstruction(ComputeInstruction instruction) { return(_computeAssembler.AssembleInstruction(instruction)); }