Skip to content

Unresolved links for some invokes for IntMath code example #1326

Closed
@amandelpie

Description

@amandelpie

Description

Very strange unresolved name for in the @utbot.invokes custom tag
@utbot.invokes {@link IntMath.1#<clinit>()}

To Reproduce

  1. Run the the IntMath example in IntelliJ Idea
  2. Set up Symbolic = 100%
  3. Use plugin to generate tests
  4. Open the generated test

Use this snippet of code to generate tests:

package custom.math;

import java.math.RoundingMode;

public class IntMath {
    /**
     * The biggest half power of two that can fit in an unsigned int.
     */
    static final int MAX_POWER_OF_SQRT2_UNSIGNED = 0xB504F333;

    public static int log2(int x, RoundingMode mode) {
        switch (mode) {
            case UNNECESSARY:
                // fall through
            case DOWN:
            case FLOOR:
                return (Integer.SIZE - 1) - Integer.numberOfLeadingZeros(x);

            case UP:
            case CEILING:
                return Integer.SIZE - Integer.numberOfLeadingZeros(x - 1);

            case HALF_DOWN:
            case HALF_UP:
            case HALF_EVEN:
                // Since sqrt(2) is irrational, log2(x) - logFloor cannot be exactly 0.5
                int leadingZeros = Integer.numberOfLeadingZeros(x);
                int cmp = MAX_POWER_OF_SQRT2_UNSIGNED >>> leadingZeros;
                // floor(2^(logFloor + 0.5))
                int logFloor = (Integer.SIZE - 1) - leadingZeros;
                return logFloor + lessThanBranchFree(cmp, x);

            default:
                throw new AssertionError();
        }
    }

    static int lessThanBranchFree(int x, int y) {
        // The double negation is optimized away by normal Java, but is necessary for GWT
        // to make sure bit twiddling works as expected.
        return ~~(x - y) >>> (Integer.SIZE - 1);
    }

    public static int pow(int b, int k) {
        switch (b) {
            case 0:
                return (k == 0) ? 1 : 0;
            case 1:
                return 1;
            case (-1):
                return ((k & 1) == 0) ? 1 : -1;
            case 2:
                return (k < Integer.SIZE) ? (1 << k) : 0;
            case (-2):
                if (k < Integer.SIZE) {
                    return ((k & 1) == 0) ? (1 << k) : -(1 << k);
                } else {
                    return 0;
                }
            default:
                // continue below to handle the general case
        }
        for (int accum = 1; ; k >>= 1) {
            switch (k) {
                case 0:
                    return accum;
                case 1:
                    return b * accum;
                default:
                    accum *= ((k & 1) == 0) ? 1 : b;
                    b *= b;
            }
        }
    }
}

Expected behavior

Correctly resolved links.

Actual behavior
This snippet is wrong

    ///region Test suites for executable custom.math.IntMath.log2

    ///region SYMBOLIC EXECUTION: ERROR SUITE for method log2(int, java.math.RoundingMode)

    /**
     * @utbot.classUnderTest {@link IntMath}
     * @utbot.methodUnderTest {@link IntMath#log2(int, RoundingMode)}
     * @utbot.invokes {@link IntMath.1#<clinit>()}
     * @utbot.invokes {@link RoundingMode#ordinal()}
     * @utbot.throwsException {@link NullPointerException} in: mode
     */
    @Test
    @DisplayName("log2: switch(mode) case:  -> ThrowNullPointerException")
    public void testLog2_RoundingModeOrdinal() {
        /* This test fails because method [custom.math.IntMath.log2] produces [java.lang.NullPointerException]
            custom.math.IntMath.log2(IntMath.java:12) */
        IntMath.log2(128, null);
    }
    ///endregion

from the whole generated file

package custom.math;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DisplayName;

import java.math.RoundingMode;

import static org.junit.jupiter.api.Assertions.assertEquals;

public final class IntMathTest {
    ///region Test suites for executable custom.math.IntMath.lessThanBranchFree

    ///region SYMBOLIC EXECUTION: SUCCESSFUL EXECUTIONS for method lessThanBranchFree(int, int)

    /**
     * @utbot.classUnderTest {@link IntMath}
     * @utbot.methodUnderTest {@link IntMath#lessThanBranchFree(int, int)}
     * @utbot.returnsFrom {@code return ~~(x - y) >>> (Integer.SIZE - 1);}
     */
    @Test
    @DisplayName("lessThanBranchFree: -> return ~~(x - y) >>> (Integer.SIZE - 1)")
    public void testLessThanBranchFree_ReturnBitwiseComplementBitwiseComplementXMinusYUnsignedRightShiftIntegerSIZEMinus1() {
        int actual = IntMath.lessThanBranchFree(1, -255);

        assertEquals(0, actual);
    }
    ///endregion

    ///endregion

    ///region Test suites for executable custom.math.IntMath.log2

    ///region SYMBOLIC EXECUTION: ERROR SUITE for method log2(int, java.math.RoundingMode)

    /**
     * @utbot.classUnderTest {@link IntMath}
     * @utbot.methodUnderTest {@link IntMath#log2(int, RoundingMode)}
     * @utbot.invokes {@link IntMath.1#<clinit>()}
     * @utbot.invokes {@link RoundingMode#ordinal()}
     * @utbot.throwsException {@link NullPointerException} in: mode
     */
    @Test
    @DisplayName("log2: switch(mode) case:  -> ThrowNullPointerException")
    public void testLog2_RoundingModeOrdinal() {
        /* This test fails because method [custom.math.IntMath.log2] produces [java.lang.NullPointerException]
            custom.math.IntMath.log2(IntMath.java:12) */
        IntMath.log2(128, null);
    }
    ///endregion

    ///region OTHER: SUCCESSFUL EXECUTIONS for method log2(int, java.math.RoundingMode)

    @Test
    public void testLog21() {
        RoundingMode mode = RoundingMode.HALF_EVEN;

        int actual = IntMath.log2(512, mode);

        assertEquals(9, actual);
    }

    @Test
    public void testLog22() {
        RoundingMode mode = RoundingMode.DOWN;

        int actual = IntMath.log2(268435712, mode);

        assertEquals(28, actual);
    }

    @Test
    public void testLog23() {
        RoundingMode mode = RoundingMode.CEILING;

        int actual = IntMath.log2(128, mode);

        assertEquals(7, actual);
    }
    ///endregion

    ///endregion

    ///region Test suites for executable custom.math.IntMath.pow

    ///region SYMBOLIC EXECUTION: SUCCESSFUL EXECUTIONS for method pow(int, int)

    /**
     * @utbot.classUnderTest {@link IntMath}
     * @utbot.methodUnderTest {@link IntMath#pow(int, int)}
     * @utbot.activatesSwitch {@code case 2}
     * @utbot.returnsFrom {@code return 1;}
     */
    @Test
    @DisplayName("pow: switch(b) case: 2 -> return 1")
    public void testPow_Return1() {
        int actual = IntMath.pow(1, -255);

        assertEquals(1, actual);
    }

    /**
     * @utbot.classUnderTest {@link IntMath}
     * @utbot.methodUnderTest {@link IntMath#pow(int, int)}
     * @utbot.executesCondition {@code (k < Integer.SIZE): False}
     * @utbot.returnsFrom {@code return 0;}
     */
    @Test
    @DisplayName("pow: k < Integer.SIZE : False -> return 0")
    public void testPow_KGreaterOrEqualIntegerSIZE() {
        int actual = IntMath.pow(-2, 32);

        assertEquals(0, actual);
    }

    /**
     * @utbot.classUnderTest {@link IntMath}
     * @utbot.methodUnderTest {@link IntMath#pow(int, int)}
     * @utbot.executesCondition {@code ((k < Integer.SIZE)): False}
     * @utbot.returnsFrom {@code return (k < Integer.SIZE) ? (1 << k) : 0;}
     */
    @Test
    @DisplayName("pow: k < Integer.SIZE : False -> return (k < Integer.SIZE) ? (1 << k) : 0")
    public void testPow_KGreaterOrEqualIntegerSIZE_1() {
        int actual = IntMath.pow(2, 32);

        assertEquals(0, actual);
    }

    /**
     * @utbot.classUnderTest {@link IntMath}
     * @utbot.methodUnderTest {@link IntMath#pow(int, int)}
     * @utbot.iterates iterate the loop {@code for(int accum = 1; ; k >>= 1)} once
     */
    @Test
    @DisplayName("pow: -> return b * accum")
    public void testPow_ReturnBMultiplyAccum() {
        int actual = IntMath.pow(3, 1);

        assertEquals(3, actual);
    }

    /**
     * @utbot.classUnderTest {@link IntMath}
     * @utbot.methodUnderTest {@link IntMath#pow(int, int)}
     * @utbot.executesCondition {@code ((k < Integer.SIZE)): True}
     * @utbot.returnsFrom {@code return (k < Integer.SIZE) ? (1 << k) : 0;}
     */
    @Test
    @DisplayName("pow: k < Integer.SIZE : True -> return (k < Integer.SIZE) ? (1 << k) : 0")
    public void testPow_KLessThanIntegerSIZE() {
        int actual = IntMath.pow(2, 31);

        assertEquals(Integer.MIN_VALUE, actual);
    }

    /**
     * @utbot.classUnderTest {@link IntMath}
     * @utbot.methodUnderTest {@link IntMath#pow(int, int)}
     * @utbot.executesCondition {@code ((k == 0)): False}
     * @utbot.returnsFrom {@code return (k == 0) ? 1 : 0;}
     */
    @Test
    @DisplayName("pow: k == 0 : False -> return (k == 0) ? 1 : 0")
    public void testPow_KNotEqualsZero() {
        int actual = IntMath.pow(0, -254);

        assertEquals(0, actual);
    }

    /**
     * @utbot.classUnderTest {@link IntMath}
     * @utbot.methodUnderTest {@link IntMath#pow(int, int)}
     * @utbot.iterates iterate the loop {@code for(int accum = 1; ; k >>= 1)} once
     */
    @Test
    @DisplayName("pow: -> return accum")
    public void testPow_ReturnAccum() {
        int actual = IntMath.pow(3, 0);

        assertEquals(1, actual);
    }

    /**
     * @utbot.classUnderTest {@link IntMath}
     * @utbot.methodUnderTest {@link IntMath#pow(int, int)}
     * @utbot.executesCondition {@code ((k == 0)): True}
     * @utbot.returnsFrom {@code return (k == 0) ? 1 : 0;}
     */
    @Test
    @DisplayName("pow: k == 0 : True -> return (k == 0) ? 1 : 0")
    public void testPow_KEqualsZero() {
        int actual = IntMath.pow(0, 0);

        assertEquals(1, actual);
    }

    /**
     * @utbot.classUnderTest {@link IntMath}
     * @utbot.methodUnderTest {@link IntMath#pow(int, int)}
     * @utbot.executesCondition {@code (k < Integer.SIZE): True}
     * @utbot.executesCondition {@code (((k & 1) == 0)): True}
     * @utbot.returnsFrom {@code return ((k & 1) == 0) ? (1 << k) : -(1 << k);}
     */
    @Test
    @DisplayName("pow: (k & 1) == 0 : True -> return ((k & 1) == 0) ? (1 << k) : -(1 << k)")
    public void testPow_KBitwiseAnd1EqualsZero() {
        int actual = IntMath.pow(-2, 0);

        assertEquals(1, actual);
    }

    /**
     * @utbot.classUnderTest {@link IntMath}
     * @utbot.methodUnderTest {@link IntMath#pow(int, int)}
     * @utbot.executesCondition {@code (k < Integer.SIZE): True}
     * @utbot.executesCondition {@code (((k & 1) == 0)): False}
     * @utbot.returnsFrom {@code return ((k & 1) == 0) ? (1 << k) : -(1 << k);}
     */
    @Test
    @DisplayName("pow: (k & 1) == 0 : False -> return ((k & 1) == 0) ? (1 << k) : -(1 << k)")
    public void testPow_KBitwiseAnd1NotEqualsZero() {
        int actual = IntMath.pow(-2, 31);

        assertEquals(Integer.MIN_VALUE, actual);
    }

    /**
     * @utbot.classUnderTest {@link IntMath}
     * @utbot.methodUnderTest {@link IntMath#pow(int, int)}
     * @utbot.executesCondition {@code (((k & 1) == 0)): False}
     * @utbot.returnsFrom {@code return ((k & 1) == 0) ? 1 : -1;}
     */
    @Test
    @DisplayName("pow: (k & 1) == 0 : False -> return ((k & 1) == 0) ? 1 : -1")
    public void testPow_KBitwiseAnd1NotEqualsZero_1() {
        int actual = IntMath.pow(-1, -255);

        assertEquals(-1, actual);
    }

    /**
     * @utbot.classUnderTest {@link IntMath}
     * @utbot.methodUnderTest {@link IntMath#pow(int, int)}
     * @utbot.executesCondition {@code (((k & 1) == 0)): True}
     * @utbot.returnsFrom {@code return ((k & 1) == 0) ? 1 : -1;}
     */
    @Test
    @DisplayName("pow: (k & 1) == 0 : True -> return ((k & 1) == 0) ? 1 : -1")
    public void testPow_KBitwiseAnd1EqualsZero_1() {
        int actual = IntMath.pow(-1, -254);

        assertEquals(1, actual);
    }

    /**
     * @utbot.classUnderTest {@link IntMath}
     * @utbot.methodUnderTest {@link IntMath#pow(int, int)}
     * @utbot.iterates iterate the loop {@code for(int accum = 1; ; k >>= 1)} twice
     */
    @Test
    @DisplayName("pow: (k & 1) == 0 : False -> return b * accum")
    public void testPow_KBitwiseAnd1NotEqualsZero_2() {
        int actual = IntMath.pow(3, 3);

        assertEquals(27, actual);
    }

    /**
     * @utbot.classUnderTest {@link IntMath}
     * @utbot.methodUnderTest {@link IntMath#pow(int, int)}
     * @utbot.iterates iterate the loop {@code for(int accum = 1; ; k >>= 1)} twice
     */
    @Test
    @DisplayName("pow: (k & 1) == 0 : True -> return b * accum")
    public void testPow_KBitwiseAnd1EqualsZero_2() {
        int actual = IntMath.pow(4, 2);

        assertEquals(16, actual);
    }
    ///endregion

    ///endregion
}

Metadata

Metadata

Assignees

Labels

comp-summariesSomething related to the method names, code comments and display names generationctg-bugIssue is a bug

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions