Exemple #1
0
        public void Should_check_int_code_at_start_position()
        {
            var validator = new IntCodeValidator();
            var adder     = new AdderProgram(validator);
            var input     = "27,0,0,0,1,0,0,0";

            Assert.DoesNotThrow(() => adder.Process(input, 4));
        }
Exemple #2
0
        public void Should_validate_op_code_is_two(string input)
        {
            var validator = new IntCodeValidator();
            var m         = new MultiplierProgram(validator);
            var ex        = Assert.Throws <InvalidOpCodeException>(() => m.Process(input));

            Assert.That(ex.Message, Is.EqualTo("Invalid input: op code (first integer)"));
        }
Exemple #3
0
        public void Program_should_accepT_argument_for_positions()
        {
            var validator  = new IntCodeValidator();
            var input      = "1,9,10,3,2,3,11,0,1,2,3,3,99,30,40,50";
            var adder      = new AdderProgram(validator);
            var multiplier = new MultiplierProgram(validator);

            Assert.DoesNotThrow(() => multiplier.Process(input, 4));
            Assert.That(multiplier.Process(input, 4), Is.EqualTo("9,9,10,3,2,3,11,0,1,2,3,3,99,30,40,50"));
            Assert.DoesNotThrow(() => adder.Process(input, 8));
        }
Exemple #4
0
        public void Solution()
        {
            using (var sr = new StreamReader(TestContext.CurrentContext.TestDirectory + "\\TestData\\day2.txt"))
            {
                var validator = new IntCodeValidator();
                var input     = sr.ReadToEnd();
                var modified  = validator.SplitString(input).ToArray();
                modified[1] = 12;
                modified[2] = 2;
                input       = validator.Join(modified);

                var actual = new RecursiveProgram(new IntCodeValidator(), new IntCodeProgramFactory()).Process(input);
                Assert.That(validator.SplitString(actual).First(), Is.EqualTo(4690667));
            }
        }