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

Uncompilable test is generated by fuzzer for Collections test #2514

Closed
tyuldashev opened this issue Aug 15, 2023 · 1 comment · Fixed by #2518
Closed

Uncompilable test is generated by fuzzer for Collections test #2514

tyuldashev opened this issue Aug 15, 2023 · 1 comment · Fixed by #2518
Assignees
Labels
ctg-bug Issue is a bug spec-regression Regression status-verified Bug fix is verified

Comments

@tyuldashev
Copy link
Collaborator

tyuldashev commented Aug 15, 2023

Description
One of generated test contains following line which could not be compiled:
concreteList.add(((Object) - 1L));

To Reproduce

  1. Install UnitTestBot plugin built from main in IntelliJ IDEA
  2. Set Fuzzer = 100%
  3. Generate tests for following code (with no mocks):
    // copied from org.utbot.fuzzing.samples.Collections.ConcreteList
    public static class ConcreteList<T extends Number> extends LinkedList<T> {
        public boolean equals(Collection<T> collection) {
            if (collection.size() != size()) {
                return false;
            }
            int i = 0;
            for (T t : collection) {
                if (!java.util.Objects.equals(get(i), t)) {
                    return false;
                }
            }
            return true;
        }
    }

Expected behavior
All generated tests can be compiled and executed.

Actual behavior
One of generated test is shown below, it doesn't compile.

    @Test
    @DisplayName("equals: collection = collection -> return false")
    public void testEqualsReturnsFalse2() {
        ConcreteList concreteList = new ConcreteList();
        concreteList.add(((Object) Byte.MIN_VALUE));
        concreteList.add(((Object) Byte.MAX_VALUE));
        concreteList.add(((Object) - 1L));                  //UNCOMPILABLE
        concreteList.add(((Object) (short) 0));
        concreteList.add(((Object) (byte) 0));
        ArrayList arrayList = new ArrayList();
        arrayList.add(Byte.MIN_VALUE);
        arrayList.add(0.0);
        arrayList.add(Float.NaN);
        arrayList.add(Double.POSITIVE_INFINITY);
        arrayList.add((byte) 0);

        boolean actual = concreteList.equals(((Collection) arrayList));

        assertFalse(actual);
    }
 

Environment

IntelliJ IDEA version - 2023.2
Project - utbot or just copy sample to any other Java project
Plugin - 2023.8.5065

@tyuldashev tyuldashev added ctg-bug Issue is a bug spec-regression Regression comp-fuzzing Issue is related to the fuzzing labels Aug 15, 2023
@EgorkaKulikov EgorkaKulikov added comp-codegen Issue is related to code generator and removed comp-fuzzing Issue is related to the fuzzing labels Aug 15, 2023
@EgorkaKulikov
Copy link
Collaborator

Can be reproduced on a minimalized example

public static class ConcreteList<T extends Number> extends LinkedList<T> {
        public boolean equals(Collection<T> collection) {
            var value = get(0);
            if (java.util.Objects.equals(value, -1)) {
                return true;
            }

            return false;
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ctg-bug Issue is a bug spec-regression Regression status-verified Bug fix is verified
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants