public void Should_resume_reading_input_after_input_has_been_added( int[] inputsAtStart, int executions, int addedInput) { var testOpCode = 11; var prg = AssembleTestProgram(executions, testOpCode); var state = new ComputerState { Memory = prg.ToArray(), Inputs = new List <int>(inputsAtStart) }; for (int i = 0; i < executions; i++) { TestedInstruction.Execute(state); } state.Inputs.Add(addedInput); TestedInstruction.Execute(state); Assert.Equal( addedInput, state.Memory[(executions - 1) * 2]); }
public void Should_write_existing_input_before_awaiting_more_input( int[] inputsAtStart, int executions) { var testOpCode = 1; var prg = AssembleTestProgram(executions, testOpCode); var state = new ComputerState { Memory = prg.ToArray(), Inputs = new List <int>(inputsAtStart) }; for (int i = 0; i < executions; i++) { TestedInstruction.Execute(state); } for (int i = 0; i < executions - 1; i++) { Assert.Equal(inputsAtStart[i], state.Memory[i * 2]); } Assert.Equal( testOpCode, state.Memory[(executions - 1) * 2]); }
public void Should_call_ExecuteInternal_on_derived_class_with_given_state() { var state = new ComputerState(); TestedInstruction.Execute(state); Assert.True(_executeInternalExecuted, "ExecuteInternal not called."); }
public void Should_set_halt_to_true_on_state() { var state = new ComputerState(); TestedInstruction.Execute(state); Assert.True(state.Halt); }
public void Should_advance_program_counter_with_length_of_instruction() { var state = new ComputerState { Memory = new[] { 0, 0 } }; TestedInstruction.Execute(state); Assert.Equal(1, state.ProgramCounter); }
public void Should_write_value_from_addr1_to_state_output( int[] prg) { var state = new ComputerState { Memory = (int[])prg.Clone() }; TestedInstruction.Execute(state); Assert.Equal(1, state.Output[0]); }
public void Should_handle_position_mode_for_parameters( int[] prg, int expected) { var state = new ComputerState { Memory = prg }; TestedInstruction.Execute(state); Assert.Equal(expected, _actual); }
public void Should_handle_immediate_mode_for_parameters( int[] prg, int expected) { var state = new ComputerState { Memory = prg }; TestedInstruction.ParameterModes = 1 << (prg[0] - 1); TestedInstruction.Execute(state); Assert.Equal(expected, _actual); }
public void Should_store_state_input_at_addr1( int[] prg) { var state = new ComputerState { Memory = (int[])prg.Clone(), Inputs = new List <int> { 9 } }; TestedInstruction.Execute(state); Assert.Equal(state.Inputs[0], state.Memory[prg[1]]); }
public void Should_store_bool_at_addr3_showing_equality_of_in1_and_in2( int parameterMode, int[] prg, int expected) { var state = new ComputerState { Memory = prg }; TestedInstruction.ParameterModes = parameterMode; TestedInstruction.Execute(state); Assert.Equal(expected, state.Memory[4]); }
public void Should_reset_halt_and_awaitingInput_flags_after_resuming_successfully() { var prg = AssembleTestProgram(1); var state = new ComputerState { Memory = prg.ToArray() }; TestedInstruction.Execute(state); state.Inputs.Add(1337); state.Halt = false; TestedInstruction.Execute(state); Assert.False(state.AwaitingInput, "State waiting for input."); }
public void Should_set_program_counter_to_p2_when_p1_is_zero( int parameterMode, int[] prg, int expected) { var state = new ComputerState { Memory = prg }; TestedInstruction.ParameterModes = parameterMode; TestedInstruction.Execute(state); Assert.Equal(expected, state.ProgramCounter); }
public void Should_use_inputs_in_sequence() { var input = new List <int> { 9, 5 }; var state = new ComputerState { Memory = new[] { 0, 0, 0, 2 }, Inputs = input }; TestedInstruction.Execute(state); TestedInstruction.Execute(state); Assert.Equal(input, state.Inputs); Assert.Equal(9, state.Memory[0]); Assert.Equal(5, state.Memory[2]); }
public void Should_handle_mixed_parameter_modes( int parameterModes, int[] prg, int prgCounter, int expected) { TestedInstruction.ParameterModes = parameterModes; var state = new ComputerState { Memory = prg, ProgramCounter = prgCounter }; TestedInstruction.Execute(state); Assert.Equal(expected, state.Memory[0]); }
public void Should_in_addr_mode_add_values_at_addr1_and_addr2_and_write_to_addr3() { var in1 = 3; var in2 = 7; var state = new ComputerState { Memory = new[] { in1, in2, TestedInstruction.OpCode, 0, 1, 0 }, ProgramCounter = 2 }; TestedInstruction.Execute(state); Assert.Equal( in1 + in2, state.Memory[0]); }
public void Should_halt_and_set_awaitingInput_flag_when_input_is_requested_but_input_is_missing( int[] inputsAtStart, int executions) { var prg = AssembleTestProgram(executions); var state = new ComputerState { Memory = prg.ToArray(), Inputs = new List <int>(inputsAtStart) }; for (int i = 0; i < executions; i++) { TestedInstruction.Execute(state); } Assert.True(state.Halt, "State not halted."); Assert.True(state.AwaitingInput, "State not waiting for input."); }
public void Should_handle_writing_multiple_output_values() { var state = new ComputerState { Memory = new[] { 1, 0, 2, 2, 3, 4 } }; TestedInstruction.Execute(state); TestedInstruction.Execute(state); TestedInstruction.Execute(state); Assert.Equal(1, state.Output[0]); Assert.Equal(2, state.Output[1]); Assert.Equal(3, state.Output[2]); }
public void Should_in_immediate_mode_multiply_value1_and_value2_and_write_to_addr3() { var in1 = 3; var in2 = 7; var state = new ComputerState { Memory = new[] { TestedInstruction.OpCode, in1, in2, 0 } }; TestedInstruction.ParameterModes = 0b11; TestedInstruction.Execute(state); Assert.Equal( in1 * in2, state.Memory[0]); }