public void Should_calculate_instruction_length_from_start_index(string program, int startIndex, int expected)
        {
            var jumpIfFalseProgram = new JumpIfFalseProgram(new IntCodeValidator());

            jumpIfFalseProgram.Process(program, startIndex);
            Assert.That(jumpIfFalseProgram.InstructionLength, Is.EqualTo(expected));
        }
        public void Accepts_parameter_mode_immediate(string program, int expected)
        {
            var jumpIfFalseProgram = new JumpIfFalseProgram(new IntCodeValidator());

            jumpIfFalseProgram.Process(program);
            Assert.That(jumpIfFalseProgram.InstructionLength, Is.EqualTo(expected));
        }
        public void DoesNothing_when_parameter_is_not_zero(string program)
        {
            var jumpIfFalseProgram = new JumpIfFalseProgram(new IntCodeValidator());

            Assert.That(jumpIfFalseProgram.Process(program), Is.EqualTo(string.Empty), "Program should not change");
            Assert.That(jumpIfFalseProgram.InstructionLength, Is.EqualTo(3));
        }
        public void Should_validate_op_code_6(string program)
        {
            var jumpIfTrueProgram = new JumpIfFalseProgram(new IntCodeValidator());
            var ex = Assert.Throws <InvalidOpCodeException>(() => jumpIfTrueProgram.Process(program));

            Assert.That(ex.Message, Does.Contain("Invalid input: op code (first integer)"));
        }
        public void Sets_instruction_pointer_increment_to_move_to_position_given_at_index(string program, int expectedInputPosition)
        {
            var startIndex  = 0;
            var jumpProgram = new JumpIfFalseProgram(new IntCodeValidator());

            jumpProgram.Process(program, startIndex);
            startIndex += jumpProgram.InstructionLength;
            Assert.That(startIndex, Is.EqualTo(expectedInputPosition));
        }
        public void Should_validate_input_is_a_valid_program()
        {
            var validatorSpy = A.Fake <IIntCodeValidator>();
            var jumpIfTrue   = new JumpIfFalseProgram(validatorSpy);
            var program      = "a,0,99,0";

            A.CallTo(() => validatorSpy.SplitString(program)).Returns(new IntCodeValidator().SplitString(program));
            Assert.Throws <Exception>(() => jumpIfTrue.Process(program));
            A.CallTo(() => validatorSpy.Validate(program)).MustHaveHappened();
        }