@Test
public void testPatchLabels() {

    List<Instruction> instructions = Arrays.asList(
            new Instruction(InstructionType.INSTRUCTION, "init", Assembler.opcodes.get("ldc"), 89L, null, null, null, 1),
            new Instruction(InstructionType.INSTRUCTION, "space", Assembler.opcodes.get("#empty"), 0L, null, null, null, 2),
            new Instruction(InstructionType.INSTRUCTION, null, Assembler.opcodes.get("#empty"), 0L, null, null, null, 2),
            new Instruction(InstructionType.INSTRUCTION, null, Assembler.opcodes.get("#empty"), 0L, null, null, null, 2),
            new Instruction(InstructionType.INSTRUCTION, "~configuration", Assembler.opcodes.get("confio"), null, null, null, null, 3),
            new Instruction(InstructionType.INSTRUCTION, "alabel", Assembler.opcodes.get("ajw"), -10L, null, null, null, 4),
            new Instruction(InstructionType.INSTRUCTION, null, Assembler.opcodes.get("ldlp"), 0L, null, null, null, 5),
            new Instruction(InstructionType.INSTRUCTION, "jump", Assembler.opcodes.get("j"), null, "~configuration", null, null, 7),
            new Instruction(InstructionType.INSTRUCTION, "end", Assembler.opcodes.get("ldc"), 0L, null, null, null, 8)
    );
    Map<String, Long> labelMap = new HashMap<>();
    labelMap.put("init", 0L);
    labelMap.put("space", 1L);
    labelMap.put("~configuration", 4L);
    labelMap.put("alabel", 5L);
    labelMap.put("jump", 7L);
    labelMap.put("end", 8L);
    Assembly patchedAssembly = Assembler.patchLabels(new Assembly(instructions, labelMap));
    checkInstructionEquality(
            new Instruction(InstructionType.INSTRUCTION, "init", Assembler.opcodes.get("pfix"), 5L, null, null, null, 1),
            patchedAssembly.instructions.get(0)
    );
    checkInstructionEquality(
            new Instruction(InstructionType.INSTRUCTION, null, Assembler.opcodes.get("ldc"), 9L, null, null, null, 1),
            patchedAssembly.instructions.get(1)
    );
    checkInstructionEquality(
            new Instruction(InstructionType.INSTRUCTION, "space", Assembler.opcodes.get("#empty"), 0L, null, null, null, 2),
            patchedAssembly.instructions.get(2)
    );
    checkInstructionEquality(
            new Instruction(InstructionType.INSTRUCTION, null, Assembler.opcodes.get("#empty"), 0L, null, null, null, 2),
            patchedAssembly.instructions.get(3)
    );
    checkInstructionEquality(
            new Instruction(InstructionType.INSTRUCTION, null, Assembler.opcodes.get("#empty"), 0L, null, null, null, 2),
            patchedAssembly.instructions.get(4)
    );
    checkInstructionEquality(
            new Instruction(InstructionType.INSTRUCTION, "~configuration", Assembler.opcodes.get("confio"), null, null, null, null, 3),
            patchedAssembly.instructions.get(5)
    );
    checkInstructionEquality(
            new Instruction(InstructionType.INSTRUCTION, "alabel", Assembler.opcodes.get("nfix"), 0L, null, null, null, 4),
            patchedAssembly.instructions.get(6)
    );
    checkInstructionEquality(
            new Instruction(InstructionType.INSTRUCTION, null, Assembler.opcodes.get("ajw"), 6L, null, null, null, 4),
            patchedAssembly.instructions.get(7)
    );
    checkInstructionEquality(
            new Instruction(InstructionType.INSTRUCTION, null, Assembler.opcodes.get("ldlp"), 0L, null, null, null, 5),
            patchedAssembly.instructions.get(8)
    );
    checkInstructionEquality(
            new Instruction(InstructionType.INSTRUCTION, "jump", Assembler.opcodes.get("j"), null, "~configuration", null, null, 7),
            patchedAssembly.instructions.get(9)
    );
    checkInstructionEquality(
            new Instruction(InstructionType.INSTRUCTION, "end", Assembler.opcodes.get("ldc"), 0L, null, null, null, 8),
            patchedAssembly.instructions.get(10)
    );
    assertEquals(new Long(0), patchedAssembly.labelMap.get("init"));
    assertEquals(new Long(2), patchedAssembly.labelMap.get("space"));
    assertEquals(new Long(5), patchedAssembly.labelMap.get("~configuration"));
    assertEquals(new Long(6), patchedAssembly.labelMap.get("alabel"));
    assertEquals(new Long(9), patchedAssembly.labelMap.get("jump"));
    assertEquals(new Long(17), patchedAssembly.labelMap.get("end"));
}