diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/testcheckers/SettingsModificators.kt b/utbot-framework-api/src/main/kotlin/org/utbot/testcheckers/SettingsModificators.kt index 7b2223947b..4936c09c54 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/testcheckers/SettingsModificators.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/testcheckers/SettingsModificators.kt @@ -99,9 +99,9 @@ inline fun withSolverTimeoutInMillis(timeoutInMillis: Int, block: () } } -inline fun withoutConcrete(block: () -> T): T { +inline fun withConcrete(useConcreteExecution: Boolean, block: () -> T): T { val prev = UtSettings.useConcreteExecution - UtSettings.useConcreteExecution = false + UtSettings.useConcreteExecution = useConcreteExecution try { return block() } finally { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithAnnotationsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithAnnotationsTest.kt index b2987df28c..b9c0085e70 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithAnnotationsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithAnnotationsTest.kt @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test import org.utbot.tests.infrastructure.DoNotCalculate import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.utbot.testcheckers.eq +import org.utbot.testcheckers.withConcrete /** * Tests for Lombok annotations @@ -15,11 +16,13 @@ import org.utbot.testcheckers.eq internal class EnumWithAnnotationsTest : UtValueTestCaseChecker(testClass = EnumWithAnnotations::class) { @Test fun testGetterWithAnnotations() { - check( - EnumWithAnnotations::getConstant, - eq(1), - { r -> r == "Constant_1" }, - coverage = DoNotCalculate, - ) + withConcrete(useConcreteExecution = true) { // TODO https://github.com/UnitTestBot/UTBotJava/issues/1249 + check( + EnumWithAnnotations::getConstant, + eq(1), + { r -> r == "Constant_1" }, + coverage = DoNotCalculate, + ) + } } } \ No newline at end of file diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithoutAnnotationsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithoutAnnotationsTest.kt index 1aa631f627..b3a8824dc6 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithoutAnnotationsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithoutAnnotationsTest.kt @@ -3,14 +3,17 @@ package org.utbot.examples.annotations.lombok import org.junit.jupiter.api.Test import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.utbot.testcheckers.eq +import org.utbot.testcheckers.withConcrete internal class EnumWithoutAnnotationsTest : UtValueTestCaseChecker(testClass = EnumWithoutAnnotations::class) { @Test fun testGetterWithoutAnnotations() { - check( - EnumWithoutAnnotations::getConstant, - eq(1), - { r -> r == "Constant_1" }, - ) + withConcrete(useConcreteExecution = true) { // TODO https://github.com/UnitTestBot/UTBotJava/issues/1249 + check( + EnumWithoutAnnotations::getConstant, + eq(1), + { r -> r == "Constant_1" }, + ) + } } } \ No newline at end of file diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/InstanceOfExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/InstanceOfExampleTest.kt index 3120762937..cbfb208f26 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/InstanceOfExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/InstanceOfExampleTest.kt @@ -8,6 +8,7 @@ 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.withConcrete import org.utbot.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation SAT-1332 @@ -278,46 +279,48 @@ internal class InstanceOfExampleTest : UtValueTestCaseChecker( @Test //TODO: fails without concrete execution fun testComplicatedInstanceOf() { - check( - InstanceOfExample::complicatedInstanceOf, - eq(8), - { _, index, _, result -> index < 0 && result == null }, - { _, index, _, result -> index > 2 && result == null }, - { objects, index, _, result -> index in 0..2 && objects == null && result == null }, - { objects, index, _, result -> index in 0..2 && objects != null && objects.size < index + 2 && result == null }, - { objects, index, objectExample, result -> - require(objects != null && result != null && objectExample is CastClassFirstSucc) - - val sizeConstraint = index in 0..2 && objects.size >= index + 2 - val resultConstraint = result[index].x == objectExample.z - - sizeConstraint && resultConstraint - }, - { objects, index, objectExample, _ -> - index in 0..2 && objects != null && objects.size >= index + 2 && objectExample == null - }, - { objects, index, objectExample, result -> - require(objects != null && result != null && result[index] is CastClassSecondSucc) - - val sizeConstraint = index in 0..2 && objects.size >= index + 2 - val typeConstraint = objectExample !is CastClassFirstSucc && result[index] is CastClassSecondSucc - val resultConstraint = result[index].x == result[index].foo() - - sizeConstraint && typeConstraint && resultConstraint - }, - { objects, index, objectExample, result -> - require(objects != null && result != null) - - val sizeConstraint = index in 0..2 && objects.size >= index + 2 - val objectExampleConstraint = objectExample !is CastClassFirstSucc - val resultTypeConstraint = result[index] !is CastClassFirstSucc && result[index] !is CastClassSecondSucc - val typeConstraint = objectExampleConstraint && resultTypeConstraint - val resultConstraint = result[index].x == result[index].foo() - - sizeConstraint && typeConstraint && resultConstraint - }, - coverage = DoNotCalculate - ) + withConcrete(useConcreteExecution = true) { + check( + InstanceOfExample::complicatedInstanceOf, + eq(8), + { _, index, _, result -> index < 0 && result == null }, + { _, index, _, result -> index > 2 && result == null }, + { objects, index, _, result -> index in 0..2 && objects == null && result == null }, + { objects, index, _, result -> index in 0..2 && objects != null && objects.size < index + 2 && result == null }, + { objects, index, objectExample, result -> + require(objects != null && result != null && objectExample is CastClassFirstSucc) + + val sizeConstraint = index in 0..2 && objects.size >= index + 2 + val resultConstraint = result[index].x == objectExample.z + + sizeConstraint && resultConstraint + }, + { objects, index, objectExample, _ -> + index in 0..2 && objects != null && objects.size >= index + 2 && objectExample == null + }, + { objects, index, objectExample, result -> + require(objects != null && result != null && result[index] is CastClassSecondSucc) + + val sizeConstraint = index in 0..2 && objects.size >= index + 2 + val typeConstraint = objectExample !is CastClassFirstSucc && result[index] is CastClassSecondSucc + val resultConstraint = result[index].x == result[index].foo() + + sizeConstraint && typeConstraint && resultConstraint + }, + { objects, index, objectExample, result -> + require(objects != null && result != null) + + val sizeConstraint = index in 0..2 && objects.size >= index + 2 + val objectExampleConstraint = objectExample !is CastClassFirstSucc + val resultTypeConstraint = + result[index] !is CastClassFirstSucc && result[index] !is CastClassSecondSucc + val typeConstraint = objectExampleConstraint && resultTypeConstraint + val resultConstraint = result[index].x == result[index].foo() + + sizeConstraint && typeConstraint && resultConstraint + }, + ) + } } @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/CodegenExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/CodegenExampleTest.kt index ae342017f3..628d81bfa8 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/CodegenExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/CodegenExampleTest.kt @@ -5,16 +5,13 @@ import org.utbot.examples.mock.MockRandomExamples import kotlin.reflect.full.functions import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test -import org.utbot.testcheckers.withoutConcrete internal class CodegenExampleTest : UtValueTestCaseChecker(testClass = CodegenExample::class) { @Test fun firstExampleTest() { - withoutConcrete { - checkAllCombinations( - CodegenExample::firstExample, - ) - } + checkAllCombinations( + CodegenExample::firstExample, + ) } @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart3Test.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart3Test.kt index d02f176ed8..4c414fd45e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart3Test.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart3Test.kt @@ -5,11 +5,12 @@ import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.between import org.utbot.tests.infrastructure.isException import org.utbot.testcheckers.eq import org.utbot.testcheckers.ge import org.utbot.tests.infrastructure.CodeGeneration +import org.utbot.tests.infrastructure.FullWithAssumptions +import org.utbot.tests.infrastructure.ignoreExecutionsNumber // TODO failed Kotlin compilation SAT-1332 internal class ListsPart3Test : UtValueTestCaseChecker( @@ -27,8 +28,7 @@ internal class ListsPart3Test : UtValueTestCaseChecker( eq(3), { a, _ -> a == null }, { a, r -> a != null && a.isEmpty() && r!!.isEmpty() }, - { a, r -> a != null && a.isNotEmpty() && r != null && r.isNotEmpty() && a.toList() == r.also { println(r) } }, - coverage = DoNotCalculate + { a, r -> a != null && a.isNotEmpty() && !r.isNullOrEmpty() && a.toList() == r.also { println(r) } }, ) } @@ -38,7 +38,7 @@ internal class ListsPart3Test : UtValueTestCaseChecker( Lists::bigListFromParameters, eq(1), { list, r -> list.size == r && list.size == 11 }, - coverage = DoNotCalculate + coverage = FullWithAssumptions(assumeCallsNumber = 1) ) } @@ -46,11 +46,10 @@ internal class ListsPart3Test : UtValueTestCaseChecker( fun testGetNonEmptyCollection() { check( Lists::getNonEmptyCollection, - eq(3), + ignoreExecutionsNumber, { collection, _ -> collection == null }, { collection, r -> collection.isEmpty() && r == null }, { collection, r -> collection.isNotEmpty() && collection == r }, - coverage = DoNotCalculate ) } @@ -63,7 +62,6 @@ internal class ListsPart3Test : UtValueTestCaseChecker( { l, _ -> l.isEmpty() }, { l, r -> l[0] == null && r == null }, { l, r -> l[0] != null && r is Array<*> && r.isArrayOf() && r.size == 1 && r[0] == l[0] }, - coverage = DoNotCalculate ) } @@ -84,7 +82,6 @@ internal class ListsPart3Test : UtValueTestCaseChecker( sizeConstraint && content }, - coverage = DoNotCalculate ) } @@ -92,7 +89,7 @@ internal class ListsPart3Test : UtValueTestCaseChecker( fun removeElementsTest() { checkWithException( Lists::removeElements, - between(7..8), + ignoreExecutionsNumber, { list, _, _, r -> list == null && r.isException() }, { list, i, _, r -> list != null && i < 0 && r.isException() }, { list, i, _, r -> list != null && i >= 0 && list.size > i && list[i] == null && r.isException() }, @@ -134,7 +131,6 @@ internal class ListsPart3Test : UtValueTestCaseChecker( precondition && postcondition }, - coverage = DoNotCalculate ) } @@ -145,7 +141,6 @@ internal class ListsPart3Test : UtValueTestCaseChecker( eq(2), { x, r -> x % 2 != 0 && r is java.util.LinkedList && r == List(4) { it } }, { x, r -> x % 2 == 0 && r is java.util.ArrayList && r == List(4) { it } }, - coverage = DoNotCalculate ) } @@ -158,7 +153,6 @@ internal class ListsPart3Test : UtValueTestCaseChecker( { x, r -> x != null && x.isEmpty() && r!!.isEmpty() }, { x, _ -> x != null && x.isNotEmpty() && x.any { it == null } }, { x, r -> x != null && x.isNotEmpty() && x.all { it is Int } && r!!.toList() == x }, - coverage = DoNotCalculate ) } @@ -170,7 +164,6 @@ internal class ListsPart3Test : UtValueTestCaseChecker( { x, _ -> x == null }, { x, r -> x != null && x.isEmpty() && r!!.isEmpty() }, { x, r -> x != null && x.isNotEmpty() && r!!.containsAll(x.toList()) && r.size == x.size }, - coverage = DoNotCalculate ) } @@ -182,7 +175,6 @@ internal class ListsPart3Test : UtValueTestCaseChecker( { list, _ -> list == null }, { list, r -> list.size >= 2 && r == emptyList() }, { list, r -> list.size < 2 && r == emptyList() }, - coverage = DoNotCalculate ) } @@ -198,7 +190,6 @@ internal class ListsPart3Test : UtValueTestCaseChecker( { list, i, r -> list != null && list.isNotEmpty() && r != null && r.size == 1 + list.size && r == listOf(i) + list }, - coverage = DoNotCalculate ) } @@ -213,7 +204,6 @@ internal class ListsPart3Test : UtValueTestCaseChecker( { list, i, r -> list != null && i in 0..list.lastIndex && r == list.toMutableList().apply { addAll(i, listOf(0, 1)) } }, - coverage = DoNotCalculate ) } diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapEntrySetTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapEntrySetTest.kt index eb468a4bac..d5be32cd80 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapEntrySetTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapEntrySetTest.kt @@ -7,8 +7,8 @@ import org.utbot.tests.infrastructure.isException import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test -import org.utbot.testcheckers.ge import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete +import org.utbot.tests.infrastructure.AtLeast import org.utbot.tests.infrastructure.CodeGeneration import org.utbot.tests.infrastructure.ignoreExecutionsNumber @@ -45,10 +45,10 @@ class MapEntrySetTest : UtValueTestCaseChecker( fun testAddToEntrySet() { checkWithException( MapEntrySet::addToEntrySet, - between(2..4), + ignoreExecutionsNumber, { map, result -> map == null && result.isException() }, { map, result -> map != null && result.isException() }, - coverage = DoNotCalculate + coverage = AtLeast(75) ) } @@ -56,11 +56,11 @@ class MapEntrySetTest : UtValueTestCaseChecker( fun testGetFromEntrySet() { check( MapEntrySet::getFromEntrySet, - between(3..7), + ignoreExecutionsNumber, { map, _, _, _ -> map == null }, { map, i, j, result -> map.none { it.key == i && it.value == j } && result == 1 }, { map, i, j, result -> map.any { it.key == i && it.value == j } && result == 1 }, - coverage = DoNotCalculate + coverage = AtLeast(94) // unreachable branch ) } @@ -68,11 +68,10 @@ class MapEntrySetTest : UtValueTestCaseChecker( fun testIteratorHasNext() { check( MapEntrySet::iteratorHasNext, - between(3..4), + ignoreExecutionsNumber, { map, _ -> map == null }, { map, result -> map.entries.isEmpty() && result == 0 }, { map, result -> map.entries.isNotEmpty() && result == map.entries.size }, - coverage = DoNotCalculate ) } @@ -80,7 +79,7 @@ class MapEntrySetTest : UtValueTestCaseChecker( fun testIteratorNext() { checkWithException( MapEntrySet::iteratorNext, - between(3..5), + ignoreExecutionsNumber, { map, result -> map == null && result.isException() }, { map, result -> map.entries.isEmpty() && result.isException() }, // test should work as long as default class for map is LinkedHashMap @@ -90,7 +89,6 @@ class MapEntrySetTest : UtValueTestCaseChecker( val (resultKey, resultValue) = resultEntry map.entries.isNotEmpty() && entryKey == resultKey && entryValue == resultValue }, - coverage = DoNotCalculate ) } @@ -98,7 +96,7 @@ class MapEntrySetTest : UtValueTestCaseChecker( fun testIteratorRemove() { checkWithException( MapEntrySet::iteratorRemove, - between(3..4), + ignoreExecutionsNumber, { map, result -> map == null && result.isException() }, { map, result -> map.entries.isEmpty() && result.isException() }, // test should work as long as default class for map is LinkedHashMap @@ -109,7 +107,6 @@ class MapEntrySetTest : UtValueTestCaseChecker( resultMap.entries.size == map.entries.size - 1 && map.entries.first() !in resultMap.entries map.entries.isNotEmpty() && mapContainsAllEntriesInResult && resultDoesntContainFirstEntry }, - coverage = DoNotCalculate ) } @@ -117,7 +114,7 @@ class MapEntrySetTest : UtValueTestCaseChecker( fun testIteratorRemoveOnIndex() { checkWithException( MapEntrySet::iteratorRemoveOnIndex, - ge(5), + ignoreExecutionsNumber, { _, i, result -> i == 0 && result.isSuccess && result.getOrNull() == null }, { map, _, result -> map == null && result.isException() }, { map, i, result -> map != null && i < 0 && result.isException() }, @@ -130,7 +127,6 @@ class MapEntrySetTest : UtValueTestCaseChecker( val resultDoesntContainIthEntry = map.entries.toList()[i - 1] !in resultMap.entries iInIndexRange && mapContainsAllEntriesInResult && resultDoesntContainIthEntry }, - coverage = DoNotCalculate ) } @@ -138,11 +134,10 @@ class MapEntrySetTest : UtValueTestCaseChecker( fun testIterateForEach() { check( MapEntrySet::iterateForEach, - between(3..5), + ignoreExecutionsNumber, { map, _ -> map == null }, { map, _ -> null in map.values }, { map, result -> result!![0] == map.keys.sum() && result[1] == map.values.sum() }, - coverage = DoNotCalculate ) } @@ -168,8 +163,8 @@ class MapEntrySetTest : UtValueTestCaseChecker( { map, result -> val mapIsNotEmptyAndSizeIsEven = map != null && map.isNotEmpty() && map.size % 2 == 0 val arrayResult = result.getOrThrow() - val evenKeysSum = map.keys.withIndex().filter { it.index % 2 == 0 }.sumBy { it.value } - val oddValuesSum = map.values.withIndex().filter { it.index % 2 == 0 }.sumBy { it.value } + val evenKeysSum = map.keys.withIndex().filter { it.index % 2 == 0 }.sumOf { it.value } + val oddValuesSum = map.values.withIndex().filter { it.index % 2 == 0 }.sumOf { it.value } mapIsNotEmptyAndSizeIsEven && arrayResult[0] == evenKeysSum && arrayResult[1] == oddValuesSum }, ) diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapKeySetTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapKeySetTest.kt index 6f2a1f5f48..660832a585 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapKeySetTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapKeySetTest.kt @@ -1,18 +1,14 @@ 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.tests.infrastructure.isException -import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testcheckers.ge +import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete import org.utbot.testcheckers.withoutMinimization +import org.utbot.tests.infrastructure.AtLeast import org.utbot.tests.infrastructure.CodeGeneration +import org.utbot.tests.infrastructure.UtValueTestCaseChecker +import org.utbot.tests.infrastructure.ignoreExecutionsNumber +import org.utbot.tests.infrastructure.isException // TODO failed Kotlin compilation SAT-1332 class MapKeySetTest : UtValueTestCaseChecker( @@ -46,10 +42,10 @@ class MapKeySetTest : UtValueTestCaseChecker( fun testAddToKeySet() { checkWithException( MapKeySet::addToKeySet, - between(2..4), + ignoreExecutionsNumber, { map, result -> map == null && result.isException() }, { map, result -> map != null && result.isException() }, - coverage = DoNotCalculate + coverage = AtLeast(70) // unreachable return ) } @@ -62,7 +58,7 @@ class MapKeySetTest : UtValueTestCaseChecker( { map, _, _ -> map == null }, { map, i, result -> i !in map && result == 1 }, // one of these will be minimized { map, i, result -> i in map && result == 1 }, // one of these will be minimized - coverage = AtLeast(90) // 18/20 instructions + coverage = AtLeast(90) // 18/20 instructions, unreachable branch ) } } @@ -71,11 +67,10 @@ class MapKeySetTest : UtValueTestCaseChecker( fun testIteratorHasNext() { check( MapKeySet::iteratorHasNext, - between(3..4), + ignoreExecutionsNumber, { map, _ -> map == null }, { map, result -> map.keys.isEmpty() && result == 0 }, { map, result -> map.keys.isNotEmpty() && result == map.keys.size }, - coverage = DoNotCalculate ) } @@ -84,12 +79,11 @@ class MapKeySetTest : UtValueTestCaseChecker( withPushingStateFromPathSelectorForConcrete { checkWithException( MapKeySet::iteratorNext, - between(3..4), + ignoreExecutionsNumber, { map, result -> map == null && result.isException() }, { map, result -> map.keys.isEmpty() && result.isException() }, // test should work as long as default class for map is LinkedHashMap { map, result -> map.keys.isNotEmpty() && result.getOrNull() == map.keys.first() }, - coverage = DoNotCalculate ) } } @@ -98,7 +92,7 @@ class MapKeySetTest : UtValueTestCaseChecker( fun testIteratorRemove() { checkWithException( MapKeySet::iteratorRemove, - between(3..4), + ignoreExecutionsNumber, { map, result -> map == null && result.isException() }, { map, result -> map.keys.isEmpty() && result.isException() }, // test should work as long as default class for map is LinkedHashMap @@ -108,7 +102,6 @@ class MapKeySetTest : UtValueTestCaseChecker( val resultDoesntContainFirstKey = resultMap.keys.size == map.keys.size - 1 && map.keys.first() !in resultMap.keys mapContainsAllKeysInResult && resultDoesntContainFirstKey }, - coverage = DoNotCalculate ) } @@ -116,7 +109,7 @@ class MapKeySetTest : UtValueTestCaseChecker( fun testIteratorRemoveOnIndex() { checkWithException( MapKeySet::iteratorRemoveOnIndex, - ge(5), + ignoreExecutionsNumber, { _, i, result -> i == 0 && result.isSuccess && result.getOrNull() == null }, { map, _, result -> map == null && result.isException() }, { map, i, result -> map != null && i < 0 && result.isException() }, @@ -129,7 +122,6 @@ class MapKeySetTest : UtValueTestCaseChecker( val resultDoesntContainIthKey = map.keys.toList()[i - 1] !in resultMap.keys iInIndexRange && mapContainsAllKeysInResult && resultDoesntContainIthKey }, - coverage = DoNotCalculate ) } @@ -159,7 +151,7 @@ class MapKeySetTest : UtValueTestCaseChecker( fun testNullKey() { check( MapKeySet::nullKey, - eq(3), + ignoreExecutionsNumber, { map, _ -> map == null }, { map, result -> map != null && null in map.keys && map[null] == result }, { map, _ -> map != null && null !in map.keys } diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapValuesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapValuesTest.kt index 7ac0205a89..11493ab8ca 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapValuesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapValuesTest.kt @@ -54,10 +54,10 @@ class MapValuesTest : UtValueTestCaseChecker( fun testAddToValues() { checkWithException( MapValues::addToValues, - between(2..4), + ignoreExecutionsNumber, { map, result -> map == null && result.isException() }, { map, result -> map != null && result.isException() }, - coverage = DoNotCalculate + coverage = AtLeast(70) // unreachable return ) } @@ -79,11 +79,10 @@ class MapValuesTest : UtValueTestCaseChecker( fun testIteratorHasNext() { check( MapValues::iteratorHasNext, - between(3..4), + ignoreExecutionsNumber, { map, _ -> map == null }, { map, result -> map.values.isEmpty() && result == 0 }, { map, result -> map.values.isNotEmpty() && result == map.values.size }, - coverage = DoNotCalculate ) } @@ -91,7 +90,7 @@ class MapValuesTest : UtValueTestCaseChecker( fun testIteratorNext() { checkWithException( MapValues::iteratorNext, - between(3..4), + ignoreExecutionsNumber, { map, result -> map == null && result.isException() }, // We might lose this branch depending on the order of the exploration since // we do not register wrappers, and, therefore, do not try to cover all of their branches @@ -106,7 +105,7 @@ class MapValuesTest : UtValueTestCaseChecker( fun testIteratorRemove() { checkWithException( MapValues::iteratorRemove, - between(3..4), + ignoreExecutionsNumber, { map, result -> map == null && result.isException() }, { map, result -> map.values.isEmpty() && result.isException() }, // test should work as long as default class for map is LinkedHashMap @@ -127,7 +126,6 @@ class MapValuesTest : UtValueTestCaseChecker( mapContainsAllValuesFromResult && firstValueWasDeleted && keyAssociatedWithFirstValueWasDeleted }, - coverage = DoNotCalculate ) } @@ -135,7 +133,7 @@ class MapValuesTest : UtValueTestCaseChecker( fun testIteratorRemoveOnIndex() { checkWithException( MapValues::iteratorRemoveOnIndex, - ge(5), + ignoreExecutionsNumber, { _, i, result -> i == 0 && result.isSuccess && result.getOrNull() == null }, { map, _, result -> map == null && result.isException() }, { map, i, result -> map != null && i < 0 && result.isException() }, @@ -156,7 +154,6 @@ class MapValuesTest : UtValueTestCaseChecker( iInIndexRange && mapContainsAllValuesFromResult && ithValueWasDeleted && keyAssociatedWIthIthValueWasDeleted }, - coverage = DoNotCalculate ) } @@ -164,11 +161,10 @@ class MapValuesTest : UtValueTestCaseChecker( fun testIterateForEach() { check( MapValues::iterateForEach, - between(3..5), + ignoreExecutionsNumber, { map, _ -> map == null }, { map, _ -> null in map.values }, { map, result -> map != null && result == map.values.sum() }, - coverage = DoNotCalculate ) } @@ -176,11 +172,10 @@ class MapValuesTest : UtValueTestCaseChecker( fun testIterateWithIterator() { check( MapValues::iterateWithIterator, - between(3..5), + ignoreExecutionsNumber, { map, _ -> map == null }, { map, _ -> null in map.values }, { map, result -> map != null && result == map.values.sum() }, - coverage = DoNotCalculate ) } } \ No newline at end of file diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapsPart1Test.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapsPart1Test.kt index 738e45f661..7089e00991 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapsPart1Test.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapsPart1Test.kt @@ -3,18 +3,16 @@ package org.utbot.examples.collections import org.junit.jupiter.api.Tag 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.utbot.framework.plugin.api.MockStrategyApi 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.withoutConcrete +import org.utbot.testcheckers.withConcrete import org.utbot.testcheckers.withoutMinimization import org.utbot.tests.infrastructure.CodeGeneration +import org.utbot.tests.infrastructure.FullWithAssumptions // TODO failed Kotlin compilation ($ in names, generics) SAT-1220 SAT-1332 internal class MapsPart1Test : UtValueTestCaseChecker( @@ -35,8 +33,8 @@ internal class MapsPart1Test : UtValueTestCaseChecker( { map, key, _, result -> map != null && key in map && result == map }, { map, key, value, result -> val valueWasPut = result!![key] == value && result.size == map.size + 1 - val otherValuesWerentTouched = result.entries.containsAll(map.entries) - key !in map && valueWasPut && otherValuesWerentTouched + val otherValuesWereNotTouched = result.entries.containsAll(map.entries) + key !in map && valueWasPut && otherValuesWereNotTouched }, coverage = AtLeast(90) // unreachable else branch in MUT ) @@ -47,15 +45,14 @@ internal class MapsPart1Test : UtValueTestCaseChecker( fun testReplaceEntry() { check( Maps::replaceEntry, - between(3..6), + ignoreExecutionsNumber, { map, _, _, _ -> map == null }, { map, key, _, result -> key !in map && result == map }, { map, key, value, result -> val valueWasReplaced = result!![key] == value - val otherValuesWerentTouched = result.entries.all { it.key == key || it in map.entries } - key in map && valueWasReplaced && otherValuesWerentTouched + val otherValuesWereNotTouched = result.entries.all { it.key == key || it in map.entries } + key in map && valueWasReplaced && otherValuesWereNotTouched }, - coverage = DoNotCalculate ) } @@ -66,62 +63,58 @@ internal class MapsPart1Test : UtValueTestCaseChecker( eq(5), { keys, _, _ -> keys == null }, { keys, _, result -> keys.isEmpty() && result!!.isEmpty() }, - { keys, values, result -> keys.isNotEmpty() && values == null }, - { keys, values, result -> keys.isNotEmpty() && values.size < keys.size }, + { keys, values, _ -> keys.isNotEmpty() && values == null }, + { keys, values, _ -> keys.isNotEmpty() && values.size < keys.size }, { keys, values, result -> keys.isNotEmpty() && values.size >= keys.size && result!!.size == keys.size && keys.indices.all { result[keys[it]] == values[it] } }, - coverage = DoNotCalculate ) } @Test fun testToString() { - check( - Maps::mapToString, - eq(1), - { a, b, c, r -> r == Maps().mapToString(a, b, c) } - ) - } - - @Test - fun testMapPutAndGet() { - withoutConcrete { + // TODO JIRA:1604 + withConcrete(useConcreteExecution = true) { check( - Maps::mapPutAndGet, + Maps::mapToString, eq(1), - { r -> r == 3 } + { a, b, c, r -> r == Maps().mapToString(a, b, c) } ) } } + @Test + fun testMapPutAndGet() { + check( + Maps::mapPutAndGet, + eq(1), + { r -> r == 3 } + ) + } + @Test fun testPutInMapFromParameters() { - withoutConcrete { - check( - Maps::putInMapFromParameters, - ignoreExecutionsNumber, - { values, _ -> values == null }, - { values, r -> 1 in values.keys && r == 3 }, - { values, r -> 1 !in values.keys && r == 3 }, - ) - } + check( + Maps::putInMapFromParameters, + ignoreExecutionsNumber, + { values, _ -> values == null }, + { values, r -> 1 in values.keys && r == 3 }, + { values, r -> 1 !in values.keys && r == 3 }, + ) } // This test doesn't check anything specific, but the code from MUT // caused errors with NPE as results while debugging `testPutInMapFromParameters`. @Test fun testContainsKeyAndPuts() { - withoutConcrete { - check( - Maps::containsKeyAndPuts, - ignoreExecutionsNumber, - { values, _ -> values == null }, - { values, r -> 1 !in values.keys && r == 3 }, - coverage = DoNotCalculate - ) - } + check( + Maps::containsKeyAndPuts, + ignoreExecutionsNumber, + { values, _ -> values == null }, + { values, r -> 1 !in values.keys && r == 3 }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) } @Test @@ -132,7 +125,6 @@ internal class MapsPart1Test : UtValueTestCaseChecker( { s, _ -> s == null }, { s, result -> s == "" && result!!.isEmpty() }, { s, result -> s != "" && result == s.groupingBy { it }.eachCount() }, - coverage = DoNotCalculate ) } @@ -140,16 +132,15 @@ internal class MapsPart1Test : UtValueTestCaseChecker( fun putElementsTest() { check( Maps::putElements, - ge(5), + ignoreExecutionsNumber, { map, _, _ -> map == null }, { map, array, _ -> map != null && map.isNotEmpty() && array == null }, { map, _, result -> map.isEmpty() && result == map }, { map, array, result -> map.isNotEmpty() && array.isEmpty() && result == map }, { map, array, result -> - map.size >= 1 && array.isNotEmpty() + map.isNotEmpty() && array.isNotEmpty() && result == map.toMutableMap().apply { putAll(array.map { it to it }) } }, - coverage = DoNotCalculate ) } @@ -157,14 +148,14 @@ internal class MapsPart1Test : UtValueTestCaseChecker( fun removeEntries() { check( Maps::removeElements, - ge(6), + ignoreExecutionsNumber, { map, _, _, _ -> map == null }, { map, i, j, res -> map != null && (i !in map || map[i] == null) && (j !in map || map[j] == null) && res == -1 }, { map, i, j, res -> map != null && map.isNotEmpty() && i !in map && j in map && res == 4 }, { map, i, j, res -> map != null && map.isNotEmpty() && i in map && (j !in map || j == i) && res == 3 }, { map, i, j, res -> map != null && map.size >= 2 && i in map && j in map && i > j && res == 2 }, { map, i, j, res -> map != null && map.size >= 2 && i in map && j in map && i < j && res == 1 }, - coverage = DoNotCalculate + coverage = AtLeast(94) // unreachable return ) } @@ -175,7 +166,6 @@ internal class MapsPart1Test : UtValueTestCaseChecker( eq(2), { seed, result -> seed % 2 != 0 && result is java.util.LinkedHashMap }, { seed, result -> seed % 2 == 0 && result !is java.util.LinkedHashMap && result is java.util.HashMap }, - coverage = DoNotCalculate ) } @@ -183,11 +173,10 @@ internal class MapsPart1Test : UtValueTestCaseChecker( fun removeCustomObjectTest() { check( Maps::removeCustomObject, - ge(3), + ignoreExecutionsNumber, { map, _, _ -> map == null }, { map, i, result -> (map.isEmpty() || CustomClass(i) !in map) && result == null }, { map, i, result -> map.isNotEmpty() && CustomClass(i) in map && result == map[CustomClass(i)] }, - coverage = DoNotCalculate ) } @@ -206,19 +195,18 @@ internal class MapsPart1Test : UtValueTestCaseChecker( fun testComputeValue() { check( Maps::computeValue, - between(3..5), + ignoreExecutionsNumber, { map, _, _ -> map == null }, { map, key, result -> val valueWasUpdated = result!![key] == key + 1 - val otherValuesWerentTouched = result.entries.all { it.key == key || it in map.entries } - map[key] == null && valueWasUpdated && otherValuesWerentTouched + val otherValuesWereNotTouched = result.entries.all { it.key == key || it in map.entries } + map[key] == null && valueWasUpdated && otherValuesWereNotTouched }, { map, key, result -> val valueWasUpdated = result!![key] == map[key]!! + 1 - val otherValuesWerentTouched = result.entries.all { it.key == key || it in map.entries } - map[key] != null && valueWasUpdated && otherValuesWerentTouched + val otherValuesWereNotTouched = result.entries.all { it.key == key || it in map.entries } + map[key] != null && valueWasUpdated && otherValuesWereNotTouched }, - coverage = DoNotCalculate ) } @@ -226,20 +214,19 @@ internal class MapsPart1Test : UtValueTestCaseChecker( fun testComputeValueWithMocks() { check( Maps::computeValue, - between(3..5), + ignoreExecutionsNumber, { map, _, _ -> map == null }, { map, key, result -> val valueWasUpdated = result!![key] == key + 1 - val otherValuesWerentTouched = result.entries.all { it.key == key || it in map.entries } - map[key] == null && valueWasUpdated && otherValuesWerentTouched + val otherValuesWereNotTouched = result.entries.all { it.key == key || it in map.entries } + map[key] == null && valueWasUpdated && otherValuesWereNotTouched }, { map, key, result -> val valueWasUpdated = result!![key] == map[key]!! + 1 - val otherValuesWerentTouched = result.entries.all { it.key == key || it in map.entries } - map[key] != null && valueWasUpdated && otherValuesWerentTouched + val otherValuesWereNotTouched = result.entries.all { it.key == key || it in map.entries } + map[key] != null && valueWasUpdated && otherValuesWereNotTouched }, mockStrategy = MockStrategyApi.OTHER_PACKAGES, // checks that we do not generate mocks for lambda classes - coverage = DoNotCalculate ) } @@ -247,15 +234,14 @@ internal class MapsPart1Test : UtValueTestCaseChecker( fun testComputeValueIfAbsent() { check( Maps::computeValueIfAbsent, - between(3..5), + ignoreExecutionsNumber, { map, _, _ -> map == null }, { map, key, result -> map[key] != null && result == map }, { map, key, result -> val valueWasUpdated = result!![key] == key + 1 - val otherValuesWerentTouched = result.entries.all { it.key == key || it in map.entries } - map[key] == null && valueWasUpdated && otherValuesWerentTouched + val otherValuesWereNotTouched = result.entries.all { it.key == key || it in map.entries } + map[key] == null && valueWasUpdated && otherValuesWereNotTouched }, - coverage = DoNotCalculate ) } @@ -263,15 +249,14 @@ internal class MapsPart1Test : UtValueTestCaseChecker( fun testComputeValueIfPresent() { check( Maps::computeValueIfPresent, - between(3..5), + ignoreExecutionsNumber, { map, _, _ -> map == null }, { map, key, result -> map[key] == null && result == map }, { map, key, result -> val valueWasUpdated = result!![key] == map[key]!! + 1 - val otherValuesWerentTouched = result.entries.all { it.key == key || it in map.entries } - map[key] != null && valueWasUpdated && otherValuesWerentTouched + val otherValuesWereNotTouched = result.entries.all { it.key == key || it in map.entries } + map[key] != null && valueWasUpdated && otherValuesWereNotTouched }, - coverage = DoNotCalculate ) } @@ -279,11 +264,11 @@ internal class MapsPart1Test : UtValueTestCaseChecker( fun testClearEntries() { check( Maps::clearEntries, - between(3..4), + ignoreExecutionsNumber, { map, _ -> map == null }, { map, result -> map.isEmpty() && result == 0 }, { map, result -> map.isNotEmpty() && result == 1 }, - coverage = DoNotCalculate + coverage = AtLeast(85) // unreachable return ) } @@ -291,11 +276,10 @@ internal class MapsPart1Test : UtValueTestCaseChecker( fun testContainsKey() { check( Maps::containsKey, - between(3..5), + ignoreExecutionsNumber, { map, _, _ -> map == null }, { map, key, result -> key !in map && result == 0 }, { map, key, result -> key in map && result == 1 }, - coverage = DoNotCalculate ) } @@ -303,11 +287,10 @@ internal class MapsPart1Test : UtValueTestCaseChecker( fun testContainsValue() { check( Maps::containsValue, - between(3..6), + ignoreExecutionsNumber, { map, _, _ -> map == null }, { map, value, result -> value !in map.values && result == 0 }, { map, value, result -> value in map.values && result == 1 }, - coverage = DoNotCalculate ) } @@ -315,12 +298,11 @@ internal class MapsPart1Test : UtValueTestCaseChecker( fun testGetOrDefaultElement() { check( Maps::getOrDefaultElement, - between(4..6), + ignoreExecutionsNumber, { map, _, _ -> map == null }, { map, i, result -> i !in map && result == 1 }, { map, i, result -> i in map && map[i] == null && result == 0 }, { map, i, result -> i in map && map[i] != null && result == map[i] }, - coverage = DoNotCalculate ) } @@ -328,14 +310,14 @@ internal class MapsPart1Test : UtValueTestCaseChecker( fun testRemoveKeyWithValue() { check( Maps::removeKeyWithValue, - ge(6), + ignoreExecutionsNumber, { map, _, _, _ -> map == null }, { map, key, value, result -> key !in map && value !in map.values && result == 0 }, { map, key, value, result -> key in map && value !in map.values && result == -1 }, { map, key, value, result -> key !in map && value in map.values && result == -2 }, { map, key, value, result -> key in map && map[key] == value && result == 3 }, { map, key, value, result -> key in map && value in map.values && map[key] != value && result == -3 }, - coverage = DoNotCalculate + coverage = AtLeast(92) // unreachable branches ) } @@ -343,7 +325,7 @@ internal class MapsPart1Test : UtValueTestCaseChecker( fun testReplaceAllEntries() { check( Maps::replaceAllEntries, - between(5..6), + ignoreExecutionsNumber, { map, _ -> map == null }, { map, result -> map.isEmpty() && result == null }, { map, _ -> map.isNotEmpty() && map.containsValue(null) }, @@ -361,28 +343,23 @@ internal class MapsPart1Test : UtValueTestCaseChecker( result == map.mapValues { if (it.key > it.value) it.value + 1 else it.value - 1 } precondition && secondBranchInLambdaExists && valuesWereReplaced }, - coverage = DoNotCalculate ) } @Test fun testCreateMapWithString() { - withoutConcrete { - check( - Maps::createMapWithString, - eq(1), - { r -> r!!.isEmpty() } - ) - } + check( + Maps::createMapWithString, + eq(1), + { r -> r!!.isEmpty() } + ) } @Test fun testCreateMapWithEnum() { - withoutConcrete { - check( - Maps::createMapWithEnum, - eq(1), - { r -> r != null && r.size == 2 && r[Maps.WorkDays.Monday] == 112 && r[Maps.WorkDays.Friday] == 567 } - ) - } + check( + Maps::createMapWithEnum, + eq(1), + { r -> r != null && r.size == 2 && r[Maps.WorkDays.Monday] == 112 && r[Maps.WorkDays.Friday] == 567 } + ) } } \ No newline at end of file diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/SetIteratorsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/SetIteratorsTest.kt index bdaa3d4f14..3e84e8e1c8 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/SetIteratorsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/SetIteratorsTest.kt @@ -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 }, @@ -33,7 +33,7 @@ class SetIteratorsTest : UtValueTestCaseChecker( fun testIteratorNext() { checkWithException( SetIterators::iteratorNext, - between(3..4), + ignoreExecutionsNumber, { set, result -> set == null && result.isException() }, { set, result -> set != null && set.isEmpty() && result.isException() }, // test should work as long as default class for set is LinkedHashSet @@ -45,7 +45,7 @@ class SetIteratorsTest : UtValueTestCaseChecker( fun testIteratorRemove() { checkWithException( SetIterators::iteratorRemove, - between(3..4), + ignoreExecutionsNumber, { set, result -> set == null && result.isException() }, { set, result -> set.isEmpty() && result.isException() }, // test should work as long as default class for set is LinkedHashSet @@ -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() }, { set, i, result -> set != null && i < 0 && result.isException() }, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/SetsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/SetsTest.kt index 525e8e4126..bf5103f2bb 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/SetsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/SetsTest.kt @@ -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 @@ -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()) }, ) } @@ -92,7 +89,7 @@ internal class SetsTest : UtValueTestCaseChecker( val resultFun = { set: Set -> 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 }, @@ -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 }, @@ -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 }, @@ -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 }, @@ -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 ) } } @@ -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 }, @@ -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 }, @@ -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 }, @@ -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 }, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/enums/ClassWithEnumTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/enums/ClassWithEnumTest.kt index 8fb8b9b67b..bd7039b877 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/enums/ClassWithEnumTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/enums/ClassWithEnumTest.kt @@ -12,14 +12,13 @@ import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.util.jField import org.utbot.testcheckers.eq import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete -import org.utbot.testcheckers.withoutConcrete +import org.utbot.testcheckers.withConcrete +import org.utbot.tests.infrastructure.ignoreExecutionsNumber class ClassWithEnumTest : UtValueTestCaseChecker(testClass = ClassWithEnum::class) { @Test fun testOrdinal() { - withoutConcrete { - checkAllCombinations(ClassWithEnum::useOrdinal) - } + checkAllCombinations(ClassWithEnum::useOrdinal) } @Test @@ -36,7 +35,7 @@ class ClassWithEnumTest : UtValueTestCaseChecker(testClass = ClassWithEnum::clas fun testDifficultIfBranch() { check( ClassWithEnum::useEnumInDifficultIf, - eq(2), + ignoreExecutionsNumber, { s, r -> s.equals("TRYIF", ignoreCase = true) && r == 1 }, { s, r -> !s.equals("TRYIF", ignoreCase = true) && r == 2 }, ) @@ -106,19 +105,21 @@ class ClassWithEnumTest : UtValueTestCaseChecker(testClass = ClassWithEnum::clas @Test fun testChangingStaticWithEnumInit() { - checkThisAndStaticsAfter( - ClassWithEnum::changingStaticWithEnumInit, - eq(1), - { t, staticsAfter, r -> - // for some reasons x is inaccessible - val x = FieldId(t.javaClass.id, "x").jField.get(t) as Int - - val y = staticsAfter[FieldId(ClassWithEnum.ClassWithStaticField::class.id, "y")]!!.value as Int - - val areStaticsCorrect = x == 1 && y == 11 - areStaticsCorrect && r == true - } - ) + withConcrete(useConcreteExecution = true) { // TODO https://github.com/UnitTestBot/UTBotJava/issues/1249 + checkThisAndStaticsAfter( + ClassWithEnum::changingStaticWithEnumInit, + eq(1), + { t, staticsAfter, r -> + // for some reasons x is inaccessible + val x = FieldId(t.javaClass.id, "x").jField.get(t) as Int + + val y = staticsAfter[FieldId(ClassWithEnum.ClassWithStaticField::class.id, "y")]!!.value as Int + + val areStaticsCorrect = x == 1 && y == 11 + areStaticsCorrect && r == true + } + ) + } } @Test @@ -168,7 +169,7 @@ class ClassWithEnumTest : UtValueTestCaseChecker(testClass = ClassWithEnum::clas withPushingStateFromPathSelectorForConcrete { check( ClassWithEnum::implementingInterfaceEnumInDifficultBranch, - eq(2), + ignoreExecutionsNumber, { s, r -> s.equals("SUCCESS", ignoreCase = true) && r == 0 }, { s, r -> !s.equals("SUCCESS", ignoreCase = true) && r == 2 }, ) diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/exceptions/ExceptionExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/exceptions/ExceptionExamplesTest.kt index 461faf48b2..45cf43992a 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/exceptions/ExceptionExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/exceptions/ExceptionExamplesTest.kt @@ -7,7 +7,7 @@ import org.utbot.tests.infrastructure.isException import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.testcheckers.withoutConcrete +import org.utbot.testcheckers.withConcrete import org.utbot.tests.infrastructure.CodeGeneration internal class ExceptionExamplesTest : UtValueTestCaseChecker( @@ -75,13 +75,15 @@ internal class ExceptionExamplesTest : UtValueTestCaseChecker( @Test fun testThrowException() { - checkWithException( - ExceptionExamples::throwException, - eq(2), - { i, r -> i <= 0 && r.getOrNull() == 101 }, - { i, r -> i > 0 && r.isException() }, - coverage = atLeast(66) // because of unexpected exception thrown - ) + withConcrete(useConcreteExecution = true) { // native method inside the MUT that throws NPE + checkWithException( + ExceptionExamples::throwException, + eq(2), + { i, r -> i <= 0 && r.getOrNull() == 101 }, + { i, r -> i > 0 && r.isException() }, + coverage = atLeast(66) // because of unexpected exception thrown + ) + } } @Test @@ -112,16 +114,14 @@ internal class ExceptionExamplesTest : UtValueTestCaseChecker( */ @Test fun testCatchExceptionAfterOtherPossibleException() { - withoutConcrete { - checkWithException( - ExceptionExamples::catchExceptionAfterOtherPossibleException, - eq(3), - { i, r -> i == -1 && r.isException() }, - { i, r -> i == 0 && r.getOrThrow() == 2 }, - { i, r -> r.getOrThrow() == 1 }, - coverage = atLeast(100) - ) - } + checkWithException( + ExceptionExamples::catchExceptionAfterOtherPossibleException, + eq(3), + { i, r -> i == -1 && r.isException() }, + { i, r -> i == 0 && r.getOrThrow() == 2 }, + { i, r -> r.getOrThrow() == 1 }, + coverage = atLeast(100) + ) } /** diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/exceptions/JvmCrashExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/exceptions/JvmCrashExamplesTest.kt index 2e654c4f06..9c77c55278 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/exceptions/JvmCrashExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/exceptions/JvmCrashExamplesTest.kt @@ -5,6 +5,7 @@ import org.utbot.tests.infrastructure.DoNotCalculate import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testcheckers.withConcrete import org.utbot.testcheckers.withoutSandbox internal class JvmCrashExamplesTest : UtValueTestCaseChecker(testClass = JvmCrashExamples::class) { @@ -19,13 +20,15 @@ internal class JvmCrashExamplesTest : UtValueTestCaseChecker(testClass = JvmCras @Test fun testCrash() { - withoutSandbox { - check( - JvmCrashExamples::crash, - eq(1), // we expect only one execution after minimization - // It seems that we can't calculate coverage when the child JVM has crashed - coverage = DoNotCalculate - ) + withConcrete(useConcreteExecution = true) { // JVM crash is possible only with concrete execution + withoutSandbox { + check( + JvmCrashExamples::crash, + eq(1), // we expect only one execution after minimization + // It seems that we can't calculate coverage when the child JVM has crashed + coverage = DoNotCalculate + ) + } } } diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/VirtualInvokeExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/VirtualInvokeExampleTest.kt index ba1ff4814a..1e75714566 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/VirtualInvokeExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/VirtualInvokeExampleTest.kt @@ -8,6 +8,7 @@ import org.utbot.tests.infrastructure.isException import java.lang.Boolean import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testcheckers.withConcrete internal class VirtualInvokeExampleTest : UtValueTestCaseChecker(testClass = VirtualInvokeExample::class) { @Test @@ -24,11 +25,13 @@ internal class VirtualInvokeExampleTest : UtValueTestCaseChecker(testClass = Vir @Test fun testVirtualNative() { - check( - VirtualInvokeExample::virtualNative, - eq(1), - { r -> r == Boolean::class.java.modifiers } - ) + withConcrete(useConcreteExecution = true) { // native method in the MUT + check( + VirtualInvokeExample::virtualNative, + eq(1), + { r -> r == Boolean::class.java.modifiers } + ) + } } @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/CustomPredicateExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/CustomPredicateExampleTest.kt index c3b9692b3e..b0e6152c59 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/CustomPredicateExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/CustomPredicateExampleTest.kt @@ -3,6 +3,7 @@ package org.utbot.examples.lambda import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq +import org.utbot.testcheckers.withConcrete import org.utbot.tests.infrastructure.CodeGeneration import org.utbot.tests.infrastructure.DoNotCalculate import org.utbot.tests.infrastructure.UtValueTestCaseChecker @@ -57,25 +58,40 @@ class CustomPredicateExampleTest : UtValueTestCaseChecker( @Test fun testCapturedStaticFieldPredicateCheck() { - checkWithException( + checkStatics( CustomPredicateExample::capturedStaticFieldPredicateCheck, eq(3), - { predicate, x, r -> !predicate.test(x) && r.getOrNull() == false }, - { predicate, x, r -> predicate.test(x) && r.getOrNull() == true }, - { predicate, _, r -> predicate == null && r.isException() }, + { predicate, x, statics, r -> + val staticField = statics.values.singleOrNull()?.value as Int + CustomPredicateExample.someStaticField = staticField + + !predicate.test(x) && r == false + }, + { predicate, x, statics, r -> + val staticField = statics.values.singleOrNull()?.value as Int + CustomPredicateExample.someStaticField = staticField + + predicate.test(x) && r == true + }, + { predicate, _, _, _ -> + predicate == null + }, coverage = DoNotCalculate ) } @Test fun testCapturedNonStaticFieldPredicateCheck() { - checkWithException( - CustomPredicateExample::capturedNonStaticFieldPredicateCheck, - eq(3), - { predicate, x, r -> !predicate.test(x) && r.getOrNull() == false }, - { predicate, x, r -> predicate.test(x) && r.getOrNull() == true }, - { predicate, _, r -> predicate == null && r.isException() }, - coverage = DoNotCalculate - ) + // TODO fails without concrete https://github.com/UnitTestBot/UTBotJava/issues/1247 + withConcrete(useConcreteExecution = true) { + checkWithException( + CustomPredicateExample::capturedNonStaticFieldPredicateCheck, + eq(3), + { predicate, x, r -> !predicate.test(x) && r.getOrNull() == false }, + { predicate, x, r -> predicate.test(x) && r.getOrNull() == true }, + { predicate, _, r -> predicate == null && r.isException() }, + coverage = DoNotCalculate + ) + } } } diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/make/symbolic/ClassWithComplicatedMethodsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/make/symbolic/ClassWithComplicatedMethodsTest.kt index 63456488d6..6b46208793 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/make/symbolic/ClassWithComplicatedMethodsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/make/symbolic/ClassWithComplicatedMethodsTest.kt @@ -9,7 +9,7 @@ import kotlin.math.sqrt import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.testcheckers.withoutConcrete +import org.utbot.testcheckers.withConcrete import org.utbot.tests.infrastructure.Compilation // This class is substituted with ComplicatedMethodsSubstitutionsStorage @@ -51,7 +51,7 @@ internal class ClassWithComplicatedMethodsTest : UtValueTestCaseChecker( @Test fun testCreateWithSubstitutedConstructor() { - withoutConcrete { // TODO: concrete execution can't handle this + withConcrete(useConcreteExecution = false) { // TODO: concrete execution can't handle this checkMocksAndInstrumentation( ClassWithComplicatedMethods::createWithSubstitutedConstructor, eq(1), @@ -63,17 +63,19 @@ internal class ClassWithComplicatedMethodsTest : UtValueTestCaseChecker( @Test fun testSqrt2() { - checkMocksAndInstrumentation( - ClassWithComplicatedMethods::sqrt2, - eq(1), - { mocks, instr, r -> abs(r!! - sqrt(2.0)) < eps && mocks.isEmpty() && instr.isEmpty() }, - coverage = DoNotCalculate - ) + withConcrete(useConcreteExecution = true) { // the sqrt method is too difficult for symbolic analysis + checkMocksAndInstrumentation( + ClassWithComplicatedMethods::sqrt2, + eq(1), + { mocks, instr, r -> abs(r!! - sqrt(2.0)) < eps && mocks.isEmpty() && instr.isEmpty() }, + coverage = DoNotCalculate + ) + } } @Test fun testReturnSubstitutedMethod() { - withoutConcrete { // TODO: concrete execution can't handle this + withConcrete(useConcreteExecution = false) { // TODO: concrete execution can't handle this checkMocksAndInstrumentation( ClassWithComplicatedMethods::returnSubstitutedMethod, eq(1), diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockStaticFieldExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockStaticFieldExampleTest.kt index 907d9b5829..9f1d24abef 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockStaticFieldExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockStaticFieldExampleTest.kt @@ -12,13 +12,13 @@ import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES import kotlin.reflect.KClass import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.testcheckers.withoutConcrete +import org.utbot.testcheckers.withConcrete internal class MockStaticFieldExampleTest : UtValueTestCaseChecker(testClass = MockStaticFieldExample::class) { @Test fun testMockStaticField() { - withoutConcrete { // TODO JIRA:1420 + withConcrete(useConcreteExecution = false) { // TODO JIRA:1420 checkMocks( MockStaticFieldExample::calculate, eq(4), // 2 NPE diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ClassWithClassRefTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ClassWithClassRefTest.kt index 7770fbf977..16eba5bad0 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ClassWithClassRefTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ClassWithClassRefTest.kt @@ -6,7 +6,7 @@ import org.utbot.tests.infrastructure.isException import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.testcheckers.withoutConcrete +import org.utbot.testcheckers.withConcrete import org.utbot.tests.infrastructure.CodeGeneration import org.utbot.tests.infrastructure.Compilation @@ -24,7 +24,7 @@ internal class ClassWithClassRefTest : UtValueTestCaseChecker( // TODO test does not work properly JIRA:1479 // TODO we don't fail now, but we do not generate correct value as well fun testClassRefGetName() { - withoutConcrete { // TODO: concrete execution returns "java.lang.Object" + withConcrete(useConcreteExecution = false) { // TODO: concrete execution returns "java.lang.Object" checkWithThisAndException( ClassWithClassRef::classRefName, eq(2), diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt index b1dbb5a64d..2101115a37 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt @@ -12,7 +12,6 @@ import org.utbot.tests.infrastructure.ignoreExecutionsNumber import org.utbot.tests.infrastructure.isException import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.testcheckers.withoutConcrete import org.utbot.tests.infrastructure.AtLeast import org.utbot.tests.infrastructure.CodeGeneration import java.util.Optional @@ -31,28 +30,24 @@ class BaseStreamExampleTest : UtValueTestCaseChecker( ) { @Test fun testReturningStreamExample() { - withoutConcrete { - check( - BaseStreamExample::returningStreamExample, - eq(2), - // NOTE: the order of the matchers is important because Stream could be used only once - { c, r -> c.isNotEmpty() && c == r!!.toList() }, - { c, r -> c.isEmpty() && c == r!!.toList() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } + check( + BaseStreamExample::returningStreamExample, + eq(2), + // NOTE: the order of the matchers is important because Stream could be used only once + { c, r -> c.isNotEmpty() && c == r!!.toList() }, + { c, r -> c.isEmpty() && c == r!!.toList() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) } @Test fun testReturningStreamAsParameterExample() { - withoutConcrete { - check( - BaseStreamExample::returningStreamAsParameterExample, - eq(1), - { s, r -> s != null && s.toList() == r!!.toList() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } + check( + BaseStreamExample::returningStreamAsParameterExample, + eq(1), + { s, r -> s != null && s.toList() == r!!.toList() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) } @Test @@ -389,16 +384,14 @@ class BaseStreamExampleTest : UtValueTestCaseChecker( @Test fun testStreamOfExample() { - withoutConcrete { - check( - BaseStreamExample::streamOfExample, - ignoreExecutionsNumber, - // NOTE: the order of the matchers is important because Stream could be used only once - { c, r -> c.isNotEmpty() && c.contentEquals(r!!.toArray()) }, - { c, r -> c.isEmpty() && Stream.empty().toArray().contentEquals(r!!.toArray()) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } + check( + BaseStreamExample::streamOfExample, + ignoreExecutionsNumber, + // NOTE: the order of the matchers is important because Stream could be used only once + { c, r -> c.isNotEmpty() && c.contentEquals(r!!.toArray()) }, + { c, r -> c.isEmpty() && Stream.empty().toArray().contentEquals(r!!.toArray()) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) } @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/DoubleStreamExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/DoubleStreamExampleTest.kt index b480daa90c..7e38c79df8 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/DoubleStreamExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/DoubleStreamExampleTest.kt @@ -5,7 +5,6 @@ import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq import org.utbot.testcheckers.withPathSelectorStepsLimit -import org.utbot.testcheckers.withoutConcrete import org.utbot.tests.infrastructure.* import java.util.OptionalDouble import java.util.stream.DoubleStream @@ -35,14 +34,12 @@ class DoubleStreamExampleTest : UtValueTestCaseChecker( @Test fun testReturningStreamAsParameterExample() { - withoutConcrete { - check( - DoubleStreamExample::returningStreamAsParameterExample, - eq(1), - { s, r -> s != null && s.toList() == r!!.toList() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } + check( + DoubleStreamExample::returningStreamAsParameterExample, + eq(1), + { s, r -> s != null && s.toList() == r!!.toList() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) } @Test @@ -325,41 +322,39 @@ class DoubleStreamExampleTest : UtValueTestCaseChecker( @Test fun testSummaryStatisticsExample() { - withoutConcrete { - check( - DoubleStreamExample::summaryStatisticsExample, - ignoreExecutionsNumber, - { c, r -> - val sum = r!!.sum - val count = r.count - val min = r.min - val max = r.max + check( + DoubleStreamExample::summaryStatisticsExample, + ignoreExecutionsNumber, + { c, r -> + val sum = r!!.sum + val count = r.count + val min = r.min + val max = r.max - val allStatisticsAreCorrect = sum == 0.0 && - count == 0L && - min == Double.POSITIVE_INFINITY && - max == Double.NEGATIVE_INFINITY + val allStatisticsAreCorrect = sum == 0.0 && + count == 0L && + min == Double.POSITIVE_INFINITY && + max == Double.NEGATIVE_INFINITY - c.isEmpty() && allStatisticsAreCorrect - }, - { c, r -> - val sum = r!!.sum - val count = r.count - val min = r.min - val max = r.max + c.isEmpty() && allStatisticsAreCorrect + }, + { c, r -> + val sum = r!!.sum + val count = r.count + val min = r.min + val max = r.max - val doubles = c.doubles() + val doubles = c.doubles() - val allStatisticsAreCorrect = sum == doubles.sum() && - count == doubles.size.toLong() && - min == doubles.minOrNull() && - max == doubles.maxOrNull() + val allStatisticsAreCorrect = sum == doubles.sum() && + count == doubles.size.toLong() && + min == doubles.minOrNull() && + max == doubles.maxOrNull() - c.isNotEmpty() && allStatisticsAreCorrect - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } + c.isNotEmpty() && allStatisticsAreCorrect + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) } @Test @@ -486,16 +481,14 @@ class DoubleStreamExampleTest : UtValueTestCaseChecker( @Test fun testStreamOfExample() { - withoutConcrete { - check( - DoubleStreamExample::streamOfExample, - ignoreExecutionsNumber, - // NOTE: the order of the matchers is important because Stream could be used only once - { c, r -> c.isNotEmpty() && c.contentEquals(r!!.toArray()) }, - { c, r -> c.isEmpty() && DoubleStream.empty().toArray().contentEquals(r!!.toArray()) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } + check( + DoubleStreamExample::streamOfExample, + ignoreExecutionsNumber, + // NOTE: the order of the matchers is important because Stream could be used only once + { c, r -> c.isNotEmpty() && c.contentEquals(r!!.toArray()) }, + { c, r -> c.isEmpty() && DoubleStream.empty().toArray().contentEquals(r!!.toArray()) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) } @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/IntStreamExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/IntStreamExampleTest.kt index 62a1ecbca0..700eb61969 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/IntStreamExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/IntStreamExampleTest.kt @@ -5,7 +5,6 @@ import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq import org.utbot.testcheckers.withPathSelectorStepsLimit -import org.utbot.testcheckers.withoutConcrete import org.utbot.tests.infrastructure.* import java.util.OptionalDouble import java.util.OptionalInt @@ -36,14 +35,12 @@ class IntStreamExampleTest : UtValueTestCaseChecker( @Test fun testReturningStreamAsParameterExample() { - withoutConcrete { - check( - IntStreamExample::returningStreamAsParameterExample, - eq(1), - { s, r -> s != null && s.toList() == r!!.toList() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } + check( + IntStreamExample::returningStreamAsParameterExample, + eq(1), + { s, r -> s != null && s.toList() == r!!.toList() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) } @Test @@ -316,41 +313,39 @@ class IntStreamExampleTest : UtValueTestCaseChecker( @Test fun testSummaryStatisticsExample() { - withoutConcrete { - check( - IntStreamExample::summaryStatisticsExample, - ignoreExecutionsNumber, - { c, r -> - val sum = r!!.sum - val count = r.count - val min = r.min - val max = r.max + check( + IntStreamExample::summaryStatisticsExample, + ignoreExecutionsNumber, + { c, r -> + val sum = r!!.sum + val count = r.count + val min = r.min + val max = r.max - val allStatisticsAreCorrect = sum == 0L && - count == 0L && - min == Int.MAX_VALUE && - max == Int.MIN_VALUE + val allStatisticsAreCorrect = sum == 0L && + count == 0L && + min == Int.MAX_VALUE && + max == Int.MIN_VALUE - c.isEmpty() && allStatisticsAreCorrect - }, - { c, r -> - val sum = r!!.sum - val count = r.count - val min = r.min - val max = r.max + c.isEmpty() && allStatisticsAreCorrect + }, + { c, r -> + val sum = r!!.sum + val count = r.count + val min = r.min + val max = r.max - val ints = c.ints() + val ints = c.ints() - val allStatisticsAreCorrect = sum == ints.sum().toLong() && - count == ints.size.toLong() && - min == ints.minOrNull() && - max == ints.maxOrNull() + val allStatisticsAreCorrect = sum == ints.sum().toLong() && + count == ints.size.toLong() && + min == ints.minOrNull() && + max == ints.maxOrNull() - c.isNotEmpty() && allStatisticsAreCorrect - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } + c.isNotEmpty() && allStatisticsAreCorrect + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) } @Test @@ -497,16 +492,14 @@ class IntStreamExampleTest : UtValueTestCaseChecker( @Test fun testStreamOfExample() { - withoutConcrete { - check( - IntStreamExample::streamOfExample, - ignoreExecutionsNumber, - // NOTE: the order of the matchers is important because Stream could be used only once - { c, r -> c.isNotEmpty() && c.contentEquals(r!!.toArray()) }, - { c, r -> c.isEmpty() && IntStream.empty().toArray().contentEquals(r!!.toArray()) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } + check( + IntStreamExample::streamOfExample, + ignoreExecutionsNumber, + // NOTE: the order of the matchers is important because Stream could be used only once + { c, r -> c.isNotEmpty() && c.contentEquals(r!!.toArray()) }, + { c, r -> c.isEmpty() && IntStream.empty().toArray().contentEquals(r!!.toArray()) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) } @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/LongStreamExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/LongStreamExampleTest.kt index 8864db2a3a..c090c5eef8 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/LongStreamExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/LongStreamExampleTest.kt @@ -5,7 +5,6 @@ import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq import org.utbot.testcheckers.withPathSelectorStepsLimit -import org.utbot.testcheckers.withoutConcrete import org.utbot.tests.infrastructure.* import java.util.OptionalDouble import java.util.OptionalLong @@ -36,14 +35,12 @@ class LongStreamExampleTest : UtValueTestCaseChecker( @Test fun testReturningStreamAsParameterExample() { - withoutConcrete { - check( - LongStreamExample::returningStreamAsParameterExample, - eq(1), - { s, r -> s != null && s.toList() == r!!.toList() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } + check( + LongStreamExample::returningStreamAsParameterExample, + eq(1), + { s, r -> s != null && s.toList() == r!!.toList() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) } @Test @@ -320,41 +317,39 @@ class LongStreamExampleTest : UtValueTestCaseChecker( @Test fun testSummaryStatisticsExample() { - withoutConcrete { - check( - LongStreamExample::summaryStatisticsExample, - ignoreExecutionsNumber, - { c, r -> - val sum = r!!.sum - val count = r.count - val min = r.min - val max = r.max + check( + LongStreamExample::summaryStatisticsExample, + ignoreExecutionsNumber, + { c, r -> + val sum = r!!.sum + val count = r.count + val min = r.min + val max = r.max - val allStatisticsAreCorrect = sum == 0L && - count == 0L && - min == Long.MAX_VALUE && - max == Long.MIN_VALUE + val allStatisticsAreCorrect = sum == 0L && + count == 0L && + min == Long.MAX_VALUE && + max == Long.MIN_VALUE - c.isEmpty() && allStatisticsAreCorrect - }, - { c, r -> - val sum = r!!.sum - val count = r.count - val min = r.min - val max = r.max + c.isEmpty() && allStatisticsAreCorrect + }, + { c, r -> + val sum = r!!.sum + val count = r.count + val min = r.min + val max = r.max - val longs = c.longs() + val longs = c.longs() - val allStatisticsAreCorrect = sum == longs.sum() && - count == longs.size.toLong() && - min == longs.minOrNull() && - max == longs.maxOrNull() + val allStatisticsAreCorrect = sum == longs.sum() && + count == longs.size.toLong() && + min == longs.minOrNull() && + max == longs.maxOrNull() - c.isNotEmpty() && allStatisticsAreCorrect - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } + c.isNotEmpty() && allStatisticsAreCorrect + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) } @Test @@ -491,16 +486,14 @@ class LongStreamExampleTest : UtValueTestCaseChecker( @Test fun testStreamOfExample() { - withoutConcrete { - check( - LongStreamExample::streamOfExample, - ignoreExecutionsNumber, - // NOTE: the order of the matchers is important because Stream could be used only once - { c, r -> c.isNotEmpty() && c.contentEquals(r!!.toArray()) }, - { c, r -> c.isEmpty() && LongStream.empty().toArray().contentEquals(r!!.toArray()) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } + check( + LongStreamExample::streamOfExample, + ignoreExecutionsNumber, + // NOTE: the order of the matchers is important because Stream could be used only once + { c, r -> c.isNotEmpty() && c.contentEquals(r!!.toArray()) }, + { c, r -> c.isEmpty() && LongStream.empty().toArray().contentEquals(r!!.toArray()) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) } @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/strings/StringExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/strings/StringExamplesTest.kt index 0b9e8500f2..23ee62e639 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/strings/StringExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/strings/StringExamplesTest.kt @@ -12,6 +12,7 @@ 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.withConcrete import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete import org.utbot.testcheckers.withSolverTimeoutInMillis import org.utbot.testcheckers.withoutMinimization @@ -665,11 +666,13 @@ internal class StringExamplesTest : UtValueTestCaseChecker( // TODO: This test fails without concrete execution as it uses a symbolic variable @Test fun testListToString() { - check( - StringExamples::listToString, - eq(1), - { r -> r == "[a, b, c]"}, - coverage = DoNotCalculate - ) + withConcrete(useConcreteExecution = true) { + check( + StringExamples::listToString, + eq(1), + { r -> r == "[a, b, c]" }, + coverage = DoNotCalculate + ) + } } } diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/strings11/StringConcatTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/strings11/StringConcatTest.kt index 10359f3b04..296c4c07ad 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/strings11/StringConcatTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/strings11/StringConcatTest.kt @@ -3,7 +3,6 @@ package org.utbot.examples.strings11 import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.testcheckers.withoutConcrete import org.utbot.tests.infrastructure.* class StringConcatTest : UtValueTestCaseChecker( @@ -16,99 +15,83 @@ class StringConcatTest : UtValueTestCaseChecker( ) { @Test fun testConcatArguments() { - withoutConcrete { - check( - StringConcat::concatArguments, - eq(1), - { a, b, c, r -> "$a$b$c" == r } - ) - } + check( + StringConcat::concatArguments, + eq(1), + { a, b, c, r -> "$a$b$c" == r } + ) } @Test fun testConcatWithConstants() { - withoutConcrete { - check( - StringConcat::concatWithConstants, - eq(4), - { a, r -> a == "head" && r == 1 }, - { a, r -> a == "body" && r == 2 }, - { a, r -> a == null && r == 3 }, - { a, r -> a != "head" && a != "body" && a != null && r == 4 }, - ) - } + check( + StringConcat::concatWithConstants, + eq(4), + { a, r -> a == "head" && r == 1 }, + { a, r -> a == "body" && r == 2 }, + { a, r -> a == null && r == 3 }, + { a, r -> a != "head" && a != "body" && a != null && r == 4 }, + ) } @Test fun testConcatWithPrimitives() { - withoutConcrete { - check( - StringConcat::concatWithPrimitives, - eq(1), - { a, r -> "$a#4253.0" == r} - ) - } + check( + StringConcat::concatWithPrimitives, + eq(1), + { a, r -> "$a#4253.0" == r} + ) } @Test fun testExceptionInToString() { - withoutConcrete { - checkWithException( - StringConcat::exceptionInToString, - ignoreExecutionsNumber, - { t, r -> t.x == 42 && r.isException() }, - { t, r -> t.x != 42 && r.getOrThrow() == "Test: x = ${t.x}!" }, - coverage = DoNotCalculate - ) - } + checkWithException( + StringConcat::exceptionInToString, + ignoreExecutionsNumber, + { t, r -> t.x == 42 && r.isException() }, + { t, r -> t.x != 42 && r.getOrThrow() == "Test: x = ${t.x}!" }, + coverage = DoNotCalculate + ) } @Test fun testConcatWithField() { - withoutConcrete { - checkWithThis( - StringConcat::concatWithField, - eq(1), - { o, a, r -> "$a${o.str}#" == r } - ) - } + checkWithThis( + StringConcat::concatWithField, + eq(1), + { o, a, r -> "$a${o.str}#" == r } + ) } @Test fun testConcatWithPrimitiveWrappers() { - withoutConcrete { - check( - StringConcat::concatWithPrimitiveWrappers, - ignoreExecutionsNumber, - { b, c, r -> b.toString().endsWith("4") && c == '2' && r == 1 }, - { _, c, r -> !c.toString().endsWith("42") && r == 2 }, - coverage = DoNotCalculate - ) - } + check( + StringConcat::concatWithPrimitiveWrappers, + ignoreExecutionsNumber, + { b, c, r -> b.toString().endsWith("4") && c == '2' && r == 1 }, + { _, c, r -> !c.toString().endsWith("42") && r == 2 }, + coverage = DoNotCalculate + ) } @Test fun testSameConcat() { - withoutConcrete { - check( - StringConcat::sameConcat, - ignoreExecutionsNumber, - { a, b, r -> a == b && r == 0 }, - { a, b, r -> a != b && r == 1 }, - coverage = DoNotCalculate - ) - } + check( + StringConcat::sameConcat, + ignoreExecutionsNumber, + { a, b, r -> a == b && r == 0 }, + { a, b, r -> a != b && r == 1 }, + coverage = DoNotCalculate + ) } @Test fun testConcatStrangeSymbols() { - withoutConcrete { - check( - StringConcat::concatStrangeSymbols, - eq(1), - { r -> r == "\u0000#\u0001!\u0002@\u0012\t" } - ) - } + check( + StringConcat::concatStrangeSymbols, + eq(1), + { r -> r == "\u0000#\u0001!\u0002@\u0012\t" } + ) } } \ No newline at end of file diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt index 5995993cee..70a5c5d53c 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt @@ -3,6 +3,7 @@ package org.utbot.examples.unsafe import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.testcheckers.eq +import org.utbot.testcheckers.withConcrete import org.utbot.testcheckers.withoutSandbox import org.utbot.tests.infrastructure.DoNotCalculate import org.utbot.tests.infrastructure.UtValueTestCaseChecker @@ -11,29 +12,33 @@ internal class UnsafeOperationsTest : UtValueTestCaseChecker(testClass = UnsafeO @Test fun checkGetAddressSizeOrZero() { withoutSandbox { - check( - UnsafeOperations::getAddressSizeOrZero, - eq(1), - { r -> r!! > 0 }, - // Coverage matcher fails (branches: 0/0, instructions: 15/21, lines: 0/0) - // TODO: check coverage calculation: https://github.com/UnitTestBot/UTBotJava/issues/807 - coverage = DoNotCalculate - ) + withConcrete(useConcreteExecution = true) { + check( + UnsafeOperations::getAddressSizeOrZero, + eq(1), + { r -> r!! > 0 }, + // Coverage matcher fails (branches: 0/0, instructions: 15/21, lines: 0/0) + // TODO: check coverage calculation: https://github.com/UnitTestBot/UTBotJava/issues/807 + coverage = DoNotCalculate + ) + } } } @Test fun checkGetAddressSizeOrZeroWithMocks() { withoutSandbox { - check( - UnsafeOperations::getAddressSizeOrZero, - eq(1), - { r -> r!! > 0 }, - // Coverage matcher fails (branches: 0/0, instructions: 15/21, lines: 0/0) - // TODO: check coverage calculation: https://github.com/UnitTestBot/UTBotJava/issues/807 - coverage = DoNotCalculate, - mockStrategy = MockStrategyApi.OTHER_CLASSES - ) + withConcrete(useConcreteExecution = true) { + check( + UnsafeOperations::getAddressSizeOrZero, + eq(1), + { r -> r!! > 0 }, + // Coverage matcher fails (branches: 0/0, instructions: 15/21, lines: 0/0) + // TODO: check coverage calculation: https://github.com/UnitTestBot/UTBotJava/issues/807 + coverage = DoNotCalculate, + mockStrategy = MockStrategyApi.OTHER_CLASSES + ) + } } } } \ No newline at end of file diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/BooleanWrapperTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/BooleanWrapperTest.kt index 649735906f..a761f6e9ff 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/BooleanWrapperTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/BooleanWrapperTest.kt @@ -4,6 +4,7 @@ import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.utbot.tests.infrastructure.DoNotCalculate import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testcheckers.withConcrete internal class BooleanWrapperTest : UtValueTestCaseChecker(testClass = BooleanWrapper::class) { @Test @@ -31,12 +32,14 @@ internal class BooleanWrapperTest : UtValueTestCaseChecker(testClass = BooleanWr @Test fun equalityTest() { - check( - BooleanWrapper::equality, - eq(2), - { a, b, result -> a == b && result == 1 }, - { a, b, result -> a != b && result == 4 }, - coverage = DoNotCalculate // method under test has unreachable branches because of caching - ) + withConcrete(useConcreteExecution = true) { // Wrappers caches are not supported in symbolic analysis + check( + BooleanWrapper::equality, + eq(2), + { a, b, result -> a == b && result == 1 }, + { a, b, result -> a != b && result == 4 }, + coverage = DoNotCalculate // method under test has unreachable branches because of caching + ) + } } } \ No newline at end of file diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/ByteWrapperTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/ByteWrapperTest.kt index c8db0cbec7..fb8661f925 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/ByteWrapperTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/ByteWrapperTest.kt @@ -4,6 +4,7 @@ import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.utbot.tests.infrastructure.DoNotCalculate import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testcheckers.withConcrete internal class ByteWrapperTest : UtValueTestCaseChecker(testClass = ByteWrapper::class) { @Test @@ -31,12 +32,14 @@ internal class ByteWrapperTest : UtValueTestCaseChecker(testClass = ByteWrapper: @Test fun equalityTest() { - check( - ByteWrapper::equality, - eq(2), - { a, b, result -> a == b && result == 1 }, - { a, b, result -> a != b && result == 4 }, - coverage = DoNotCalculate // method under test has unreachable branches because of caching - ) + withConcrete(useConcreteExecution = true) { // Wrappers caches are not supported in symbolic analysis + check( + ByteWrapper::equality, + eq(2), + { a, b, result -> a == b && result == 1 }, + { a, b, result -> a != b && result == 4 }, + coverage = DoNotCalculate // method under test has unreachable branches because of caching + ) + } } } \ No newline at end of file diff --git a/utbot-framework/src/main/java/org/utbot/engine/overrides/stream/UtStream.java b/utbot-framework/src/main/java/org/utbot/engine/overrides/stream/UtStream.java index 132635a43e..b73ecab449 100644 --- a/utbot-framework/src/main/java/org/utbot/engine/overrides/stream/UtStream.java +++ b/utbot-framework/src/main/java/org/utbot/engine/overrides/stream/UtStream.java @@ -579,7 +579,14 @@ public boolean allMatch(Predicate predicate) { public boolean noneMatch(Predicate predicate) { preconditionCheckWithClosingStream(); - return !anyMatch(predicate); + int size = elementData.end; + for (int i = 0; i < size; i++) { + if (predicate.test(elementData.get(i))) { + return false; + } + } + + return true; } @NotNull diff --git a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/UtValueTestCaseChecker.kt b/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/UtValueTestCaseChecker.kt index 1cd5467b06..5067f19fc1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/UtValueTestCaseChecker.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/UtValueTestCaseChecker.kt @@ -89,6 +89,8 @@ abstract class UtValueTestCaseChecker( UtSettings.useFuzzing = false UtSettings.useCustomJavaDocTags = false UtSettings.enableSummariesGeneration = true + // Disable concrete execution to detect failed symbolic tests + UtSettings.useConcreteExecution = false } // checks paramsBefore and result diff --git a/utbot-sample/src/main/java/org/utbot/examples/collections/Maps.java b/utbot-sample/src/main/java/org/utbot/examples/collections/Maps.java index 2d20a80a72..84c822bdb9 100644 --- a/utbot-sample/src/main/java/org/utbot/examples/collections/Maps.java +++ b/utbot-sample/src/main/java/org/utbot/examples/collections/Maps.java @@ -73,6 +73,7 @@ Map createWithDifferentType(int seed) { } } + @SuppressWarnings({"SingleStatementInBlock", "ForLoopReplaceableByForEach"}) Map putElements(Map map, int[] array) { if (map.size() > 0 && array.length > 0) { for (int i = 0; i < array.length; i++) { @@ -107,6 +108,7 @@ Map computeValueIfPresent(Map map, int key) } } + @SuppressWarnings("ConstantConditions") int clearEntries(Map map) { if (map.isEmpty()) { return 0; @@ -115,6 +117,8 @@ int clearEntries(Map map) { if (map.isEmpty()) { return 1; } + + // unreachable return return 2; } @@ -153,12 +157,14 @@ int removeKeyWithValue(Map map, int key, int value) { return 0; } else if (containsKey && !containsValue) { if (map.remove(key, value)) { + // unreachable branch return 1; } else { return -1; } } else if (!containsKey) { if (map.remove(key, value)) { + // unreachable branch return 2; } else { return -2; @@ -222,6 +228,7 @@ int replaceEntryWithValue(Map map, int key, int oldValue) { } } + @SuppressWarnings("ConstantConditions") Map merge(Map map, int key, Integer value) { if (map.merge(key, value, Integer::sum) == null) { return map; @@ -271,6 +278,7 @@ int removeElements(Map map, int i, int j) { } } + @SuppressWarnings("RedundantIfStatement") CustomClass removeCustomObject(Map map, int i) { CustomClass removed = map.remove(new CustomClass(i)); if (removed == null) {