-
Notifications
You must be signed in to change notification settings - Fork 46
Add wrappers for queues #524 #822
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f43a15d
Add assemble model heuristic
sergeypospelov c74fb35
Fix comment
sergeypospelov d935426
Add UtLinkedListWithNullableCheck
sergeypospelov 2724065
Plug wrappers for queues in
sergeypospelov 1bf06ec
Add UtModelConstructors in ConcreteExecutor
sergeypospelov cfee03c
Add tests
sergeypospelov 5c21f15
Fix pipeline phases
sergeypospelov 9329c1d
Fix UtBotJavaApiTest
sergeypospelov afa97d1
Fix Egor's migration
sergeypospelov 77e6a57
Fix duplicate line
sergeypospelov 72f40b5
Fix kotlin documentation on ListWrapper
sergeypospelov 82176b2
Fix incorrect matcher
sergeypospelov bf44d09
Limit new heuristic usage
sergeypospelov b042516
Clean up runSoot usages
sergeypospelov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
12 changes: 1 addition & 11 deletions
12
utbot-framework-test/src/main/java/org/utbot/examples/manual/KotlinWrappers.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/QueueUsagesTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package org.utbot.examples.collections | ||
|
||
import org.junit.jupiter.api.Disabled | ||
import org.junit.jupiter.api.Test | ||
import org.utbot.framework.plugin.api.CodegenLanguage | ||
import org.utbot.testcheckers.eq | ||
import org.utbot.tests.infrastructure.CodeGeneration | ||
import org.utbot.tests.infrastructure.UtValueTestCaseChecker | ||
import org.utbot.tests.infrastructure.isException | ||
|
||
class QueueUsagesTest : UtValueTestCaseChecker( | ||
testClass = QueueUsages::class, | ||
testCodeGeneration = true, | ||
languagePipelines = listOf( | ||
CodeGenerationLanguageLastStage(CodegenLanguage.JAVA), | ||
CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, CodeGeneration) | ||
) | ||
) { | ||
@Test | ||
fun testCreateArrayDeque() { | ||
checkWithException( | ||
QueueUsages::createArrayDeque, | ||
eq(3), | ||
{ init, next, r -> init == null && next == null && r.isException<NullPointerException>() }, | ||
{ init, next, r -> init != null && next == null && r.isException<NullPointerException>() }, | ||
{ init, next, r -> init != null && next != null && r.getOrNull() == 2 }, | ||
) | ||
} | ||
|
||
@Test | ||
fun testCreateLinkedList() { | ||
checkWithException( | ||
QueueUsages::createLinkedList, | ||
eq(1), | ||
{ _, _, r -> r.getOrNull()!! == 2 }, | ||
) | ||
} | ||
|
||
@Test | ||
fun testCreateLinkedBlockingDeque() { | ||
checkWithException( | ||
QueueUsages::createLinkedBlockingDeque, | ||
eq(3), | ||
{ init, next, r -> init == null && next == null && r.isException<NullPointerException>() }, | ||
{ init, next, r -> init != null && next == null && r.isException<NullPointerException>() }, | ||
{ init, next, r -> init != null && next != null && r.getOrNull() == 2 }, | ||
) | ||
} | ||
|
||
@Test | ||
fun testContainsQueue() { | ||
checkWithException( | ||
QueueUsages::containsQueue, | ||
eq(3), | ||
{ q, _, r -> q == null && r.isException<NullPointerException>() }, | ||
{ q, x, r -> x in q && r.getOrNull() == 1 }, | ||
{ q, x, r -> x !in q && r.getOrNull() == 0 }, | ||
) | ||
} | ||
|
||
@Test | ||
fun testAddQueue() { | ||
checkWithException( | ||
QueueUsages::addQueue, | ||
eq(3), | ||
{ q, _, r -> q == null && r.isException<NullPointerException>() }, | ||
{ q, x, r -> q != null && x in r.getOrNull()!! }, | ||
{ q, x, r -> q != null && x == null && r.isException<NullPointerException>() }, ) | ||
} | ||
|
||
@Test | ||
fun testAddAllQueue() { | ||
checkWithException( | ||
QueueUsages::addAllQueue, | ||
eq(3), | ||
{ q, _, r -> q == null && r.isException<NullPointerException>() }, | ||
{ q, x, r -> q != null && x != null && x in r.getOrNull()!! }, | ||
{ q, x, r -> q != null && x == null && r.isException<NullPointerException>() }, | ||
) | ||
} | ||
|
||
@Test | ||
fun testCastQueueToDeque() { | ||
check( | ||
QueueUsages::castQueueToDeque, | ||
eq(2), | ||
{ q, r -> q !is java.util.Deque<*> && r == null }, | ||
{ q, r -> q is java.util.Deque<*> && r is java.util.Deque<*> }, | ||
) | ||
} | ||
|
||
@Test | ||
fun testCheckSubtypesOfQueue() { | ||
check( | ||
QueueUsages::checkSubtypesOfQueue, | ||
eq(4), | ||
{ q, r -> q == null && r == 0 }, | ||
{ q, r -> q is java.util.LinkedList<*> && r == 1 }, | ||
{ q, r -> q is java.util.ArrayDeque<*> && r == 2 }, | ||
{ q, r -> q !is java.util.LinkedList<*> && q !is java.util.ArrayDeque && r == 3 } | ||
) | ||
} | ||
|
||
@Test | ||
@Disabled("TODO: Related to https://github.com/UnitTestBot/UTBotJava/issues/820") | ||
fun testCheckSubtypesOfQueueWithUsage() { | ||
check( | ||
QueueUsages::checkSubtypesOfQueueWithUsage, | ||
eq(4), | ||
{ q, r -> q == null && r == 0 }, | ||
{ q, r -> q is java.util.LinkedList<*> && r == 1 }, | ||
{ q, r -> q is java.util.ArrayDeque<*> && r == 2 }, | ||
{ q, r -> q !is java.util.LinkedList<*> && q !is java.util.ArrayDeque && r == 3 } // this is uncovered | ||
) | ||
} | ||
|
||
@Test | ||
fun testAddConcurrentLinkedQueue() { | ||
checkWithException( | ||
QueueUsages::addConcurrentLinkedQueue, | ||
eq(3), | ||
{ q, _, r -> q == null && r.isException<NullPointerException>() }, | ||
{ q, x, r -> q != null && x != null && x in r.getOrNull()!! }, | ||
{ q, x, r -> q != null && x == null && r.isException<NullPointerException>() }, | ||
) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...k/src/main/java/org/utbot/engine/overrides/collections/UtLinkedListWithNullableCheck.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package org.utbot.engine.overrides.collections; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* This list forbids inserting null elements to support some implementations of {@link java.util.Deque} like | ||
* {@link java.util.ArrayDeque}. | ||
* | ||
* TODO: <a href="https://github.com/UnitTestBot/UTBotJava/issues/819">Support super calls in inherited wrappers</a> | ||
* | ||
* @see UtLinkedList | ||
* @param <E> | ||
*/ | ||
public class UtLinkedListWithNullableCheck<E> extends UtLinkedList<E> { | ||
@SuppressWarnings("unused") | ||
UtLinkedListWithNullableCheck(RangeModifiableUnlimitedArray<E> elementData, int fromIndex, int toIndex) { | ||
super(elementData, fromIndex, toIndex); | ||
for (int i = elementData.begin; i < elementData.end; i++) { | ||
if (elementData.get(i) == null) { | ||
throw new NullPointerException(); | ||
} | ||
} | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public UtLinkedListWithNullableCheck() { | ||
super(); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public UtLinkedListWithNullableCheck(Collection<? extends E> c) { | ||
super(c); | ||
} | ||
|
||
@Override | ||
public E set(int index, E element) { | ||
if (element == null) { | ||
throw new NullPointerException(); | ||
} | ||
preconditionCheck(); | ||
rangeCheck(index); | ||
E oldElement = elementData.get(index + elementData.begin); | ||
elementData.set(index + elementData.begin, element); | ||
return oldElement; | ||
} | ||
|
||
@Override | ||
public void addFirst(E e) { | ||
if (e == null) { | ||
throw new NullPointerException(); | ||
} | ||
preconditionCheck(); | ||
elementData.set(--elementData.begin, e); | ||
} | ||
|
||
@Override | ||
public void addLast(E e) { | ||
if (e == null) { | ||
throw new NullPointerException(); | ||
} | ||
preconditionCheck(); | ||
elementData.set(elementData.end++, e); | ||
} | ||
|
||
@Override | ||
public boolean offerFirst(E e) { | ||
if (e == null) { | ||
throw new NullPointerException(); | ||
} | ||
preconditionCheck(); | ||
elementData.set(--elementData.begin, e); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean offerLast(E e) { | ||
if (e == null) { | ||
throw new NullPointerException(); | ||
} | ||
preconditionCheck(); | ||
elementData.set(elementData.end++, e); | ||
return true; | ||
} | ||
|
||
@Override | ||
public void add(int index, E element) { | ||
if (element == null) { | ||
throw new NullPointerException(); | ||
} | ||
preconditionCheck(); | ||
rangeCheckForAdd(index); | ||
elementData.end++; | ||
elementData.insert(index + elementData.begin, element); | ||
} | ||
|
||
@Override | ||
public boolean addAll(Collection<? extends E> c) { | ||
for (Object elem : c.toArray()) { | ||
if (elem == null) { | ||
throw new NullPointerException(); | ||
} | ||
} | ||
preconditionCheck(); | ||
elementData.setRange(elementData.end, c.toArray(), 0, c.size()); | ||
elementData.end += c.size(); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean addAll(int index, Collection<? extends E> c) { | ||
for (Object elem : c.toArray()) { | ||
if (elem == null) { | ||
throw new NullPointerException(); | ||
} | ||
} | ||
preconditionCheck(); | ||
rangeCheckForAdd(index); | ||
elementData.insertRange(index + elementData.begin, c.toArray(), 0, c.size()); | ||
elementData.end += c.size(); | ||
return true; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.