def test_immediate_to_binary_signed(): test.assertEquals(asm.immediate_to_binary_signed('0b111', 4), '0111') test.assertEquals(asm.immediate_to_binary_signed('-1', 4), '1' * 4) test.assert_exception(asm.immediate_to_binary_signed, ['0b11', 1], errors.immediate_out_of_range_exception) test.assert_exception(asm.immediate_to_binary_signed, ['-0b11', 2], errors.immediate_out_of_range_exception)
def test_write_regs(): test.assertEquals(asm.write_regs('R11', '0' * 6), '0' * 5 + get_register_string(11)) test.assert_exception(asm.write_regs, ['R45', '0' * 32], errors.illegal_register_number_exception) test.assertEquals( asm.write_regs('R15 R15', '0' * 32), '0' * 5 + get_register_string(15) + get_register_string(15) + '0' * 15)
def test_get_opcode(): test.assertEquals(asm.get_opcode(['+'], '+'), '00000') test.assertEquals(asm.get_opcode(['+', '-', '/'], '+'), '00000') test.assertEquals(asm.get_opcode([], '+'), '') test.assert_exception(asm.get_opcode, [['+'], 'get'], errors.invalid_command_exception) test.assert_exception(asm.get_opcode, [['-'], '+'], errors.invalid_command_exception)
def test_get_registers(): test.assertEquals(asm.get_registers('R12'), [get_register_string(12)]) test.assertEquals(asm.get_registers('0xFF'), []) test.assertEquals(asm.get_registers('R1'), [get_register_string(1)]) test.assertEquals(asm.get_registers('hallo R1 hallo R2'), [get_register_string(1), get_register_string(2)]) test.assert_exception(asm.get_registers, ['R45'], errors.illegal_register_number_exception)
def test_immediate_to_binary_unsigned(): test.assertEquals(asm.immediate_to_binary_unsigned('0b11', 2), '11') test.assertEquals(asm.immediate_to_binary_unsigned('0xF', 4), '1111') test.assertEquals(asm.immediate_to_binary_unsigned('15', 4), '1111') test.assert_exception(asm.immediate_to_binary_unsigned, ['-11', 20], errors.immediate_out_of_range_exception) test.assert_exception(asm.immediate_to_binary_unsigned, ['0b1111', 3], errors.immediate_out_of_range_exception) test.assert_exception(asm.immediate_to_binary_unsigned, ['0b100', 2], errors.immediate_out_of_range_exception)
def test_write_regs_idx(): test.assertEquals( asm.write_regs_idx('R11 R13 hallo R13', '0' * 18, [0, 6, 12]), get_register_string(11) + get_register_string(13) + get_register_string(13)) test.assertEquals(asm.write_regs_idx('', '0' * 32, []), '0' * 32) test.assert_exception(asm.write_regs_idx, ['R11', '0' * 32, [0, 7]], errors.illegal_number_of_indexes_exception) test.assert_exception(asm.write_regs_idx, ['R43', '0' * 32, [0]], errors.illegal_register_number_exception) test.assert_exception(asm.write_regs_idx, ['', '0' * 32, [0]], errors.illegal_number_of_indexes_exception)