public void ThrowExceptionWithBadOpCode()
        {
            var input        = "4,30,40,50";
            var intProcessor = new IntCodeProcessor(input);

            Should.Throw <InvalidEnumArgumentException>(() => intProcessor.FindOperation(0));
        }
        public void CreateArrayFromInput()
        {
            var input        = "1,9,10,3,2,3,11,0,99,30,40,50";
            var intProcessor = new IntCodeProcessor(input);

            intProcessor.Code.ShouldBeOfType <int[]>();
            intProcessor.Code[0].ShouldBe(1);
            intProcessor.Code[11].ShouldBe(50);
        }
        public void FindIndexToUpdate()
        {
            var input        = "1,3,3,1";
            var intProcessor = new IntCodeProcessor(input);

            int result = intProcessor.FindUpdateIndex(0);

            result.ShouldBe(1);
        }
        public void FindArgumentsToOperateOn()
        {
            var input        = "1,3,3,1";
            var intProcessor = new IntCodeProcessor(input);

            (int, int)result = intProcessor.FindArguments(0);

            result.ShouldBe((1, 1));
        }
        public void IdentifyMultiplicationCode()
        {
            var input        = "2,3,11,0";
            var intProcessor = new IntCodeProcessor(input);

            OpCodes actual = intProcessor.FindOperation(0);

            actual.ShouldBe(OpCodes.Multiplication);
        }
        public void IdentifyStopCode()
        {
            var input        = "99,30,40,50";
            var intProcessor = new IntCodeProcessor(input);

            OpCodes actual = intProcessor.FindOperation(0);

            actual.ShouldBe(OpCodes.Stop);
        }
        public void IdentifyAdditionCode()
        {
            var input        = "1,9,10,3";
            var intProcessor = new IntCodeProcessor(input);

            OpCodes actual = intProcessor.FindOperation(0);

            actual.ShouldBe(OpCodes.Addition);
        }
        public void ExecuteAdditionalSegements()
        {
            var input = "1,1,1,4,99,5,6,0,99";

            int[] expected     = new int[] { 30, 1, 1, 4, 2, 5, 6, 0, 99 };
            var   intProcessor = new IntCodeProcessor(input);

            intProcessor.RunIntCode();

            intProcessor.Code.ShouldBe(expected);
        }
        public void ExecuteAllSegements()
        {
            var input = "1,9,10,3,2,3,11,0,99,30,40,50";

            int[] expected     = new int[] { 3500, 9, 10, 70, 2, 3, 11, 0, 99, 30, 40, 50 };
            var   intProcessor = new IntCodeProcessor(input);

            intProcessor.RunIntCode();

            intProcessor.Code.ShouldBe(expected);
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            Console.WriteLine("Thank you for not trying to do this math by hand!\n\n");

            var input = "1,12,2,3,1,1,2,3,1,3,4,3,1,5,0,3,2,13,1,19,1,19,10,23,1,23,13,27,1,6,27,31,1,9,31,35,2,10,35,39,1,39,6,43,1,6,43,47,2,13,47,51,1,51,6,55,2,6,55,59,2,59,6,63,2,63,13,67,1,5,67,71,2,9,71,75,1,5,75,79,1,5,79,83,1,83,6,87,1,87,6,91,1,91,5,95,2,10,95,99,1,5,99,103,1,10,103,107,1,107,9,111,2,111,10,115,1,115,9,119,1,13,119,123,1,123,9,127,1,5,127,131,2,13,131,135,1,9,135,139,1,2,139,143,1,13,143,0,99,2,0,14,0";

            var processor = new IntCodeProcessor(input);

            processor.RunIntCode();
            Console.WriteLine($"Value at Position 0 = {processor.Code[0]}");

            Console.ReadLine();
        }
        public void ExecuteStopCodeSegment()
        {
            var input       = "1,9,10,3,2,3,11,0,99,30,40,50";
            var testSegment = new CodeSegment
            {
                Index          = 8,
                OpCode         = OpCodes.Stop,
                Arguments      = (30, 50),
                UpdatePosition = 50
            };

            int[] expected     = new int[] { 1, 9, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50 };
            var   intProcessor = new IntCodeProcessor(input);

            intProcessor.RunSegment(testSegment);

            intProcessor.Code.ShouldBe(expected);
        }
        public void GenerateCodeSegment()
        {
            var input    = "1,9,10,3,2,3,11,0,99,30,40,50";
            var expected = new CodeSegment
            {
                Index          = 0,
                OpCode         = OpCodes.Addition,
                Arguments      = (30, 40),
                UpdatePosition = 3
            };
            var intProcessor = new IntCodeProcessor(input);

            CodeSegment actual = intProcessor.GenerateCodeSegment(0);

            actual.Index.ShouldBe(expected.Index);
            actual.OpCode.ShouldBe(expected.OpCode);
            actual.Arguments.ShouldBe(expected.Arguments);
            actual.UpdatePosition.ShouldBe(expected.UpdatePosition);
        }
        public void GeneratePartialCodeSegmentIfStop()
        {
            var input    = "1,9,10,3,2,3,11,0,99,30,40,50";
            var expected = new CodeSegment
            {
                Index          = 8,
                OpCode         = OpCodes.Stop,
                Arguments      = (-1, -1),
                UpdatePosition = -1
            };
            var intProcessor = new IntCodeProcessor(input);

            CodeSegment actual = intProcessor.GenerateCodeSegment(8);

            actual.Index.ShouldBe(expected.Index);
            actual.OpCode.ShouldBe(expected.OpCode);
            actual.Arguments.ShouldBe(expected.Arguments);
            actual.UpdatePosition.ShouldBe(expected.UpdatePosition);
        }
Exemplo n.º 14
0
 public void Initialize()
 {
     _processor = new IntCodeProcessor();
 }
Exemplo n.º 15
0
 public void TestInit()
 {
     _processor = new IntCodeProcessor();
 }