Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Favor arrays with different values #2547

Open
alisevych opened this issue Aug 23, 2023 · 0 comments
Open

Favor arrays with different values #2547

alisevych opened this issue Aug 23, 2023 · 0 comments
Labels
comp-symbolic-engine Issue is related to the symbolic execution engine ctg-enhancement New feature, improvement or change request

Comments

@alisevych
Copy link
Member

alisevych commented Aug 23, 2023

Description

Suggestion to make arrays with different values more prioritized.

Expected behavior

Arrays with different values inside should be generated if and only if values equality is not included in path constraints.

Environment

For both IntelliJ Plugin and CLI

Context

Now equal values are generated for successful execution of Sort::swap
The coverage is reached. But it is not really informative for such a method.
Different values are generated only when such an assumption is explicitly added inside the method.

Method under test:

    public void swap(long[] array, int i, int j) {
        UtMock.assume(array[i] != array[j]);
        long tmp = array[i];
        array[i] = array[j];
        array[j] = tmp;
    }

Compare successful test being generated.
Without assume:

    public void testSwap() {
        Sort sort = new Sort();
        long[] array = {-255L, -255L};

        sort.swap(array, 0, 1);
    }

With assume:

    public void testSwap_UtMockAssume() {
        Sort sort = new Sort();
        long[] array = {5L, 4L};

        sort.swap(array, 0, 1);

        long finalArray0 = array[0];
        long finalArray1 = array[1];

        assertEquals(4L, finalArray0);

        assertEquals(5L, finalArray1);
    }

Autotest on this (to be added in SortTest.kt):

    @Test
    fun testSwapMutation() {
        withoutConcrete {
            checkParamsMutations(
                Sort::swap,
                ignoreExecutionsNumber,
                { a, i, j, a1, _, _ -> a != null && i in a.indices && j in a.indices && !a1.contentEquals(a) }
                , coverage = atLeast(percents = 95)
            )
        }
    }
@alisevych alisevych added ctg-enhancement New feature, improvement or change request comp-symbolic-engine Issue is related to the symbolic execution engine labels Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-symbolic-engine Issue is related to the symbolic execution engine ctg-enhancement New feature, improvement or change request
Projects
Status: Todo
Development

No branches or pull requests

1 participant