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_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)
def test_get_label_values_dictionary(): test.assertEquals(lb.get_label_values_dictionary(['R4 = R5 _label']), {'label': 'R4 = R5 '}) test.assertEquals( lb.get_label_values_dictionary(['R4 = R5 _label #hier nicht']), {}) test.assertEquals(lb.get_label_values_dictionary([' _label']), {'label': ' '}) test.assertEquals(lb.get_label_values_dictionary(['R4 = R5 _?']), {})
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_cut_comments(): test.assertEquals(lb.cut_comments(['hallo welt _sdf #hier erst cutten']), ['hallo welt _sdf ']) test.assertEquals(lb.cut_comments(['hallo welt _sdf#hier erst cutten']), ['hallo welt _sdf']) test.assertEquals( lb.cut_comments( ['hallo welt #hier erst cutten _keine_labels_mitzählen']), ['hallo welt ']) test.assertEquals(lb.cut_comments(['#hallo welt _sdf #hier erst cutten']), [''])
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_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_not_command(): command = 'R4 = ~R4' test.assert_not_equals(asm.not_command(command)[0], command) test.assertEquals(asm.not_command('R5 = ~R5')[0], 'R5 ~ R5')
def test_get_binary_string_for_command(): test.assertEquals( asm.get_binary_string_for_command(rules['arithmetic'], 'R14 = R1 + R31'), '00000001110000001011111' + '0' * 9) test.assertEquals( asm.get_binary_string_for_command(rules['not'], 'R15 ~ R25'), '10010001111011001' + '0' * (32 - (2 * 6 + 5))) test.assertEquals( asm.get_binary_string_for_command(rules['shift'], 'R2 = R17 << R28 times'), '10100000010010001011100' + '0' * (32 - (3 * 6 + 5))) test.assertEquals( asm.get_binary_string_for_command(rules['copy'], 'copy R4 to R18'), '00001010010000100' + '0' * (32 - 17)) test.assertEquals( asm.get_binary_string_for_command(rules['set'], 'R31 set 1'), '00010011111' + '0' * 20 + '1') test.assertEquals( asm.get_binary_string_for_command(rules['set'], 'R31 set -1'), '00010011111' + '1' * 21) test.assertEquals( asm.get_binary_string_for_command( rules['get_compare_information_compare'], 'get_compare_information_compare= R5 = R6'), '00011' + '0' * 6 + get_register_string(5) + get_register_string(6) + '0' * 9) test.assertEquals( asm.get_binary_string_for_command(rules['jump'], 'jump to R4'), '00110' + '0' * 6 + get_register_string(4) + '0' * (32 - 17)) test.assertEquals( asm.get_binary_string_for_command(rules['jump_rel'], 'jump_rel to -1'), '00111' + '1' * (32 - 5)) test.assertEquals( asm.get_binary_string_for_command(rules['jump_rel'], 'jump_rel to 1'), '00111' + '0' * (32 - 6) + '1') test.assertEquals( asm.get_binary_string_for_command(rules['noop_halt'], 'noop'), '01100' + '0' * (32 - 5)) test.assertEquals( asm.get_binary_string_for_command(rules['store'], 'store R4 to R4 + 32767'), '01011000100000100' + '1' * 15) test.assertEquals( asm.get_binary_string_for_command(rules['load'], 'load R4 + 32767 to R5'), '01010000101000100' + '1' * 15)
def test_cut_whitespace_lines(): test.assertEquals(lb.cut_whitespace_lines(['']), []) test.assertEquals(lb.cut_whitespace_lines(['\t', 'a']), ['a']) test.assertEquals(lb.cut_whitespace_lines(['\n']), []) test.assertEquals(lb.cut_whitespace_lines(['hallo', '', 'hallo']), ['hallo', 'hallo'])
def test_cut_labels(): test.assertEquals(lb.cut_labels(['hallo welt _sdf']), ['hallo welt']) test.assertEquals(lb.cut_labels(['hallo welt_sdf']), ['hallo welt_sdf']) test.assertEquals(lb.cut_labels(['hallo_welt _sdf']), ['hallo_welt']) test.assertEquals(lb.cut_labels(['hallo welt _sdf usw ']), ['hallo welt _sdf usw ']) test.assertEquals(lb.cut_labels(['hallo welt _??']), ['hallo welt _??']) test.assertEquals(lb.cut_labels(['']), [''])
def test_necessary_byte_storage(): test.assertEquals(lb.necessary_byte_storage('R4 = R5 + R6'), 4) test.assertEquals(lb.necessary_byte_storage('\t'), 0) test.assertEquals(lb.necessary_byte_storage('0xFFFFFF'), 3) test.assertEquals(lb.necessary_byte_storage('0'), 1) test.assertEquals(lb.necessary_byte_storage('256'), 2) test.assertEquals(lb.necessary_byte_storage('255'), 1)
def test_get_datastring_indexes(): test.assertEquals(datastr.get_datastring_indexes(['R4 = R5 + R6']), []) test.assertEquals(datastr.get_datastring_indexes(['R4 = R5 + R6', '0xFF']), [1]) test.assertEquals( datastr.get_datastring_indexes(['R4 = R5 + R6', '0b101011']), [1]) test.assertEquals(datastr.get_datastring_indexes(['R4 = R5 + R6', '124']), [1]) test.assertEquals(datastr.get_datastring_indexes(['R4 = R5 + R6', '-124']), [1]) test.assertEquals(datastr.get_datastring_indexes(['0xFf', '-124']), [0, 1]) test.assertEquals(datastr.get_datastring_indexes(['-0xFf', '-124']), [1])