private async Task TestIntcodeProgramAsync(long[] memory, int input, int expectedOutput)
        {
            // Arrange
            var program = new IntcodeProgram(NullLogger <IntcodeProgram> .Instance);

            program.Init(memory);
            var output = Channel.CreateUnbounded <long>();

            // Act
            await program.RunAsync(await input.ToChannelAsync(), output);

            // Assert
            var result = await output.Reader.ReadAsync();

            Assert.Equal(expectedOutput, result);
        }
Пример #2
0
        public async Task Part1_Example3_ShouldOutputLong2()
        {
            // Arrange
            var input   = new long[] { 104, 1125899906842624, 99 };
            var program = new IntcodeProgram(NullLogger <IntcodeProgram> .Instance);

            program.Init(input);
            var output = Channel.CreateUnbounded <long>();

            // Act
            await program.RunAsync(Channel.CreateUnbounded <long>(), output);

            // Assert
            var result = await output.Reader.ReadAsync();

            Assert.Equal(1125899906842624, result);
        }
Пример #3
0
        public async Task Part1_Example2_ShouldOutputLong()
        {
            // Arrange
            var input   = new long[] { 1102, 34915192, 34915192, 7, 4, 7, 99, 0 };
            var program = new IntcodeProgram(NullLogger <IntcodeProgram> .Instance);

            program.Init(input);
            var output = Channel.CreateUnbounded <long>();

            // Act
            await program.RunAsync(Channel.CreateUnbounded <long>(), output);

            // Assert
            var result = await output.Reader.ReadAsync();

            Assert.Equal(1219070632396864, result);
        }
Пример #4
0
        public async Task Part1_Example1_ShouldOutputItself()
        {
            // Arrange
            var input   = new long[] { 109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0, 99 };
            var program = new IntcodeProgram(NullLogger <IntcodeProgram> .Instance);

            program.Init(input);
            var output = Channel.CreateUnbounded <long>();

            // Act
            await program.RunAsync(Channel.CreateUnbounded <long>(), output);

            // Assert
            var result = await output.Reader.ReadAllAsync().ToListAsync();

            Assert.Equal(input, result);
        }
Пример #5
0
        public async Task Part1_Example4_ShouldInputSupportRelativeMode()
        {
            // Arrange
            var input = new long[]
            {
                9, 1,    // adjust relative base int position 1
                203, 4,  // input relative into (1 + 4) where is -1 now
                104, -1, // -1 is now the input, output it
                99
            };
            var program = new IntcodeProgram(NullLogger <IntcodeProgram> .Instance);

            program.Init(input);
            var output = Channel.CreateUnbounded <long>();

            // Act
            await program.RunAsync(await 1000.ToChannelAsync(), output);

            // Assert
            var result = await output.Reader.ReadAsync();

            Assert.Equal(1000, result);
        }