Skip to content

Commit cfee03c

Browse files
Add tests
1 parent 1bf06ec commit cfee03c

File tree

3 files changed

+220
-2
lines changed

3 files changed

+220
-2
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package org.utbot.examples.collections
2+
3+
import org.junit.jupiter.api.Disabled
4+
import org.junit.jupiter.api.Test
5+
import org.utbot.examples.UtValueTestCaseChecker
6+
import org.utbot.examples.eq
7+
import org.utbot.examples.isException
8+
import org.utbot.framework.codegen.CodeGeneration
9+
import org.utbot.framework.plugin.api.CodegenLanguage
10+
11+
class QueueUsagesTest : UtValueTestCaseChecker(
12+
testClass = QueueUsages::class,
13+
testCodeGeneration = true,
14+
languagePipelines = listOf(
15+
CodeGenerationLanguageLastStage(CodegenLanguage.JAVA),
16+
CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, CodeGeneration)
17+
)
18+
) {
19+
@Test
20+
fun testCreateArrayDeque() {
21+
checkWithException(
22+
QueueUsages::createArrayDeque,
23+
eq(3),
24+
{ init, next, r -> init == null && next == null && r.isException<NullPointerException>() },
25+
{ init, next, r -> init != null && next == null && r.isException<NullPointerException>() },
26+
{ init, next, r -> init != null && next != null && r.getOrNull() == 2 },
27+
)
28+
}
29+
30+
@Test
31+
fun testCreateLinkedList() {
32+
checkWithException(
33+
QueueUsages::createLinkedList,
34+
eq(1),
35+
{ _, _, r -> r.getOrNull()!! == 2 },
36+
)
37+
}
38+
39+
@Test
40+
fun testCreateLinkedBlockingDeque() {
41+
checkWithException(
42+
QueueUsages::createLinkedBlockingDeque,
43+
eq(3),
44+
{ init, next, r -> init == null && next == null && r.isException<NullPointerException>() },
45+
{ init, next, r -> init != null && next == null && r.isException<NullPointerException>() },
46+
{ init, next, r -> init != null && next != null && r.getOrNull() == 2 },
47+
)
48+
}
49+
50+
@Test
51+
fun testContainsQueue() {
52+
checkWithException(
53+
QueueUsages::containsQueue,
54+
eq(3),
55+
{ q, _, r -> q == null && r.isException<NullPointerException>() },
56+
{ q, x, r -> x in q && r.getOrNull() == 1 },
57+
{ q, x, r -> x !in q && r.getOrNull() == 0 },
58+
)
59+
}
60+
61+
@Test
62+
fun testAddQueue() {
63+
checkWithException(
64+
QueueUsages::addQueue,
65+
eq(3),
66+
{ q, _, r -> q == null && r.isException<NullPointerException>() },
67+
{ q, x, r -> q != null && x in r.getOrNull()!! },
68+
{ q, x, r -> q != null && x == null && r.isException<NullPointerException>() }, )
69+
}
70+
71+
@Test
72+
fun testAddAllQueue() {
73+
checkWithException(
74+
QueueUsages::addAllQueue,
75+
eq(3),
76+
{ q, _, r -> q == null && r.isException<NullPointerException>() },
77+
{ q, x, r -> q != null && x != null && x in r.getOrNull()!! },
78+
{ q, x, r -> q != null && x == null && r.isException<NullPointerException>() },
79+
)
80+
}
81+
82+
@Test
83+
fun testCastQueueToDeque() {
84+
check(
85+
QueueUsages::castQueueToDeque,
86+
eq(2),
87+
{ q, r -> q !is java.util.Deque<*> && r == null },
88+
{ q, r -> q is java.util.Deque<*> && r is java.util.Deque<*> },
89+
)
90+
}
91+
92+
@Test
93+
fun testCheckSubtypesOfQueue() {
94+
check(
95+
QueueUsages::checkSubtypesOfQueue,
96+
eq(4),
97+
{ q, r -> q == null && r == 0 },
98+
{ q, r -> q is java.util.LinkedList<*> && r == 1 },
99+
{ q, r -> q is java.util.ArrayDeque<*> && r == 2 },
100+
{ q, r -> q !is java.util.LinkedList<*> && q !is java.util.ArrayDeque && r == 3 }
101+
)
102+
}
103+
104+
@Test
105+
@Disabled("TODO: Related to https://github.com/UnitTestBot/UTBotJava/issues/820")
106+
fun testCheckSubtypesOfQueueWithUsage() {
107+
check(
108+
QueueUsages::checkSubtypesOfQueueWithUsage,
109+
eq(4),
110+
{ q, r -> q == null && r == 0 },
111+
{ q, r -> q is java.util.LinkedList<*> && r == 1 },
112+
{ q, r -> q is java.util.ArrayDeque<*> && r == 2 },
113+
{ q, r -> q !is java.util.LinkedList<*> && q !is java.util.ArrayDeque && r == 3 } // this is uncovered
114+
)
115+
}
116+
117+
@Test
118+
fun testAddConcurrentLinkedQueue() {
119+
checkWithException(
120+
QueueUsages::addConcurrentLinkedQueue,
121+
eq(3),
122+
{ q, _, r -> q == null && r.isException<NullPointerException>() },
123+
{ q, x, r -> q != null && x != null && x in r.getOrNull()!! },
124+
{ q, x, r -> q != null && x == null && r.isException<NullPointerException>() },
125+
)
126+
}
127+
}

utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ internal class StandardStructuresTest : UtValueTestCaseChecker(testClass = Stand
4545
}
4646

4747
@Test
48-
@Disabled("TODO use correct wrapper JIRA:1495")
4948
fun testGetDeque() {
5049
val dequeSummary = listOf<DocStatement>(
5150
DocPreTagStatement(
@@ -72,7 +71,7 @@ internal class StandardStructuresTest : UtValueTestCaseChecker(testClass = Stand
7271
{ d, r -> d is LinkedList && r is LinkedList },
7372
{ d, r -> d == null && r == null },
7473
{ d, r ->
75-
d !is ArrayDeque<*> && d !is LinkedList && d != null && r !is ArrayDeque<*> && r !is LinkedList && r != null
74+
d !is java.util.ArrayDeque<*> && d !is LinkedList && d != null && r !is java.util.ArrayDeque<*> && r !is LinkedList && r != null
7675
},
7776
coverage = DoNotCalculate,
7877
summaryTextChecks = listOf(
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package org.utbot.examples.collections;
2+
3+
import org.utbot.examples.objects.WrappedInt;
4+
5+
import java.util.ArrayDeque;
6+
import java.util.Arrays;
7+
import java.util.Collection;
8+
import java.util.Collections;
9+
import java.util.Deque;
10+
import java.util.LinkedList;
11+
import java.util.Queue;
12+
import java.util.concurrent.ConcurrentLinkedQueue;
13+
import java.util.concurrent.LinkedBlockingDeque;
14+
15+
public class QueueUsages {
16+
public int createArrayDeque(WrappedInt init, WrappedInt next) {
17+
Queue<WrappedInt> q = new ArrayDeque<>(Collections.singletonList(init));
18+
q.add(next);
19+
return q.size();
20+
}
21+
22+
public int createLinkedList(WrappedInt init, WrappedInt next) {
23+
Queue<WrappedInt> q = new LinkedList<>(Collections.singletonList(init));
24+
q.add(next);
25+
return q.size();
26+
}
27+
28+
public int createLinkedBlockingDeque(WrappedInt init, WrappedInt next) {
29+
Queue<WrappedInt> q = new LinkedBlockingDeque<>(Collections.singletonList(init));
30+
q.add(next);
31+
return q.size();
32+
}
33+
34+
public int containsQueue(Queue<Integer> q, int x) {
35+
if (q.contains(x)) {
36+
return 1;
37+
} else {
38+
return 0;
39+
}
40+
}
41+
42+
public Queue<WrappedInt> addQueue(Queue<WrappedInt> q, WrappedInt x) {
43+
q.add(x);
44+
return q;
45+
}
46+
47+
public Queue<WrappedInt> addAllQueue(Queue<WrappedInt> q, WrappedInt o) {
48+
Collection<WrappedInt> lst = Arrays.asList(new WrappedInt(1), o);
49+
q.addAll(lst);
50+
return q;
51+
}
52+
53+
public Deque<Object> castQueueToDeque(Queue<Object> q) {
54+
if (q instanceof Deque) {
55+
return (Deque<Object>)q;
56+
} else {
57+
return null;
58+
}
59+
}
60+
61+
public int checkSubtypesOfQueue(Queue<Integer> q) {
62+
if (q == null) {
63+
return 0;
64+
}
65+
if (q instanceof LinkedList) {
66+
return 1;
67+
} else if (q instanceof ArrayDeque) {
68+
return 2;
69+
} else {
70+
return 3;
71+
}
72+
}
73+
74+
public int checkSubtypesOfQueueWithUsage(Queue<Integer> q) {
75+
if (q == null) {
76+
return 0;
77+
}
78+
q.add(1);
79+
if (q instanceof LinkedList) {
80+
return 1;
81+
} else if (q instanceof ArrayDeque) {
82+
return 2;
83+
} else {
84+
return 3;
85+
}
86+
}
87+
88+
public ConcurrentLinkedQueue<WrappedInt> addConcurrentLinkedQueue(ConcurrentLinkedQueue<WrappedInt> q, WrappedInt o) {
89+
q.add(o);
90+
return q;
91+
}
92+
}

0 commit comments

Comments
 (0)