From 70b31dda7c50551e97f4abab325dbe797759280d Mon Sep 17 00:00:00 2001 From: Kamenev Yury Date: Wed, 14 Sep 2022 12:23:08 +0300 Subject: [PATCH 1/3] Fixed wrong types for virtual invokes --- .../examples/stream/BaseStreamExampleTest.kt | 3 +-- .../src/main/kotlin/org/utbot/engine/Traverser.kt | 11 +++++++++-- .../utbot/examples/stream/BaseStreamExample.java | 15 +++++---------- 3 files changed, 15 insertions(+), 14 deletions(-) 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 0ee5a87163..ac4d25fac8 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 @@ -343,14 +343,13 @@ class BaseStreamExampleTest : UtValueTestCaseChecker( } @Test - @Disabled("TODO unsat type constraints https://github.com/UnitTestBot/UTBotJava/issues/253") fun testCustomCollectionStreamExample() { check( BaseStreamExample::customCollectionStreamExample, ignoreExecutionsNumber, { c, r -> c.isEmpty() && r == 0L }, { c, r -> c.isNotEmpty() && c.size.toLong() == r }, - coverage = DoNotCalculate + coverage = DoNotCalculate // TODO failed coverage calculation ) } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt index d5139836bd..bb80c97fea 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt @@ -2346,8 +2346,15 @@ class Traverser( // for objects (especially objects with type equals to type parameter of generic) // better than engine. val types = instanceOfConstraint?.typeStorage?.possibleConcreteTypes ?: instance.possibleConcreteTypes - val methodInvocationTargets = findLibraryTargets(instance.type, methodSubSignature) - ?: findMethodInvocationTargets(types, methodSubSignature) + + val allConcreteInvocationTargets = findMethodInvocationTargets(types, methodSubSignature) + val libraryTargets = findLibraryTargets(instance.type, methodSubSignature) + + // to choose only "good" targets take only library targets in case they present in all targets, + // otherwise take all targets + val methodInvocationTargets = libraryTargets?.takeIf { + allConcreteInvocationTargets.containsAll(it) + } ?: allConcreteInvocationTargets return methodInvocationTargets .map { (method, implementationClass, possibleTypes) -> diff --git a/utbot-sample/src/main/java/org/utbot/examples/stream/BaseStreamExample.java b/utbot-sample/src/main/java/org/utbot/examples/stream/BaseStreamExample.java index f8ba8061cb..409cca216b 100644 --- a/utbot-sample/src/main/java/org/utbot/examples/stream/BaseStreamExample.java +++ b/utbot-sample/src/main/java/org/utbot/examples/stream/BaseStreamExample.java @@ -410,21 +410,16 @@ long closedStreamExample(List values) { } @SuppressWarnings({"ReplaceInefficientStreamCount", "ConstantConditions"}) + // TODO wrong generic type for data field https://github.com/UnitTestBot/UTBotJava/issues/730 long customCollectionStreamExample(CustomCollection customCollection) { UtMock.assume(customCollection != null && customCollection.data != null); - if (customCollection.isEmpty()) { - return customCollection.stream().count(); + final Stream stream = customCollection.stream(); - // simplified example, does not generate branch too - /*customCollection.removeIf(Objects::isNull); - return customCollection.toArray().length;*/ + if (customCollection.isEmpty()) { + return stream.count(); } else { - return customCollection.stream().count(); - - // simplified example, does not generate branch too - /*customCollection.removeIf(Objects::isNull); - return customCollection.toArray().length;*/ + return stream.count(); } } From d4bf5b4ad11fcb9d15d71e992b32becfc857f308 Mon Sep 17 00:00:00 2001 From: Kamenev Yury Date: Fri, 16 Sep 2022 12:06:43 +0300 Subject: [PATCH 2/3] Changed behavior according to review --- .../src/main/kotlin/org/utbot/engine/Traverser.kt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt index bb80c97fea..1309b6d770 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt @@ -2347,14 +2347,12 @@ class Traverser( // better than engine. val types = instanceOfConstraint?.typeStorage?.possibleConcreteTypes ?: instance.possibleConcreteTypes - val allConcreteInvocationTargets = findMethodInvocationTargets(types, methodSubSignature) - val libraryTargets = findLibraryTargets(instance.type, methodSubSignature) - - // to choose only "good" targets take only library targets in case they present in all targets, - // otherwise take all targets - val methodInvocationTargets = libraryTargets?.takeIf { - allConcreteInvocationTargets.containsAll(it) - } ?: allConcreteInvocationTargets + val allPossibleConcreteTypes = typeRegistry.findInheritorsIncludingTypes(instance.type) { setOf(instance.type) } + + val methodInvocationTargets = findLibraryTargets(instance.type, methodSubSignature)?.takeIf { + // we have no specified types, so we can take only library targets (if present) for optimization purposes + types.size == allPossibleConcreteTypes.size + } ?: findMethodInvocationTargets(types, methodSubSignature) return methodInvocationTargets .map { (method, implementationClass, possibleTypes) -> From aaa514abce094ca335fece339edd4ec775ad55ab Mon Sep 17 00:00:00 2001 From: Kamenev Yury Date: Wed, 21 Sep 2022 16:08:05 +0300 Subject: [PATCH 3/3] Fixed failed tests --- utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt index 1309b6d770..bb8fe91e87 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt @@ -2347,7 +2347,9 @@ class Traverser( // better than engine. val types = instanceOfConstraint?.typeStorage?.possibleConcreteTypes ?: instance.possibleConcreteTypes - val allPossibleConcreteTypes = typeRegistry.findInheritorsIncludingTypes(instance.type) { setOf(instance.type) } + val allPossibleConcreteTypes = typeResolver + .constructTypeStorage(instance.type, useConcreteType = false) + .possibleConcreteTypes val methodInvocationTargets = findLibraryTargets(instance.type, methodSubSignature)?.takeIf { // we have no specified types, so we can take only library targets (if present) for optimization purposes