def test_scenario1(values): """Test CMC instruction functionality.""" chip_test = Processor() chip_base = Processor() # Perform the instruction under test: chip_test.PROGRAM_COUNTER = 0 chip_test.CARRY = values[0] # Simulate conditions at end of instruction in base chip chip_base.PROGRAM_COUNTER = 0 chip_base.increment_pc(1) chip_base.CARRY = values[1] # Carry out the instruction under test # Perform a CMC operation Processor.cmc(chip_test) # Make assertions that the base chip is now at the same state as # the test chip which has been operated on by the instruction under test. assert chip_test.read_program_counter() == chip_base.read_program_counter() assert chip_test.read_carry() == chip_base.read_carry() # Pickling each chip and comparing will show equality or not. assert pickle.dumps(chip_test) == pickle.dumps(chip_base)
def test_scenario1(values): """Test ADD instruction functionality.""" chip_test = Processor() chip_base = Processor() rr = random.randint(0, 15) # Select a random value # Perform the instruction under test: chip_test.PROGRAM_COUNTER = 0 chip_test.set_accumulator(values[1]) chip_test.CARRY = values[0] chip_test.insert_register(rr, values[2]) # Simulate conditions at end of instruction in base chip chip_base.PROGRAM_COUNTER = 0 chip_base.increment_pc(1) chip_base.CARRY = values[4] chip_base.set_accumulator(values[3]) chip_base.insert_register(rr, values[2]) # Carry out the instruction under test # Perform aN ADD operation Processor.add(chip_test, rr) # Make assertions that the base chip is now at the same state as # the test chip which has been operated on by the instruction under test. assert chip_test.read_program_counter() == chip_base.read_program_counter() assert chip_test.read_carry() == chip_base.read_carry() assert chip_test.read_accumulator() == chip_base.read_accumulator() # Pickling each chip and comparing will show equality or not. assert pickle.dumps(chip_test) == pickle.dumps(chip_base)
def test_adm_scenario1(values): """Test ADM instruction functionality.""" chip_test = Processor() chip_base = Processor() rambank = values[0] chip = values[1] register = values[2] address = values[3] value = values[4] accumulator = 2 cr = encode_command_register(chip, register, address, 'DATA_RAM_CHAR') chip_test.CARRY = 0 chip_test.COMMAND_REGISTER = cr chip_test.CURRENT_RAM_BANK = rambank absolute_address = convert_to_absolute_address( chip_test, rambank, chip, register, address) chip_test.RAM[absolute_address] = value chip_test.set_accumulator(accumulator) Processor.adm(chip_test) # Simulate conditions at end of instruction in base chip chip_base.CARRY = 0 chip_base.COMMAND_REGISTER = cr absolute_address = convert_to_absolute_address( chip_base, rambank, chip, register, address) chip_base.RAM[absolute_address] = value chip_base.increment_pc(1) chip_base.CURRENT_RAM_BANK = rambank chip_base.set_accumulator(value + accumulator) # Make assertions that the base chip is now at the same state as # the test chip which has been operated on by the instruction under test. assert chip_test.read_program_counter() == chip_base.read_program_counter() assert chip_test.read_accumulator() == chip_base.read_accumulator() # Pickling each chip and comparing will show equality or not. assert pickle.dumps(chip_test) == pickle.dumps(chip_base)
def test_adm_scenario1(rambank, chip, register, address, value, accumulator, carry): """Test ADM instruction functionality.""" chip_test = Processor() chip_base = Processor() cr = encode_command_register(chip, register, address, 'DATA_RAM_CHAR') chip_test.CARRY = carry chip_test.COMMAND_REGISTER = cr chip_test.CURRENT_RAM_BANK = rambank absolute_address = convert_to_absolute_address( chip_test, rambank, chip, register, address) chip_test.RAM[absolute_address] = value chip_test.set_accumulator(accumulator) Processor.sbm(chip_test) # Simulate conditions at end of instruction in base chip chip_base.CARRY = carry chip_base.COMMAND_REGISTER = cr absolute_address = convert_to_absolute_address( chip_base, rambank, chip, register, address) chip_base.RAM[absolute_address] = value chip_base.increment_pc(1) chip_base.CURRENT_RAM_BANK = rambank chip_base.set_accumulator(accumulator) value_complement = int(ones_complement(value, 4), 2) carry_complement = chip_base.read_complement_carry() chip_base.ACCUMULATOR = (chip_base.ACCUMULATOR + value_complement + carry_complement) Processor.check_overflow(chip_base) # Make assertions that the base chip is now at the same state as # the test chip which has been operated on by the instruction under test. assert chip_test.read_program_counter() == chip_base.read_program_counter() assert chip_test.read_accumulator() == chip_base.read_accumulator() # Pickling each chip and comparing will show equality or not. assert pickle.dumps(chip_test) == pickle.dumps(chip_base)