コード例 #1
0
  @Test
  public void testComparisonZeroNE() {
    // x != 0 vs x == 0
    assertEquals(
        0.0, ReplaceComparisonOperator.getInfectionDistance(0, Opcodes.IFNE, Opcodes.IFEQ), 0.0);
    assertEquals(
        0.0, ReplaceComparisonOperator.getInfectionDistance(1, Opcodes.IFNE, Opcodes.IFEQ), 0.0);
    assertEquals(
        0.0, ReplaceComparisonOperator.getInfectionDistance(-1, Opcodes.IFNE, Opcodes.IFEQ), 0.0);

    // x != 0 vs x < 0
    assertEquals(
        1.0, ReplaceComparisonOperator.getInfectionDistance(0, Opcodes.IFNE, Opcodes.IFLT), 0.0);
    assertEquals(
        0.0, ReplaceComparisonOperator.getInfectionDistance(1, Opcodes.IFNE, Opcodes.IFLT), 0.0);
    assertEquals(
        2.0, ReplaceComparisonOperator.getInfectionDistance(-1, Opcodes.IFNE, Opcodes.IFLT), 0.0);

    // x != 0 vs x <= 0
    assertEquals(
        0.0, ReplaceComparisonOperator.getInfectionDistance(0, Opcodes.IFNE, Opcodes.IFLE), 0.0);
    assertEquals(
        0.0, ReplaceComparisonOperator.getInfectionDistance(1, Opcodes.IFNE, Opcodes.IFLE), 0.0);
    assertEquals(
        1.0, ReplaceComparisonOperator.getInfectionDistance(-1, Opcodes.IFNE, Opcodes.IFLE), 0.0);

    // x != 0 vs x > 0
    assertEquals(
        1.0, ReplaceComparisonOperator.getInfectionDistance(0, Opcodes.IFNE, Opcodes.IFGT), 0.0);
    assertEquals(
        2.0, ReplaceComparisonOperator.getInfectionDistance(1, Opcodes.IFNE, Opcodes.IFGT), 0.0);
    assertEquals(
        0.0, ReplaceComparisonOperator.getInfectionDistance(-1, Opcodes.IFNE, Opcodes.IFGT), 0.0);

    // x != 0 vs x >= 0
    assertEquals(
        0.0, ReplaceComparisonOperator.getInfectionDistance(0, Opcodes.IFNE, Opcodes.IFGE), 0.0);
    assertEquals(
        1.0, ReplaceComparisonOperator.getInfectionDistance(1, Opcodes.IFNE, Opcodes.IFGE), 0.0);
    assertEquals(
        0.0, ReplaceComparisonOperator.getInfectionDistance(-1, Opcodes.IFNE, Opcodes.IFGE), 0.0);
  }
コード例 #2
0
  @Test
  public void testComparisonTwoEQ2() {
    // x == 0 vs x != 0
    assertEquals(
        0.0,
        ReplaceComparisonOperator.getInfectionDistance(
            10, 10, Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPNE),
        0.0);
    assertEquals(
        0.0,
        ReplaceComparisonOperator.getInfectionDistance(
            11, 10, Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPNE),
        0.0);
    assertEquals(
        0.0,
        ReplaceComparisonOperator.getInfectionDistance(
            -11, 10, Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPNE),
        0.0);

    // x == 0 vs x < 0
    assertEquals(
        0.0,
        ReplaceComparisonOperator.getInfectionDistance(
            10, 10, Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPLT),
        0.0);
    assertEquals(
        1.0,
        ReplaceComparisonOperator.getInfectionDistance(
            11, 10, Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPLT),
        0.0);
    assertEquals(
        0.0,
        ReplaceComparisonOperator.getInfectionDistance(
            -11, 10, Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPLT),
        0.0);

    // x == 0 vs x <= 0
    assertEquals(
        1.0,
        ReplaceComparisonOperator.getInfectionDistance(
            10, 10, Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPLE),
        0.0);
    assertEquals(
        2.0,
        ReplaceComparisonOperator.getInfectionDistance(
            11, 10, Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPLE),
        0.0);
    assertEquals(
        0.0,
        ReplaceComparisonOperator.getInfectionDistance(
            -11, 10, Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPLE),
        0.0);

    // x == 0 vs x > 0
    assertEquals(
        0.0,
        ReplaceComparisonOperator.getInfectionDistance(
            10, 10, Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPGT),
        0.0);
    assertEquals(
        0.0,
        ReplaceComparisonOperator.getInfectionDistance(
            11, 10, Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPGT),
        0.0);
    assertEquals(
        21.0,
        ReplaceComparisonOperator.getInfectionDistance(
            -11, 10, Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPGT),
        0.0);

    // x == 0 vs x >= 0
    assertEquals(
        1.0,
        ReplaceComparisonOperator.getInfectionDistance(
            10, 10, Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPGE),
        0.0);
    assertEquals(
        0.0,
        ReplaceComparisonOperator.getInfectionDistance(
            11, 10, Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPGE),
        0.0);
    assertEquals(
        22.0,
        ReplaceComparisonOperator.getInfectionDistance(
            -11, 10, Opcodes.IF_ICMPEQ, Opcodes.IF_ICMPGE),
        0.0);
  }