コード例 #1
0
        public void Example_program_1()
        {
            var cpu = new CPU
            {
                Program = new List <Instruction>
                {
                    new NoOperation(0),
                    new Accumulate(1),
                    new Jump(4),
                    new Accumulate(3),
                    new Jump(-3),
                    new Accumulate(-99),
                    new Accumulate(1),
                    new Jump(-4),
                    new Accumulate(6)
                }
            };

            AssertAsync.CompletesIn(3, () =>
            {
                cpu.Run();
            });

            Assert.Equal(5, cpu.Accumulator);
        }
コード例 #2
0
        public void TestOutput(uint[][] rows, uint[][] columns)
        {
            var solve = new Solver();

            AssertAsync.CompletesIn(5, () =>
            {
                var result = solve.Run(rows, columns);

                output.WriteLine(GraphicsHelper.Map(result));
            });
        }
コード例 #3
0
        public void Puzzle_8A()
        {
            var cpu = new CPU();

            new ProgramLoader().Load(PuzzleInputs.Puzzle8, cpu);

            AssertAsync.CompletesIn(1, () =>
            {
                cpu.Run();
            });

            Assert.Equal(1451, cpu.Accumulator);
        }
コード例 #4
0
            public void Should_stop_execution_on_halt()
            {
                InstructionDecoderMock
                .Setup(x => x.Decode(It.IsAny <ComputerState>()))
                .Callback((ComputerState state) =>
                {
                    state.Instruction = new Halt();
                });

                Computer.State.Memory = new[] { 0 };

                AssertAsync
                .CompletesIn(1, () => Computer.Run())
                .Wait();

                Assert.True(Computer.State.Halt, "Not halted.");
            }
コード例 #5
0
            public void Run_will_halt_when_before_executing_an_instruction_a_second_time()
            {
                var cpu = new CPU
                {
                    Program = new List <Instruction>
                    {
                        new Accumulate(1),
                        new Jump(-1)
                    }
                };

                AssertAsync.CompletesIn(1, () =>
                {
                    cpu.Run();
                });

                Assert.Equal(1, cpu.Accumulator);
            }