Skip to content
Prev Previous commit
Next Next commit
Used coverage calculation instead of matchers for flaky executions nu…
…mber in some Set tests
  • Loading branch information
Damtev committed Oct 28, 2022
commit f972a93fd30bab6b589018e3b924c8aeb7eca3e7
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SetIteratorsTest : UtValueTestCaseChecker(
fun testIteratorHasNext() {
check(
SetIterators::iteratorHasNext,
between(3..4),
ignoreExecutionsNumber,
{ set, _ -> set == null },
{ set, result -> set.isEmpty() && result == 0 },
{ set, result -> set.isNotEmpty() && result == set.size },
Expand All @@ -33,7 +33,7 @@ class SetIteratorsTest : UtValueTestCaseChecker(
fun testIteratorNext() {
checkWithException(
SetIterators::iteratorNext,
between(3..4),
ignoreExecutionsNumber,
{ set, result -> set == null && result.isException<NullPointerException>() },
{ set, result -> set != null && set.isEmpty() && result.isException<NoSuchElementException>() },
// test should work as long as default class for set is LinkedHashSet
Expand All @@ -45,7 +45,7 @@ class SetIteratorsTest : UtValueTestCaseChecker(
fun testIteratorRemove() {
checkWithException(
SetIterators::iteratorRemove,
between(3..4),
ignoreExecutionsNumber,
{ set, result -> set == null && result.isException<NullPointerException>() },
{ set, result -> set.isEmpty() && result.isException<NoSuchElementException>() },
// test should work as long as default class for set is LinkedHashSet
Expand All @@ -62,7 +62,7 @@ class SetIteratorsTest : UtValueTestCaseChecker(
fun testIteratorRemoveOnIndex() {
checkWithException(
SetIterators::iteratorRemoveOnIndex,
ge(5),
ignoreExecutionsNumber,
{ _, i, result -> i == 0 && result.isSuccess && result.getOrNull() == null },
{ set, _, result -> set == null && result.isException<NullPointerException>() },
{ set, i, result -> set != null && i < 0 && result.isException<IllegalStateException>() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ package org.utbot.examples.collections

import org.utbot.tests.infrastructure.UtValueTestCaseChecker
import org.utbot.tests.infrastructure.AtLeast
import org.utbot.tests.infrastructure.DoNotCalculate
import org.utbot.tests.infrastructure.between
import org.utbot.tests.infrastructure.ignoreExecutionsNumber
import org.utbot.framework.plugin.api.CodegenLanguage
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.utbot.testcheckers.eq
import org.utbot.testcheckers.ge
import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete
import org.utbot.testcheckers.withoutMinimization
import org.utbot.tests.infrastructure.CodeGeneration
Expand All @@ -30,7 +27,7 @@ internal class SetsTest : UtValueTestCaseChecker(
eq(3),
{ a, _ -> a == null },
{ a, r -> a != null && a.isEmpty() && r!!.isEmpty() },
{ a, r -> a != null && a.isNotEmpty() && r != null && r.isNotEmpty() && r.containsAll(a.toList()) },
{ a, r -> a != null && a.isNotEmpty() && !r.isNullOrEmpty() && r.containsAll(a.toList()) },
)
}

Expand Down Expand Up @@ -92,7 +89,7 @@ internal class SetsTest : UtValueTestCaseChecker(
val resultFun = { set: Set<Char> -> listOf(' ', '\t', '\r', '\n').intersect(set).size }
check(
Sets::removeSpace,
ge(3),
ignoreExecutionsNumber,
{ set, _ -> set == null },
{ set, res -> ' ' in set && resultFun(set) == res },
{ set, res -> '\t' in set && resultFun(set) == res },
Expand All @@ -109,7 +106,7 @@ internal class SetsTest : UtValueTestCaseChecker(
fun addElementsTest() {
check(
Sets::addElements,
ge(5),
ignoreExecutionsNumber,
{ set, _, _ -> set == null },
{ set, a, _ -> set != null && set.isNotEmpty() && a == null },
{ set, _, r -> set.isEmpty() && r == set },
Expand All @@ -124,7 +121,7 @@ internal class SetsTest : UtValueTestCaseChecker(
fun removeElementsTest() {
check(
Sets::removeElements,
between(6..8),
ignoreExecutionsNumber,
{ set, _, _, _ -> set == null },
{ set, i, j, res -> set != null && i !in set && j !in set && res == -1 },
{ set, i, j, res -> set != null && set.size >= 1 && i !in set && j in set && res == 4 },
Expand All @@ -150,7 +147,7 @@ internal class SetsTest : UtValueTestCaseChecker(
withoutMinimization { // TODO: JIRA:1506
check(
Sets::removeCustomObject,
ge(4),
ignoreExecutionsNumber,
{ set, _, _ -> set == null },
{ set, _, result -> set.isEmpty() && result == 0 },
{ set, i, result -> set.isNotEmpty() && CustomClass(i) !in set && result == 0 },
Expand Down Expand Up @@ -188,7 +185,6 @@ internal class SetsTest : UtValueTestCaseChecker(
//TODO: JIRA:1666 -- Engine ignores branches in Wrappers sometimes
// TODO: cannot find branch with result == 2
// { set, other, result -> !set.containsAll(other) && other.any { it in set } && result == 2 },
coverage = DoNotCalculate
)
}
}
Expand All @@ -197,7 +193,7 @@ internal class SetsTest : UtValueTestCaseChecker(
fun testRetainAllElements() {
check(
Sets::retainAllElements,
ge(4),
ignoreExecutionsNumber,
{ set, _, _ -> set == null },
{ set, other, _ -> set != null && other == null },
{ set, other, result -> other.containsAll(set) && result == 1 },
Expand All @@ -209,7 +205,7 @@ internal class SetsTest : UtValueTestCaseChecker(
fun testContainsAllElements() {
check(
Sets::containsAllElements,
ge(5),
ignoreExecutionsNumber,
{ set, _, _ -> set == null },
{ set, other, _ -> set != null && other == null },
{ set, other, result -> set.isEmpty() || other.isEmpty() && result == -1 },
Expand All @@ -223,7 +219,7 @@ internal class SetsTest : UtValueTestCaseChecker(
fun testClearElements() {
check(
Sets::clearElements,
eq(3),
ignoreExecutionsNumber,
{ set, _ -> set == null },
{ set, result -> set.isEmpty() && result == 0 },
{ set, result -> set.isNotEmpty() && result == 1 },
Expand All @@ -236,7 +232,7 @@ internal class SetsTest : UtValueTestCaseChecker(
fun testContainsElement() {
check(
Sets::containsElement,
between(3..5),
ignoreExecutionsNumber,
{ set, _, _ -> set == null },
{ set, i, result -> i !in set && result == 0 },
{ set, i, result -> i in set && result == 1 },
Expand Down