From 42954c8f0040173b89e15b683b80433576eb16d0 Mon Sep 17 00:00:00 2001 From: Denis Fokin Date: Tue, 8 Nov 2022 15:53:55 +0300 Subject: [PATCH 01/12] Move test-specific implementation --- .../framework/plugin/api/UtExecutionResult.kt | 5 ----- utbot-framework-test/build.gradle | 4 ++-- .../kotlin/org/utbot/testing}/CheckersUtil.kt | 2 +- .../testing}/CodeGenerationIntegrationTest.kt | 5 +++-- .../utbot/testing}/CompilationAndRunUtils.kt | 18 +++++++++--------- .../testing}/TestCodeGeneratorPipeline.kt | 3 ++- .../testing}/TestSpecificTestCaseGenerator.kt | 3 ++- .../utbot/testing}/UtModelTestCaseChecker.kt | 4 ++-- .../utbot/testing}/UtValueTestCaseChecker.kt | 5 ++++- .../src/main/kotlin/org/utbot/testing/Utils.kt | 11 +++++++++++ .../examples/mock/InnerMockWithFieldChecker.kt | 6 +++--- .../examples/mock/MockWithFieldChecker.kt | 6 +++--- 12 files changed, 42 insertions(+), 30 deletions(-) rename {utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure => utbot-framework-test/src/main/kotlin/org/utbot/testing}/CheckersUtil.kt (99%) rename {utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure => utbot-framework-test/src/main/kotlin/org/utbot/testing}/CodeGenerationIntegrationTest.kt (98%) rename {utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure => utbot-framework-test/src/main/kotlin/org/utbot/testing}/CompilationAndRunUtils.kt (84%) rename {utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure => utbot-framework-test/src/main/kotlin/org/utbot/testing}/TestCodeGeneratorPipeline.kt (99%) rename {utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure => utbot-framework-test/src/main/kotlin/org/utbot/testing}/TestSpecificTestCaseGenerator.kt (98%) rename {utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure => utbot-framework-test/src/main/kotlin/org/utbot/testing}/UtModelTestCaseChecker.kt (98%) rename {utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure => utbot-framework-test/src/main/kotlin/org/utbot/testing}/UtValueTestCaseChecker.kt (99%) create mode 100644 utbot-framework-test/src/main/kotlin/org/utbot/testing/Utils.kt diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/UtExecutionResult.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/UtExecutionResult.kt index cb6d6c9f61..fd58b9795f 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/UtExecutionResult.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/UtExecutionResult.kt @@ -102,11 +102,6 @@ inline fun UtExecutionResult.onFailure(action: (exception: Throwable) -> Unit): return this } -fun UtExecutionResult.getOrThrow(): UtModel = when (this) { - is UtExecutionSuccess -> model - is UtExecutionFailure -> throw exception -} - fun UtExecutionResult.exceptionOrNull(): Throwable? = when (this) { is UtExecutionFailure -> rootCauseException is UtExecutionSuccess -> null diff --git a/utbot-framework-test/build.gradle b/utbot-framework-test/build.gradle index 1d4167e128..e087e6a924 100644 --- a/utbot-framework-test/build.gradle +++ b/utbot-framework-test/build.gradle @@ -48,8 +48,8 @@ dependencies { // To use JUnit4, comment out JUnit5 and uncomment JUnit4 dependencies here. Please also check "test" section // testImplementation group: 'junit', name: 'junit', version: '4.13.1' - testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.8.1' - testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.1' + implementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.8.1' + implementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.1' // used for testing code generation testImplementation group: 'commons-io', name: 'commons-io', version: commonsIoVersion diff --git a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/CheckersUtil.kt b/utbot-framework-test/src/main/kotlin/org/utbot/testing/CheckersUtil.kt similarity index 99% rename from utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/CheckersUtil.kt rename to utbot-framework-test/src/main/kotlin/org/utbot/testing/CheckersUtil.kt index a59fa685f3..91535184a7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/CheckersUtil.kt +++ b/utbot-framework-test/src/main/kotlin/org/utbot/testing/CheckersUtil.kt @@ -1,4 +1,4 @@ -package org.utbot.tests.infrastructure +package org.utbot.testing import org.utbot.framework.codegen.ForceStaticMocking import org.utbot.framework.codegen.Junit4 diff --git a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/CodeGenerationIntegrationTest.kt b/utbot-framework-test/src/main/kotlin/org/utbot/testing/CodeGenerationIntegrationTest.kt similarity index 98% rename from utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/CodeGenerationIntegrationTest.kt rename to utbot-framework-test/src/main/kotlin/org/utbot/testing/CodeGenerationIntegrationTest.kt index fd0333d5c0..fa35e08052 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/CodeGenerationIntegrationTest.kt +++ b/utbot-framework-test/src/main/kotlin/org/utbot/testing/CodeGenerationIntegrationTest.kt @@ -1,4 +1,4 @@ -package org.utbot.tests.infrastructure +package org.utbot.testing import org.utbot.common.FileUtil import org.utbot.common.withAccessibility @@ -135,7 +135,8 @@ abstract class CodeGenerationIntegrationTest( ) } - val config = TestCodeGeneratorPipeline.defaultTestFrameworkConfiguration(language, parameterizationMode) + val config = + TestCodeGeneratorPipeline.defaultTestFrameworkConfiguration(language, parameterizationMode) TestCodeGeneratorPipeline(config).runClassesCodeGenerationTests(classStages) } catch (e: RuntimeException) { pipelineErrors.add(e.message) diff --git a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/CompilationAndRunUtils.kt b/utbot-framework-test/src/main/kotlin/org/utbot/testing/CompilationAndRunUtils.kt similarity index 84% rename from utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/CompilationAndRunUtils.kt rename to utbot-framework-test/src/main/kotlin/org/utbot/testing/CompilationAndRunUtils.kt index 151d34b1ec..5e852bf6bd 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/CompilationAndRunUtils.kt +++ b/utbot-framework-test/src/main/kotlin/org/utbot/testing/CompilationAndRunUtils.kt @@ -1,4 +1,4 @@ -package org.utbot.tests.infrastructure +package org.utbot.testing import org.utbot.framework.plugin.api.CodegenLanguage import java.io.File @@ -33,7 +33,7 @@ fun writeTest( File(buildDirectory.toFile(), "${testClassName.substringAfterLast(".")}${generatedLanguage.extension}") ) - logger.info { + org.utbot.testing.logger.info { "File size for ${classUnderTest.testClassSimpleName}: ${FileUtil.byteCountToDisplaySize(testContents.length.toLong())}" } return writeFile(testContents, classUnderTest.generatedTestFile) @@ -47,9 +47,9 @@ fun compileTests( val classpath = System.getProperty("java.class.path") val command = generatedLanguage.getCompilationCommand(buildDirectory, classpath, sourcesFiles) - logger.trace { "Command to compile [${sourcesFiles.joinToString(" ")}]: [${command.joinToString(" ")}]" } + org.utbot.testing.logger.trace { "Command to compile [${sourcesFiles.joinToString(" ")}]: [${command.joinToString(" ")}]" } val exitCode = execCommandLine(command, "Tests compilation") - logger.info { "Compilation exit code: $exitCode" } + org.utbot.testing.logger.info { "Compilation exit code: $exitCode" } } fun runTests( @@ -74,7 +74,7 @@ fun runTests( additionalArguments ) - logger.trace { "Command to run test: [${command.joinToString(" ")}]" } + org.utbot.testing.logger.trace { "Command to run test: [${command.joinToString(" ")}]" } // We use argument file to pass classpath, so we should just call execCommand. // Because of some reason, it is impossible to use the same approach with Junit4 and TestNg, therefore, @@ -85,7 +85,7 @@ fun runTests( setClassPathAndExecCommandLine(command, "Tests execution", classpath) } - logger.info { "Run for [${testsNames.joinToString(" ")}] completed with exit code: $exitCode" } + org.utbot.testing.logger.info { "Run for [${testsNames.joinToString(" ")}] completed with exit code: $exitCode" } } /** @@ -105,13 +105,13 @@ private fun constructProcess(command: List, classpath: String? = null): private fun generateReportByProcess(process: Process, executionName: String, command: List): Int { val report = process.inputStream.reader().readText() - logger.info { "$executionName report: [$report]" } + org.utbot.testing.logger.info { "$executionName report: [$report]" } val exitCode = process.waitFor() if (exitCode != 0) { - logger.warn { "Exit code for process run: $exitCode" } - logger.warn { "The command line led to the pipeline failure: [${command.joinToString(" ")}]" } + org.utbot.testing.logger.warn { "Exit code for process run: $exitCode" } + org.utbot.testing.logger.warn { "The command line led to the pipeline failure: [${command.joinToString(" ")}]" } throw RuntimeException("$executionName failed with non-zero exit code = $exitCode") } diff --git a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/TestCodeGeneratorPipeline.kt b/utbot-framework-test/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt similarity index 99% rename from utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/TestCodeGeneratorPipeline.kt rename to utbot-framework-test/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt index fec4ed43bb..eb6a1133d2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/TestCodeGeneratorPipeline.kt +++ b/utbot-framework-test/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt @@ -1,4 +1,4 @@ -package org.utbot.tests.infrastructure +package org.utbot.testing import mu.KotlinLogging import org.junit.jupiter.api.Assertions.assertTrue @@ -22,6 +22,7 @@ import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.description import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.withUtContext +import org.utbot.testing.TestFrameworkConfiguration import java.io.File import java.nio.file.Path import kotlin.reflect.KClass diff --git a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/TestSpecificTestCaseGenerator.kt b/utbot-framework-test/src/main/kotlin/org/utbot/testing/TestSpecificTestCaseGenerator.kt similarity index 98% rename from utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/TestSpecificTestCaseGenerator.kt rename to utbot-framework-test/src/main/kotlin/org/utbot/testing/TestSpecificTestCaseGenerator.kt index 2a77280aff..dbe5dadb18 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/TestSpecificTestCaseGenerator.kt +++ b/utbot-framework-test/src/main/kotlin/org/utbot/testing/TestSpecificTestCaseGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.tests.infrastructure +package org.utbot.testing import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking @@ -20,6 +20,7 @@ import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.services.JdkInfoDefaultProvider import org.utbot.framework.util.Conflict import org.utbot.framework.util.jimpleBody +import org.utbot.testing.conflictTriggers import java.nio.file.Path /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/UtModelTestCaseChecker.kt b/utbot-framework-test/src/main/kotlin/org/utbot/testing/UtModelTestCaseChecker.kt similarity index 98% rename from utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/UtModelTestCaseChecker.kt rename to utbot-framework-test/src/main/kotlin/org/utbot/testing/UtModelTestCaseChecker.kt index e47675135a..ce6f64851a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/UtModelTestCaseChecker.kt +++ b/utbot-framework-test/src/main/kotlin/org/utbot/testing/UtModelTestCaseChecker.kt @@ -1,6 +1,6 @@ @file:Suppress("NestedLambdaShadowedImplicitParameter") -package org.utbot.tests.infrastructure +package org.utbot.testing import org.junit.jupiter.api.Assertions.assertTrue import org.utbot.common.ClassLocation @@ -25,7 +25,6 @@ import org.utbot.framework.plugin.api.UtExecutionResult import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.exceptionOrNull -import org.utbot.framework.plugin.api.getOrThrow import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.declaringClazz import org.utbot.framework.plugin.api.util.defaultValueModel @@ -34,6 +33,7 @@ import org.utbot.framework.plugin.api.util.jClass import org.utbot.framework.plugin.api.util.withUtContext import org.utbot.framework.util.Conflict import org.utbot.testcheckers.ExecutionsNumberMatcher +import org.utbot.testing.conflictTriggers import java.nio.file.Path import kotlin.reflect.KClass import kotlin.reflect.KFunction diff --git a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/UtValueTestCaseChecker.kt b/utbot-framework-test/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt similarity index 99% rename from utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/UtValueTestCaseChecker.kt rename to utbot-framework-test/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt index 1cd5467b06..896f2920f4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/UtValueTestCaseChecker.kt +++ b/utbot-framework-test/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt @@ -1,6 +1,6 @@ @file:Suppress("NestedLambdaShadowedImplicitParameter") -package org.utbot.tests.infrastructure +package org.utbot.testing import org.junit.jupiter.api.Assertions.assertTrue import org.utbot.common.ClassLocation @@ -54,6 +54,9 @@ import org.utbot.framework.util.Conflict import org.utbot.framework.util.toValueTestCase import org.utbot.summary.summarize import org.utbot.testcheckers.ExecutionsNumberMatcher +import org.utbot.testing.TestFrameworkConfiguration +import org.utbot.testing.allTestFrameworkConfigurations +import org.utbot.testing.conflictTriggers import java.io.File import java.nio.file.Path import java.nio.file.Paths diff --git a/utbot-framework-test/src/main/kotlin/org/utbot/testing/Utils.kt b/utbot-framework-test/src/main/kotlin/org/utbot/testing/Utils.kt new file mode 100644 index 0000000000..6c927d85b6 --- /dev/null +++ b/utbot-framework-test/src/main/kotlin/org/utbot/testing/Utils.kt @@ -0,0 +1,11 @@ +package org.utbot.testing + +import org.utbot.framework.plugin.api.UtExecutionFailure +import org.utbot.framework.plugin.api.UtExecutionResult +import org.utbot.framework.plugin.api.UtExecutionSuccess +import org.utbot.framework.plugin.api.UtModel + +fun UtExecutionResult.getOrThrow(): UtModel = when (this) { + is UtExecutionSuccess -> model + is UtExecutionFailure -> throw exception +} \ No newline at end of file diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/InnerMockWithFieldChecker.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/InnerMockWithFieldChecker.kt index f648affdce..30a746e0c1 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/InnerMockWithFieldChecker.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/InnerMockWithFieldChecker.kt @@ -1,15 +1,15 @@ package org.utbot.examples.mock -import org.utbot.tests.infrastructure.UtModelTestCaseChecker -import org.utbot.tests.infrastructure.primitiveValue import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES import org.utbot.framework.plugin.api.UtModel -import org.utbot.framework.plugin.api.getOrThrow import org.utbot.framework.plugin.api.isMockModel import org.utbot.framework.plugin.api.isNotNull import org.utbot.framework.plugin.api.isNull import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtModelTestCaseChecker +import org.utbot.testing.getOrThrow +import org.utbot.testing.primitiveValue internal class InnerMockWithFieldChecker : UtModelTestCaseChecker(testClass = InnerMockWithFieldExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockWithFieldChecker.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockWithFieldChecker.kt index ac185f2b82..397981d54e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockWithFieldChecker.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockWithFieldChecker.kt @@ -1,14 +1,14 @@ package org.utbot.examples.mock -import org.utbot.tests.infrastructure.UtModelTestCaseChecker -import org.utbot.tests.infrastructure.primitiveValue import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES import org.utbot.framework.plugin.api.UtModel -import org.utbot.framework.plugin.api.getOrThrow import org.utbot.framework.plugin.api.isMockModel import org.utbot.framework.plugin.api.isNull import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtModelTestCaseChecker +import org.utbot.testing.getOrThrow +import org.utbot.testing.primitiveValue internal class MockWithFieldChecker : UtModelTestCaseChecker(testClass = MockWithFieldExample::class) { @Test From c127dc418ed3ff688491cf360b9628c0e4b6dc0e Mon Sep 17 00:00:00 2001 From: Denis Fokin Date: Tue, 8 Nov 2022 17:46:02 +0300 Subject: [PATCH 02/12] Visibility fixes --- .../org/utbot/testing/CompilationAndRunUtils.kt | 17 ++++++++--------- .../utbot/testing/TestCodeGeneratorPipeline.kt | 2 +- .../testing/TestSpecificTestCaseGenerator.kt | 1 - .../org/utbot/testing/UtModelTestCaseChecker.kt | 1 - 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/utbot-framework-test/src/main/kotlin/org/utbot/testing/CompilationAndRunUtils.kt b/utbot-framework-test/src/main/kotlin/org/utbot/testing/CompilationAndRunUtils.kt index 5e852bf6bd..7c508b13af 100644 --- a/utbot-framework-test/src/main/kotlin/org/utbot/testing/CompilationAndRunUtils.kt +++ b/utbot-framework-test/src/main/kotlin/org/utbot/testing/CompilationAndRunUtils.kt @@ -4,7 +4,6 @@ import org.utbot.framework.plugin.api.CodegenLanguage import java.io.File import java.nio.file.Path import org.utbot.common.FileUtil -import org.utbot.engine.logger import org.utbot.framework.codegen.Junit5 import org.utbot.framework.codegen.TestFramework @@ -33,7 +32,7 @@ fun writeTest( File(buildDirectory.toFile(), "${testClassName.substringAfterLast(".")}${generatedLanguage.extension}") ) - org.utbot.testing.logger.info { + logger.info { "File size for ${classUnderTest.testClassSimpleName}: ${FileUtil.byteCountToDisplaySize(testContents.length.toLong())}" } return writeFile(testContents, classUnderTest.generatedTestFile) @@ -47,9 +46,9 @@ fun compileTests( val classpath = System.getProperty("java.class.path") val command = generatedLanguage.getCompilationCommand(buildDirectory, classpath, sourcesFiles) - org.utbot.testing.logger.trace { "Command to compile [${sourcesFiles.joinToString(" ")}]: [${command.joinToString(" ")}]" } + logger.trace { "Command to compile [${sourcesFiles.joinToString(" ")}]: [${command.joinToString(" ")}]" } val exitCode = execCommandLine(command, "Tests compilation") - org.utbot.testing.logger.info { "Compilation exit code: $exitCode" } + logger.info { "Compilation exit code: $exitCode" } } fun runTests( @@ -74,7 +73,7 @@ fun runTests( additionalArguments ) - org.utbot.testing.logger.trace { "Command to run test: [${command.joinToString(" ")}]" } + logger.trace { "Command to run test: [${command.joinToString(" ")}]" } // We use argument file to pass classpath, so we should just call execCommand. // Because of some reason, it is impossible to use the same approach with Junit4 and TestNg, therefore, @@ -85,7 +84,7 @@ fun runTests( setClassPathAndExecCommandLine(command, "Tests execution", classpath) } - org.utbot.testing.logger.info { "Run for [${testsNames.joinToString(" ")}] completed with exit code: $exitCode" } + logger.info { "Run for [${testsNames.joinToString(" ")}] completed with exit code: $exitCode" } } /** @@ -105,13 +104,13 @@ private fun constructProcess(command: List, classpath: String? = null): private fun generateReportByProcess(process: Process, executionName: String, command: List): Int { val report = process.inputStream.reader().readText() - org.utbot.testing.logger.info { "$executionName report: [$report]" } + logger.info { "$executionName report: [$report]" } val exitCode = process.waitFor() if (exitCode != 0) { - org.utbot.testing.logger.warn { "Exit code for process run: $exitCode" } - org.utbot.testing.logger.warn { "The command line led to the pipeline failure: [${command.joinToString(" ")}]" } + logger.warn { "Exit code for process run: $exitCode" } + logger.warn { "The command line led to the pipeline failure: [${command.joinToString(" ")}]" } throw RuntimeException("$executionName failed with non-zero exit code = $exitCode") } diff --git a/utbot-framework-test/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt b/utbot-framework-test/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt index eb6a1133d2..0596f092ad 100644 --- a/utbot-framework-test/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt +++ b/utbot-framework-test/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt @@ -27,7 +27,7 @@ import java.io.File import java.nio.file.Path import kotlin.reflect.KClass -private val logger = KotlinLogging.logger {} +internal val logger = KotlinLogging.logger {} class TestCodeGeneratorPipeline(private val testFrameworkConfiguration: TestFrameworkConfiguration) { diff --git a/utbot-framework-test/src/main/kotlin/org/utbot/testing/TestSpecificTestCaseGenerator.kt b/utbot-framework-test/src/main/kotlin/org/utbot/testing/TestSpecificTestCaseGenerator.kt index dbe5dadb18..ea3c761f54 100644 --- a/utbot-framework-test/src/main/kotlin/org/utbot/testing/TestSpecificTestCaseGenerator.kt +++ b/utbot-framework-test/src/main/kotlin/org/utbot/testing/TestSpecificTestCaseGenerator.kt @@ -20,7 +20,6 @@ import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.services.JdkInfoDefaultProvider import org.utbot.framework.util.Conflict import org.utbot.framework.util.jimpleBody -import org.utbot.testing.conflictTriggers import java.nio.file.Path /** diff --git a/utbot-framework-test/src/main/kotlin/org/utbot/testing/UtModelTestCaseChecker.kt b/utbot-framework-test/src/main/kotlin/org/utbot/testing/UtModelTestCaseChecker.kt index ce6f64851a..cb76ef0cbc 100644 --- a/utbot-framework-test/src/main/kotlin/org/utbot/testing/UtModelTestCaseChecker.kt +++ b/utbot-framework-test/src/main/kotlin/org/utbot/testing/UtModelTestCaseChecker.kt @@ -33,7 +33,6 @@ import org.utbot.framework.plugin.api.util.jClass import org.utbot.framework.plugin.api.util.withUtContext import org.utbot.framework.util.Conflict import org.utbot.testcheckers.ExecutionsNumberMatcher -import org.utbot.testing.conflictTriggers import java.nio.file.Path import kotlin.reflect.KClass import kotlin.reflect.KFunction From 27cbff5bb29ee8f1e5b260b4bf0909231797beb3 Mon Sep 17 00:00:00 2001 From: Denis Fokin Date: Tue, 8 Nov 2022 18:02:44 +0300 Subject: [PATCH 03/12] Eliminate unnecessary imports --- .../main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/utbot-framework-test/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt b/utbot-framework-test/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt index 896f2920f4..190d76654d 100644 --- a/utbot-framework-test/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt +++ b/utbot-framework-test/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt @@ -54,9 +54,6 @@ import org.utbot.framework.util.Conflict import org.utbot.framework.util.toValueTestCase import org.utbot.summary.summarize import org.utbot.testcheckers.ExecutionsNumberMatcher -import org.utbot.testing.TestFrameworkConfiguration -import org.utbot.testing.allTestFrameworkConfigurations -import org.utbot.testing.conflictTriggers import java.io.File import java.nio.file.Path import java.nio.file.Paths From 8a654e0ede6f10fc2ada29313bebee4567a422ce Mon Sep 17 00:00:00 2001 From: Denis Fokin Date: Wed, 9 Nov 2022 11:28:09 +0300 Subject: [PATCH 04/12] Fix sammaries --- utbot-summary-tests/build.gradle | 1 + .../src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/utbot-summary-tests/build.gradle b/utbot-summary-tests/build.gradle index 376fc6af1b..94a163f68b 100644 --- a/utbot-summary-tests/build.gradle +++ b/utbot-summary-tests/build.gradle @@ -10,6 +10,7 @@ dependencies { implementation(project(':utbot-instrumentation')) testImplementation project(':utbot-sample') testImplementation group: 'junit', name: 'junit', version: junit4Version + testImplementation project(':utbot-framework-test').sourceSets.test.output testImplementation project(':utbot-framework').sourceSets.test.output } diff --git a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt index fcdc5d4b30..f540ed242e 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt @@ -3,8 +3,6 @@ package examples import org.junit.jupiter.api.* import org.utbot.common.WorkaroundReason import org.utbot.common.workaround -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.CoverageMatcher import org.utbot.framework.UtSettings.checkNpeInNestedMethods import org.utbot.framework.UtSettings.checkNpeInNestedNotPrivateMethods import org.utbot.framework.UtSettings.checkSolverTimeoutMillis @@ -13,7 +11,7 @@ import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.executableId import org.utbot.summary.comment.nextSynonyms import org.utbot.summary.summarize -import org.utbot.tests.infrastructure.TestExecution +import org.utbot.testing import kotlin.reflect.KClass import kotlin.reflect.KFunction From 31600f67af4a45b5b40018348e16448ade90ace4 Mon Sep 17 00:00:00 2001 From: Denis Fokin Date: Wed, 9 Nov 2022 18:05:46 +0300 Subject: [PATCH 05/12] Imports and dependencies --- utbot-analytics/build.gradle | 1 + .../FeatureProcessorWithStatesRepetition.kt | 2 +- .../FeatureProcessorWithRepetitionTest.kt | 2 +- utbot-framework-test/build.gradle | 2 +- .../examples/algorithms/BinarySearchTest.kt | 6 +++--- .../algorithms/CorrectBracketSequencesTest.kt | 7 ------- .../org/utbot/examples/algorithms/GraphTest.kt | 3 --- .../org/utbot/examples/algorithms/SortTest.kt | 5 ----- .../annotations/NotNullAnnotationTest.kt | 2 +- .../lombok/EnumWithAnnotationsTest.kt | 4 ++-- .../lombok/EnumWithoutAnnotationsTest.kt | 2 +- .../lombok/NotNullAnnotationsTest.kt | 4 ++-- .../utbot/examples/arrays/ArrayOfArraysTest.kt | 8 ++++---- .../examples/arrays/ArrayOfObjectsTest.kt | 7 ------- .../arrays/ArrayStoreExceptionExamplesTest.kt | 4 ---- .../arrays/ArraysOverwriteValueTest.kt | 4 ++-- .../arrays/FinalStaticFieldArrayTest.kt | 4 ++-- .../examples/arrays/IntArrayBasicsTest.kt | 4 ---- .../examples/arrays/PrimitiveArraysTest.kt | 8 ++++---- .../examples/casts/ArrayCastExampleTest.kt | 3 --- .../org/utbot/examples/casts/CastClassTest.kt | 6 +++--- .../utbot/examples/casts/CastExampleTest.kt | 4 ---- .../examples/casts/GenericCastExampleTest.kt | 4 ---- .../examples/casts/InstanceOfExampleTest.kt | 4 ---- .../ClassWithStaticAndInnerClassesTest.kt | 4 ---- .../examples/codegen/CodegenExampleTest.kt | 1 - .../codegen/FileWithTopLevelFunctionsTest.kt | 2 +- .../utbot/examples/codegen/JavaAssertTest.kt | 4 ++-- .../examples/codegen/VoidStaticMethodsTest.kt | 6 ++---- .../ClassWithCrossReferenceRelationshipTest.kt | 6 +++--- .../deepequals/ClassWithNullableFieldTest.kt | 3 --- .../codegen/deepequals/DeepEqualsTest.kt | 3 --- ...WithPrivateMutableFieldOfPrivateTypeTest.kt | 4 ++-- .../collections/CustomerExamplesTest.kt | 6 ------ .../collections/GenericListsExampleTest.kt | 3 --- .../examples/collections/LinkedListsTest.kt | 4 ---- .../examples/collections/ListAlgorithmsTest.kt | 6 +++--- .../examples/collections/ListIteratorsTest.kt | 4 ---- .../collections/ListWrapperReturnsVoidTest.kt | 4 ---- .../examples/collections/ListsPart1Test.kt | 6 +++--- .../examples/collections/ListsPart2Test.kt | 3 --- .../examples/collections/ListsPart3Test.kt | 5 ----- .../examples/collections/MapEntrySetTest.kt | 6 ------ .../examples/collections/MapKeySetTest.kt | 7 ------- .../examples/collections/MapValuesTest.kt | 7 ------- .../examples/collections/MapsPart1Test.kt | 6 ------ .../examples/collections/MapsPart2Test.kt | 4 ---- .../examples/collections/OptionalsTest.kt | 6 ------ .../examples/collections/QueueUsagesTest.kt | 6 +++--- .../examples/collections/SetIteratorsTest.kt | 5 ----- .../org/utbot/examples/collections/SetsTest.kt | 6 ------ .../examples/controlflow/ConditionsTest.kt | 4 ---- .../controlflow/CycleDependedConditionTest.kt | 3 --- .../utbot/examples/controlflow/CyclesTest.kt | 7 ------- .../utbot/examples/controlflow/SwitchTest.kt | 3 --- .../utbot/examples/enums/ClassWithEnumTest.kt | 3 --- .../examples/enums/ComplexEnumExamplesTest.kt | 3 --- .../exceptions/ExceptionClusteringChecker.kt | 6 +++--- .../exceptions/ExceptionExamplesTest.kt | 5 ----- .../exceptions/JvmCrashExamplesTest.kt | 4 ++-- .../examples/invokes/InvokeExampleTest.kt | 4 ---- .../examples/invokes/NativeExampleTest.kt | 3 --- .../invokes/SimpleInterfaceExampleTest.kt | 2 +- .../invokes/StaticInvokeExampleTest.kt | 4 ++-- .../invokes/VirtualInvokeExampleTest.kt | 3 --- .../lambda/CustomPredicateExampleTest.kt | 4 ---- .../examples/lambda/PredicateNotExampleTest.kt | 2 +- .../lambda/SimpleLambdaExamplesTest.kt | 4 ---- .../ClassWithComplicatedMethodsTest.kt | 3 --- .../utbot/examples/math/BitOperatorsTest.kt | 2 -- .../utbot/examples/math/DivRemExamplesTest.kt | 4 ++-- .../utbot/examples/math/DoubleFunctionsTest.kt | 6 +++--- .../utbot/examples/math/OverflowAsErrorTest.kt | 5 ----- .../utbot/examples/mixed/LoggerExampleTest.kt | 6 +++--- .../utbot/examples/mixed/MonitorUsageTest.kt | 6 +++--- .../org/utbot/examples/mixed/OverloadTest.kt | 2 +- .../mixed/PrivateConstructorExampleTest.kt | 3 --- .../examples/mixed/SimpleNoConditionTest.kt | 2 +- .../org/utbot/examples/mixed/SimplifierTest.kt | 6 ++++-- .../mixed/StaticInitializerExampleTest.kt | 3 ++- .../examples/mixed/StaticMethodExamplesTest.kt | 2 +- .../utbot/examples/mock/ArgumentsMockTest.kt | 12 ++++++------ .../examples/mock/CommonMocksExampleTest.kt | 4 ++-- .../org/utbot/examples/mock/FieldMockTest.kt | 7 ------- .../utbot/examples/mock/MockFinalClassTest.kt | 7 +------ .../org/utbot/examples/mock/MockRandomTest.kt | 10 ---------- .../mock/MockReturnObjectExampleTest.kt | 7 +------ .../mock/MockStaticFieldExampleTest.kt | 6 +----- .../mock/MockStaticMethodExampleTest.kt | 5 ----- .../mock/MockWithSideEffectExampleTest.kt | 3 --- .../utbot/examples/mock/StaticFieldMockTest.kt | 6 ++---- .../org/utbot/examples/mock/UseNetworkTest.kt | 4 ---- .../aliasing/AliasingInParamsExampleTest.kt | 2 -- .../examples/mock/model/FieldMockChecker.kt | 4 ++-- .../mock/model/UseNetworkModelBasedTest.kt | 3 ++- .../CompositeModelMinimizationChecker.kt | 4 ++-- .../examples/models/ModelsIdEqualityChecker.kt | 2 -- .../examples/natives/NativeExamplesTest.kt | 3 --- .../objects/AnonymousClassesExampleTest.kt | 5 ----- .../org/utbot/examples/objects/ClassRefTest.kt | 3 --- .../examples/objects/ClassWithClassRefTest.kt | 5 ----- .../objects/HiddenFieldAccessModifiersTest.kt | 2 +- .../examples/objects/HiddenFieldExampleTest.kt | 2 -- .../objects/ModelMinimizationExamplesTest.kt | 2 -- .../objects/ObjectWithFinalStaticTest.kt | 4 ---- .../objects/ObjectWithPrimitivesClassTest.kt | 2 -- .../objects/ObjectWithPrimitivesExampleTest.kt | 5 ----- .../objects/ObjectWithRefFieldsExampleTest.kt | 5 ----- .../ObjectWithStaticFieldsExampleTest.kt | 5 ----- .../ObjectWithThrowableConstructorTest.kt | 4 ++-- .../examples/objects/PrivateFieldsTest.kt | 6 ++++-- .../examples/objects/RecursiveTypeTest.kt | 4 ++-- .../examples/objects/SimpleClassExampleTest.kt | 6 ------ .../SimpleClassMultiInstanceExampleTest.kt | 5 ++--- .../examples/primitives/ByteExamplesTest.kt | 2 +- .../examples/primitives/CharExamplesTest.kt | 4 ++-- .../examples/primitives/DoubleExamplesTest.kt | 2 +- .../examples/primitives/FloatExamplesTest.kt | 2 +- .../examples/primitives/IntExamplesTest.kt | 2 +- .../utbot/examples/recursion/RecursionTest.kt | 7 ------- .../substitution/StaticsSubstitutionTest.kt | 2 -- .../utbot/examples/stdlib/DateExampleTest.kt | 4 ++-- .../examples/stream/BaseStreamExampleTest.kt | 18 +++++++++--------- .../examples/stream/DoubleStreamExampleTest.kt | 2 +- .../examples/stream/IntStreamExampleTest.kt | 2 +- .../examples/stream/LongStreamExampleTest.kt | 2 +- .../stream/StreamsAsMethodResultExampleTest.kt | 8 ++++---- .../examples/strings/GenericExamplesTest.kt | 3 --- .../examples/strings/StringExamplesTest.kt | 8 -------- .../examples/strings11/StringConcatTest.kt | 1 - .../org/utbot/examples/structures/HeapTest.kt | 2 -- .../examples/structures/MinStackExampleTest.kt | 3 --- .../structures/StandardStructuresTest.kt | 5 ----- .../thirdparty/numbers/ArithmeticUtilsTest.kt | 2 +- .../utbot/examples/types/CastExamplesTest.kt | 2 +- .../utbot/examples/types/TypeBordersTest.kt | 2 -- .../utbot/examples/types/TypeMatchesTest.kt | 2 +- .../examples/unsafe/UnsafeOperationsTest.kt | 4 ++-- .../examples/unsafe/UnsafeWithFieldTest.kt | 2 +- .../examples/wrappers/BooleanWrapperTest.kt | 2 -- .../utbot/examples/wrappers/ByteWrapperTest.kt | 2 -- .../examples/wrappers/CharacterWrapperTest.kt | 3 --- .../examples/wrappers/DoubleWrapperTest.kt | 2 -- .../examples/wrappers/FloatWrapperTest.kt | 2 -- .../examples/wrappers/IntegerWrapperTest.kt | 2 -- .../utbot/examples/wrappers/LongWrapperTest.kt | 3 --- .../examples/wrappers/ShortWrapperTest.kt | 2 -- utbot-summary-tests/build.gradle | 2 +- .../examples/SummaryTestCaseGeneratorTest.kt | 1 - .../SummaryArrayQuickSortExampleTest.kt | 2 +- .../algorithms/SummaryReturnExampleTest.kt | 2 +- .../SummaryListWrapperReturnsVoidTest.kt | 2 +- .../controlflow/SummaryConditionsTest.kt | 2 +- .../examples/controlflow/SummaryCycleTest.kt | 2 +- .../examples/controlflow/SummarySwitchTest.kt | 1 - .../examples/enums/ComplexEnumExampleTest.kt | 2 +- .../SummaryExceptionClusteringExamplesTest.kt | 2 +- .../exceptions/SummaryExceptionExampleTest.kt | 2 +- .../examples/inner/SummaryInnerCallsTest.kt | 2 +- .../examples/inner/SummaryNestedCallsTest.kt | 2 +- .../examples/recursion/SummaryRecursionTest.kt | 1 - .../examples/structures/SummaryMinStackTest.kt | 2 +- .../examples/ternary/SummaryTernaryTest.kt | 2 +- .../examples/unsafe/UnsafeWithFieldTest.kt | 1 - .../src/test/kotlin/math/SummaryIntMathTest.kt | 2 +- .../src/test/kotlin/math/SummaryOfMathTest.kt | 2 +- 166 files changed, 151 insertions(+), 489 deletions(-) diff --git a/utbot-analytics/build.gradle b/utbot-analytics/build.gradle index 1023802c5b..5cf17fd4da 100644 --- a/utbot-analytics/build.gradle +++ b/utbot-analytics/build.gradle @@ -33,6 +33,7 @@ dependencies { implementation group: 'org.apache.commons', name: 'commons-text', version: '1.9' implementation group: 'com.github.javaparser', name: 'javaparser-core', version: '3.22.1' + testImplementation project(':utbot-framework-test').sourceSets.main.output testImplementation project(':utbot-framework').sourceSets.test.output } diff --git a/utbot-analytics/src/main/kotlin/org/utbot/features/FeatureProcessorWithStatesRepetition.kt b/utbot-analytics/src/main/kotlin/org/utbot/features/FeatureProcessorWithStatesRepetition.kt index 62e7e398d3..4c80f18dda 100644 --- a/utbot-analytics/src/main/kotlin/org/utbot/features/FeatureProcessorWithStatesRepetition.kt +++ b/utbot-analytics/src/main/kotlin/org/utbot/features/FeatureProcessorWithStatesRepetition.kt @@ -107,7 +107,7 @@ class FeatureProcessorWithStatesRepetition( } } -internal class RewardEstimator { +class RewardEstimator { fun calculateRewards(testCases: List): Map { val rewards = mutableMapOf() diff --git a/utbot-analytics/src/test/kotlin/org/utbot/features/FeatureProcessorWithRepetitionTest.kt b/utbot-analytics/src/test/kotlin/org/utbot/features/FeatureProcessorWithRepetitionTest.kt index 8ab741488c..b2020d374b 100644 --- a/utbot-analytics/src/test/kotlin/org/utbot/features/FeatureProcessorWithRepetitionTest.kt +++ b/utbot-analytics/src/test/kotlin/org/utbot/features/FeatureProcessorWithRepetitionTest.kt @@ -5,9 +5,9 @@ import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.Test import org.utbot.analytics.EngineAnalyticsContext -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.utbot.testcheckers.eq import org.utbot.testcheckers.withFeaturePath +import org.utbot.testing.UtValueTestCaseChecker import java.io.File import java.io.FileInputStream diff --git a/utbot-framework-test/build.gradle b/utbot-framework-test/build.gradle index e087e6a924..4352a518b2 100644 --- a/utbot-framework-test/build.gradle +++ b/utbot-framework-test/build.gradle @@ -1,6 +1,6 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { kotlinOptions { - jvmTarget = JavaVersion.VERSION_11 + jvmTarget = JavaVersion.VERSION_1_8 freeCompilerArgs += ["-Xallow-result-return-type", "-Xsam-conversions=class"] } } diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/BinarySearchTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/BinarySearchTest.kt index d197e8a838..f826a1d413 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/BinarySearchTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/BinarySearchTest.kt @@ -1,13 +1,13 @@ package org.utbot.examples.algorithms -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.ignoreExecutionsNumber -import org.utbot.tests.infrastructure.isException import org.utbot.framework.plugin.api.DocCodeStmt import org.utbot.framework.plugin.api.DocPreTagStatement import org.utbot.framework.plugin.api.DocRegularStmt import org.utbot.framework.plugin.api.DocStatement import org.junit.jupiter.api.Test +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException class BinarySearchTest : UtValueTestCaseChecker(testClass = BinarySearch::class,) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt index 02e9eae72a..415d7e0b12 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt @@ -1,18 +1,11 @@ package org.utbot.examples.algorithms -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.examples.algorithms.CorrectBracketSequences.isBracket -import org.utbot.examples.algorithms.CorrectBracketSequences.isOpen -import org.utbot.tests.infrastructure.ignoreExecutionsNumber -import org.utbot.tests.infrastructure.isException -import org.utbot.tests.infrastructure.keyMatch import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.framework.plugin.api.DocCodeStmt import org.utbot.framework.plugin.api.DocPreTagStatement import org.utbot.framework.plugin.api.DocRegularStmt import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration internal class CorrectBracketSequencesTest : UtValueTestCaseChecker( testClass = CorrectBracketSequences::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/GraphTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/GraphTest.kt index 71d13c4383..2ac25b02f9 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/GraphTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/GraphTest.kt @@ -1,8 +1,5 @@ package org.utbot.examples.algorithms -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.ignoreExecutionsNumber -import org.utbot.tests.infrastructure.isException import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt index 0df50b9009..354558b3fb 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt @@ -1,9 +1,5 @@ package org.utbot.examples.algorithms -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.ignoreExecutionsNumber -import org.utbot.tests.infrastructure.isException -import org.utbot.tests.infrastructure.keyMatch import org.utbot.framework.plugin.api.DocCodeStmt import org.utbot.framework.plugin.api.DocPreTagStatement import org.utbot.framework.plugin.api.DocRegularStmt @@ -12,7 +8,6 @@ import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq import org.utbot.testcheckers.ge -import org.utbot.tests.infrastructure.CodeGeneration // TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 internal class SortTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/annotations/NotNullAnnotationTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/annotations/NotNullAnnotationTest.kt index 0b64573d0e..6ba1d8bf06 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/annotations/NotNullAnnotationTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/annotations/NotNullAnnotationTest.kt @@ -1,9 +1,9 @@ package org.utbot.examples.annotations -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker internal class NotNullAnnotationTest : UtValueTestCaseChecker(testClass = NotNullAnnotation::class) { @Test 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..b4c8097e10 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 @@ -1,9 +1,9 @@ package org.utbot.examples.annotations.lombok 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.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker /** * Tests for Lombok annotations 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..c9977326d6 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 @@ -1,8 +1,8 @@ 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.testing.UtValueTestCaseChecker internal class EnumWithoutAnnotationsTest : UtValueTestCaseChecker(testClass = EnumWithoutAnnotations::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/annotations/lombok/NotNullAnnotationsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/annotations/lombok/NotNullAnnotationsTest.kt index b73330d07c..1d3e95b33c 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/annotations/lombok/NotNullAnnotationsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/annotations/lombok/NotNullAnnotationsTest.kt @@ -1,9 +1,9 @@ package org.utbot.examples.annotations.lombok 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.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker /** * Tests for Lombok NonNull annotation diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayOfArraysTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayOfArraysTest.kt index 0e63fec970..4aa433b0b7 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayOfArraysTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayOfArraysTest.kt @@ -1,15 +1,15 @@ package org.utbot.examples.arrays import org.junit.jupiter.api.Disabled -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.atLeast import org.utbot.examples.casts.ColoredPoint import org.utbot.examples.casts.Point -import org.utbot.tests.infrastructure.ignoreExecutionsNumber import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq import org.utbot.testcheckers.withoutMinimization +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast +import org.utbot.testing.ignoreExecutionsNumber @Suppress("NestedLambdaShadowedImplicitParameter") internal class ArrayOfArraysTest : UtValueTestCaseChecker(testClass = ArrayOfArrays::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt index 0f279c793a..f26c944212 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt @@ -1,16 +1,9 @@ package org.utbot.examples.arrays -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.atLeast -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.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation SAT-1332 internal class ArrayOfObjectsTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayStoreExceptionExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayStoreExceptionExamplesTest.kt index 0d23117b75..dfd48eafad 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayStoreExceptionExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayStoreExceptionExamplesTest.kt @@ -4,10 +4,6 @@ import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.AtLeast -import org.utbot.tests.infrastructure.CodeGeneration -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.isException class ArrayStoreExceptionExamplesTest : UtValueTestCaseChecker( testClass = ArrayStoreExceptionExamples::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArraysOverwriteValueTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArraysOverwriteValueTest.kt index 00f896bfe8..6f6f5f3b23 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArraysOverwriteValueTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArraysOverwriteValueTest.kt @@ -1,10 +1,10 @@ package org.utbot.examples.arrays -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker // TODO failed Kotlin compilation SAT-1332 class ArraysOverwriteValueTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/FinalStaticFieldArrayTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/FinalStaticFieldArrayTest.kt index e6cfd39049..55b0d37eed 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/FinalStaticFieldArrayTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/FinalStaticFieldArrayTest.kt @@ -1,8 +1,8 @@ package org.utbot.examples.arrays -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.ignoreExecutionsNumber import org.junit.jupiter.api.Test +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber internal class FinalStaticFieldArrayTest : UtValueTestCaseChecker(testClass = FinalStaticFieldArray::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/IntArrayBasicsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/IntArrayBasicsTest.kt index 158d2402fd..aedb08e43a 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/IntArrayBasicsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/IntArrayBasicsTest.kt @@ -1,14 +1,10 @@ package org.utbot.examples.arrays import org.junit.jupiter.api.Disabled -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -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.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation SAT-1332 internal class IntArrayBasicsTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/PrimitiveArraysTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/PrimitiveArraysTest.kt index f2009247aa..b1fc9d41db 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/PrimitiveArraysTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/PrimitiveArraysTest.kt @@ -1,12 +1,12 @@ package org.utbot.examples.arrays -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.atLeast -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.tests.infrastructure.CodeGeneration +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast +import org.utbot.testing.isException // TODO failed Kotlin compilation SAT-1332 internal class PrimitiveArraysTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/ArrayCastExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/ArrayCastExampleTest.kt index 78a2a8b548..51c4c3123f 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/ArrayCastExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/ArrayCastExampleTest.kt @@ -1,12 +1,9 @@ package org.utbot.examples.casts import org.junit.jupiter.api.Disabled -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation (generics) SAT-1332 //TODO: SAT-1487 calculate coverage for all methods of this test class diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/CastClassTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/CastClassTest.kt index 0de77bbb9d..220e11cc33 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/CastClassTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/CastClassTest.kt @@ -1,11 +1,11 @@ package org.utbot.examples.casts import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class CastClassTest : UtValueTestCaseChecker( testClass = CastClass::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/CastExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/CastExampleTest.kt index 7206db0cea..77747a3035 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/CastExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/CastExampleTest.kt @@ -1,12 +1,8 @@ package org.utbot.examples.casts -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -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.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation SAT-1332 internal class CastExampleTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/GenericCastExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/GenericCastExampleTest.kt index faa8f103f4..e62fe49cbe 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/GenericCastExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/GenericCastExampleTest.kt @@ -1,12 +1,8 @@ package org.utbot.examples.casts -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.between import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation SAT-1332 internal class GenericCastExampleTest : UtValueTestCaseChecker( 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..fe9fa10068 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 @@ -1,14 +1,10 @@ package org.utbot.examples.casts -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -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.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation SAT-1332 internal class InstanceOfExampleTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/ClassWithStaticAndInnerClassesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/ClassWithStaticAndInnerClassesTest.kt index 0f9f32fdb7..a2576397ee 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/ClassWithStaticAndInnerClassesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/ClassWithStaticAndInnerClassesTest.kt @@ -1,12 +1,8 @@ package org.utbot.examples.codegen -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.Compilation -import org.utbot.tests.infrastructure.TestExecution @Suppress("INACCESSIBLE_TYPE") internal class ClassWithStaticAndInnerClassesTest : UtValueTestCaseChecker( 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..ce9b6b757f 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 @@ -1,6 +1,5 @@ package org.utbot.examples.codegen -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.utbot.examples.mock.MockRandomExamples import kotlin.reflect.full.functions import org.junit.jupiter.api.Disabled diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/FileWithTopLevelFunctionsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/FileWithTopLevelFunctionsTest.kt index 307f143d91..6af41eb6d4 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/FileWithTopLevelFunctionsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/FileWithTopLevelFunctionsTest.kt @@ -2,7 +2,7 @@ package org.utbot.examples.codegen import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.UtValueTestCaseChecker +import org.utbot.testing.UtValueTestCaseChecker import kotlin.reflect.KFunction3 @Suppress("UNCHECKED_CAST") diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt index 9c18e0a1a1..2133cf2ef8 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt @@ -1,9 +1,9 @@ package org.utbot.examples.codegen import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.isException import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException class JavaAssertTest : UtValueTestCaseChecker( testClass = JavaAssert::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/VoidStaticMethodsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/VoidStaticMethodsTest.kt index 2348360e27..42af7ff925 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/VoidStaticMethodsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/VoidStaticMethodsTest.kt @@ -1,11 +1,9 @@ package org.utbot.examples.codegen -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.Compilation +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker class VoidStaticMethodsTest : UtValueTestCaseChecker( testClass = VoidStaticMethodsTestingClass::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithCrossReferenceRelationshipTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithCrossReferenceRelationshipTest.kt index d7ca1dc689..1e962818ed 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithCrossReferenceRelationshipTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithCrossReferenceRelationshipTest.kt @@ -3,9 +3,9 @@ package org.utbot.examples.codegen.deepequals import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.UtValueTestCaseChecker +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker class ClassWithCrossReferenceRelationshipTest : UtValueTestCaseChecker( testClass = ClassWithCrossReferenceRelationship::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithNullableFieldTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithNullableFieldTest.kt index f39c394b4b..4dbf645bd8 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithNullableFieldTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithNullableFieldTest.kt @@ -1,11 +1,8 @@ package org.utbot.examples.codegen.deepequals import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration class ClassWithNullableFieldTest : UtValueTestCaseChecker( testClass = ClassWithNullableField::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/DeepEqualsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/DeepEqualsTest.kt index 398a7be8fc..9d206c61d4 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/DeepEqualsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/DeepEqualsTest.kt @@ -1,12 +1,9 @@ package org.utbot.examples.codegen.deepequals -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate 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.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation (generics) SAT-1332 class DeepEqualsTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt index a31980f59e..200047ea44 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt @@ -7,8 +7,8 @@ import org.utbot.framework.plugin.api.FieldId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.jField import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.Compilation -import org.utbot.tests.infrastructure.UtValueTestCaseChecker +import org.utbot.testing.Compilation +import org.utbot.testing.UtValueTestCaseChecker // TODO failed Kotlin tests execution with non-nullable expected field class ClassWithPrivateMutableFieldOfPrivateTypeTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt index 33d51fcd0e..94e1a81f36 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt @@ -1,16 +1,10 @@ package org.utbot.examples.collections -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.ignoreExecutionsNumber import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.framework.plugin.api.FieldId import org.utbot.framework.plugin.api.UtConcreteValue import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration -import org.utbot.tests.infrastructure.Compilation -import org.utbot.tests.infrastructure.TestExecution internal class CustomerExamplesTest: UtValueTestCaseChecker( testClass = CustomerExamples::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/GenericListsExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/GenericListsExampleTest.kt index 6c541525ab..fbabf6523c 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/GenericListsExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/GenericListsExampleTest.kt @@ -1,12 +1,9 @@ package org.utbot.examples.collections -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate 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.tests.infrastructure.CodeGeneration // TODO disabled tests should be fixes with SAT-1441 internal class GenericListsExampleTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/LinkedListsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/LinkedListsTest.kt index d8fa642c3f..ca667af7e9 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/LinkedListsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/LinkedListsTest.kt @@ -1,12 +1,8 @@ package org.utbot.examples.collections -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -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.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation (generics) SAT-1332 internal class LinkedListsTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListAlgorithmsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListAlgorithmsTest.kt index 9e88ec075a..ef1083217e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListAlgorithmsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListAlgorithmsTest.kt @@ -1,11 +1,11 @@ package org.utbot.examples.collections -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.atLeast import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast // TODO failed Kotlin compilation SAT-1332 class ListAlgorithmsTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListIteratorsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListIteratorsTest.kt index 153d845930..a8274f04df 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListIteratorsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListIteratorsTest.kt @@ -1,14 +1,10 @@ package org.utbot.examples.collections import org.junit.jupiter.api.Disabled -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.ignoreExecutionsNumber import org.utbot.framework.plugin.api.CodegenLanguage import kotlin.math.min import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation (generics) SAT-1332 internal class ListIteratorsTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListWrapperReturnsVoidTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListWrapperReturnsVoidTest.kt index 8916476ec9..d4c5cae8dc 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListWrapperReturnsVoidTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListWrapperReturnsVoidTest.kt @@ -1,13 +1,9 @@ package org.utbot.examples.collections import org.junit.jupiter.api.Disabled -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -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.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation ($ in function names, generics) SAT-1220 SAT-1332 @Disabled("Java 11 transition") diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart1Test.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart1Test.kt index cec153c583..397276453e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart1Test.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart1Test.kt @@ -2,10 +2,10 @@ package org.utbot.examples.collections import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.ignoreExecutionsNumber import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.tests.infrastructure.CodeGeneration +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber // TODO failed Kotlin compilation SAT-1332 @Disabled diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart2Test.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart2Test.kt index 166e321fc1..616ec2e4a7 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart2Test.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart2Test.kt @@ -3,9 +3,6 @@ package org.utbot.examples.collections import org.junit.jupiter.api.Disabled import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.CodeGeneration -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.ignoreExecutionsNumber // TODO failed Kotlin compilation SAT-1332 @Disabled 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..d7ac68b90a 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 @@ -3,13 +3,8 @@ package org.utbot.examples.collections import org.utbot.framework.plugin.api.CodegenLanguage 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 // TODO failed Kotlin compilation SAT-1332 internal class ListsPart3Test : UtValueTestCaseChecker( 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..4c9bd82989 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 @@ -1,16 +1,10 @@ package org.utbot.examples.collections -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.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.CodeGeneration -import org.utbot.tests.infrastructure.ignoreExecutionsNumber // TODO failed Kotlin compilation SAT-1332 class MapEntrySetTest : UtValueTestCaseChecker( 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..92aa202c2e 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,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.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.testcheckers.withPushingStateFromPathSelectorForConcrete import org.utbot.testcheckers.withoutMinimization -import org.utbot.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation SAT-1332 class MapKeySetTest : UtValueTestCaseChecker( 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..cd92dfb0b8 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 @@ -1,16 +1,9 @@ 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.ge import org.utbot.testcheckers.withoutMinimization -import org.utbot.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation SAT-1332 class MapValuesTest : UtValueTestCaseChecker( 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..4f73aec84b 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 @@ -1,11 +1,6 @@ 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 @@ -14,7 +9,6 @@ import org.utbot.testcheckers.ge import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete import org.utbot.testcheckers.withoutConcrete import org.utbot.testcheckers.withoutMinimization -import org.utbot.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation ($ in names, generics) SAT-1220 SAT-1332 internal class MapsPart1Test : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapsPart2Test.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapsPart2Test.kt index b4ae041c13..12a0c585e4 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapsPart2Test.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapsPart2Test.kt @@ -1,14 +1,10 @@ package org.utbot.examples.collections -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.isException import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.ge import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete import org.utbot.testcheckers.withoutMinimization -import org.utbot.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation ($ in names, generics) SAT-1220 SAT-1332 internal class MapsPart2Test : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt index 964dd93f2c..fab2ca1d57 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt @@ -1,14 +1,8 @@ package org.utbot.examples.collections -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -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.tests.infrastructure.CodeGeneration import java.util.* class OptionalsTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/QueueUsagesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/QueueUsagesTest.kt index 69dd432ada..8822b05365 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/QueueUsagesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/QueueUsagesTest.kt @@ -4,9 +4,9 @@ import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.isException +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException class QueueUsagesTest : UtValueTestCaseChecker( testClass = QueueUsages::class, 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..21c9945b94 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 @@ -1,13 +1,8 @@ package org.utbot.examples.collections -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -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.ge -import org.utbot.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation SAT-1332 class SetIteratorsTest : UtValueTestCaseChecker( 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..4e368f8085 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 @@ -1,10 +1,5 @@ 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 @@ -12,7 +7,6 @@ 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 // TODO failed Kotlin compilation SAT-1332 internal class SetsTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/ConditionsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/ConditionsTest.kt index c781994415..4cd9376ef9 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/ConditionsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/ConditionsTest.kt @@ -1,9 +1,5 @@ package org.utbot.examples.controlflow -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.ignoreExecutionsNumber -import org.utbot.tests.infrastructure.keyContain -import org.utbot.tests.infrastructure.keyMatch import org.utbot.framework.plugin.api.DocCodeStmt import org.utbot.framework.plugin.api.DocPreTagStatement import org.utbot.framework.plugin.api.DocRegularStmt diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CycleDependedConditionTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CycleDependedConditionTest.kt index 4899e41931..c0dc060e96 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CycleDependedConditionTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CycleDependedConditionTest.kt @@ -1,8 +1,5 @@ package org.utbot.examples.controlflow -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.keyContain -import org.utbot.tests.infrastructure.keyMatch import org.utbot.framework.plugin.api.DocCodeStmt import org.utbot.framework.plugin.api.DocPreTagStatement import org.utbot.framework.plugin.api.DocRegularStmt diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt index f3d2d7d981..878ecb6ca5 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt @@ -1,12 +1,5 @@ package org.utbot.examples.controlflow -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.atLeast -import org.utbot.tests.infrastructure.between -import org.utbot.tests.infrastructure.ignoreExecutionsNumber -import org.utbot.tests.infrastructure.isException -import org.utbot.tests.infrastructure.keyContain -import org.utbot.tests.infrastructure.keyMatch import org.utbot.framework.plugin.api.DocCodeStmt import org.utbot.framework.plugin.api.DocPreTagStatement import org.utbot.framework.plugin.api.DocRegularStmt diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/SwitchTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/SwitchTest.kt index e503715393..381c097be9 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/SwitchTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/SwitchTest.kt @@ -1,8 +1,5 @@ package org.utbot.examples.controlflow -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.keyContain -import org.utbot.tests.infrastructure.keyMatch import org.utbot.framework.plugin.api.DocCodeStmt import org.utbot.framework.plugin.api.DocPreTagStatement import org.utbot.framework.plugin.api.DocRegularStmt 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..a6d62721ca 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 @@ -1,10 +1,7 @@ package org.utbot.examples.enums -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.utbot.examples.enums.ClassWithEnum.StatusEnum.ERROR import org.utbot.examples.enums.ClassWithEnum.StatusEnum.READY -import org.utbot.tests.infrastructure.isException import org.utbot.framework.plugin.api.FieldId import org.utbot.framework.plugin.api.util.id import org.junit.jupiter.api.Disabled diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/enums/ComplexEnumExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/enums/ComplexEnumExamplesTest.kt index 7b8b064b0c..e0d35726a4 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/enums/ComplexEnumExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/enums/ComplexEnumExamplesTest.kt @@ -2,15 +2,12 @@ package org.utbot.examples.enums import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.utbot.examples.enums.ComplexEnumExamples.Color import org.utbot.examples.enums.ComplexEnumExamples.Color.BLUE import org.utbot.examples.enums.ComplexEnumExamples.Color.GREEN import org.utbot.examples.enums.ComplexEnumExamples.Color.RED -import org.utbot.tests.infrastructure.ignoreExecutionsNumber import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration class ComplexEnumExamplesTest : UtValueTestCaseChecker( testClass = ComplexEnumExamples::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/exceptions/ExceptionClusteringChecker.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/exceptions/ExceptionClusteringChecker.kt index 53abd8bf53..4e67505768 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/exceptions/ExceptionClusteringChecker.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/exceptions/ExceptionClusteringChecker.kt @@ -1,8 +1,5 @@ package org.utbot.examples.exceptions -import org.utbot.tests.infrastructure.UtModelTestCaseChecker -import org.utbot.tests.infrastructure.ignoreExecutionsNumber -import org.utbot.tests.infrastructure.primitiveValue import org.utbot.framework.plugin.api.UtExecutionSuccess import org.utbot.framework.plugin.api.UtExplicitlyThrownException import org.utbot.framework.plugin.api.UtImplicitlyThrownException @@ -10,6 +7,9 @@ import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtTimeoutException import org.junit.jupiter.api.Test import org.utbot.testcheckers.ge +import org.utbot.testing.UtModelTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.primitiveValue internal class ExceptionClusteringChecker : UtModelTestCaseChecker(testClass = ExceptionClusteringExamples::class) { 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..29b62857fa 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 @@ -1,14 +1,9 @@ package org.utbot.examples.exceptions -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.atLeast -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.withoutConcrete -import org.utbot.tests.infrastructure.CodeGeneration internal class ExceptionExamplesTest : UtValueTestCaseChecker( testClass = ExceptionExamples::class, 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..6a9449d4f7 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 @@ -1,11 +1,11 @@ package org.utbot.examples.exceptions -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -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.withoutSandbox +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class JvmCrashExamplesTest : UtValueTestCaseChecker(testClass = JvmCrashExamples::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/InvokeExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/InvokeExampleTest.kt index 4f8379a08e..44ec7ceb69 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/InvokeExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/InvokeExampleTest.kt @@ -1,9 +1,5 @@ package org.utbot.examples.invokes -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.ignoreExecutionsNumber -import org.utbot.tests.infrastructure.isException import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/NativeExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/NativeExampleTest.kt index 1323697b42..9949638cb1 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/NativeExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/NativeExampleTest.kt @@ -1,8 +1,5 @@ package org.utbot.examples.invokes -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.atLeast -import org.utbot.tests.infrastructure.ignoreExecutionsNumber import kotlin.math.ln import kotlin.math.sqrt import org.junit.jupiter.api.Tag diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/SimpleInterfaceExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/SimpleInterfaceExampleTest.kt index 8b1fc9bec7..98e19a19b8 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/SimpleInterfaceExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/SimpleInterfaceExampleTest.kt @@ -1,8 +1,8 @@ package org.utbot.examples.invokes -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker internal class SimpleInterfaceExampleTest : UtValueTestCaseChecker( testClass = SimpleInterfaceExample::class diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/StaticInvokeExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/StaticInvokeExampleTest.kt index 34c54d5a29..5c75b0f0cb 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/StaticInvokeExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/StaticInvokeExampleTest.kt @@ -1,9 +1,9 @@ package org.utbot.examples.invokes -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.between import kotlin.math.max import org.junit.jupiter.api.Test +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.between internal class StaticInvokeExampleTest : UtValueTestCaseChecker(testClass = StaticInvokeExample::class) { // TODO: inline local variables when types inference bug in Kotlin fixed 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..05f4395083 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 @@ -2,9 +2,6 @@ package org.utbot.examples.invokes -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.isException import java.lang.Boolean import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq 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..868273353e 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,10 +3,6 @@ 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.tests.infrastructure.CodeGeneration -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.isException class CustomPredicateExampleTest : UtValueTestCaseChecker( testClass = CustomPredicateExample::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/PredicateNotExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/PredicateNotExampleTest.kt index 659b6a63cc..739cff5964 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/PredicateNotExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/PredicateNotExampleTest.kt @@ -3,7 +3,7 @@ package org.utbot.examples.lambda import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.UtValueTestCaseChecker +import org.utbot.testing.UtValueTestCaseChecker class PredicateNotExampleTest : UtValueTestCaseChecker(testClass = PredicateNotExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt index 32f83ef9e2..2c893b55b6 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt @@ -3,10 +3,6 @@ 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.tests.infrastructure.CodeGeneration -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.isException // TODO failed Kotlin compilation (generics) SAT-1332 class SimpleLambdaExamplesTest : UtValueTestCaseChecker( 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..083220f4c5 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 @@ -1,7 +1,5 @@ package org.utbot.examples.make.symbolic -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.framework.plugin.api.MockStrategyApi import kotlin.math.abs @@ -10,7 +8,6 @@ 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.tests.infrastructure.Compilation // This class is substituted with ComplicatedMethodsSubstitutionsStorage // but we cannot do in code generation. diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/BitOperatorsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/BitOperatorsTest.kt index 7f9f63dbe6..a54b0146dc 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/BitOperatorsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/BitOperatorsTest.kt @@ -1,7 +1,5 @@ package org.utbot.examples.math -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.atLeast import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/DivRemExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/DivRemExamplesTest.kt index 8d8d8249a3..acd9124d5d 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/DivRemExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/DivRemExamplesTest.kt @@ -1,9 +1,9 @@ package org.utbot.examples.math -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.isException import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException internal class DivRemExamplesTest : UtValueTestCaseChecker(testClass = DivRemExamples::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/DoubleFunctionsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/DoubleFunctionsTest.kt index 0f1c0a7db1..a69f6565f2 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/DoubleFunctionsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/DoubleFunctionsTest.kt @@ -1,13 +1,13 @@ package org.utbot.examples.math -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.isException import kotlin.math.abs import kotlin.math.hypot import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException @Suppress("SimplifyNegatedBinaryExpression") internal class DoubleFunctionsTest : UtValueTestCaseChecker(testClass = DoubleFunctions::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt index 625f195710..4adc79d13b 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt @@ -2,16 +2,11 @@ package org.utbot.examples.math import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.AtLeast import org.utbot.examples.algorithms.Sort -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.withSolverTimeoutInMillis import org.utbot.testcheckers.withTreatingOverflowAsError -import org.utbot.tests.infrastructure.Compilation import kotlin.math.floor import kotlin.math.sqrt diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/LoggerExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/LoggerExampleTest.kt index b751e01672..9655f9119a 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/LoggerExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/LoggerExampleTest.kt @@ -1,7 +1,5 @@ package org.utbot.examples.mixed -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.framework.plugin.api.UtConcreteValue import org.utbot.framework.plugin.api.UtInstrumentation @@ -10,7 +8,9 @@ import org.utbot.framework.plugin.api.UtStaticMethodInstrumentation import org.utbot.framework.plugin.api.isNull import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class LoggerExampleTest : UtValueTestCaseChecker( testClass = LoggerExample::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/MonitorUsageTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/MonitorUsageTest.kt index 92c29a00f1..09974c3c22 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/MonitorUsageTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/MonitorUsageTest.kt @@ -1,9 +1,9 @@ package org.utbot.examples.mixed -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.atLeast -import org.utbot.tests.infrastructure.ignoreExecutionsNumber import org.junit.jupiter.api.Test +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast +import org.utbot.testing.ignoreExecutionsNumber internal class MonitorUsageTest : UtValueTestCaseChecker(testClass = MonitorUsage::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/OverloadTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/OverloadTest.kt index 7bf7baa316..b6012d8d8b 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/OverloadTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/OverloadTest.kt @@ -1,8 +1,8 @@ package org.utbot.examples.mixed -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker internal class OverloadTest : UtValueTestCaseChecker(testClass = Overload::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt index 79662edf90..45126e0bad 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt @@ -1,11 +1,8 @@ package org.utbot.examples.mixed -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.Compilation internal class PrivateConstructorExampleTest : UtValueTestCaseChecker( testClass = PrivateConstructorExample::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/SimpleNoConditionTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/SimpleNoConditionTest.kt index a68bd75eef..8bddaa3e66 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/SimpleNoConditionTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/SimpleNoConditionTest.kt @@ -1,8 +1,8 @@ package org.utbot.examples.mixed -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker internal class SimpleNoConditionTest : UtValueTestCaseChecker(testClass = SimpleNoCondition::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/SimplifierTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/SimplifierTest.kt index c6358e1024..0092e68eab 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/SimplifierTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/SimplifierTest.kt @@ -1,9 +1,11 @@ package org.utbot.examples.mixed -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.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class SimplifierTest: UtValueTestCaseChecker(testClass = Simplifier::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticInitializerExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticInitializerExampleTest.kt index 97d959117b..e5b15f10fa 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticInitializerExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticInitializerExampleTest.kt @@ -3,8 +3,9 @@ package org.utbot.examples.mixed import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.examples.StaticInitializerExample -import org.utbot.tests.infrastructure.UtValueTestCaseChecker + import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker @Disabled("Unknown build failure") internal class StaticInitializerExampleTest : UtValueTestCaseChecker(testClass = StaticInitializerExample::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt index 34bbf5a7fe..40cfd0945d 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt @@ -1,6 +1,6 @@ package org.utbot.examples.mixed -import org.utbot.tests.infrastructure.UtValueTestCaseChecker + import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt index 36e997b811..5fa176228b 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt @@ -1,14 +1,14 @@ package org.utbot.examples.mock -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.between -import org.utbot.tests.infrastructure.isParameter + + + + import org.utbot.examples.mock.provider.Provider import org.utbot.examples.mock.service.impl.ExampleClass import org.utbot.examples.mock.service.impl.ServiceWithArguments -import org.utbot.tests.infrastructure.mocksMethod -import org.utbot.tests.infrastructure.value + + import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt index 0e5d1dc4f8..5c4a3a24d0 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt @@ -1,7 +1,7 @@ package org.utbot.examples.mock -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate + + import org.utbot.framework.plugin.api.MockStrategyApi import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt index 936eb2e353..3edd155c0b 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt @@ -1,19 +1,12 @@ package org.utbot.examples.mock -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.between import org.utbot.examples.mock.provider.Provider import org.utbot.examples.mock.service.impl.ExampleClass import org.utbot.examples.mock.service.impl.ServiceWithField -import org.utbot.tests.infrastructure.mocksMethod -import org.utbot.tests.infrastructure.value import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.Compilation -import org.utbot.tests.infrastructure.TestExecution internal class FieldMockTest : UtValueTestCaseChecker( testClass = ServiceWithField::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockFinalClassTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockFinalClassTest.kt index 0e844d275c..e3a8707bb7 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockFinalClassTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockFinalClassTest.kt @@ -1,16 +1,11 @@ package org.utbot.examples.mock -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.utbot.examples.mock.others.FinalClass -import org.utbot.tests.infrastructure.singleMock -import org.utbot.tests.infrastructure.value import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_CLASSES import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.ge -import org.utbot.tests.infrastructure.Compilation -import org.utbot.tests.infrastructure.TestExecution +import org.utbot.testing.* internal class MockFinalClassTest : UtValueTestCaseChecker( testClass = MockFinalClassExample::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt index bdca4c5e46..d46281fd6c 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt @@ -1,21 +1,11 @@ package org.utbot.examples.mock -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.isParameter -import org.utbot.tests.infrastructure.mockValues -import org.utbot.tests.infrastructure.mocksMethod -import org.utbot.tests.infrastructure.singleMock -import org.utbot.tests.infrastructure.value import org.utbot.framework.plugin.api.UtCompositeModel import org.utbot.framework.plugin.api.UtNewInstanceInstrumentation import java.util.Random import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration -import org.utbot.tests.infrastructure.Compilation -import org.utbot.tests.infrastructure.TestExecution // TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 internal class MockRandomTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockReturnObjectExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockReturnObjectExampleTest.kt index 446f5d25c6..3120626749 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockReturnObjectExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockReturnObjectExampleTest.kt @@ -1,17 +1,12 @@ package org.utbot.examples.mock import org.junit.jupiter.api.Disabled -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.utbot.examples.mock.others.Generator import org.utbot.examples.mock.others.Locator -import org.utbot.tests.infrastructure.mockValue -import org.utbot.tests.infrastructure.singleMock -import org.utbot.tests.infrastructure.singleMockOrNull -import org.utbot.tests.infrastructure.value import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.* internal class MockReturnObjectExampleTest : UtValueTestCaseChecker(testClass = MockReturnObjectExample::class) { @Test 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..2c1188af36 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 @@ -1,11 +1,6 @@ package org.utbot.examples.mock -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.utbot.examples.mock.others.Generator -import org.utbot.tests.infrastructure.singleMock -import org.utbot.tests.infrastructure.singleMockOrNull -import org.utbot.tests.infrastructure.value import org.utbot.framework.plugin.api.FieldMockTarget import org.utbot.framework.plugin.api.MockInfo import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES @@ -13,6 +8,7 @@ import kotlin.reflect.KClass import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq import org.utbot.testcheckers.withoutConcrete +import org.utbot.testing.* internal class MockStaticFieldExampleTest : UtValueTestCaseChecker(testClass = MockStaticFieldExample::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt index fcdbf694ad..821435ca21 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt @@ -1,7 +1,5 @@ package org.utbot.examples.mock -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtPrimitiveModel import org.utbot.framework.util.singleModel @@ -10,9 +8,6 @@ import org.utbot.framework.util.singleValue import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration -import org.utbot.tests.infrastructure.Compilation -import org.utbot.tests.infrastructure.TestExecution // TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 internal class MockStaticMethodExampleTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockWithSideEffectExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockWithSideEffectExampleTest.kt index 5b234c9e0f..1fba9e414b 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockWithSideEffectExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockWithSideEffectExampleTest.kt @@ -1,8 +1,5 @@ package org.utbot.examples.mock -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.isException import org.utbot.framework.plugin.api.MockStrategyApi import org.junit.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt index 4207e1585c..9246daad57 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt @@ -1,12 +1,10 @@ package org.utbot.examples.mock -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.utbot.examples.mock.provider.Provider import org.utbot.examples.mock.service.impl.ExampleClass import org.utbot.examples.mock.service.impl.ServiceWithStaticField -import org.utbot.tests.infrastructure.mocksMethod -import org.utbot.tests.infrastructure.value + + import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/UseNetworkTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/UseNetworkTest.kt index acff778b01..f481cb78be 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/UseNetworkTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/UseNetworkTest.kt @@ -1,14 +1,10 @@ package org.utbot.examples.mock -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.isException import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtConcreteValue import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.Compilation internal class UseNetworkTest : UtValueTestCaseChecker(testClass = UseNetwork::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/aliasing/AliasingInParamsExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/aliasing/AliasingInParamsExampleTest.kt index 6177ac7922..c0ce27528f 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/aliasing/AliasingInParamsExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/aliasing/AliasingInParamsExampleTest.kt @@ -1,7 +1,5 @@ package org.utbot.examples.mock.aliasing -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.utbot.framework.plugin.api.MockStrategyApi import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt index 25cd7d4d88..2499893bf3 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt @@ -2,13 +2,13 @@ package org.utbot.examples.mock.model import org.utbot.examples.mock.provider.impl.ProviderImpl import org.utbot.examples.mock.service.impl.ServiceWithField -import org.utbot.tests.infrastructure.primitiveValue + import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.isNotNull import org.utbot.framework.plugin.api.isNull import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.UtModelTestCaseChecker + import org.utbot.testcheckers.eq internal class FieldMockChecker : UtModelTestCaseChecker(testClass = ServiceWithField::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/UseNetworkModelBasedTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/UseNetworkModelBasedTest.kt index 063c199216..dcdd58e4d0 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/UseNetworkModelBasedTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/UseNetworkModelBasedTest.kt @@ -1,12 +1,13 @@ package org.utbot.examples.mock.model -import org.utbot.tests.infrastructure.UtModelTestCaseChecker + import org.utbot.examples.mock.UseNetwork import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtCompositeModel import org.utbot.framework.plugin.api.UtVoidModel import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtModelTestCaseChecker internal class UseNetworkModelBasedTest : UtModelTestCaseChecker(testClass = UseNetwork::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/models/CompositeModelMinimizationChecker.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/models/CompositeModelMinimizationChecker.kt index 271d950301..cb2556af49 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/models/CompositeModelMinimizationChecker.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/models/CompositeModelMinimizationChecker.kt @@ -1,6 +1,5 @@ package org.utbot.examples.models -import org.utbot.tests.infrastructure.UtModelTestCaseChecker import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.framework.plugin.api.FieldId import org.utbot.framework.plugin.api.UtAssembleModel @@ -9,7 +8,8 @@ import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtReferenceModel import org.junit.Test import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtModelTestCaseChecker internal class CompositeModelMinimizationChecker : UtModelTestCaseChecker( testClass = CompositeModelMinimizationExample::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/models/ModelsIdEqualityChecker.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/models/ModelsIdEqualityChecker.kt index eea119bcbc..8e50a4b48b 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/models/ModelsIdEqualityChecker.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/models/ModelsIdEqualityChecker.kt @@ -1,6 +1,5 @@ package org.utbot.examples.models -import org.utbot.tests.infrastructure.UtModelTestCaseChecker import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.framework.plugin.api.UtArrayModel import org.utbot.framework.plugin.api.UtAssembleModel @@ -9,7 +8,6 @@ import org.utbot.framework.plugin.api.UtExecutionSuccess import org.utbot.framework.plugin.api.UtReferenceModel import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation SAT-1332 internal class ModelsIdEqualityChecker : UtModelTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/natives/NativeExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/natives/NativeExamplesTest.kt index 5c3d4da5ab..4b7bd42a9e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/natives/NativeExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/natives/NativeExamplesTest.kt @@ -1,13 +1,10 @@ package org.utbot.examples.natives -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq import org.utbot.testcheckers.ge import org.utbot.testcheckers.withSolverTimeoutInMillis -import org.utbot.tests.infrastructure.CodeGeneration // TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 internal class NativeExamplesTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt index 6b7b74a045..efab9304b1 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt @@ -1,13 +1,8 @@ package org.utbot.examples.objects -import org.utbot.tests.infrastructure.Full -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.isException import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.Compilation -import org.utbot.tests.infrastructure.TestExecution class AnonymousClassesExampleTest : UtValueTestCaseChecker( testClass = AnonymousClassesExample::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ClassRefTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ClassRefTest.kt index 31297e978e..6382bc09c5 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ClassRefTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ClassRefTest.kt @@ -2,8 +2,6 @@ package org.utbot.examples.objects -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.atLeast import org.utbot.framework.plugin.api.CodegenLanguage import java.lang.Boolean import kotlin.Array @@ -11,7 +9,6 @@ import kotlin.Suppress import kotlin.arrayOf import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration internal class ClassRefTest : UtValueTestCaseChecker( testClass = ClassRef::class, 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..d081c8c0a3 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 @@ -1,14 +1,9 @@ package org.utbot.examples.objects -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -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.tests.infrastructure.CodeGeneration -import org.utbot.tests.infrastructure.Compilation // TODO Kotlin compilation SAT-1332 // Code generation executions fail due we cannot analyze strings properly for now diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/HiddenFieldAccessModifiersTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/HiddenFieldAccessModifiersTest.kt index 84820fb0d2..c9ef29e55e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/HiddenFieldAccessModifiersTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/HiddenFieldAccessModifiersTest.kt @@ -1,8 +1,8 @@ package org.utbot.examples.objects -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker internal class HiddenFieldAccessModifiersTest : UtValueTestCaseChecker(testClass = HiddenFieldAccessModifiersExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt index 8f8ebf7771..41d2edfbfb 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt @@ -1,7 +1,5 @@ package org.utbot.examples.objects -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ModelMinimizationExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ModelMinimizationExamplesTest.kt index 1752e2b7cd..80ab112c2b 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ModelMinimizationExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ModelMinimizationExamplesTest.kt @@ -1,7 +1,5 @@ package org.utbot.examples.objects -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.junit.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithFinalStaticTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithFinalStaticTest.kt index ec219a7022..4f2e04c94c 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithFinalStaticTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithFinalStaticTest.kt @@ -1,12 +1,8 @@ package org.utbot.examples.objects -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.singleValue import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration class ObjectWithFinalStaticTest : UtValueTestCaseChecker( testClass = ObjectWithFinalStatic::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesClassTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesClassTest.kt index ef9b11d1c5..aa568046f5 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesClassTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesClassTest.kt @@ -1,7 +1,5 @@ package org.utbot.examples.objects -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import kotlin.reflect.KFunction0 import kotlin.reflect.KFunction3 import org.junit.jupiter.api.Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt index e2eff5b8e8..bff483ad3f 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt @@ -1,10 +1,5 @@ package org.utbot.examples.objects -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.atLeast -import org.utbot.tests.infrastructure.ignoreExecutionsNumber -import org.utbot.tests.infrastructure.isException import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt index d85212e204..1d331f9d0d 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt @@ -1,10 +1,5 @@ package org.utbot.examples.objects -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.atLeast -import org.utbot.tests.infrastructure.ignoreExecutionsNumber -import org.utbot.tests.infrastructure.isException import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt index 6717bd4d3d..6af50704af 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt @@ -1,10 +1,5 @@ package org.utbot.examples.objects -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.findByName -import org.utbot.tests.infrastructure.ignoreExecutionsNumber -import org.utbot.tests.infrastructure.singleValue import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithThrowableConstructorTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithThrowableConstructorTest.kt index 45f999e00d..297bf4c932 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithThrowableConstructorTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithThrowableConstructorTest.kt @@ -1,11 +1,11 @@ package org.utbot.examples.objects -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import kotlin.reflect.KFunction2 import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class ObjectWithThrowableConstructorTest : UtValueTestCaseChecker(testClass = ObjectWithThrowableConstructor::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt index 08c26a5c40..985bc1ee4e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt @@ -1,9 +1,11 @@ package org.utbot.examples.objects -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.isException + + import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException internal class PrivateFieldsTest : UtValueTestCaseChecker(testClass = PrivateFields::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/RecursiveTypeTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/RecursiveTypeTest.kt index 44e7c9cee3..e1dc21ad88 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/RecursiveTypeTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/RecursiveTypeTest.kt @@ -1,9 +1,9 @@ package org.utbot.examples.objects -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.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class RecursiveTypeTest : UtValueTestCaseChecker(testClass = RecursiveType::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt index ed71ca4e24..67bad2c9f3 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt @@ -1,11 +1,5 @@ package org.utbot.examples.objects -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.tests.infrastructure.keyContain -import org.utbot.tests.infrastructure.keyMatch import org.utbot.framework.plugin.api.DocCodeStmt import org.utbot.framework.plugin.api.DocPreTagStatement import org.utbot.framework.plugin.api.DocRegularStmt diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassMultiInstanceExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassMultiInstanceExampleTest.kt index bb7ddc71af..d7d427cd5e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassMultiInstanceExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassMultiInstanceExampleTest.kt @@ -1,11 +1,10 @@ package org.utbot.examples.objects -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.junit.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.Compilation +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class SimpleClassMultiInstanceExampleTest : UtValueTestCaseChecker(testClass = SimpleClassMultiInstanceExample::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/ByteExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/ByteExamplesTest.kt index d418b38e89..4b709e11f5 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/ByteExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/ByteExamplesTest.kt @@ -1,8 +1,8 @@ package org.utbot.examples.primitives -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker internal class ByteExamplesTest : UtValueTestCaseChecker(testClass = ByteExamples::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/CharExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/CharExamplesTest.kt index d3621440be..c93b615eb9 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/CharExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/CharExamplesTest.kt @@ -1,9 +1,9 @@ package org.utbot.examples.primitives -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.isException import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException internal class CharExamplesTest : UtValueTestCaseChecker(testClass = CharExamples::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/DoubleExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/DoubleExamplesTest.kt index 4318c6ef2c..157d5be275 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/DoubleExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/DoubleExamplesTest.kt @@ -1,8 +1,8 @@ package org.utbot.examples.primitives -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker @Suppress("SimplifyNegatedBinaryExpression") internal class DoubleExamplesTest : UtValueTestCaseChecker(testClass = DoubleExamples::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/FloatExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/FloatExamplesTest.kt index 390714174a..87baa7a2a3 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/FloatExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/FloatExamplesTest.kt @@ -1,8 +1,8 @@ package org.utbot.examples.primitives -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker internal class FloatExamplesTest : UtValueTestCaseChecker(testClass = FloatExamples::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt index 07e0b463fc..ba51507276 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt @@ -2,7 +2,7 @@ package org.utbot.examples.primitives import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.UtValueTestCaseChecker + import org.utbot.testcheckers.eq @Suppress("ConvertTwoComparisonsToRangeCheck") diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt index ec2746f191..a5ee5eda7e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt @@ -1,11 +1,5 @@ package org.utbot.examples.recursion -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.atLeast -import org.utbot.tests.infrastructure.between -import org.utbot.tests.infrastructure.isException -import org.utbot.tests.infrastructure.keyContain -import org.utbot.tests.infrastructure.keyMatch import org.utbot.framework.plugin.api.DocCodeStmt import org.utbot.framework.plugin.api.DocPreTagStatement import org.utbot.framework.plugin.api.DocRegularStmt @@ -16,7 +10,6 @@ import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq import org.utbot.testcheckers.ge -import org.utbot.tests.infrastructure.CodeGeneration // TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 internal class RecursionTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/statics/substitution/StaticsSubstitutionTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/statics/substitution/StaticsSubstitutionTest.kt index 4b495cc750..0b97f4e0c7 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/statics/substitution/StaticsSubstitutionTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/statics/substitution/StaticsSubstitutionTest.kt @@ -1,7 +1,5 @@ package org.utbot.examples.statics.substitution -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.withoutSubstituteStaticsWithSymbolicVariable diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt index 1e04bb4799..ddbe69d720 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt @@ -3,8 +3,8 @@ package org.utbot.examples.stdlib import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.isException + + import org.utbot.testcheckers.eq import org.utbot.testcheckers.withUsingReflectionForMaximizingCoverage import java.util.Date 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 ff0407947e..b3bed63f70 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 @@ -3,18 +3,18 @@ package org.utbot.examples.stream import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.Full -import org.utbot.tests.infrastructure.FullWithAssumptions -import org.utbot.tests.infrastructure.StaticsType -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 import java.util.stream.Stream import kotlin.streams.toList 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 53216b306f..71062b8b82 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 @@ -6,7 +6,7 @@ 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 import kotlin.streams.toList 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 5aef3eb609..89a8b5d69e 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 @@ -6,7 +6,7 @@ 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 import java.util.stream.IntStream 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 0ac7785d6c..7cac365890 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 @@ -6,7 +6,7 @@ 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 import java.util.stream.LongStream diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt index 54706bb9bb..30fb1d0553 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt @@ -4,10 +4,10 @@ import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.framework.plugin.api.visible.UtStreamConsumingException import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration -import org.utbot.tests.infrastructure.FullWithAssumptions -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.isException + + + + import kotlin.streams.toList // TODO 1 instruction is always uncovered https://github.com/UnitTestBot/UTBotJava/issues/193 diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/strings/GenericExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/strings/GenericExamplesTest.kt index f08a69c94a..8548f82b13 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/strings/GenericExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/strings/GenericExamplesTest.kt @@ -1,8 +1,5 @@ package org.utbot.examples.strings -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.isException -import org.utbot.tests.infrastructure.CodeGeneration import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.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..f219660f44 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 @@ -1,12 +1,5 @@ package org.utbot.examples.strings -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.atLeast -import org.utbot.tests.infrastructure.between -import org.utbot.tests.infrastructure.ignoreExecutionsNumber -import org.utbot.tests.infrastructure.isException -import org.utbot.tests.infrastructure.keyMatch import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test @@ -15,7 +8,6 @@ import org.utbot.testcheckers.ge import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete import org.utbot.testcheckers.withSolverTimeoutInMillis import org.utbot.testcheckers.withoutMinimization -import org.utbot.tests.infrastructure.CodeGeneration internal class StringExamplesTest : UtValueTestCaseChecker( testClass = StringExamples::class, 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..090cbb2c7f 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 @@ -4,7 +4,6 @@ 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( testClass = StringConcat::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/HeapTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/HeapTest.kt index d28e3ecbe0..92f87808f8 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/HeapTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/HeapTest.kt @@ -1,7 +1,5 @@ package org.utbot.examples.structures -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.ignoreExecutionsNumber import org.junit.jupiter.api.Test internal class HeapTest : UtValueTestCaseChecker(testClass = Heap::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/MinStackExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/MinStackExampleTest.kt index 42a7a77913..53676ee1d1 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/MinStackExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/MinStackExampleTest.kt @@ -1,8 +1,5 @@ package org.utbot.examples.structures -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.between import kotlin.math.min import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt index 7287a964c6..5f2c35d34f 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt @@ -1,9 +1,5 @@ package org.utbot.examples.structures -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.keyContain -import org.utbot.tests.infrastructure.keyMatch import org.utbot.framework.plugin.api.DocCodeStmt import org.utbot.framework.plugin.api.DocPreTagStatement import org.utbot.framework.plugin.api.DocRegularStmt @@ -14,7 +10,6 @@ import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.tests.infrastructure.CodeGeneration internal class StandardStructuresTest : UtValueTestCaseChecker( testClass = StandardStructures::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/thirdparty/numbers/ArithmeticUtilsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/thirdparty/numbers/ArithmeticUtilsTest.kt index 54a24c8124..fc7658c50d 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/thirdparty/numbers/ArithmeticUtilsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/thirdparty/numbers/ArithmeticUtilsTest.kt @@ -1,9 +1,9 @@ package org.utbot.examples.thirdparty.numbers -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker // example from Apache common-numbers internal class ArithmeticUtilsTest : UtValueTestCaseChecker(testClass = ArithmeticUtils::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/types/CastExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/types/CastExamplesTest.kt index a30bcb4f39..1cc939a373 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/types/CastExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/types/CastExamplesTest.kt @@ -1,8 +1,8 @@ package org.utbot.examples.types -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker @Suppress("SimplifyNegatedBinaryExpression") internal class CastExamplesTest : UtValueTestCaseChecker(testClass = CastExamples::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/types/TypeBordersTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/types/TypeBordersTest.kt index a379e4518b..e1325710de 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/types/TypeBordersTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/types/TypeBordersTest.kt @@ -1,7 +1,5 @@ package org.utbot.examples.types -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.atLeast import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/types/TypeMatchesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/types/TypeMatchesTest.kt index 1b0735f765..4a3f8d3c76 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/types/TypeMatchesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/types/TypeMatchesTest.kt @@ -1,8 +1,8 @@ package org.utbot.examples.types -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker @Suppress("SimplifyNegatedBinaryExpression") internal class TypeMatchesTest : UtValueTestCaseChecker(testClass = TypeMatches::class) { 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..03d29c8eab 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 @@ -4,8 +4,8 @@ import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.testcheckers.eq import org.utbot.testcheckers.withoutSandbox -import org.utbot.tests.infrastructure.DoNotCalculate -import org.utbot.tests.infrastructure.UtValueTestCaseChecker +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class UnsafeOperationsTest : UtValueTestCaseChecker(testClass = UnsafeOperations::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/unsafe/UnsafeWithFieldTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/unsafe/UnsafeWithFieldTest.kt index 919c0da3cf..4b486a3d23 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/unsafe/UnsafeWithFieldTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/unsafe/UnsafeWithFieldTest.kt @@ -1,8 +1,8 @@ package org.utbot.examples.unsafe -import org.utbot.tests.infrastructure.UtValueTestCaseChecker import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker internal class UnsafeWithFieldTest: UtValueTestCaseChecker(UnsafeWithField::class) { 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..aa874a5f3e 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 @@ -1,7 +1,5 @@ package org.utbot.examples.wrappers -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq 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..51241e7880 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 @@ -1,7 +1,5 @@ package org.utbot.examples.wrappers -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/CharacterWrapperTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/CharacterWrapperTest.kt index 3d81e52688..bce33bb2f5 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/CharacterWrapperTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/CharacterWrapperTest.kt @@ -1,12 +1,9 @@ package org.utbot.examples.wrappers -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate 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.tests.infrastructure.CodeGeneration // TODO failed Kotlin compilation internal class CharacterWrapperTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/DoubleWrapperTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/DoubleWrapperTest.kt index 3c7cb5f2f1..049fba0fa5 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/DoubleWrapperTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/DoubleWrapperTest.kt @@ -1,7 +1,5 @@ package org.utbot.examples.wrappers -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/FloatWrapperTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/FloatWrapperTest.kt index 2265aa1bda..2142305a1d 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/FloatWrapperTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/FloatWrapperTest.kt @@ -1,7 +1,5 @@ package org.utbot.examples.wrappers -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/IntegerWrapperTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/IntegerWrapperTest.kt index 29231c1b1a..27c78191af 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/IntegerWrapperTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/IntegerWrapperTest.kt @@ -1,7 +1,5 @@ package org.utbot.examples.wrappers -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/LongWrapperTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/LongWrapperTest.kt index 990367c628..78ead57ad4 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/LongWrapperTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/LongWrapperTest.kt @@ -1,13 +1,10 @@ package org.utbot.examples.wrappers -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate 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.withoutMinimization -import org.utbot.tests.infrastructure.CodeGeneration internal class LongWrapperTest : UtValueTestCaseChecker( testClass = LongWrapper::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/ShortWrapperTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/ShortWrapperTest.kt index a8b179d805..9e8281ddfe 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/ShortWrapperTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/ShortWrapperTest.kt @@ -1,7 +1,5 @@ package org.utbot.examples.wrappers -import org.utbot.tests.infrastructure.UtValueTestCaseChecker -import org.utbot.tests.infrastructure.DoNotCalculate import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-summary-tests/build.gradle b/utbot-summary-tests/build.gradle index 94a163f68b..e9565f60b8 100644 --- a/utbot-summary-tests/build.gradle +++ b/utbot-summary-tests/build.gradle @@ -10,7 +10,7 @@ dependencies { implementation(project(':utbot-instrumentation')) testImplementation project(':utbot-sample') testImplementation group: 'junit', name: 'junit', version: junit4Version - testImplementation project(':utbot-framework-test').sourceSets.test.output + testImplementation project(':utbot-framework-test').sourceSets.main.output testImplementation project(':utbot-framework').sourceSets.test.output } diff --git a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt index f540ed242e..e991b3919f 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt @@ -11,7 +11,6 @@ import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.executableId import org.utbot.summary.comment.nextSynonyms import org.utbot.summary.summarize -import org.utbot.testing import kotlin.reflect.KClass import kotlin.reflect.KFunction diff --git a/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryArrayQuickSortExampleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryArrayQuickSortExampleTest.kt index 2187f50f4d..3f2e42789d 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryArrayQuickSortExampleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryArrayQuickSortExampleTest.kt @@ -4,7 +4,7 @@ import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test import org.utbot.examples.algorithms.ArraysQuickSort -import org.utbot.tests.infrastructure.DoNotCalculate + import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtClusterInfo diff --git a/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt index d52bc5a02f..33e22341ae 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt @@ -3,7 +3,7 @@ package examples.algorithms import examples.SummaryTestCaseGeneratorTest import org.utbot.examples.algorithms.ReturnExample import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.DoNotCalculate + import org.utbot.framework.plugin.api.MockStrategyApi class SummaryReturnExampleTest : SummaryTestCaseGeneratorTest( diff --git a/utbot-summary-tests/src/test/kotlin/examples/collections/SummaryListWrapperReturnsVoidTest.kt b/utbot-summary-tests/src/test/kotlin/examples/collections/SummaryListWrapperReturnsVoidTest.kt index 787c630847..b7cb654af2 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/collections/SummaryListWrapperReturnsVoidTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/collections/SummaryListWrapperReturnsVoidTest.kt @@ -2,7 +2,7 @@ package examples.collections import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.DoNotCalculate + import org.utbot.examples.collections.ListWrapperReturnsVoidExample import org.utbot.framework.plugin.api.MockStrategyApi diff --git a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryConditionsTest.kt b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryConditionsTest.kt index 239951a80c..39ef48f31a 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryConditionsTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryConditionsTest.kt @@ -4,7 +4,7 @@ import examples.CustomJavaDocTagsEnabler import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith -import org.utbot.tests.infrastructure.DoNotCalculate + import org.utbot.examples.controlflow.Conditions import org.utbot.framework.plugin.api.MockStrategyApi diff --git a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt index 1f37c2db2b..a62c2a02c1 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt @@ -2,7 +2,7 @@ package examples.controlflow import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.DoNotCalculate + import org.utbot.examples.controlflow.Cycles import org.utbot.framework.plugin.api.MockStrategyApi diff --git a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummarySwitchTest.kt b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummarySwitchTest.kt index 13d377a1d1..9e851c3c37 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummarySwitchTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummarySwitchTest.kt @@ -6,7 +6,6 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.utbot.examples.controlflow.Switch import org.utbot.framework.plugin.api.MockStrategyApi -import org.utbot.tests.infrastructure.DoNotCalculate @ExtendWith(CustomJavaDocTagsEnabler::class) class SummarySwitchTest : SummaryTestCaseGeneratorTest( diff --git a/utbot-summary-tests/src/test/kotlin/examples/enums/ComplexEnumExampleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/enums/ComplexEnumExampleTest.kt index 0c879dd7ee..51c802043c 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/enums/ComplexEnumExampleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/enums/ComplexEnumExampleTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.utbot.examples.enums.ComplexEnumExamples import org.utbot.framework.plugin.api.MockStrategyApi -import org.utbot.tests.infrastructure.DoNotCalculate + @ExtendWith(CustomJavaDocTagsEnabler::class) class ComplexEnumExampleTest : SummaryTestCaseGeneratorTest( diff --git a/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt b/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt index f2a7ede1ab..068fe807a4 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt @@ -4,7 +4,7 @@ import examples.CustomJavaDocTagsEnabler import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith -import org.utbot.tests.infrastructure.DoNotCalculate + import org.utbot.examples.exceptions.ExceptionClusteringExamples import org.utbot.framework.plugin.api.MockStrategyApi diff --git a/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionExampleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionExampleTest.kt index 5dfca3db48..e2fc49fcf6 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionExampleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionExampleTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.utbot.examples.exceptions.ExceptionExamples import org.utbot.framework.plugin.api.MockStrategyApi -import org.utbot.tests.infrastructure.DoNotCalculate + @ExtendWith(CustomJavaDocTagsEnabler::class) class SummaryExceptionExampleTest : SummaryTestCaseGeneratorTest( diff --git a/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt index d264d2c3f6..540c58dab8 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt @@ -2,7 +2,7 @@ package examples.inner import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.DoNotCalculate + import org.utbot.examples.inner.InnerCalls import org.utbot.framework.plugin.api.MockStrategyApi diff --git a/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt index 19e14e9b41..e4a1a2f4d0 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt @@ -2,7 +2,7 @@ package examples.inner import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.DoNotCalculate + import org.utbot.examples.inner.NestedCalls import org.utbot.framework.plugin.api.MockStrategyApi diff --git a/utbot-summary-tests/src/test/kotlin/examples/recursion/SummaryRecursionTest.kt b/utbot-summary-tests/src/test/kotlin/examples/recursion/SummaryRecursionTest.kt index 283d49141a..40e8a3c84e 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/recursion/SummaryRecursionTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/recursion/SummaryRecursionTest.kt @@ -6,7 +6,6 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.utbot.examples.recursion.Recursion import org.utbot.framework.plugin.api.MockStrategyApi -import org.utbot.tests.infrastructure.DoNotCalculate @ExtendWith(CustomJavaDocTagsEnabler::class) class SummaryRecursionTest : SummaryTestCaseGeneratorTest( diff --git a/utbot-summary-tests/src/test/kotlin/examples/structures/SummaryMinStackTest.kt b/utbot-summary-tests/src/test/kotlin/examples/structures/SummaryMinStackTest.kt index 0b8d9f35f5..ddec782eab 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/structures/SummaryMinStackTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/structures/SummaryMinStackTest.kt @@ -4,7 +4,7 @@ import examples.CustomJavaDocTagsEnabler import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith -import org.utbot.tests.infrastructure.DoNotCalculate + import org.utbot.examples.structures.MinStack import org.utbot.framework.plugin.api.MockStrategyApi diff --git a/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernaryTest.kt b/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernaryTest.kt index cf8c456096..2616cf889c 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernaryTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernaryTest.kt @@ -2,7 +2,7 @@ package examples.ternary import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.DoNotCalculate + import org.utbot.examples.ternary.Ternary import org.utbot.framework.plugin.api.MockStrategyApi diff --git a/utbot-summary-tests/src/test/kotlin/examples/unsafe/UnsafeWithFieldTest.kt b/utbot-summary-tests/src/test/kotlin/examples/unsafe/UnsafeWithFieldTest.kt index b085657a9a..a25faa41f6 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/unsafe/UnsafeWithFieldTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/unsafe/UnsafeWithFieldTest.kt @@ -6,7 +6,6 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.utbot.examples.unsafe.UnsafeWithField import org.utbot.framework.plugin.api.MockStrategyApi -import org.utbot.tests.infrastructure.DoNotCalculate @ExtendWith(CustomJavaDocTagsEnabler::class) class UnsafeWithFieldTest : SummaryTestCaseGeneratorTest( diff --git a/utbot-summary-tests/src/test/kotlin/math/SummaryIntMathTest.kt b/utbot-summary-tests/src/test/kotlin/math/SummaryIntMathTest.kt index 6eb31b4504..f167939a2d 100644 --- a/utbot-summary-tests/src/test/kotlin/math/SummaryIntMathTest.kt +++ b/utbot-summary-tests/src/test/kotlin/math/SummaryIntMathTest.kt @@ -3,7 +3,7 @@ package math import examples.SummaryTestCaseGeneratorTest import guava.examples.math.IntMath import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.DoNotCalculate + import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtClusterInfo diff --git a/utbot-summary-tests/src/test/kotlin/math/SummaryOfMathTest.kt b/utbot-summary-tests/src/test/kotlin/math/SummaryOfMathTest.kt index 50b84e1c05..6b61da7b09 100644 --- a/utbot-summary-tests/src/test/kotlin/math/SummaryOfMathTest.kt +++ b/utbot-summary-tests/src/test/kotlin/math/SummaryOfMathTest.kt @@ -4,7 +4,7 @@ import examples.SummaryTestCaseGeneratorTest import guava.examples.math.Stats import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test -import org.utbot.tests.infrastructure.DoNotCalculate + import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtClusterInfo From 1ac9fcd085099df37f3fbb53e5659094744913c1 Mon Sep 17 00:00:00 2001 From: Denis Fokin Date: Thu, 10 Nov 2022 10:56:30 +0300 Subject: [PATCH 06/12] Move testing utilities in a separate module --- utbot-analytics/build.gradle | 2 +- utbot-framework-test/build.gradle | 3 +- utbot-summary-tests/build.gradle | 2 +- .../examples/SummaryTestCaseGeneratorTest.kt | 3 +- .../SummaryArrayQuickSortExampleTest.kt | 1 + .../controlflow/SummaryConditionsTest.kt | 1 + .../examples/controlflow/SummarySwitchTest.kt | 1 + .../examples/enums/ComplexEnumExampleTest.kt | 1 + .../SummaryExceptionClusteringExamplesTest.kt | 1 + .../exceptions/SummaryExceptionExampleTest.kt | 1 + .../recursion/SummaryRecursionTest.kt | 1 + .../examples/unsafe/UnsafeWithFieldTest.kt | 1 + .../src/test/kotlin/math/SummaryOfMathTest.kt | 1 + utbot-summary/build.gradle.kts | 1 + utbot-testing/build.gradle | 88 + .../kotlin/org/utbot/testing/CheckersUtil.kt | 0 .../testing/CodeGenerationIntegrationTest.kt | 0 .../utbot/testing/CompilationAndRunUtils.kt | 0 .../testing/TestCodeGeneratorPipeline.kt | 0 .../testing/TestSpecificTestCaseGenerator.kt | 0 .../utbot/testing/UtModelTestCaseChecker.kt | 0 .../utbot/testing/UtValueTestCaseChecker.kt | 0 .../main/kotlin/org/utbot/testing/Utils.kt | 0 .../examples/manual/UtBotJavaApiTest.java | 1359 +++++++++++++++ .../org/utbot/bytecode/versions/SootTest.kt | 69 + .../utbot/engine/pc/QueryOptimizationsTest.kt | 642 +++++++ .../org/utbot/engine/z3/ExtensionsKtTest.kt | 396 +++++ .../org/utbot/engine/z3/OperatorsKtTest.kt | 76 + .../examples/algorithms/BinarySearchTest.kt | 97 ++ .../algorithms/CorrectBracketSequencesTest.kt | 145 ++ .../utbot/examples/algorithms/GraphTest.kt | 50 + .../org/utbot/examples/algorithms/SortTest.kt | 183 ++ .../annotations/NotNullAnnotationTest.kt | 101 ++ .../lombok/EnumWithAnnotationsTest.kt | 25 + .../lombok/EnumWithoutAnnotationsTest.kt | 16 + .../lombok/NotNullAnnotationsTest.kt | 25 + .../examples/arrays/ArrayOfArraysTest.kt | 283 ++++ .../examples/arrays/ArrayOfObjectsTest.kt | 111 ++ .../arrays/ArrayStoreExceptionExamplesTest.kt | 210 +++ .../arrays/ArraysOverwriteValueTest.kt | 153 ++ .../arrays/FinalStaticFieldArrayTest.kt | 21 + .../examples/arrays/IntArrayBasicsTest.kt | 228 +++ .../examples/arrays/PrimitiveArraysTest.kt | 186 ++ .../examples/casts/ArrayCastExampleTest.kt | 172 ++ .../org/utbot/examples/casts/CastClassTest.kt | 26 + .../utbot/examples/casts/CastExampleTest.kt | 89 + .../examples/casts/GenericCastExampleTest.kt | 77 + .../examples/casts/InstanceOfExampleTest.kt | 406 +++++ .../ClassWithStaticAndInnerClassesTest.kt | 129 ++ .../examples/codegen/CodegenExampleTest.kt | 56 + .../codegen/FileWithTopLevelFunctionsTest.kt | 43 + .../utbot/examples/codegen/JavaAssertTest.kt | 21 + .../examples/codegen/VoidStaticMethodsTest.kt | 36 + ...ClassWithCrossReferenceRelationshipTest.kt | 26 + .../deepequals/ClassWithNullableFieldTest.kt | 32 + .../codegen/deepequals/DeepEqualsTest.kt | 164 ++ ...ithPrivateMutableFieldOfPrivateTypeTest.kt | 41 + .../collections/CustomerExamplesTest.kt | 76 + .../collections/GenericListsExampleTest.kt | 160 ++ .../examples/collections/LinkedListsTest.kt | 261 +++ .../collections/ListAlgorithmsTest.kt | 32 + .../examples/collections/ListIteratorsTest.kt | 108 ++ .../collections/ListWrapperReturnsVoidTest.kt | 43 + .../examples/collections/ListsPart1Test.kt | 30 + .../examples/collections/ListsPart2Test.kt | 27 + .../examples/collections/ListsPart3Test.kt | 246 +++ .../examples/collections/MapEntrySetTest.kt | 172 ++ .../examples/collections/MapKeySetTest.kt | 161 ++ .../examples/collections/MapValuesTest.kt | 179 ++ .../examples/collections/MapsPart1Test.kt | 382 +++++ .../examples/collections/MapsPart2Test.kt | 87 + .../examples/collections/OptionalsTest.kt | 489 ++++++ .../examples/collections/QueueUsagesTest.kt | 127 ++ .../examples/collections/SetIteratorsTest.kt | 98 ++ .../utbot/examples/collections/SetsTest.kt | 239 +++ .../examples/controlflow/ConditionsTest.kt | 55 + .../controlflow/CycleDependedConditionTest.kt | 117 ++ .../utbot/examples/controlflow/CyclesTest.kt | 216 +++ .../utbot/examples/controlflow/SwitchTest.kt | 88 + .../utbot/examples/enums/ClassWithEnumTest.kt | 194 +++ .../examples/enums/ComplexEnumExamplesTest.kt | 106 ++ .../exceptions/ExceptionClusteringChecker.kt | 57 + .../exceptions/ExceptionExamplesTest.kt | 135 ++ .../exceptions/JvmCrashExamplesTest.kt | 41 + .../examples/invokes/InvokeExampleTest.kt | 212 +++ .../examples/invokes/NativeExampleTest.kt | 52 + .../invokes/SimpleInterfaceExampleTest.kt | 40 + .../invokes/StaticInvokeExampleTest.kt | 22 + .../invokes/VirtualInvokeExampleTest.kt | 145 ++ .../lambda/CustomPredicateExampleTest.kt | 77 + .../lambda/PredicateNotExampleTest.kt | 19 + .../lambda/SimpleLambdaExamplesTest.kt | 35 + .../ClassWithComplicatedMethodsTest.kt | 95 ++ .../utbot/examples/math/BitOperatorsTest.kt | 175 ++ .../utbot/examples/math/DivRemExamplesTest.kt | 78 + .../examples/math/DoubleFunctionsTest.kt | 61 + .../examples/math/OverflowAsErrorTest.kt | 282 ++++ .../utbot/examples/mixed/LoggerExampleTest.kt | 58 + .../utbot/examples/mixed/MonitorUsageTest.kt | 19 + .../org/utbot/examples/mixed/OverloadTest.kt | 29 + .../mixed/PrivateConstructorExampleTest.kt | 39 + .../examples/mixed/SimpleNoConditionTest.kt | 32 + .../utbot/examples/mixed/SimplifierTest.kt | 20 + .../mixed/StaticInitializerExampleTest.kt | 31 + .../mixed/StaticMethodExamplesTest.kt | 42 + .../utbot/examples/mock/ArgumentsMockTest.kt | 363 ++++ .../examples/mock/CommonMocksExampleTest.kt | 59 + .../org/utbot/examples/mock/FieldMockTest.kt | 290 ++++ .../mock/InnerMockWithFieldChecker.kt | 52 + .../utbot/examples/mock/MockFinalClassTest.kt | 34 + .../org/utbot/examples/mock/MockRandomTest.kt | 146 ++ .../mock/MockReturnObjectExampleTest.kt | 69 + .../mock/MockStaticFieldExampleTest.kt | 71 + .../mock/MockStaticMethodExampleTest.kt | 46 + .../examples/mock/MockWithFieldChecker.kt | 47 + .../mock/MockWithSideEffectExampleTest.kt | 66 + .../examples/mock/StaticFieldMockTest.kt | 277 +++ .../org/utbot/examples/mock/UseNetworkTest.kt | 57 + .../aliasing/AliasingInParamsExampleTest.kt | 31 + .../examples/mock/model/FieldMockChecker.kt | 38 + .../mock/model/UseNetworkModelBasedTest.kt | 28 + .../CompositeModelMinimizationChecker.kt | 78 + .../models/ModelsIdEqualityChecker.kt | 143 ++ .../examples/natives/NativeExamplesTest.kt | 39 + .../objects/AnonymousClassesExampleTest.kt | 57 + .../utbot/examples/objects/ClassRefTest.kt | 137 ++ .../examples/objects/ClassWithClassRefTest.kt | 32 + .../objects/HiddenFieldAccessModifiersTest.kt | 20 + .../objects/HiddenFieldExampleTest.kt | 34 + .../objects/ModelMinimizationExamplesTest.kt | 131 ++ .../objects/ObjectWithFinalStaticTest.kt | 26 + .../objects/ObjectWithPrimitivesClassTest.kt | 34 + .../ObjectWithPrimitivesExampleTest.kt | 266 +++ .../objects/ObjectWithRefFieldsExampleTest.kt | 154 ++ .../ObjectWithStaticFieldsExampleTest.kt | 186 ++ .../ObjectWithThrowableConstructorTest.kt | 22 + .../examples/objects/PrivateFieldsTest.kt | 21 + .../examples/objects/RecursiveTypeTest.kt | 36 + .../objects/SimpleClassExampleTest.kt | 100 ++ .../SimpleClassMultiInstanceExampleTest.kt | 22 + .../examples/primitives/ByteExamplesTest.kt | 39 + .../examples/primitives/CharExamplesTest.kt | 52 + .../examples/primitives/DoubleExamplesTest.kt | 161 ++ .../examples/primitives/FloatExamplesTest.kt | 18 + .../examples/primitives/IntExamplesTest.kt | 119 ++ .../utbot/examples/recursion/RecursionTest.kt | 138 ++ .../substitution/StaticsSubstitutionTest.kt | 30 + .../utbot/examples/stdlib/DateExampleTest.kt | 67 + .../examples/stream/BaseStreamExampleTest.kt | 462 +++++ .../stream/DoubleStreamExampleTest.kt | 534 ++++++ .../examples/stream/IntStreamExampleTest.kt | 565 +++++++ .../examples/stream/LongStreamExampleTest.kt | 559 ++++++ .../StreamsAsMethodResultExampleTest.kt | 69 + .../examples/strings/GenericExamplesTest.kt | 35 + .../examples/strings/StringExamplesTest.kt | 667 ++++++++ .../examples/strings11/StringConcatTest.kt | 113 ++ .../org/utbot/examples/structures/HeapTest.kt | 20 + .../structures/MinStackExampleTest.kt | 103 ++ .../structures/StandardStructuresTest.kt | 100 ++ .../thirdparty/numbers/ArithmeticUtilsTest.kt | 46 + .../utbot/examples/types/CastExamplesTest.kt | 77 + .../utbot/examples/types/TypeBordersTest.kt | 76 + .../utbot/examples/types/TypeMatchesTest.kt | 60 + .../examples/unsafe/UnsafeOperationsTest.kt | 39 + .../examples/unsafe/UnsafeWithFieldTest.kt | 18 + .../examples/wrappers/BooleanWrapperTest.kt | 40 + .../examples/wrappers/ByteWrapperTest.kt | 40 + .../examples/wrappers/CharacterWrapperTest.kt | 50 + .../examples/wrappers/DoubleWrapperTest.kt | 30 + .../examples/wrappers/FloatWrapperTest.kt | 30 + .../examples/wrappers/IntegerWrapperTest.kt | 70 + .../examples/wrappers/LongWrapperTest.kt | 69 + .../examples/wrappers/ShortWrapperTest.kt | 43 + .../kotlin/org/utbot/framework/JUnitSetup.kt | 38 + .../assemble/AssembleModelGeneratorTests.kt | 1503 +++++++++++++++++ .../constructors/BaseConstructorTest.kt | 34 + .../constructors/ListConstructorTest.kt | 38 + .../constructors/MapConstructorTest.kt | 36 + .../constructors/OptionalConstructorTest.kt | 65 + .../constructors/SetConstructorTest.kt | 36 + .../MinimizationGreedyEssentialTest.kt | 71 + .../UtBotFieldModificatorsTest.kt | 324 ++++ .../plugin/api/MockStrategyApiTest.kt | 48 + .../z3/extension/Z3ExtensionForTests.kt | 60 + .../framework/z3/extension/Z3ExtensionTest.kt | 155 ++ .../kotlin/org/utbot/sarif/SarifReportTest.kt | 351 ++++ .../test/resources/junit-platform.properties | 1 + utbot-testing/src/test/resources/log4j2.xml | 36 + .../org.mockito.plugins.MockMaker | 1 + .../org.junit.jupiter.api.extension.Extension | 1 + 190 files changed, 21836 insertions(+), 4 deletions(-) create mode 100644 utbot-testing/build.gradle rename {utbot-framework-test => utbot-testing}/src/main/kotlin/org/utbot/testing/CheckersUtil.kt (100%) rename {utbot-framework-test => utbot-testing}/src/main/kotlin/org/utbot/testing/CodeGenerationIntegrationTest.kt (100%) rename {utbot-framework-test => utbot-testing}/src/main/kotlin/org/utbot/testing/CompilationAndRunUtils.kt (100%) rename {utbot-framework-test => utbot-testing}/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt (100%) rename {utbot-framework-test => utbot-testing}/src/main/kotlin/org/utbot/testing/TestSpecificTestCaseGenerator.kt (100%) rename {utbot-framework-test => utbot-testing}/src/main/kotlin/org/utbot/testing/UtModelTestCaseChecker.kt (100%) rename {utbot-framework-test => utbot-testing}/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt (100%) rename {utbot-framework-test => utbot-testing}/src/main/kotlin/org/utbot/testing/Utils.kt (100%) create mode 100644 utbot-testing/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java create mode 100644 utbot-testing/src/test/kotlin/org/utbot/bytecode/versions/SootTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/engine/pc/QueryOptimizationsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/engine/z3/ExtensionsKtTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/engine/z3/OperatorsKtTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/BinarySearchTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/GraphTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/annotations/NotNullAnnotationTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithAnnotationsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithoutAnnotationsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/NotNullAnnotationsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayOfArraysTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayStoreExceptionExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArraysOverwriteValueTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/arrays/FinalStaticFieldArrayTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/arrays/IntArrayBasicsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/arrays/PrimitiveArraysTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/casts/ArrayCastExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/casts/CastClassTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/casts/CastExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/casts/GenericCastExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/casts/InstanceOfExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/ClassWithStaticAndInnerClassesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/CodegenExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/FileWithTopLevelFunctionsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/VoidStaticMethodsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithCrossReferenceRelationshipTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithNullableFieldTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/DeepEqualsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/GenericListsExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/LinkedListsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListAlgorithmsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListIteratorsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListWrapperReturnsVoidTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart1Test.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart2Test.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart3Test.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapEntrySetTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapKeySetTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapValuesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapsPart1Test.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapsPart2Test.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/QueueUsagesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/SetIteratorsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/SetsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/ConditionsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/CycleDependedConditionTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/SwitchTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/enums/ClassWithEnumTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/enums/ComplexEnumExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/ExceptionClusteringChecker.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/ExceptionExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/JvmCrashExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/invokes/InvokeExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/invokes/NativeExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/invokes/SimpleInterfaceExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/invokes/StaticInvokeExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/invokes/VirtualInvokeExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/lambda/CustomPredicateExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/lambda/PredicateNotExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/make/symbolic/ClassWithComplicatedMethodsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/math/BitOperatorsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/math/DivRemExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/math/DoubleFunctionsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mixed/LoggerExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mixed/MonitorUsageTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mixed/OverloadTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mixed/SimpleNoConditionTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mixed/SimplifierTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mixed/StaticInitializerExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/InnerMockWithFieldChecker.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockFinalClassTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockReturnObjectExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockStaticFieldExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockWithFieldChecker.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockWithSideEffectExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/UseNetworkTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/aliasing/AliasingInParamsExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/model/UseNetworkModelBasedTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/models/CompositeModelMinimizationChecker.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/models/ModelsIdEqualityChecker.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/natives/NativeExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ClassRefTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ClassWithClassRefTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/HiddenFieldAccessModifiersTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ModelMinimizationExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithFinalStaticTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesClassTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithThrowableConstructorTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/RecursiveTypeTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/SimpleClassMultiInstanceExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/primitives/ByteExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/primitives/CharExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/primitives/DoubleExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/primitives/FloatExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/statics/substitution/StaticsSubstitutionTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/stream/DoubleStreamExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/stream/IntStreamExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/stream/LongStreamExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/strings/GenericExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/strings/StringExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/strings11/StringConcatTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/structures/HeapTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/structures/MinStackExampleTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/thirdparty/numbers/ArithmeticUtilsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/types/CastExamplesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/types/TypeBordersTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/types/TypeMatchesTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/unsafe/UnsafeWithFieldTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/BooleanWrapperTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/ByteWrapperTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/CharacterWrapperTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/DoubleWrapperTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/FloatWrapperTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/IntegerWrapperTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/LongWrapperTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/ShortWrapperTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/JUnitSetup.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/BaseConstructorTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/ListConstructorTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/MapConstructorTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/OptionalConstructorTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/SetConstructorTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/minimization/MinimizationGreedyEssentialTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/plugin/api/MockStrategyApiTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/z3/extension/Z3ExtensionForTests.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/z3/extension/Z3ExtensionTest.kt create mode 100644 utbot-testing/src/test/kotlin/org/utbot/sarif/SarifReportTest.kt create mode 100644 utbot-testing/src/test/resources/junit-platform.properties create mode 100644 utbot-testing/src/test/resources/log4j2.xml create mode 100644 utbot-testing/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker create mode 100644 utbot-testing/src/test/resources/services/org.junit.jupiter.api.extension.Extension diff --git a/utbot-analytics/build.gradle b/utbot-analytics/build.gradle index 5cf17fd4da..a72b3b8b74 100644 --- a/utbot-analytics/build.gradle +++ b/utbot-analytics/build.gradle @@ -33,7 +33,7 @@ dependencies { implementation group: 'org.apache.commons', name: 'commons-text', version: '1.9' implementation group: 'com.github.javaparser', name: 'javaparser-core', version: '3.22.1' - testImplementation project(':utbot-framework-test').sourceSets.main.output + testImplementation project(':utbot-testing') testImplementation project(':utbot-framework').sourceSets.test.output } diff --git a/utbot-framework-test/build.gradle b/utbot-framework-test/build.gradle index 4352a518b2..00590c6dde 100644 --- a/utbot-framework-test/build.gradle +++ b/utbot-framework-test/build.gradle @@ -1,6 +1,6 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { kotlinOptions { - jvmTarget = JavaVersion.VERSION_1_8 + jvmTarget = JavaVersion.VERSION_11 freeCompilerArgs += ["-Xallow-result-return-type", "-Xsam-conversions=class"] } } @@ -22,6 +22,7 @@ configurations { dependencies { api project(':utbot-framework-api') + testImplementation project(':utbot-testing') api project(':utbot-fuzzers') api project(':utbot-instrumentation') diff --git a/utbot-summary-tests/build.gradle b/utbot-summary-tests/build.gradle index e9565f60b8..5be71747e1 100644 --- a/utbot-summary-tests/build.gradle +++ b/utbot-summary-tests/build.gradle @@ -10,7 +10,7 @@ dependencies { implementation(project(':utbot-instrumentation')) testImplementation project(':utbot-sample') testImplementation group: 'junit', name: 'junit', version: junit4Version - testImplementation project(':utbot-framework-test').sourceSets.main.output + testImplementation project(':utbot-testing') testImplementation project(':utbot-framework').sourceSets.test.output } diff --git a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt index e991b3919f..f6799edf6a 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt @@ -13,7 +13,8 @@ import org.utbot.summary.comment.nextSynonyms import org.utbot.summary.summarize import kotlin.reflect.KClass import kotlin.reflect.KFunction - +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.TestLastStage private const val NEW_LINE = "\n" private const val POINT_IN_THE_LIST = " * " diff --git a/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryArrayQuickSortExampleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryArrayQuickSortExampleTest.kt index 3f2e42789d..4a235f7680 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryArrayQuickSortExampleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryArrayQuickSortExampleTest.kt @@ -7,6 +7,7 @@ import org.utbot.examples.algorithms.ArraysQuickSort import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtClusterInfo +import org.utbot.testing.DoNotCalculate @Tag("slow") class SummaryArrayQuickSortExampleTest : SummaryTestCaseGeneratorTest( diff --git a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryConditionsTest.kt b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryConditionsTest.kt index 39ef48f31a..ab0c150599 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryConditionsTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryConditionsTest.kt @@ -4,6 +4,7 @@ import examples.CustomJavaDocTagsEnabler import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import org.utbot.testing.DoNotCalculate import org.utbot.examples.controlflow.Conditions import org.utbot.framework.plugin.api.MockStrategyApi diff --git a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummarySwitchTest.kt b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummarySwitchTest.kt index 9e851c3c37..52fce1f26a 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummarySwitchTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummarySwitchTest.kt @@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.utbot.examples.controlflow.Switch import org.utbot.framework.plugin.api.MockStrategyApi +import org.utbot.testing.DoNotCalculate @ExtendWith(CustomJavaDocTagsEnabler::class) class SummarySwitchTest : SummaryTestCaseGeneratorTest( diff --git a/utbot-summary-tests/src/test/kotlin/examples/enums/ComplexEnumExampleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/enums/ComplexEnumExampleTest.kt index 51c802043c..a7730d6f97 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/enums/ComplexEnumExampleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/enums/ComplexEnumExampleTest.kt @@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.utbot.examples.enums.ComplexEnumExamples import org.utbot.framework.plugin.api.MockStrategyApi +import org.utbot.testing.DoNotCalculate @ExtendWith(CustomJavaDocTagsEnabler::class) diff --git a/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt b/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt index 068fe807a4..ed045c9c6e 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt @@ -4,6 +4,7 @@ import examples.CustomJavaDocTagsEnabler import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import org.utbot.testing.DoNotCalculate import org.utbot.examples.exceptions.ExceptionClusteringExamples import org.utbot.framework.plugin.api.MockStrategyApi diff --git a/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionExampleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionExampleTest.kt index e2fc49fcf6..77293a24c7 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionExampleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionExampleTest.kt @@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.utbot.examples.exceptions.ExceptionExamples import org.utbot.framework.plugin.api.MockStrategyApi +import org.utbot.testing.DoNotCalculate @ExtendWith(CustomJavaDocTagsEnabler::class) diff --git a/utbot-summary-tests/src/test/kotlin/examples/recursion/SummaryRecursionTest.kt b/utbot-summary-tests/src/test/kotlin/examples/recursion/SummaryRecursionTest.kt index 40e8a3c84e..1eb049c229 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/recursion/SummaryRecursionTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/recursion/SummaryRecursionTest.kt @@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.utbot.examples.recursion.Recursion import org.utbot.framework.plugin.api.MockStrategyApi +import org.utbot.testing.DoNotCalculate @ExtendWith(CustomJavaDocTagsEnabler::class) class SummaryRecursionTest : SummaryTestCaseGeneratorTest( diff --git a/utbot-summary-tests/src/test/kotlin/examples/unsafe/UnsafeWithFieldTest.kt b/utbot-summary-tests/src/test/kotlin/examples/unsafe/UnsafeWithFieldTest.kt index a25faa41f6..ad0c12c0ff 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/unsafe/UnsafeWithFieldTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/unsafe/UnsafeWithFieldTest.kt @@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.utbot.examples.unsafe.UnsafeWithField import org.utbot.framework.plugin.api.MockStrategyApi +import org.utbot.testing.DoNotCalculate @ExtendWith(CustomJavaDocTagsEnabler::class) class UnsafeWithFieldTest : SummaryTestCaseGeneratorTest( diff --git a/utbot-summary-tests/src/test/kotlin/math/SummaryOfMathTest.kt b/utbot-summary-tests/src/test/kotlin/math/SummaryOfMathTest.kt index 6b61da7b09..c4f0eccc08 100644 --- a/utbot-summary-tests/src/test/kotlin/math/SummaryOfMathTest.kt +++ b/utbot-summary-tests/src/test/kotlin/math/SummaryOfMathTest.kt @@ -7,6 +7,7 @@ import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtClusterInfo +import org.utbot.testing.DoNotCalculate /** * It runs test generation for the poor analogue of the Stats.of method ported from the guava-26.0 framework diff --git a/utbot-summary/build.gradle.kts b/utbot-summary/build.gradle.kts index e087927bbb..736c4e7fb8 100644 --- a/utbot-summary/build.gradle.kts +++ b/utbot-summary/build.gradle.kts @@ -17,4 +17,5 @@ dependencies { implementation("com.github.javaparser:javaparser-core:3.22.1") testImplementation("org.mockito:mockito-core:4.2.0") testImplementation("org.junit.jupiter:junit-jupiter:$junit5Version") + testImplementation(project(":utbot-testing")) } diff --git a/utbot-testing/build.gradle b/utbot-testing/build.gradle new file mode 100644 index 0000000000..dbc4955144 --- /dev/null +++ b/utbot-testing/build.gradle @@ -0,0 +1,88 @@ +tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8 + freeCompilerArgs += ["-Xallow-result-return-type", "-Xsam-conversions=class"] + } +} + +tasks.withType(JavaCompile) { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +repositories { + flatDir { + dirs 'dist' + } +} + +configurations { + z3native +} + +dependencies { + api project(':utbot-framework-api') + + api project(':utbot-fuzzers') + api project(':utbot-instrumentation') + api project(':utbot-summary') + + implementation(project(":utbot-framework")) + testImplementation project(':utbot-sample') + testImplementation project(":utbot-framework").sourceSets.test.output + testImplementation project(":utbot-core").sourceSets.test.output + + implementation("org.unittestbot.soot:soot-utbot-fork:${sootVersion}") { + exclude group:'com.google.guava', module:'guava' + } + + implementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-kotlin', version: jacksonVersion + implementation group: 'org.sosy-lab', name: 'javasmt-solver-z3', version: javasmtSolverZ3Version + implementation group: 'com.github.curious-odd-man', name: 'rgxgen', version: rgxgenVersion + implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: log4j2Version + implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlinLoggingVersion + implementation group: 'org.jacoco', name: 'org.jacoco.report', version: jacocoVersion + implementation group: 'org.apache.commons', name: 'commons-text', version: apacheCommonsTextVersion + // we need this for construction mocks from composite models + implementation group: 'org.mockito', name: 'mockito-core', version: '4.2.0' + + // To use JUnit4, comment out JUnit5 and uncomment JUnit4 dependencies here. Please also check "test" section + // testImplementation group: 'junit', name: 'junit', version: '4.13.1' + implementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.8.1' + implementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.1' + + // used for testing code generation + testImplementation group: 'commons-io', name: 'commons-io', version: commonsIoVersion + testImplementation group: 'junit', name: 'junit', version: junit4Version + testImplementation group: 'org.junit.platform', name: 'junit-platform-console-standalone', version: junit4PlatformVersion + testImplementation group: 'org.antlr', name: 'antlr4', version: antlrVersion + testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion + testImplementation group: 'org.testng', name: 'testng', version: testNgVersion + testImplementation group: 'org.mockito', name: 'mockito-inline', version: mockitoInlineVersion + testImplementation group: 'com.google.guava', name: 'guava', version: guavaVersion + + testImplementation group: 'org.mockito', name: 'mockito-inline', version: mockitoInlineVersion + testImplementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: log4j2Version + + z3native group: 'com.microsoft.z3', name: 'z3-native-win64', version: z3Version, ext: 'zip' + z3native group: 'com.microsoft.z3', name: 'z3-native-linux64', version: z3Version, ext: 'zip' + z3native group: 'com.microsoft.z3', name: 'z3-native-osx', version: z3Version, ext: 'zip' +} + + +test { + + minHeapSize = "128m" + maxHeapSize = "2048m" + + jvmArgs '-XX:MaxHeapSize=2048m' + + // To use JUnit4, comment out useJUnitPlatform and uncomment useJUnit. Please also check "dependencies" section + //useJUnit() + useJUnitPlatform() { + excludeTags 'slow', 'IntegrationTest' + } + if (System.getProperty('DEBUG', 'false') == 'true') { + jvmArgs '-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9009' + } +} diff --git a/utbot-framework-test/src/main/kotlin/org/utbot/testing/CheckersUtil.kt b/utbot-testing/src/main/kotlin/org/utbot/testing/CheckersUtil.kt similarity index 100% rename from utbot-framework-test/src/main/kotlin/org/utbot/testing/CheckersUtil.kt rename to utbot-testing/src/main/kotlin/org/utbot/testing/CheckersUtil.kt diff --git a/utbot-framework-test/src/main/kotlin/org/utbot/testing/CodeGenerationIntegrationTest.kt b/utbot-testing/src/main/kotlin/org/utbot/testing/CodeGenerationIntegrationTest.kt similarity index 100% rename from utbot-framework-test/src/main/kotlin/org/utbot/testing/CodeGenerationIntegrationTest.kt rename to utbot-testing/src/main/kotlin/org/utbot/testing/CodeGenerationIntegrationTest.kt diff --git a/utbot-framework-test/src/main/kotlin/org/utbot/testing/CompilationAndRunUtils.kt b/utbot-testing/src/main/kotlin/org/utbot/testing/CompilationAndRunUtils.kt similarity index 100% rename from utbot-framework-test/src/main/kotlin/org/utbot/testing/CompilationAndRunUtils.kt rename to utbot-testing/src/main/kotlin/org/utbot/testing/CompilationAndRunUtils.kt diff --git a/utbot-framework-test/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt b/utbot-testing/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt similarity index 100% rename from utbot-framework-test/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt rename to utbot-testing/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt diff --git a/utbot-framework-test/src/main/kotlin/org/utbot/testing/TestSpecificTestCaseGenerator.kt b/utbot-testing/src/main/kotlin/org/utbot/testing/TestSpecificTestCaseGenerator.kt similarity index 100% rename from utbot-framework-test/src/main/kotlin/org/utbot/testing/TestSpecificTestCaseGenerator.kt rename to utbot-testing/src/main/kotlin/org/utbot/testing/TestSpecificTestCaseGenerator.kt diff --git a/utbot-framework-test/src/main/kotlin/org/utbot/testing/UtModelTestCaseChecker.kt b/utbot-testing/src/main/kotlin/org/utbot/testing/UtModelTestCaseChecker.kt similarity index 100% rename from utbot-framework-test/src/main/kotlin/org/utbot/testing/UtModelTestCaseChecker.kt rename to utbot-testing/src/main/kotlin/org/utbot/testing/UtModelTestCaseChecker.kt diff --git a/utbot-framework-test/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt b/utbot-testing/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt similarity index 100% rename from utbot-framework-test/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt rename to utbot-testing/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt diff --git a/utbot-framework-test/src/main/kotlin/org/utbot/testing/Utils.kt b/utbot-testing/src/main/kotlin/org/utbot/testing/Utils.kt similarity index 100% rename from utbot-framework-test/src/main/kotlin/org/utbot/testing/Utils.kt rename to utbot-testing/src/main/kotlin/org/utbot/testing/Utils.kt diff --git a/utbot-testing/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java b/utbot-testing/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java new file mode 100644 index 0000000000..b04512aafc --- /dev/null +++ b/utbot-testing/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java @@ -0,0 +1,1359 @@ +package org.utbot.examples.manual; + +import kotlin.Pair; +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.utbot.common.PathUtil; +import org.utbot.examples.assemble.DirectAccess; +import org.utbot.examples.assemble.PrimitiveFields; +import org.utbot.examples.assemble.ArrayOfComplexArrays; +import org.utbot.examples.assemble.ArrayOfPrimitiveArrays; +import org.utbot.examples.assemble.AssignedArray; +import org.utbot.examples.assemble.ComplexArray; +import org.utbot.examples.manual.examples.*; +import org.utbot.examples.manual.examples.customer.B; +import org.utbot.examples.manual.examples.customer.C; +import org.utbot.examples.manual.examples.customer.Demo9; +import org.utbot.external.api.TestMethodInfo; +import org.utbot.external.api.UtBotJavaApi; +import org.utbot.external.api.UtModelFactory; +import org.utbot.framework.codegen.ForceStaticMocking; +import org.utbot.framework.codegen.Junit4; +import org.utbot.framework.codegen.MockitoStaticMocking; +import org.utbot.framework.plugin.api.*; +import org.utbot.framework.plugin.api.util.UtContext; +import org.utbot.framework.plugin.services.JdkInfoDefaultProvider; +import org.utbot.framework.util.Snippet; +import org.utbot.framework.util.SootUtils; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.framework.plugin.api.MockFramework.MOCKITO; +import static org.utbot.framework.plugin.api.util.IdUtilKt.getIntArrayClassId; +import static org.utbot.framework.util.TestUtilsKt.compileClassAndGetClassPath; +import static org.utbot.framework.util.TestUtilsKt.compileClassFile; + +class PredefinedGeneratorParameters { + + static String destinationClassName = "GeneratedTest"; + + static Method getMethodByName(Class clazz, String name, Class... parameters) { + try { + return clazz.getDeclaredMethod(name, parameters); + } catch (NoSuchMethodException ignored) { + Assertions.fail(); + } + throw new RuntimeException(); + } +} + +public class UtBotJavaApiTest { + private AutoCloseable context; + private UtModelFactory modelFactory; + + @BeforeEach + public void setUp() { + context = UtContext.Companion.setUtContext(new UtContext(PrimitiveFields.class.getClassLoader())); + modelFactory = new UtModelFactory(); + } + + @AfterEach + public void tearDown() { + try { + context.close(); + modelFactory = null; + } catch (Exception e) { + Assertions.fail(); + } + } + + @Test + public void testMultiMethodClass() { + + UtBotJavaApi.setStopConcreteExecutorOnExit(false); + + String classpath = getClassPath(MultiMethodExample.class); + String dependencyClassPath = getDependencyClassPath(); + + UtCompositeModel classUnderTestModel = modelFactory.produceCompositeModel( + classIdForType(MultiMethodExample.class) + ); + + EnvironmentModels initialState = new EnvironmentModels( + classUnderTestModel, + Collections.emptyList(), + Collections.emptyMap() + ); + + EnvironmentModels thirdMethodState = new EnvironmentModels( + classUnderTestModel, + Collections.singletonList(new UtPrimitiveModel("some")), + Collections.emptyMap() + ); + + + Method firstMethodUnderTest = PredefinedGeneratorParameters.getMethodByName( + MultiMethodExample.class, + "firstMethod" + ); + + Method secondMethodUnderTest = PredefinedGeneratorParameters.getMethodByName( + MultiMethodExample.class, + "secondMethod" + ); + + Method thirdMethodUnderTest = PredefinedGeneratorParameters.getMethodByName( + MultiMethodExample.class, + "thirdMethod", + String.class + ); + + TestMethodInfo firstTestMethodInfo = new TestMethodInfo( + firstMethodUnderTest, + initialState); + TestMethodInfo secondTestMethodInfo = new TestMethodInfo( + secondMethodUnderTest, + initialState); + TestMethodInfo thirdTestMethodInfo = new TestMethodInfo( + thirdMethodUnderTest, + thirdMethodState); + + List testSets = UtBotJavaApi.generateTestSets( + Arrays.asList(firstTestMethodInfo, secondTestMethodInfo, thirdTestMethodInfo), + MultiMethodExample.class, + classpath, + dependencyClassPath, + MockStrategyApi.OTHER_PACKAGES, + 3000L + ); + + String generationResult = UtBotJavaApi.generate( + Collections.emptyList(), + testSets, + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + MultiMethodExample.class, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE, + MultiMethodExample.class.getPackage().getName() + ); + + Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); + String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( + Arrays.asList(firstTestMethodInfo, secondTestMethodInfo, thirdTestMethodInfo), + Collections.emptyList(), + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + MultiMethodExample.class + ); + + Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); + } + + @Test + public void testCustomPackage() { + + UtBotJavaApi.setStopConcreteExecutorOnExit(false); + + String classpath = getClassPath(DirectAccess.class); + String dependencyClassPath = getDependencyClassPath(); + + HashMap fields = new HashMap<>(); + fields.put("stringClass", modelFactory.produceClassRefModel(String.class)); + + UtCompositeModel classUnderTestModel = modelFactory.produceCompositeModel( + classIdForType(ClassRefExample.class), + fields + ); + + UtClassRefModel classRefModel = modelFactory.produceClassRefModel(Class.class); + + EnvironmentModels initialState = new EnvironmentModels( + classUnderTestModel, + Collections.singletonList(classRefModel), + Collections.emptyMap() + ); + + Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( + ClassRefExample.class, + "assertInstance", + Class.class + ); + + List testSets = UtBotJavaApi.generateTestSets( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + initialState) + ), + ClassRefExample.class, + classpath, + dependencyClassPath, + MockStrategyApi.OTHER_PACKAGES, + 3000L + ); + + String generationResult = UtBotJavaApi.generate( + Collections.emptyList(), + testSets, + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + ClassRefExample.class, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE, + "some.custom.name" + ); + + Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); + + String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + initialState) + ), + Collections.emptyList(), + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + ClassRefExample.class, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE, + "some.custom.name" + ); + + Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); + } + + @Test + public void testOnObjectWithAssignedArrayField() { + + UtBotJavaApi.setStopConcreteExecutorOnExit(false); + + String classpath = getClassPath(DirectAccess.class); + String dependencyClassPath = getDependencyClassPath(); + + ClassId classIdAssignedArray = classIdForType(AssignedArray.class); + + HashMap values = new HashMap<>(); + values.put(0, new UtPrimitiveModel(1)); + values.put(1, new UtPrimitiveModel(2)); + + UtArrayModel utArrayModel = modelFactory.produceArrayModel( + getIntArrayClassId(), + 10, + new UtPrimitiveModel(0), + values + ); + + UtCompositeModel compositeModel = modelFactory.produceCompositeModel( + classIdAssignedArray, + Collections.singletonMap("array", utArrayModel) + ); + + UtCompositeModel classUnderTestModel = modelFactory.produceCompositeModel( + classIdForType(AssignedArrayExample.class) + ); + + EnvironmentModels initialState = new EnvironmentModels( + classUnderTestModel, + Collections.singletonList(compositeModel), + Collections.emptyMap() + ); + + + Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( + AssignedArrayExample.class, + "foo", + AssignedArray.class + ); + + List testSets = UtBotJavaApi.generateTestSets( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + initialState) + ), + AssignedArrayExample.class, + classpath, + dependencyClassPath, + MockStrategyApi.OTHER_PACKAGES, + 3000L + ); + + String generationResult = UtBotJavaApi.generate( + Collections.emptyList(), + testSets, + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + AssignedArrayExample.class, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE + ); + + Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); + + String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + initialState) + ), + Collections.emptyList(), + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + AssignedArrayExample.class, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE + ); + + Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); + } + + @Test + public void testClassRef() { + + UtBotJavaApi.setStopConcreteExecutorOnExit(false); + + String classpath = getClassPath(DirectAccess.class); + String dependencyClassPath = getDependencyClassPath(); + + HashMap fields = new HashMap<>(); + fields.put("stringClass", modelFactory.produceClassRefModel(String.class)); + + UtCompositeModel classUnderTestModel = modelFactory.produceCompositeModel( + classIdForType(ClassRefExample.class), + fields + ); + + UtClassRefModel classRefModel = modelFactory.produceClassRefModel(Class.class); + + EnvironmentModels initialState = new EnvironmentModels( + classUnderTestModel, + Collections.singletonList(classRefModel), + Collections.emptyMap() + ); + + Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( + ClassRefExample.class, + "assertInstance", + Class.class + ); + + List testSets = UtBotJavaApi.generateTestSets( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + initialState) + ), + ClassRefExample.class, + classpath, + dependencyClassPath, + MockStrategyApi.OTHER_PACKAGES, + 3000L + ); + + String generationResult = UtBotJavaApi.generate( + Collections.emptyList(), + testSets, + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + ClassRefExample.class, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE + ); + + + Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); + + String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + initialState) + ), + Collections.emptyList(), + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + ClassRefExample.class, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE + ); + + Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); + } + + @Test + public void testObjectWithPublicFields() { + + UtBotJavaApi.setStopConcreteExecutorOnExit(false); + + String classpath = getClassPath(DirectAccess.class); + String dependencyClassPath = getDependencyClassPath(); + + ClassId testClassId = classIdForType(DirectAccess.class); + ClassId innerClassId = classIdForType(PrimitiveFields.class); + + HashMap primitiveFields = new HashMap<>(); + primitiveFields.put("a", new UtPrimitiveModel(2)); + primitiveFields.put("b", new UtPrimitiveModel(4)); + + HashMap fields = new HashMap<>(); + fields.put("a", new UtPrimitiveModel(2)); + fields.put("b", new UtPrimitiveModel(4)); + fields.put("s", + modelFactory.produceCompositeModel( + innerClassId, + primitiveFields, + Collections.emptyMap() + ) + ); + + UtCompositeModel compositeModel = modelFactory.produceCompositeModel( + testClassId, + fields, + Collections.emptyMap() + ); + + // This class does not contain any fields. Using overloads + UtCompositeModel classUnderTestModel = modelFactory.produceCompositeModel( + classIdForType(DirectAccessExample.class) + ); + + EnvironmentModels initialState = new EnvironmentModels( + classUnderTestModel, + Collections.singletonList(compositeModel), + Collections.emptyMap() + ); + + + Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( + DirectAccessExample.class, + "foo", + DirectAccess.class + ); + + List testSets = UtBotJavaApi.generateTestSets( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + initialState) + ), + DirectAccessExample.class, + classpath, + dependencyClassPath, + MockStrategyApi.OTHER_PACKAGES, + 3000L + ); + + String generationResult = UtBotJavaApi.generate( + Collections.emptyList(), + testSets, + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + DirectAccessExample.class, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE + ); + + Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); + + String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + initialState) + ), + Collections.emptyList(), + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + DirectAccessExample.class, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE + ); + + Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); + } + + @Test + public void testObjectWithPublicFieldsWithAssembleModel() { + + UtBotJavaApi.setStopConcreteExecutorOnExit(false); + + String classpath = getClassPath(DirectAccess.class); + String dependencyClassPath = getDependencyClassPath(); + + ClassId testClassId = classIdForType(DirectAccess.class); + ClassId innerClassId = classIdForType(PrimitiveFields.class); + + HashMap primitiveFields = new HashMap<>(); + primitiveFields.put("a", new UtPrimitiveModel(2)); + primitiveFields.put("b", new UtPrimitiveModel(4)); + + HashMap fields = new HashMap<>(); + fields.put("a", new UtPrimitiveModel(2)); + fields.put("b", new UtPrimitiveModel(4)); + fields.put("s", + modelFactory.produceCompositeModel( + innerClassId, + primitiveFields, + Collections.emptyMap() + ) + ); + + UtCompositeModel compositeModel = modelFactory.produceCompositeModel( + testClassId, + fields, + Collections.emptyMap() + ); + + // This class does not contain any fields. Using overloads + UtCompositeModel classUnderTestModel = modelFactory.produceCompositeModel( + classIdForType(DirectAccessExample.class) + ); + + EnvironmentModels initialState = new EnvironmentModels( + classUnderTestModel, + Collections.singletonList(compositeModel), + Collections.emptyMap() + ); + + Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( + DirectAccessExample.class, + "foo", + DirectAccess.class + ); + + List testSets = UtBotJavaApi.generateTestSets( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + initialState) + ), + DirectAccessExample.class, + classpath, + dependencyClassPath, + MockStrategyApi.OTHER_PACKAGES, + 3000L + ); + + String generationResult = UtBotJavaApi.generate( + Collections.emptyList(), + testSets, + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + DirectAccessExample.class, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE + ); + + Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); + } + + + @Test + public void testOnObjectWithArrayOfPrimitiveArrays() { + + UtBotJavaApi.setStopConcreteExecutorOnExit(false); + + String classpath = getClassPath(ArrayOfPrimitiveArraysExample.class); + String dependencyClassPath = getDependencyClassPath(); + + ClassId cidPrimitiveArrays = getIntArrayClassId(); + ClassId cidPrimitiveArraysOuter = new ClassId("[[I", cidPrimitiveArrays); + ClassId classIdArrayOfPrimitiveArraysClass = classIdForType(ArrayOfPrimitiveArrays.class); + ClassId cidArrayOfPrimitiveArraysTest = classIdForType(ArrayOfPrimitiveArraysExample.class); + + HashMap arrayParameters = new HashMap<>(); + arrayParameters.put(0, new UtPrimitiveModel(88)); + arrayParameters.put(1, new UtPrimitiveModel(42)); + + UtArrayModel innerArrayOfPrimitiveArrayModel = modelFactory.produceArrayModel( + cidPrimitiveArrays, + 2, + new UtPrimitiveModel(0), + arrayParameters + ); + + HashMap enclosingArrayParameters = new HashMap<>(); + enclosingArrayParameters.put(0, innerArrayOfPrimitiveArrayModel); + enclosingArrayParameters.put(1, innerArrayOfPrimitiveArrayModel); + + UtArrayModel enclosingArrayOfPrimitiveArrayModel = modelFactory.produceArrayModel( + cidPrimitiveArraysOuter, + 1, + new UtNullModel(getIntArrayClassId()), + enclosingArrayParameters + ); + + UtCompositeModel cmArrayOfPrimitiveArrays = modelFactory.produceCompositeModel( + classIdArrayOfPrimitiveArraysClass, + Collections.singletonMap("array", enclosingArrayOfPrimitiveArrayModel) + ); + + UtCompositeModel testClassCompositeModel = modelFactory.produceCompositeModel( + cidArrayOfPrimitiveArraysTest + ); + + EnvironmentModels initialState = new EnvironmentModels( + testClassCompositeModel, + Collections.singletonList(cmArrayOfPrimitiveArrays), + Collections.emptyMap() + ); + + Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( + ArrayOfPrimitiveArraysExample.class, + "assign10", + ArrayOfPrimitiveArrays.class + ); + + List testSets = UtBotJavaApi.generateTestSets( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + initialState) + ), + ArrayOfPrimitiveArraysExample.class, + classpath, + dependencyClassPath, + MockStrategyApi.OTHER_PACKAGES, + 3000L + ); + + String generationResult = UtBotJavaApi.generate( + Collections.emptyList(), + testSets, + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + ArrayOfPrimitiveArraysExample.class, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE + ); + + Snippet snippet = new Snippet(CodegenLanguage.JAVA, generationResult); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet); + + String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + initialState) + ), + Collections.emptyList(), + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + ArrayOfPrimitiveArraysExample.class, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE + ); + + Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); + } + + /** + * The test is inspired by the API customers + */ + @Test + public void testProvided3() { + + UtBotJavaApi.setStopConcreteExecutorOnExit(false); + + String classpath = getClassPath(ArrayOfComplexArraysExample.class); + String dependencyClassPath = getDependencyClassPath(); + + UtCompositeModel cClassModel = modelFactory. + produceCompositeModel( + classIdForType(C.class), + Collections.singletonMap("integer", new UtPrimitiveModel(1)) + ); + + UtCompositeModel bClassModel = modelFactory + .produceCompositeModel( + classIdForType(B.class), + Collections.singletonMap("c", cClassModel) + ); + + UtCompositeModel demo9Model = modelFactory. + produceCompositeModel( + classIdForType(Demo9.class), + Collections.singletonMap("b0", bClassModel) + ); + + EnvironmentModels environmentModels = new EnvironmentModels( + demo9Model, + Collections.singletonList(bClassModel), + Collections.emptyMap() + ); + + Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( + Demo9.class, + "test", + B.class + ); + + List testSets = UtBotJavaApi.generateTestSets( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + environmentModels + ) + ), + Demo9.class, + classpath, + dependencyClassPath, + MockStrategyApi.OTHER_PACKAGES, + 3000L + ); + + String generationResult = UtBotJavaApi.generate( + Collections.emptyList(), + testSets, + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + Demo9.class, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE + ); + + Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); + + String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + environmentModels + ) + ), + Collections.emptyList(), + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + Demo9.class + ); + + Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); + } + + @Test + public void testCustomAssertion() { + String classpath = getClassPath(Trivial.class); + String dependencyClassPath = getDependencyClassPath(); + + UtCompositeModel model = modelFactory. + produceCompositeModel( + classIdForType(Trivial.class) + ); + + EnvironmentModels environmentModels = new EnvironmentModels( + model, + Collections.singletonList(new UtPrimitiveModel(2)), + Collections.emptyMap() + ); + + Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( + Trivial.class, + "aMethod", + int.class + ); + + List testSets = UtBotJavaApi.generateTestSets( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + environmentModels + ) + ), + Trivial.class, + classpath, + dependencyClassPath, + MockStrategyApi.OTHER_PACKAGES, + 3000L + ); + + String generationResult = UtBotJavaApi.generate( + Collections.emptyList(), + testSets, + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + Trivial.class, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE + ); + + Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); + + String generationResult2 = UtBotJavaApi.generate( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + environmentModels + ) + ), + Collections.emptyList(), + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + Trivial.class, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE + ); + + Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResult2); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); + } + + /** + * The test is inspired by the API customers + */ + @Test + public void testProvided3Reused() { + + UtBotJavaApi.setStopConcreteExecutorOnExit(true); + + String dependencyClassPath = getDependencyClassPath(); + + // The method in the class contains only one parameter + String classSourceAsString = + "public class Demo9Recompiled {" + + " public int test(int b1) {" + + " return 0;" + + " }" + + "}"; + + String demo9RecompiledClassName = "Demo9Recompiled"; + Pair classpathToClassLoader = + compileClassAndGetClassPath(new Pair<>(demo9RecompiledClassName, classSourceAsString)); + + + String classpath = classpathToClassLoader.getFirst(); + ClassLoader classLoader = classpathToClassLoader.getSecond(); + + Class compiledClass = null; + + try { + compiledClass = classLoader.loadClass(demo9RecompiledClassName); + } catch (ClassNotFoundException e) { + Assertions.fail("Failed to load a class; Classpath: " + classpathToClassLoader.getFirst()); + } + + if (compiledClass == null) { + Assertions.fail("Failed to load the class"); + } + + UtCompositeModel demo9Model = modelFactory. + produceCompositeModel( + classIdForType(compiledClass), + Collections.emptyMap() + ); + + EnvironmentModels environmentModels = new EnvironmentModels( + demo9Model, + Collections.singletonList(new UtPrimitiveModel(3)), + Collections.emptyMap() + ); + + Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( + compiledClass, + "test", + int.class + ); + + List testSets = UtBotJavaApi.generateTestSets( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + environmentModels + ) + ), + compiledClass, + classpath, + dependencyClassPath, + MockStrategyApi.OTHER_PACKAGES, + 3000L + ); + + String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( + Collections.emptyList(), + testSets, + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + compiledClass, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE + ); + + Snippet snippet = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet); + + // The test compiles and everything goes well. + // Let's recompile the initial clas file + + // The method below has an extra parameter + classSourceAsString = + "public class Demo9Recompiled {" + + " public int test(int b1, String s) {" + + " return 0;" + + " }" + + "}"; + + Pair stringClassLoaderPair = + compileClassAndGetClassPath(new Pair<>(demo9RecompiledClassName, classSourceAsString), classpath); + + ClassLoader reloadedClassLoader = stringClassLoaderPair.getSecond(); + + Class recompiledClass = null; + + try { + recompiledClass = reloadedClassLoader.loadClass(demo9RecompiledClassName); + } catch (ClassNotFoundException e) { + Assertions.fail("Failed to load the class after recompilation; classpath: " + stringClassLoaderPair.getFirst()); + } + + if (recompiledClass == null) { + Assertions.fail("Failed to load the class after recompilation"); + } + + EnvironmentModels environmentModels2 = new EnvironmentModels( + demo9Model, + Arrays.asList(new UtPrimitiveModel(4), new UtPrimitiveModel("Some String")), + Collections.emptyMap() + ); + + Method methodUnderTest2 = PredefinedGeneratorParameters.getMethodByName( + recompiledClass, + "test", + int.class, + String.class + ); + + List testSets1 = UtBotJavaApi.generateTestSets( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest2, + environmentModels + ) + ), + recompiledClass, + classpath, + dependencyClassPath, + MockStrategyApi.OTHER_PACKAGES, + 3000L + ); + + String generationResultWithConcreteExecutionOnly2 = UtBotJavaApi.generate( + Collections.emptyList(), + testSets1, + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + recompiledClass, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE + ); + + Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly2); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); + } + + @Test + public void testProvided1() { + + UtBotJavaApi.setStopConcreteExecutorOnExit(false); + + String classpath = getClassPath(ArrayOfComplexArraysExample.class); + String dependencyClassPath = getDependencyClassPath(); + + UtCompositeModel providedTestModel = modelFactory.produceCompositeModel( + classIdForType(ProvidedExample.class), + Collections.emptyMap(), + Collections.emptyMap() + ); + + List parameters = Arrays.asList( + new UtPrimitiveModel(5), + new UtPrimitiveModel(9), + new UtPrimitiveModel("Some Text") + ); + + EnvironmentModels initialState = new EnvironmentModels( + providedTestModel, + parameters, + Collections.emptyMap() + ); + + Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( + ProvidedExample.class, + "test0", + int.class, int.class, String.class + ); + + List testSets = UtBotJavaApi.generateTestSets( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + initialState + ) + ), + ProvidedExample.class, + classpath, + dependencyClassPath, + MockStrategyApi.OTHER_PACKAGES, + 3000L + ); + + String generationResult = UtBotJavaApi.generate( + Collections.emptyList(), + testSets, + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + ProvidedExample.class, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE + ); + + Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); + + String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + initialState + ) + ), + Collections.emptyList(), + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + ProvidedExample.class + ); + + Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); + } + + @Test + public void testOnObjectWithArrayOfComplexArrays() { + + UtBotJavaApi.setStopConcreteExecutorOnExit(false); + + String classpath = getClassPath(ArrayOfComplexArraysExample.class); + String dependencyClassPath = getDependencyClassPath(); + + UtCompositeModel cmArrayOfComplexArrays = createArrayOfComplexArraysModel(); + + UtCompositeModel testClassCompositeModel = modelFactory.produceCompositeModel( + classIdForType(ArrayOfComplexArraysExample.class) + ); + + EnvironmentModels initialState = new EnvironmentModels( + testClassCompositeModel, + Collections.singletonList(cmArrayOfComplexArrays), + Collections.emptyMap() + ); + + Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( + ArrayOfComplexArraysExample.class, + "getValue", + ArrayOfComplexArrays.class + ); + + List testSets = UtBotJavaApi.generateTestSets( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + initialState + ) + ), + ArrayOfComplexArraysExample.class, + classpath, + dependencyClassPath, + MockStrategyApi.OTHER_PACKAGES, + 3000L + ); + + String generationResult = UtBotJavaApi.generate( + Collections.emptyList(), + testSets, + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + ArrayOfComplexArraysExample.class, + Junit4.INSTANCE, + MOCKITO, + CodegenLanguage.JAVA, + MockitoStaticMocking.INSTANCE, + false, + ForceStaticMocking.DO_NOT_FORCE + ); + + Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); + + String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( + Collections.singletonList( + new TestMethodInfo( + methodUnderTest, + initialState + ) + ), + Collections.emptyList(), + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + ArrayOfComplexArraysExample.class + ); + + Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); + } + + @Test + public void testFuzzingSimple() { + SootUtils.INSTANCE.runSoot(StringSwitchExample.class, false, new JdkInfoDefaultProvider().getInfo()); + UtBotJavaApi.setStopConcreteExecutorOnExit(false); + + String classpath = getClassPath(StringSwitchExample.class); + String dependencyClassPath = getDependencyClassPath(); + + UtCompositeModel classUnderTestModel = modelFactory.produceCompositeModel( + classIdForType(StringSwitchExample.class) + ); + + Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName(StringSwitchExample.class, "validate", String.class, int.class, int.class); + + IdentityHashMap models = modelFactory.produceAssembleModel( + methodUnderTest, + StringSwitchExample.class, + Collections.singletonList(classUnderTestModel) + ); + + EnvironmentModels methodState = new EnvironmentModels( + models.get(classUnderTestModel), + Arrays.asList(new UtPrimitiveModel("initial model"), new UtPrimitiveModel(-10), new UtPrimitiveModel(0)), + Collections.emptyMap() + ); + + TestMethodInfo methodInfo = new TestMethodInfo( + methodUnderTest, + methodState); + List testSets1 = UtBotJavaApi.fuzzingTestSets( + Collections.singletonList( + methodInfo + ), + StringSwitchExample.class, + classpath, + dependencyClassPath, + MockStrategyApi.OTHER_PACKAGES, + 3000L, + (type) -> { + if (int.class.equals(type) || Integer.class.equals(type)) { + return Arrays.asList(0, Integer.MIN_VALUE, Integer.MAX_VALUE); + } + return null; + } + ); + + String generate = UtBotJavaApi.generate( + Collections.singletonList(methodInfo), + testSets1, + PredefinedGeneratorParameters.destinationClassName, + classpath, + dependencyClassPath, + StringSwitchExample.class + ); + + Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generate); + compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); + } + + @NotNull + private String getClassPath(Class clazz) { + return clazz.getProtectionDomain().getCodeSource().getLocation().getPath(); + } + + @NotNull + private String getDependencyClassPath() { + + ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + URL[] urls = PathUtil.getUrlsFromClassLoader(contextClassLoader); + + + return Arrays.stream(urls).map(url -> + { + try { + return new File(url.toURI()).toString(); + } catch (URISyntaxException e) { + Assertions.fail(e); + } + throw new RuntimeException(); + }).collect(Collectors.joining(File.pathSeparator)); + } + public UtCompositeModel createArrayOfComplexArraysModel() { + ClassId classIdOfArrayOfComplexArraysClass = classIdForType(ArrayOfComplexArrays.class); + ClassId classIdOfComplexArray = classIdForType(ComplexArray.class); + ClassId classIdOfPrimitiveFieldsClass = classIdForType(PrimitiveFields.class); + + ClassId classIdOfArrayOfPrimitiveFieldsClass = new ClassId("[L" + classIdOfPrimitiveFieldsClass.getCanonicalName() + ";", classIdOfPrimitiveFieldsClass); + + Map elementsOfComplexArrayArray = new HashMap<>(); + + Map elementsWithPrimitiveFieldsClasses = new HashMap<>(); + + elementsWithPrimitiveFieldsClasses.put(0, modelFactory.produceCompositeModel( + classIdOfPrimitiveFieldsClass, + Collections.singletonMap("a", new UtPrimitiveModel(5)), + Collections.emptyMap() + )); + + elementsWithPrimitiveFieldsClasses.put(1, modelFactory.produceCompositeModel( + classIdOfPrimitiveFieldsClass, + Collections.singletonMap("b", new UtPrimitiveModel(4)), + Collections.emptyMap() + )); + + UtArrayModel arrayOfPrimitiveFieldsModel = modelFactory.produceArrayModel( + classIdOfArrayOfPrimitiveFieldsClass, + 2, + new UtNullModel(classIdOfPrimitiveFieldsClass), + elementsWithPrimitiveFieldsClasses + ); + + UtCompositeModel complexArrayClassModel = modelFactory.produceCompositeModel( + classIdOfComplexArray, + Collections.singletonMap("array", arrayOfPrimitiveFieldsModel) + ); + + elementsOfComplexArrayArray.put(1, complexArrayClassModel); + + ClassId classIdOfArraysOfComplexArrayClass = new ClassId("[L" + classIdOfComplexArray.getCanonicalName() + ";", classIdOfComplexArray); + + UtArrayModel arrayOfComplexArrayClasses = modelFactory.produceArrayModel( + classIdOfArraysOfComplexArrayClass, + 2, + new UtNullModel(classIdOfComplexArray), + elementsOfComplexArrayArray + ); + + return modelFactory.produceCompositeModel( + classIdOfArrayOfComplexArraysClass, + Collections.singletonMap("array", arrayOfComplexArrayClasses)); + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/bytecode/versions/SootTest.kt b/utbot-testing/src/test/kotlin/org/utbot/bytecode/versions/SootTest.kt new file mode 100644 index 0000000000..e988274ce0 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/bytecode/versions/SootTest.kt @@ -0,0 +1,69 @@ +package org.utbot.bytecode.versions + +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertNotNull +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.examples.objects.SimpleDataClass +import org.utbot.framework.util.SootUtils.runSoot +import soot.Scene + +@Suppress("UNREACHABLE_CODE") +@Disabled("TODO: https://github.com/UnitTestBot/UTBotJava/issues/891") +class SootTest { + @Test + fun `no method isBlank in JDK 8`() { + runSoot( + SimpleDataClass::class.java, + forceReload = true, + TODO("Get JDK 8") + ) + + val stringClass = Scene.v().getSootClass("java.lang.String") + assertFalse(stringClass.isPhantomClass) + + val isBlankMethod = stringClass.getMethodByNameUnsafe("isBlank") // no such method in JDK 8 + assertNull(isBlankMethod) + } + + @Test + fun `method isBlank exists in JDK 11`() { + runSoot( + SimpleDataClass::class.java, + forceReload = true, + TODO("Get JDK 11") + ) + + val stringClass = Scene.v().getSootClass("java.lang.String") + assertFalse(stringClass.isPhantomClass) + + val isBlankMethod = stringClass.getMethodByNameUnsafe("isBlank") // there is such method in JDK 11 + assertNotNull(isBlankMethod) + } + + @Test + fun `no records in JDK 11`() { + runSoot( + SimpleDataClass::class.java, + forceReload = true, + TODO("Get JDK 11") + ) + + val stringClass = Scene.v().getSootClass("java.lang.Record") // must not exist in JDK 11 + assertTrue(stringClass.isPhantomClass) + } + + @Test + fun `records exists in JDK 17`() { + runSoot( + SimpleDataClass::class.java, + forceReload = true, + TODO("Get JDK 17") + ) + + val stringClass = Scene.v().getSootClass("java.lang.Record") // must exist in JDK 17 + assertFalse(stringClass.isPhantomClass) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/engine/pc/QueryOptimizationsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/engine/pc/QueryOptimizationsTest.kt new file mode 100644 index 0000000000..498c3ee2e5 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/engine/pc/QueryOptimizationsTest.kt @@ -0,0 +1,642 @@ +package org.utbot.engine.pc + +import org.utbot.engine.Add +import org.utbot.engine.And +import org.utbot.engine.Cmp +import org.utbot.engine.Cmpg +import org.utbot.engine.Cmpl +import org.utbot.engine.Div +import org.utbot.engine.Eq +import org.utbot.engine.Ge +import org.utbot.engine.Gt +import org.utbot.engine.Le +import org.utbot.engine.Lt +import org.utbot.engine.Mul +import org.utbot.engine.Ne +import org.utbot.engine.Or +import org.utbot.engine.Rem +import org.utbot.engine.Shl +import org.utbot.engine.Shr +import org.utbot.engine.Sub +import org.utbot.engine.Ushr +import org.utbot.engine.Xor +import org.utbot.engine.primitiveToSymbolic +import org.utbot.engine.toBoolValue +import org.utbot.engine.toByteValue +import org.utbot.engine.toDoubleValue +import org.utbot.engine.toFloatValue +import org.utbot.engine.toIntValue +import org.utbot.engine.toLongValue +import org.utbot.engine.toPrimitiveValue +import org.utbot.engine.toShortValue +import org.utbot.framework.UtSettings +import kotlinx.collections.immutable.persistentListOf +import org.junit.jupiter.api.AfterAll +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.Test + +private var expressionSimplificationValue: Boolean = UtSettings.useExpressionSimplification + +@BeforeAll +fun beforeAll() { + UtSettings.useExpressionSimplification = true +} + +@AfterAll +fun afterAll() { + UtSettings.useExpressionSimplification = expressionSimplificationValue +} + + +class QueryOptimizationsTest { + + private fun BaseQuery.check(vararg exprs: UtBoolExpression, checker: (BaseQuery) -> Unit = {}): BaseQuery = + this.with(hard = exprs.toList(), soft = emptyList(), assumptions = emptyList()).also { + checker(it) + } + + private fun BaseQuery.checkUnsat(vararg exprs: UtBoolExpression): BaseQuery = + this.check(*exprs) { unsat(it) } + + private val empty: (BaseQuery) -> Unit = { query -> + assert(query.hard.isEmpty()) { "$query isn't empty" } + } + + private val notEmpty: (BaseQuery) -> Unit = { query -> + assert(query.hard.isNotEmpty()) { "$query is empty" } + } + + private fun size(value: Int): (BaseQuery) -> Unit = { query -> + assert(query.hard.size == value) { "$query size doesn't match with $value" } + } + + private fun contains(constraint: UtBoolExpression): (BaseQuery) -> Unit = { query -> + assert(query.hard.contains(constraint)) { "$query doesn't contain $constraint" } + } + + private val unsat: (BaseQuery) -> Unit = { query -> + assert(query.status is UtSolverStatusUNSAT) { "$query isn't unsat" } + } + + private val unknown: (BaseQuery) -> Unit = { query -> + assert(query.status is UtSolverStatusUNDEFINED) { "$query status is known" } + } + + private fun `is`(vararg checkers: (BaseQuery) -> Unit): (BaseQuery) -> Unit = { query -> + checkers.forEach { it(query) } + } + + @Test + fun testConcreteEq() { + var query: BaseQuery = Query() + query = query.check(Eq(0.toPrimitiveValue(), 0)) { + `is`(empty, unknown)(it) + } + query.check(Eq(1.toPrimitiveValue(), 0)) { + `is`(contains(UtFalse), unsat)(it) + } + } + + @Test + fun testSymbolicEq() { + var query: BaseQuery = Query() + val p = mkBVConst("p", UtIntSort).toIntValue() + // p == p === true + query.check(Eq(p, p)) { + `is`(empty, unknown)(it) + } + // query = Query(p == 0) + query = query.check(Eq(p, 0)) { + `is`(notEmpty, unknown)(it) + } + // p == 0, p == 1 is unsat + query.checkUnsat(Eq(p, 1)) + // p == 0, p != 0 is unsat + query.checkUnsat(Ne(p, 0)) + // p == 0, not (p == 0) is unsat + query.checkUnsat(NotBoolExpression(Eq(p, 0))) + // p == 0, p == p === p == 0 + query.check(Eq(p, p)) { + `is`(size(1), contains(Eq(p, 0)), unknown)(it) + } + } + + @Test + fun testArbitraryExpressionEq() { + var query: BaseQuery = Query() + val a = mkBVConst("a", UtIntSort).toIntValue() + val b = mkBVConst("b", UtIntSort).toIntValue() + // query = Query(a + b == 0) + query = query.check(Eq(Add(a, b).toIntValue(), 0)) { + `is`(size(1), unknown)(it) + } + // a + b == 0, a + b == 1 is unsat + query.checkUnsat(Eq(Add(a, b).toIntValue(), 1)) + val array = mkArrayConst("a", UtIntSort, UtIntSort) + val first = array.select(mkInt(0)).toIntValue() + // query = Query(a + b == 0, select(array, 0) == 0) + query = query.check(Eq(first, 0)) { + `is`(size(2), unknown)(it) + } + // select(array, 0) == 0, select(array, 0) == 1 is unsat + query.checkUnsat(Eq(first, 1)) + } + + @Test + fun testEvalIndexOfSelect() { + var query: BaseQuery = Query() + val array = mkArrayConst("a", UtIntSort, UtIntSort) + // query = Query(select(array, 3) == 0) + query = query.check(Eq(array.select(mkInt(3)).toIntValue(), 0)) { + `is`(size(1), unknown)(it) + } + // select(array, 3) == 0, select(array, 1 + 2) == 2 is unsat + query.checkUnsat( + Eq(array.select(Add(1.toPrimitiveValue(), 2.toPrimitiveValue())).toIntValue(), 2) + ) + } + + @Test + fun testFpEq() { + var query: BaseQuery = Query() + val fp = mkFpConst("a", Double.SIZE_BITS).toDoubleValue() + // query = Query(a == 0.0) + query = query.check(Eq(fp, 0.0.toPrimitiveValue())) { + `is`(size(1), unknown)(it) + } + // a == 0.0, a == 1.0 is unsat + query.checkUnsat(Eq(fp, 1.0.toPrimitiveValue())) + // a == 0.0, a == 0.0 === a == 0.0 + query.check(Eq(0.0.toPrimitiveValue(), fp)) { + `is`(size(1), unknown)(it) + } + } + + @Test + fun testOperations() { + val query: BaseQuery = Query() + val a = 10.toPrimitiveValue() + val b = 5.toPrimitiveValue() + query.check( + // 10 + 5 == 15 + Eq(Add(a, b).toIntValue(), 15), + // 10 - 5 == 5 + Eq(Sub(a, b).toIntValue(), 5), + // 10 * 5 == 50 + Eq(Mul(a, b).toIntValue(), 50), + // 10 / 5 == 2 + Eq(Div(a, b).toIntValue(), 2), + // 5 % 10 == 5 + Eq(Rem(b, a).toIntValue(), 5), + // 10 cmp 5 == 1 + Eq(Cmp(a, b).toIntValue(), 1), + Eq(Cmpg(a, b).toIntValue(), 1), + Eq(Cmpl(a, b).toIntValue(), 1), + // 10 and 5 + Eq(And(a, b).toIntValue(), 10 and 5), + // 10 or 5 + Eq(Or(a, b).toIntValue(), 10 or 5), + // 10 xor 5 + Eq(Xor(a, b).toIntValue(), 10 xor 5), + // 10 << 5 + Eq(Shl(a, b).toIntValue(), 10 shl 5), + // -1 >> 5 == -1 + Eq(Shr((-1).toPrimitiveValue(), b).toIntValue(), -1 shr 5), + // -1 >>> 5 + Eq(Ushr((-1).toPrimitiveValue(), b).toIntValue(), -1 ushr 5), + // 10 << 37 == 10 << 5 + Eq(Shl(a, 37.toPrimitiveValue()).toIntValue(), 10 shl 37), + // -5 >> 37 == -5 >> 5 + Eq(Shr(mkByte(-5).toIntValue(), 37.toPrimitiveValue()).toIntValue(), -5 shr 37), + Eq(Ushr((-5).toPrimitiveValue(), 37.toPrimitiveValue()).toIntValue(), -5 ushr 37), + ) { + `is`(empty, unknown)(it) + } + } + + @Test + fun testUtEqExpression() { + var query: BaseQuery = Query() + // 0 == 0 === true + query.check(UtEqExpression(mkInt(0), mkInt(0))) { + `is`(empty, unknown)(it) + } + // 1 == 0 === false + query.checkUnsat(UtEqExpression(mkInt(1), mkInt(0))) + val array = mkArrayConst("a", UtIntSort, UtIntSort) + val first = array.select(mkInt(0)) + // query = Query(select(array, 0) == 0) + query = query.check(UtEqExpression(first, mkInt(0))) { + `is`(size(1), unknown)(it) + } + // select(array, 0) == 0, select(array, 0) == 1 is unsat + query.checkUnsat(UtEqExpression(first, mkInt(1))) + } + + @Test + fun testSplitAndExpression() { + val query: BaseQuery = Query() + val a = mkBoolConst("a") + val b = mkBoolConst("b") + val c = mkBoolConst("c") + // a and b and c and true === a, b, c + query.check(mkAnd(a, b, c, UtTrue)) { + `is`(size(3), contains(a), contains(b), contains(c), unknown)(it) + } + } + + @Test + fun testAndExpression() { + val query: BaseQuery = Query() + val a = mkBoolConst("a") + val b = mkBoolConst("b") + val c = mkBoolConst("c") + // a and b and false === false + query.check(mkAnd(a, b, UtFalse)) { + `is`(unsat, contains(UtFalse))(it) + } + // a and b and true and c === a and b and c + query.check(mkAnd(a, b, UtTrue, c)) { + `is`(size(3), contains(a), contains(b), contains(c), unknown)(it) + } + // true and true and true === true + query.check(mkAnd(UtTrue, UtTrue, UtTrue)) { + `is`(empty, unknown)(it) + } + // a and true === a + query.check(mkAnd(a, UtTrue)) { + `is`(size(1), contains(a), unknown)(it) + } + // a and b and (true and true) === a and b + query.check(mkAnd(a, b, (mkAnd(UtTrue, UtTrue)))) { + `is`(size(2), contains(a), contains(b), unknown)(it) + } + } + + @Test + fun testOrExpression() { + val query: BaseQuery = Query() + val a = mkBoolConst("a") + val b = mkBoolConst("b") + val c = mkBoolConst("c") + // a or b or true === a or b + query.check(mkOr(a, b, UtTrue)) { + `is`(empty, unknown)(it) + } + // a or b or false or c === a or b or c + query.check(mkOr(a, b, UtFalse, c)) { + `is`(size(1), contains(mkOr(a, b, c)), unknown)(it) + } + // false or false or false === false + query.checkUnsat(mkOr(UtFalse, UtFalse, UtFalse)) + // a or false === a + query.check(mkOr(a, UtFalse)) { + `is`(size(1), contains(a), unknown)(it) + } + // a or b or (false or false) === a or b + query.check(mkOr(a, b, mkOr(UtFalse, UtFalse))) { + `is`(size(1), contains(mkOr(a, b)))(it) + } + } + + @Test + fun testNotExpression() { + val query: BaseQuery = Query() + val a = mkBoolConst("a") + val b = mkBoolConst("b") + // not true === false + query.checkUnsat(NotBoolExpression(UtTrue)) + // not false === true + query.check(NotBoolExpression(UtFalse)) { + `is`(empty, unknown)(it) + } + // not (a and b) === (not a) or (not b) + query.check(NotBoolExpression(mkAnd(a, b))) { + `is`(size(1), contains(mkOr(NotBoolExpression(a), NotBoolExpression(b))), unknown)(it) + } + // not (a and true) === (not a) + query.check(NotBoolExpression(mkAnd(a, UtTrue))) { + `is`(size(1), contains(NotBoolExpression(a)), unknown)(it) + } + // not (a or b) === (not a) and (not b) + query.check(NotBoolExpression(mkOr(a, b))) { + `is`(size(2), contains(NotBoolExpression(a)), contains(NotBoolExpression(b)), unknown)(it) + } + // not (a or false) === not a + query.check(NotBoolExpression(mkOr(a, UtFalse))) { + `is`(size(1), contains(NotBoolExpression(a)), unknown)(it) + } + // not (a != b) === a == b + query.check(NotBoolExpression(Ne(a.toBoolValue(), b.toBoolValue()))) { + `is`(size(1), contains(Eq(a.toBoolValue(), b.toBoolValue())), unknown)(it) + } + } + + @Test + fun testUtNegExpression() { + val query: BaseQuery = Query() + val a = 50 + query.check( + // neg Byte(50) == Byte(-50) + Eq(UtNegExpression(a.toByte().toPrimitiveValue()).toByteValue(), (-a).toPrimitiveValue()), + // neg Short(50) == Short(-50) + Eq(UtNegExpression(a.toShort().toPrimitiveValue()).toShortValue(), (-a).toPrimitiveValue()), + // neg 50 == -50 + Eq(UtNegExpression(a.toPrimitiveValue()).toIntValue(), (-a).toPrimitiveValue()), + // neg Long(50) == Long(-50) + Eq(UtNegExpression(a.toLong().toPrimitiveValue()).toLongValue(), (-a).toLong().toPrimitiveValue()), + // neg Float(50) == Float(-50) + Eq( + UtNegExpression(a.toFloat().toPrimitiveValue()).toFloatValue(), + (-a).toFloat().toPrimitiveValue() + ), + // neg Double(50) == Double(-50) + Eq( + UtNegExpression(a.toDouble().toPrimitiveValue()).toDoubleValue(), + (-a).toDouble().toPrimitiveValue() + ) + ) { + `is`(empty, unknown)(it) + } + } + + @Test + fun testSelectStoreExpression() { + val query: BaseQuery = Query() + val constArray = mkArrayWithConst(UtArraySort(UtIntSort, UtIntSort), mkInt(10)) + // select(constArray(1), 10) == 10 + query.check(Eq(constArray.select(mkInt(1)).toIntValue(), 10)) { + `is`(empty, unknown)(it) + } + // select(constArray(1), 10) != 20 + query.checkUnsat(Eq(constArray.select(mkInt(1)).toIntValue(), 20)) + val a = mkBVConst("a", UtIntSort) + val array = mkArrayConst("array", UtIntSort, UtIntSort) + val multistore1 = UtArrayMultiStoreExpression( + array, + persistentListOf( + UtStore(mkInt(2), mkInt(10)), + UtStore(a, mkInt(30)), + UtStore(mkInt(0), mkInt(10)), + UtStore(mkInt(0), mkInt(20)), + UtStore(mkInt(1), mkInt(10)) + ) + ) + val multistore2 = UtArrayMultiStoreExpression( + array, + persistentListOf( + UtStore(mkInt(2), mkInt(10)), + UtStore(mkInt(0), mkInt(10)), + UtStore(mkInt(0), mkInt(20)), + UtStore(mkInt(1), mkInt(10)), + UtStore(a, mkInt(30)) + ) + ) + query.check( + // select(store(...., 1, 10), 1) == 10 + Eq(multistore1.select(mkInt(1)).toIntValue(), 10), + // select(store(store(store(..., 0, 10), 0, 20), 1, 10), 1) == 20 + Eq(multistore1.select(mkInt(0)).toIntValue(), 20), + // select(store(...., a, 30), a) == 30 + Eq(multistore2.select(a).toIntValue(), 30) + ) { + `is`(empty, unknown)(it) + } + query.check( + // select(store(...(store(store(..., 2, 10), a, 30)...), 2) == 10 can't be simplified + Eq(multistore1.select(mkInt(2)).toIntValue(), 10) + ) { + `is`(size(1), unknown)(it) + } + query.check( + // select(store(...(store(..., a, 30))...), a) == 30 can't be simplified + Eq(multistore1.select(a).toIntValue(), 30) + ) { + `is`(size(1), unknown)(it) + } + } + + @Test + fun testPartialArithmeticExpression() { + val query: BaseQuery = Query() + + val a = mkBVConst("a", UtIntSort).toIntValue() + val zero = 0.toPrimitiveValue() + val one = 1.toPrimitiveValue() + val minusOne = (-1).toPrimitiveValue() + query.check( + // a + 0 == a + Eq(Add(a, zero).toIntValue(), a), + // a - 0 == a + Eq(Sub(a, zero).toIntValue(), a), + // 0 + a == a + Eq(Add(zero, a).toIntValue(), a), + // 0 - a == neg a + Eq(Sub(zero, a).toIntValue(), UtNegExpression(a).toIntValue()), + // 0 * a == 0 + Eq(Mul(zero, a).toIntValue(), zero), + Eq(Mul(a, zero).toIntValue(), zero), + // a * 1 == a + Eq(Mul(a, one).toIntValue(), a), + Eq(Mul(one, a).toIntValue(), a), + // a * (-1) == neg a + Eq(Mul(a, minusOne).toIntValue(), UtNegExpression(a).toIntValue()), + Eq(Mul(minusOne, a).toIntValue(), UtNegExpression(a).toIntValue()), + ) { + `is`(empty, unknown)(it) + } + } + + @Test + fun testOpenLiteralFromInnerExpr() { + val query: BaseQuery = Query() + + val a = mkBVConst("a", UtIntSort).toIntValue() + val five = 5.toPrimitiveValue() + val ten = 10.toPrimitiveValue() + val fifteen = 15.toPrimitiveValue() + val fifty = 50.toPrimitiveValue() + query.check( + // ((a + 5) + 10) == a + 15 + Eq(Add(Add(a, five).toIntValue(), ten).toIntValue(), Add(a, fifteen).toIntValue()), + Eq(Add(Add(five, a).toIntValue(), ten).toIntValue(), Add(a, fifteen).toIntValue()), + Eq(Add(ten, Add(a, five).toIntValue()).toIntValue(), Add(a, fifteen).toIntValue()), + Eq(Add(ten, Add(five, a).toIntValue()).toIntValue(), Add(a, fifteen).toIntValue()), + // ((a * 5) * 10) == a * 50 + Eq(Mul(Mul(a, five).toIntValue(), ten).toIntValue(), Mul(a, fifty).toIntValue()), + Eq(Mul(Mul(five, a).toIntValue(), ten).toIntValue(), Mul(a, fifty).toIntValue()), + Eq(Mul(ten, Mul(a, five).toIntValue()).toIntValue(), Mul(a, fifty).toIntValue()), + Eq(Mul(ten, Mul(five, a).toIntValue()).toIntValue(), Mul(a, fifty).toIntValue()), + // ((a - 5) + 10) == a + 5 + Eq(Add(Sub(a, five).toIntValue(), ten).toIntValue(), Add(a, five).toIntValue()), + Eq(Add(ten, Sub(a, five).toIntValue()).toIntValue(), Add(a, five).toIntValue()), + // ((a + 5) * 10) == a * 10 + 50 + Eq(Mul(Add(a, five).toIntValue(), ten).toIntValue(), Add(Mul(a, ten).toIntValue(), fifty).toIntValue()), + Eq(Mul(Add(five, a).toIntValue(), ten).toIntValue(), Add(Mul(a, ten).toIntValue(), fifty).toIntValue()), + Eq(Mul(ten, Add(a, five).toIntValue()).toIntValue(), Add(Mul(a, ten).toIntValue(), fifty).toIntValue()), + Eq(Mul(ten, Add(five, a).toIntValue()).toIntValue(), Add(Mul(a, ten).toIntValue(), fifty).toIntValue()), + ) { + `is`(empty, unknown)(it) + } + } + + @Test + fun testEqSimplificationWithInnerExpr() { + val query: BaseQuery = Query() + + val a = mkBVConst("a", UtIntSort).toIntValue() + val five = 5.toPrimitiveValue() + val ten = 10.toPrimitiveValue() + val fifteen = 15.toPrimitiveValue() + // (a + 5) == 10 === a == 5 + query.check(Eq(Add(a, five).toIntValue(), ten)) { + `is`(contains(Eq(a, five)), unknown)(it) + } + // (a - 5) == 10 === a == 15 + query.check(Eq(Sub(a, five).toIntValue(), ten)) { + `is`(contains(Eq(a, fifteen)), unknown)(it) + } + // (a xor 5) == 10 === a == 5 xor 10 + query.check(Eq(Xor(a, five).toIntValue(), ten)) { + `is`(contains(Eq(a, (10 xor 5).toPrimitiveValue())), unknown)(it) + } + } + + @Test + fun testLtSimplifications() { + val query: BaseQuery = Query() + + val a = mkBVConst("a", UtIntSort).toIntValue() + val five = 5.toPrimitiveValue() + val ten = 10.toPrimitiveValue() + val fifteen = 15.toPrimitiveValue() + val nine = 9.toPrimitiveValue() + val four = 4.toPrimitiveValue() + // ltQuery = Query(a < 10) + val ltQuery = query.check(Lt(a, ten)) { + `is`(size(1), unknown)(it) + } + // a < 10, a < 15, a <= 10, a > 5 === a < 10, a > 5 + ltQuery.check(Lt(a, fifteen), Le(a, ten), Gt(a, five)) { + `is`(contains(Lt(a, ten)), contains(Gt(a, five)), unknown)(it) + } + // a < 10, a >= 9 === a == 9 + ltQuery.check(Ge(a, nine)) { `is`(contains(Eq(a, nine)), unknown)(it) } + // a < 10, a >= 10 is unsat + ltQuery.checkUnsat(Ge(a, ten)) + // a < 10, a > 10 is unsat + ltQuery.checkUnsat(Gt(a, ten)) + // a < 10, a == 10 is unsat + ltQuery.checkUnsat(Eq(a, ten)) + val lessLtQuery = ltQuery.check(Lt(a, five)) { `is`(size(1), unknown)(it) } + // a < 5, a >= 5 is unsat + lessLtQuery.checkUnsat(Ge(a, five)) + // a < 5, a >= 4 === a == 4 + lessLtQuery.check(Ge(a, four)) { `is`(contains(Eq(a, four)), unknown)(it) } + // a < Long.MIN_VALUE is unsat + query.checkUnsat(Lt(a, Long.MIN_VALUE.primitiveToSymbolic())) + } + + @Test + fun testLeSimplifications() { + val query: BaseQuery = Query() + + val a = mkBVConst("a", UtIntSort).toIntValue() + val five = 5.toPrimitiveValue() + val ten = 10.toPrimitiveValue() + val fifteen = 15.toPrimitiveValue() + val nine = 9.toPrimitiveValue() + // geQuery = Query(a <= 10) + val leQuery = query.check(Le(a, ten)) { + `is`(size(1), unknown)(it) + } + // a <= 10, a < 15, a < 10, a > 5 === a < 10, a > 5 + leQuery.check(Lt(a, fifteen), Lt(a, ten), Gt(a, five)) { + `is`(contains(Lt(a, ten)), contains(Gt(a, five)), unknown)(it) + } + // a <= 10, a > 9 === a == 10 + leQuery.check(Gt(a, nine)) { `is`(contains(Eq(a, ten)), unknown)(it) } + // a <= 10, a >= 10 === a == 10 + leQuery.check(Ge(a, ten)) { `is`(contains(Eq(a, ten)), unknown)(it) } + // a <= 10, a > 10 is unsat + leQuery.checkUnsat(Gt(a, ten)) + // a <= 10, a == 15 is unsat + leQuery.checkUnsat(Eq(a, fifteen)) + val lessLeQuery = leQuery.check(Le(a, five)) { `is`(size(1), unknown)(it) } + // a <= 5, a > 5 is unsat + lessLeQuery.checkUnsat(Gt(a, five)) + // a <= 5, a >= 5 === a == 5 + lessLeQuery.check(Ge(a, five)) { `is`(contains(Eq(a, five)), unknown)(it) } + // a <= Long.MIN_VALUE is unsat + query.check(Le(a, Long.MIN_VALUE.primitiveToSymbolic())) { `is`(size(1), unknown)(it) } + } + + @Test + fun testGtSimplifications() { + val query: BaseQuery = Query() + + val a = mkBVConst("a", UtIntSort).toIntValue() + val five = 5.toPrimitiveValue() + val ten = 10.toPrimitiveValue() + val fifteen = 15.toPrimitiveValue() + val eleven = 11.toPrimitiveValue() + val sixteen = 16.toPrimitiveValue() + // geQuery = Query(a > 10) + val gtQuery = query.check(Gt(a, ten)) { + `is`(size(1), unknown)(it) + } + // a > 10, a > 5, a >= 10, a < 15 === a > 10, a < 15 + gtQuery.check(Gt(a, five), Ge(a, ten), Lt(a, fifteen)) { + `is`(contains(Gt(a, ten)), contains(Lt(a, fifteen)), unknown)(it) + } + // a > 10, a <= 11 === a == 11 + gtQuery.check(Le(a, eleven)) { `is`(contains(Eq(a, eleven)), unknown)(it) } + // a > 10, a <= 10 is unsat + gtQuery.checkUnsat(Le(a, ten)) + // a > 10, a < 10 is unsat + gtQuery.checkUnsat(Lt(a, ten)) + // a > 10, a == 10 is unsat + gtQuery.checkUnsat(Eq(a, ten)) + val greaterGtQuery = gtQuery.check(Gt(a, fifteen)) { `is`(size(1), unknown)(it) } + // a > 15, a <= 15 is unsat + greaterGtQuery.checkUnsat(Le(a, fifteen)) + // a > 15, a <= 16 === a == 16 + greaterGtQuery.check(Le(a, sixteen)) { `is`(contains(Eq(a, sixteen)), unknown)(it) } + // a > Long.MAX_VALUE is unsat + query.checkUnsat(Gt(a, Long.MAX_VALUE.primitiveToSymbolic())) + } + + @Test + fun testGeSimplifications() { + val query: BaseQuery = Query() + + val a = mkBVConst("a", UtIntSort).toIntValue() + val five = 5.toPrimitiveValue() + val ten = 10.toPrimitiveValue() + val fifteen = 15.toPrimitiveValue() + val eleven = 11.toPrimitiveValue() + // geQuery = Query(a >= 10) + val geQuery = query.check(Ge(a, ten)) { + `is`(size(1), unknown)(it) + } + // a >= 10, a > 5, a > 10, a < 15 === a > 10, a < 15 + geQuery.check(Gt(a, five), Gt(a, ten), Lt(a, fifteen)) { + `is`(contains(Gt(a, ten)), contains(Lt(a, fifteen)), unknown)(it) + } + // a >= 10, a < 11 === a == 10 + geQuery.check(Lt(a, eleven)) { `is`(contains(Eq(a, ten)), unknown)(it) } + // a >= 10, a <= 10 === a == 10 + geQuery.check(Le(a, ten)) { `is`(contains(Eq(a, ten)), unknown)(it) } + // a >= 10, a < 10 is unsat + geQuery.checkUnsat(Lt(a, ten)) + // a >= 10, a == 5 is unsat + geQuery.checkUnsat(Eq(a, five)) + val greaterGeQuery = geQuery.check(Ge(a, fifteen)) { `is`(size(1), unknown)(it) } + // a >= 15, a < 15 is unsat + greaterGeQuery.checkUnsat(Lt(a, fifteen)) + // a >= 15, a <= 15 === a == 15 + greaterGeQuery.check(Le(a, fifteen)) { `is`(contains(Eq(a, fifteen)), unknown)(it) } + // a >= Long.MaxVAlue is sat + query.check(Ge(a, Long.MAX_VALUE.primitiveToSymbolic())) { `is`(size(1), unknown)(it) } + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/engine/z3/ExtensionsKtTest.kt b/utbot-testing/src/test/kotlin/org/utbot/engine/z3/ExtensionsKtTest.kt new file mode 100644 index 0000000000..6beffa785e --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/engine/z3/ExtensionsKtTest.kt @@ -0,0 +1,396 @@ +@file:Suppress("unused") + +package org.utbot.engine.z3 + +import org.utbot.engine.pc.Z3Variable +import com.microsoft.z3.BoolExpr +import com.microsoft.z3.FPExpr +import com.microsoft.z3.Sort +import kotlin.random.Random +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.Arguments.arguments +import org.junit.jupiter.params.provider.MethodSource +import org.utbot.engine.z3.ExtensionsKtTest.Companion.toSort +import soot.BooleanType +import soot.ByteType +import soot.CharType +import soot.DoubleType +import soot.FloatType +import soot.IntType +import soot.LongType +import soot.ShortType +import soot.Type + +internal class ExtensionsKtTest { + @ParameterizedTest + @MethodSource("convertVarArgs") + fun testConvertVar(variable: Z3Variable, type: Type) { + val expr = variable.expr + when { + // this fine, we don't have such conversion, so let's check fail here + expr is FPExpr && type is BooleanType -> assertThrows { + context.convertVar( + variable, + type + ) + } + expr is BoolExpr && type !is BooleanType -> assertThrows { + context.convertVar( + variable, + type + ) + } + else -> { + val alignVar = context.convertVar(variable, type) + assertEquals(type, alignVar.type) + assertEquals(context.toSort(type), alignVar.expr.sort) + } + } + } + + @ParameterizedTest + @MethodSource("conversions") + fun testConversions(conversion: Conversion) { + with(conversion) { + for ((i, number) in numbers.withIndex()) { + testConversions(number, numbers.subList(i + 1, numbers.size)) + } + } + } + + @ParameterizedTest + @MethodSource("fromCharArgs") + fun testFromChar(from: Char, result: Number) { + testCharJavaConversion(from, result) + val variable = variable(from) + val value = context.convertVar(variable, result.toType()).expr.simplify().value() + when (result) { + is Byte -> assertEquals(result, value as Byte) { "$from to $result" } + is Short -> assertEquals(result, value as Short) { "$from to $result" } + is Int -> assertEquals(result, value as Int) { "$from to $result" } + is Long -> assertEquals(result, value as Long) { "$from to $result" } + is Float -> assertEquals(result, value as Float) { "$from to $result" } + is Double -> assertEquals(result, value as Double) { "$from to $result" } + } + } + + @ParameterizedTest + @MethodSource("toCharArgs") + fun testToChar(from: Number, result: Char) { + assertEquals(result, from.toChar()) { + "Java: $from (${ + from.toChar().prettify() + }) to $result (${result.prettify()})" + } + val variable = variable(from) + val value = context.convertVar(variable, CharType.v()).expr.simplify().value(true) as Char + assertEquals(result, value) { "$from to $result" } + } + + @ParameterizedTest + @MethodSource("fromSolverStringArgs") + fun testConvertFromSolver(from: String, to: String) { + val converted = convertSolverString(from) + assertEquals(to, converted) { "${to.codes()} != ${converted.codes()}" } + } + + private fun String.codes() = map { it.toInt() }.joinToString() + + private fun testConversions(from: Number, to: List) { + to.forEach { result -> + testJavaConversion(from, result) + val variable = variable(from) + val value = context.convertVar(variable, result.toType()).expr.simplify().value() + when (result) { + is Byte -> assertEquals(result, value as Byte) { "$from to $result" } + is Short -> assertEquals(result, value as Short) { "$from to $result" } + is Int -> assertEquals(result, value as Int) { "$from to $result" } + is Long -> assertEquals(result, value as Long) { "$from to $result" } + is Float -> assertEquals(result, value as Float) { "$from to $result" } + is Double -> assertEquals(result, value as Double) { "$from to $result" } + } + } + } + + private fun testJavaConversion(from: Number, result: Number) { + when (result) { + is Byte -> assertEquals(result, from.toByte()) { "Java: $from to $result" } + is Short -> assertEquals(result, from.toShort()) { "Java: $from to $result" } + is Int -> assertEquals(result, from.toInt()) { "Java: $from to $result" } + is Long -> assertEquals(result, from.toLong()) { "Java: $from to $result" } + is Float -> assertEquals(result, from.toFloat()) { "Java: $from to $result" } + is Double -> assertEquals(result, from.toDouble()) { "Java: $from to $result" } + } + } + + private fun testCharJavaConversion(from: Char, result: Number) { + when (result) { + is Byte -> assertEquals(result, from.toByte()) { "Java: $from to $result" } + is Short -> assertEquals(result, from.toShort()) { "Java: $from to $result" } + is Int -> assertEquals(result, from.toInt()) { "Java: $from to $result" } + is Long -> assertEquals(result, from.toLong()) { "Java: $from to $result" } + is Float -> assertEquals(result, from.toFloat()) { "Java: $from to $result" } + is Double -> assertEquals(result, from.toDouble()) { "Java: $from to $result" } + } + } + + companion object : Z3Initializer() { + @JvmStatic + fun convertVarArgs() = + series.flatMap { left -> series.map { right -> arguments(left, right.type) } } + + private val series = listOf( + Z3Variable(ByteType.v(), context.mkBV(Random.nextInt(0, 100), Byte.SIZE_BITS)), + Z3Variable(ShortType.v(), context.mkBV(Random.nextInt(0, 100), Short.SIZE_BITS)), + Z3Variable(CharType.v(), context.mkBV(Random.nextInt(50000, 60000), Char.SIZE_BITS)), + Z3Variable(IntType.v(), context.mkBV(Random.nextInt(0, 100), Int.SIZE_BITS)), + Z3Variable(LongType.v(), context.mkBV(Random.nextInt(0, 100), Long.SIZE_BITS)), + Z3Variable(FloatType.v(), context.mkFP(Random.nextFloat(), context.mkFPSort32())), + Z3Variable(DoubleType.v(), context.mkFP(Random.nextDouble(), context.mkFPSort64())), + Z3Variable(BooleanType.v(), context.mkBool(Random.nextBoolean())) + ) + + /** + * Arguments for conversion checks. + * + * How to read conversion line: from left to right each number can be converted to all following, + * so Conversion(100.toByte(), 100.toShort(), 100, 100L) means it checks: + * - byte to short, int, long + * - short to int, long + * - int to long + * + * Notes: + * - char primitive class is missing with its conversions + * + * @see + * Java Language Specification + */ + @JvmStatic + fun conversions() = listOf( + // A widening, from an integral type to another integral type, sign-extends + Conversion((-100).toByte(), (-100).toShort(), -100, -100L), + Conversion(100.toByte(), 100.toShort(), 100, 100L), + + /** + * A narrowing conversion may lose information about the overall magnitude of a numeric value + * and may also lose precision and range. + * Integral: simply discards all but the n lowest order bits + */ + Conversion(-100L, -100, (-100).toShort(), (-100).toByte()), + Conversion(0x1111222233334444L, 0x33334444, (0x4444).toShort(), (0x44).toByte()), + Conversion(4000000012L, -294967284, 10252.toShort(), 12.toByte()), + Conversion(-1L, -1, (-1).toShort(), (-1).toByte()), + + // Int to float, long to double, may lose some of the least significant bits of the value + Conversion(1234567890, 1.23456794E9f), + Conversion(-1234567890, -1.23456794E9f), + Conversion(6000372036854775807L, 6.0003720368547758E18), + Conversion(-6000372036854775807L, -6.0003720368547758E18), + + /** + * Double to float, narrowing. + * A finite value too small to be represented as a float is converted to a zero of the same sign; + * a finite value too large to be represented as a float is converted to an infinity of the same sign. + * A double NaN is converted to a float NaN. + */ + Conversion(100.0, 100.0f), + Conversion(-100.0, -100.0f), + Conversion(Double.NaN, Float.NaN), + Conversion(Double.POSITIVE_INFINITY, Float.POSITIVE_INFINITY), + Conversion(Double.MAX_VALUE, Float.POSITIVE_INFINITY), + Conversion(1E40, Float.POSITIVE_INFINITY), + Conversion(Double.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY), + Conversion(-Double.MAX_VALUE, Float.NEGATIVE_INFINITY), + Conversion(-1E40, Float.NEGATIVE_INFINITY), + Conversion(0.0, 0.0f), + Conversion(-0.0, -0.0f), + Conversion(Double.MIN_VALUE, 0.0f), + Conversion(-Double.MIN_VALUE, -0.0f), + + /** + * Float to double, widening. + * A float infinity is converted to a double infinity of the same sign. + * A float NaN is converted to a double NaN. + */ + Conversion(100.0f, 100.0), + Conversion(-100.0f, -100.0), + Conversion(Float.NaN, Double.NaN), + Conversion(Float.POSITIVE_INFINITY, Double.POSITIVE_INFINITY), + Conversion(Float.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), + Conversion(0.0f, 0.0), + Conversion(-0.0f, -0.0), + + // float/double to long + Conversion(100.999, 100L), + Conversion(-100.999, -100L), + Conversion(0.0, 0L), + Conversion(-0.0, 0L), + Conversion(Double.MIN_VALUE, 0L), + Conversion(-Double.MIN_VALUE, 0L), + Conversion(100.999f, 100L), + Conversion(-100.999f, -100L), + Conversion(0.0f, 0L), + Conversion(-0.0f, -0L), + + // Special cases + Conversion(Float.NaN, 0L), + Conversion(Float.POSITIVE_INFINITY, Long.MAX_VALUE), + Conversion(Float.NEGATIVE_INFINITY, Long.MIN_VALUE), + Conversion(Double.NaN, 0L), + Conversion(Double.POSITIVE_INFINITY, Long.MAX_VALUE), + Conversion(Double.MAX_VALUE, Long.MAX_VALUE), + Conversion(1E40, Long.MAX_VALUE), + Conversion(Double.NEGATIVE_INFINITY, Long.MIN_VALUE), + Conversion(-Double.MAX_VALUE, Long.MIN_VALUE), + Conversion(-1E40, Long.MIN_VALUE), + + // float/double to int + Conversion(100.999, 100), + Conversion(-100.999, -100), + Conversion(0.0, 0), + Conversion(-0.0, 0), + Conversion(Double.MIN_VALUE, 0), + Conversion(-Double.MIN_VALUE, 0), + Conversion(100.999f, 100), + Conversion(-100.999f, -100), + Conversion(0.0f, 0), + Conversion(-0.0f, -0), + + // Special cases + Conversion(Float.NaN, 0), + Conversion(Float.POSITIVE_INFINITY, Int.MAX_VALUE), + Conversion(Float.NEGATIVE_INFINITY, Int.MIN_VALUE), + Conversion(Double.NaN, 0), + Conversion(Double.POSITIVE_INFINITY, Int.MAX_VALUE), + Conversion(Double.MAX_VALUE, Int.MAX_VALUE), + Conversion(1E40, Int.MAX_VALUE), + Conversion(Double.NEGATIVE_INFINITY, Int.MIN_VALUE), + Conversion(-Double.MAX_VALUE, Int.MIN_VALUE), + Conversion(-1E40, Int.MIN_VALUE), + + // float/double to byte (through int) + Conversion(100.999, 100.toByte()), + Conversion(-100.999, (-100).toByte()), + Conversion(0.0, 0.toByte()), + Conversion(-0.0, 0.toByte()), + Conversion(Double.MIN_VALUE, 0.toByte()), + Conversion(-Double.MIN_VALUE, 0.toByte()), + Conversion(100.999f, 100.toByte()), + Conversion(-100.999f, (-100).toByte()), + Conversion(0.0f, 0.toByte()), + Conversion(-0.0f, (-0).toByte()), + + // Special cases + Conversion(Float.NaN, 0.toByte()), + Conversion(Float.POSITIVE_INFINITY, (-1).toByte()), // narrowing from int to byte + Conversion(Float.NEGATIVE_INFINITY, 0.toByte()), // narrowing from int to byte + Conversion(Double.NaN, 0.toByte()), + Conversion(Double.POSITIVE_INFINITY, (-1).toByte()), // narrowing from int to byte + Conversion(Double.MAX_VALUE, (-1).toByte()), // narrowing from int to byte + Conversion(1E40, (-1).toByte()), // narrowing from int to byte + Conversion(Double.NEGATIVE_INFINITY, 0.toByte()), // narrowing from int to byte + Conversion(-Double.MAX_VALUE, 0.toByte()), // narrowing from int to byte + Conversion(-1E40, 0.toByte()), // narrowing from int to byte + ) + + @JvmStatic + fun fromCharArgs() = listOf( + arguments('\u9999', (-103).toByte()), + arguments('\u9999', (-26215).toShort()), + arguments('\u9999', 39321), + arguments('\u9999', 39321L), + arguments('\u9999', 39321.0f), + arguments('\u9999', 39321.0), + ) + + @JvmStatic + fun toCharArgs() = listOf( + arguments((-103).toByte(), '\uFF99'), + arguments(103.toByte(), '\u0067'), + arguments((-26215).toShort(), '\u9999'), + arguments(26215.toShort(), '\u6667'), + arguments(1234567890, '\u02D2'), + arguments(-1234567890, '\uFD2E'), + arguments(6000372036854775807L, '\u7FFF'), + arguments(-6000372036854775807L, '\u8001'), + + // float/double to char (through int) + arguments(-39321.0, '\u6667'), + arguments(100.999, '\u0064'), + arguments(-100.999, '\uFF9C'), + arguments(0.0, '\u0000'), + arguments(-0.0, '\u0000'), + arguments(Double.MIN_VALUE, '\u0000'), + arguments(-Double.MIN_VALUE, '\u0000'), + arguments(-39321.0f, '\u6667'), + arguments(100.999f, '\u0064'), + arguments(-100.999f, '\uFF9C'), + arguments(0.0f, '\u0000'), + arguments(-0.0f, '\u0000'), + + // Special cases + arguments(Float.NaN, '\u0000'), + arguments(Float.POSITIVE_INFINITY, '\uFFFF'), // narrowing from int to char + arguments(Float.NEGATIVE_INFINITY, '\u0000'), // narrowing from int to char + arguments(Double.NaN, '\u0000'), + arguments(Double.POSITIVE_INFINITY, '\uFFFF'), // narrowing from int to char + arguments(Double.MAX_VALUE, '\uFFFF'), // narrowing from int to char + arguments(1E40, '\uFFFF'), // narrowing from int to char + arguments(Double.NEGATIVE_INFINITY, '\u0000'), // narrowing from int to char + arguments(-Double.MAX_VALUE, '\u0000'), // narrowing from int to char + arguments(-1E40, '\u0000'), // narrowing from int to char + ) + + @JvmStatic + fun fromSolverStringArgs() = listOf( + arguments("", ""), + arguments("\\a", "\u0007"), + arguments("\\b", "\b"), + arguments("\\f", "\u000C"), + arguments("\\n", "\n"), + arguments("\\r", "\r"), + arguments("\\t", "\t"), + arguments("\\v", "\u000B"), + + arguments("\\x00", "\u0000"), + arguments("\\xAB", "\u00AB"), + arguments("AaBbCc (){}[]<>,.!@#$%^&*-=_+/?`~\\\\", "AaBbCc (){}[]<>,.!@#$%^&*-=_+/?`~\\"), + ) + + private fun variable(from: Any): Z3Variable = when (from) { + is Number -> Z3Variable(from.toType(), context.makeConst(from, from.toSort())) + is Char -> Z3Variable(CharType.v(), context.mkBV(from.toInt(), Char.SIZE_BITS)) + else -> error("Unknown constant: ${from::class}") + } + + private fun Any.toSort(): Sort = when (this) { + is Byte -> context.mkBitVecSort(Byte.SIZE_BITS) + is Short -> context.mkBitVecSort(Short.SIZE_BITS) + is Char -> context.mkBitVecSort(Char.SIZE_BITS) + is Int -> context.mkBitVecSort(Int.SIZE_BITS) + is Long -> context.mkBitVecSort(Long.SIZE_BITS) + is Float -> context.mkFPSort32() + is Double -> context.mkFPSort64() + else -> error("Unknown type $this") + } + + private fun Any.toType(): Type = when (this) { + is Byte -> ByteType.v() + is Short -> ShortType.v() + is Char -> CharType.v() + is Int -> IntType.v() + is Long -> LongType.v() + is Float -> FloatType.v() + is Double -> DoubleType.v() + else -> error("Unknown type $this") + } + } +} + +private fun Char.prettify(): String = "%04X".format(this.toInt()).let { "'\\u$it'" } + +data class Conversion(val numbers: List) { + constructor(vararg numbers: Number) : this(numbers.toList()) +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/engine/z3/OperatorsKtTest.kt b/utbot-testing/src/test/kotlin/org/utbot/engine/z3/OperatorsKtTest.kt new file mode 100644 index 0000000000..0325e4c873 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/engine/z3/OperatorsKtTest.kt @@ -0,0 +1,76 @@ +@file:Suppress("unused") + +package org.utbot.engine.z3 + +import org.utbot.engine.pc.Z3Variable +import com.microsoft.z3.BitVecSort +import com.microsoft.z3.BoolExpr +import com.microsoft.z3.FPExpr +import kotlin.random.Random +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.assertThrows +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.Arguments.arguments +import org.junit.jupiter.params.provider.MethodSource +import soot.BooleanType +import soot.ByteType +import soot.CharType +import soot.DoubleType +import soot.FloatType +import soot.IntType +import soot.LongType +import soot.ShortType + +internal class OperatorsKtTest { + @ParameterizedTest + @MethodSource("alignVarsArgs") + fun testAlignVars(left: Z3Variable, right: Z3Variable) { + if (left.expr is BoolExpr && right.expr is FPExpr || left.expr is FPExpr && right.expr is BoolExpr) { + // this fine, we don't have such conversion, so let's check fail here + assertThrows { context.alignVars(left, right) } + } else { + val (aleft, aright) = context.alignVars(left, right) + // Binary numeric promotion - byte, short and char converted to int before operation + if (left.expr.sort is BitVecSort && aleft.sort is BitVecSort) { + assertTrue((aleft.sort as BitVecSort).size >= Int.SIZE_BITS) + } + if (right.expr.sort is BitVecSort && aright.sort is BitVecSort) { + assertTrue((aright.sort as BitVecSort).size >= Int.SIZE_BITS) + } + assertEquals(aleft.sort, aright.sort) + } + } + + @ParameterizedTest + @MethodSource("alignVarArgs") + fun testAlignVar(variable: Z3Variable) { + val aligned = context.alignVar(variable) + // Unary numeric promotion - byte, short and char converted to int before operation + if (variable.expr.sort is BitVecSort && (variable.expr.sort as BitVecSort).size < Int.SIZE_BITS) { + assertTrue((aligned.expr.sort as BitVecSort).size == Int.SIZE_BITS) + } else { + assertEquals(variable, aligned) + } + } + + companion object : Z3Initializer() { + @JvmStatic + fun alignVarsArgs() = + series.flatMap { left -> series.map { right -> arguments(left, right) } } + + @JvmStatic + fun alignVarArgs() = series + + private val series = listOf( + Z3Variable(ByteType.v(), context.mkBV(Random.nextInt(0, 100), Byte.SIZE_BITS)), + Z3Variable(ShortType.v(), context.mkBV(Random.nextInt(0, 100), Short.SIZE_BITS)), + Z3Variable(CharType.v(), context.mkBV(Random.nextInt(50000, 60000), Char.SIZE_BITS)), + Z3Variable(IntType.v(), context.mkBV(Random.nextInt(0, 100), Int.SIZE_BITS)), + Z3Variable(LongType.v(), context.mkBV(Random.nextInt(0, 100), Long.SIZE_BITS)), + Z3Variable(FloatType.v(), context.mkFP(Random.nextFloat(), context.mkFPSort32())), + Z3Variable(DoubleType.v(), context.mkFP(Random.nextDouble(), context.mkFPSort64())), + Z3Variable(BooleanType.v(), context.mkBool(Random.nextBoolean())) + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/BinarySearchTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/BinarySearchTest.kt new file mode 100644 index 0000000000..f826a1d413 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/BinarySearchTest.kt @@ -0,0 +1,97 @@ +package org.utbot.examples.algorithms + +import org.utbot.framework.plugin.api.DocCodeStmt +import org.utbot.framework.plugin.api.DocPreTagStatement +import org.utbot.framework.plugin.api.DocRegularStmt +import org.utbot.framework.plugin.api.DocStatement +import org.junit.jupiter.api.Test +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException + +class BinarySearchTest : UtValueTestCaseChecker(testClass = BinarySearch::class,) { + @Test + fun testLeftBinarySearch() { + val fullSummary = listOf( + DocPreTagStatement( + listOf( + DocRegularStmt("Test "), + DocRegularStmt("does not iterate "), + DocCodeStmt("while(left < right - 1)"), + DocRegularStmt(", "), + DocRegularStmt("executes conditions:\n"), + DocRegularStmt(" "), + DocCodeStmt("(found): False"), + DocRegularStmt("\n"), + DocRegularStmt("returns from: "), + DocCodeStmt("return -1;"), + DocRegularStmt("\n") + + ) + ) + ) + checkWithException( + BinarySearch::leftBinSearch, + ignoreExecutionsNumber, + { a, _, r -> a == null && r.isException() }, + { a, _, r -> a.size >= 2 && a[0] > a[1] && r.isException() }, + { a, _, r -> a.isEmpty() && r.getOrNull() == -1 }, + { a, key, r -> a.isNotEmpty() && key >= a[(a.size - 1) / 2] && key !in a && r.getOrNull() == -1 }, + { a, key, r -> a.isNotEmpty() && key in a && r.getOrNull() == a.indexOfFirst { it == key } + 1 }, + // TODO enable it JIRA:1442 + /* + summaryTextChecks = listOf( + keyContain(DocCodeStmt("(found): False")), + keyContain(DocCodeStmt("(found): True")), + keyContain(DocRegularStmt(" BinarySearch::isUnsorted once")), + keyContain(DocRegularStmt("throws NullPointerException in: isUnsorted(array)")), + keyContain(DocRegularStmt("throws IllegalArgumentException after condition: isUnsorted(array)")), + keyContain(DocCodeStmt("(array[middle] < key): True")), + keyContain(DocCodeStmt("(array[middle] == key): True")), + keyContain(DocCodeStmt("(array[middle] < key): True")), + keyMatch(fullSummary) + ), + summaryNameChecks = listOf( + keyContain("testLeftBinSearch_BinarySearchIsUnsorted"), + keyContain("testLeftBinSearch_ThrowIllegalArgumentException"), + keyContain("testLeftBinSearch_NotFound"), + keyContain("testLeftBinSearch_MiddleOfArrayLessThanKey"), + keyContain("testLeftBinSearch_Found") + ), + summaryDisplayNameChecks = listOf( + keyMatch("isUnsorted(array) -> ThrowIllegalArgumentException"), + keyMatch("isUnsorted(array) -> ThrowIllegalArgumentException"), + keyMatch("found : False -> return -1"), + keyMatch("array[middle] == key : True -> return right + 1"), + keyMatch("array[middle] < key : True -> return -1") + ) + */ + ) + } + + @Test + fun testRightBinarySearch() { + checkWithException( + BinarySearch::rightBinSearch, + ignoreExecutionsNumber, + { a, _, r -> a == null && r.isException() }, + { a, _, r -> a.isEmpty() && r.getOrNull() == -1 }, + { a, _, r -> a.size >= 2 && a[0] > a[1] && r.isException() }, + { a, key, r -> a.isNotEmpty() && key !in a && r.getOrNull() == -1 }, + { a, key, r -> a.isNotEmpty() && key in a && r.getOrNull() == a.indexOfLast { it == key } + 1 } + ) + } + + @Test + fun testDefaultBinarySearch() { + checkWithException( + BinarySearch::defaultBinarySearch, + ignoreExecutionsNumber, + { a, _, r -> a == null && r.isException() }, + { a, _, r -> a.isEmpty() && r.getOrNull() == -1 }, + { a, _, r -> a.size >= 2 && a[0] > a[1] && r.isException() }, + { a, key, r -> a.isNotEmpty() && key < a.first() && r.getOrNull() == a.binarySearch(key) }, + { a, key, r -> a.isNotEmpty() && key == a.first() && r.getOrNull() == a.binarySearch(key) }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt new file mode 100644 index 0000000000..415d7e0b12 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt @@ -0,0 +1,145 @@ +package org.utbot.examples.algorithms + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.framework.plugin.api.DocCodeStmt +import org.utbot.framework.plugin.api.DocPreTagStatement +import org.utbot.framework.plugin.api.DocRegularStmt +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class CorrectBracketSequencesTest : UtValueTestCaseChecker( + testClass = CorrectBracketSequences::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) // TODO generics in lists + ) +) { + @Test + fun testIsOpen() { + val isOpenSummary = listOf( + DocPreTagStatement( + listOf( + DocRegularStmt("Test "), + DocRegularStmt("returns from: "), + DocCodeStmt("return a == '(' || a == '{' || a == '[';"), + DocRegularStmt("\n") + ) + ) + ) + + checkStaticMethod( + CorrectBracketSequences::isOpen, + eq(4), + { c, r -> c == '(' && r == true }, + { c, r -> c == '{' && r == true }, + { c, r -> c == '[' && r == true }, + { c, r -> c !in "({[".toList() && r == false }, + summaryNameChecks = listOf( + keyMatch("testIsOpen_AEqualsCharOrAEqualsCharOrAEqualsChar"), + keyMatch("testIsOpen_ANotEqualsCharOrANotEqualsCharOrANotEqualsChar") + ), + summaryDisplayNameChecks = listOf( + keyMatch("return a == '(' || a == '{' || a == '[' : False -> return a == '(' || a == '{' || a == '['"), + keyMatch("return a == '(' || a == '{' || a == '[' : True -> return a == '(' || a == '{' || a == '['") + ), + summaryTextChecks = listOf( + keyMatch(isOpenSummary) + ) + ) + } + + @Test + fun testIsBracket() { + val isBracketSummary = listOf( + DocPreTagStatement( + listOf( + DocRegularStmt("Test "), + DocRegularStmt("returns from: "), + DocCodeStmt("return isOpen(a) || a == ')' || a == '}' || a == ']';"), + DocRegularStmt("\n") + ) + ) + ) + checkStaticMethod( + CorrectBracketSequences::isBracket, + eq(7), + { c, r -> c == '(' && r == true }, + { c, r -> c == '{' && r == true }, + { c, r -> c == '[' && r == true }, + { c, r -> c == ')' && r == true }, + { c, r -> c == '}' && r == true }, + { c, r -> c == ']' && r == true }, + { c, r -> c !in "(){}[]".toList() && r == false }, + summaryNameChecks = listOf( + keyMatch("testIsBracket_IsOpenOrANotEqualsCharOrANotEqualsCharOrANotEqualsChar"), + keyMatch("testIsBracket_IsOpenOrAEqualsCharOrAEqualsCharOrAEqualsChar") + ), + summaryDisplayNameChecks = listOf( + keyMatch("return isOpen(a) || a == ')' || a == '}' || a == ']' : False -> return isOpen(a) || a == ')' || a == '}' || a == ']'"), + keyMatch("return isOpen(a) || a == ')' || a == '}' || a == ']' : True -> return isOpen(a) || a == ')' || a == '}' || a == ']'") + ), + summaryTextChecks = listOf( + keyMatch(isBracketSummary) + ) + ) + } + + @Test + fun testIsTheSameType() { + val isTheSameTypeSummary = listOf( + DocPreTagStatement( + listOf( + DocRegularStmt("Test "), + DocRegularStmt("returns from: "), + DocCodeStmt("return a == '(' && b == ')' || a == '{' && b == '}' || a == '[' && b == ']';"), + DocRegularStmt("\n") + ) + ) + ) + checkStaticMethod( + CorrectBracketSequences::isTheSameType, + ignoreExecutionsNumber, + { a, b, r -> a == '(' && b == ')' && r == true }, + { a, b, r -> a == '{' && b == '}' && r == true }, + { a, b, r -> a == '[' && b == ']' && r == true }, + { a, b, r -> a == '(' && b != ')' && r == false }, + { a, b, r -> a == '{' && b != '}' && r == false }, + { a, b, r -> a == '[' && b != ']' && r == false }, + { a, b, r -> (a != '(' || b != ')') && (a != '{' || b != '}') && (a != '[' || b != ']') && r == false }, + summaryNameChecks = listOf( + keyMatch("testIsTheSameType_ANotEqualsCharAndBNotEqualsCharOrANotEqualsCharAndBNotEqualsCharOrANotEqualsCharAndBNotEqualsChar"), + keyMatch("testIsTheSameType_AEqualsCharAndBEqualsCharOrAEqualsCharAndBEqualsCharOrAEqualsCharAndBEqualsChar"), + ), + summaryDisplayNameChecks = listOf( + keyMatch("return a == '(' && b == ')' || a == '{' && b == '}' || a == '[' && b == ']' : False -> return a == '(' && b == ')' || a == '{' && b == '}' || a == '[' && b == ']'"), + keyMatch("return a == '(' && b == ')' || a == '{' && b == '}' || a == '[' && b == ']' : True -> return a == '(' && b == ')' || a == '{' && b == '}' || a == '[' && b == ']'") + ), + summaryTextChecks = listOf( + keyMatch(isTheSameTypeSummary) + ) + ) + } + + @Test + fun testIsCbs() { + val method = CorrectBracketSequences::isCbs + checkStaticMethodWithException( + method, + ignoreExecutionsNumber, + { chars, r -> chars == null && r.isException() }, + { chars, r -> chars != null && chars.isEmpty() && r.getOrNull() == true }, + { chars, r -> chars.any { it == null } && r.isException() }, + { chars, r -> !isBracket(chars.first()) && r.getOrNull() == false }, + { chars, r -> !isOpen(chars.first()) && r.getOrNull() == false }, + { chars, _ -> isOpen(chars.first()) }, + { chars, r -> chars.all { isOpen(it) } && r.getOrNull() == false }, + { chars, _ -> + val charsWithoutFirstOpenBrackets = chars.dropWhile { isOpen(it) } + val firstNotOpenBracketChar = charsWithoutFirstOpenBrackets.first() + + isBracket(firstNotOpenBracketChar) && !isOpen(firstNotOpenBracketChar) + }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/GraphTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/GraphTest.kt new file mode 100644 index 0000000000..2ac25b02f9 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/GraphTest.kt @@ -0,0 +1,50 @@ +package org.utbot.examples.algorithms + +import org.junit.jupiter.api.Tag +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class GraphTest : UtValueTestCaseChecker(testClass = GraphExample::class) { + @Test + @Tag("slow") + fun testRunFindCycle() { + checkWithException( + GraphExample::runFindCycle, + ignoreExecutionsNumber, + { e, r -> e == null && r.isException() }, + { e, r -> e != null && e.contains(null) && r.isException() }, + { e, r -> e != null && e.any { it.first < 0 || it.first >= 10 } && r.isException() }, + { e, r -> e != null && e.any { it.second < 0 || it.second >= 10 } && r.isException() }, + { e, r -> e != null && e.all { it != null } && r.isSuccess } + ) + } + + @Test + fun testDijkstra() { + // The graph is fixed, there should be exactly one execution path, so no matchers are necessary + check( + GraphExample::runDijkstra, + eq(1) + ) + } + + /** + * TODO: fix Dijkstra algorithm. + */ + @Test + fun testRunDijkstraWithParameter() { + checkWithException( + GraphExample::runDijkstraWithParameter, + ignoreExecutionsNumber, + { g, r -> g == null && r.isException() }, + { g, r -> g.isEmpty() && r.isException() }, + { g, r -> g.size == 1 && r.getOrNull()?.size == 1 && r.getOrNull()?.first() == 0 }, + { g, r -> g.size > 1 && g[1] == null && r.isException() }, + { g, r -> g.isNotEmpty() && g.size != g.first().size && r.isException() }, + { g, r -> + val concreteResult = GraphExample().runDijkstraWithParameter(g) + g.isNotEmpty() && r.getOrNull().contentEquals(concreteResult) + } + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt new file mode 100644 index 0000000000..354558b3fb --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt @@ -0,0 +1,183 @@ +package org.utbot.examples.algorithms + +import org.utbot.framework.plugin.api.DocCodeStmt +import org.utbot.framework.plugin.api.DocPreTagStatement +import org.utbot.framework.plugin.api.DocRegularStmt +import org.utbot.framework.plugin.api.MockStrategyApi +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq +import org.utbot.testcheckers.ge + +// TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 +internal class SortTest : UtValueTestCaseChecker( + testClass = Sort::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testQuickSort() { + check( + Sort::quickSort, + ignoreExecutionsNumber, + mockStrategy = MockStrategyApi.OTHER_PACKAGES + ) + } + + @Test + fun testSwap() { + checkWithException( + Sort::swap, + ge(4), + { a, _, _, r -> a == null && r.isException() }, + { a, i, _, r -> a != null && (i < 0 || i >= a.size) && r.isException() }, + { a, i, j, r -> a != null && i in a.indices && (j < 0 || j >= a.size) && r.isException() }, + { a, i, j, _ -> a != null && i in a.indices && j in a.indices } + ) + } + + @Test + fun testArrayCopy() { + check( + Sort::arrayCopy, + eq(1), + { r -> r contentEquals intArrayOf(1, 2, 3) } + ) + } + + @Test + fun testMergeSort() { + check( + Sort::mergeSort, + eq(4), + { a, r -> a == null && r == null }, + { a, r -> a != null && r != null && a.size < 2 }, + { a, r -> + require(a is IntArray && r is IntArray) + + val sortedConstraint = a.size >= 2 && a.sorted() == r.toList() + + val maxInLeftHalf = a.slice(0 until a.size / 2).maxOrNull()!! + val maxInRightHalf = a.slice(a.size / 2 until a.size).maxOrNull()!! + + sortedConstraint && maxInLeftHalf >= maxInRightHalf + }, + { a, r -> + require(a is IntArray && r is IntArray) + + val sortedConstraint = a.size >= 2 && a.sorted() == r.toList() + + val maxInLeftHalf = a.slice(0 until a.size / 2).maxOrNull()!! + val maxInRightHalf = a.slice(a.size / 2 until a.size).maxOrNull()!! + + sortedConstraint && maxInLeftHalf < maxInRightHalf + }, + ) + } + + @Test + fun testMerge() { + checkWithException( + Sort::merge, + eq(6), + { lhs, _, r -> lhs == null && r.isException() }, + { lhs, rhs, r -> lhs != null && lhs.isEmpty() && r.getOrNull() contentEquals rhs }, + { lhs, rhs, _ -> lhs != null && lhs.isNotEmpty() && rhs == null }, + { lhs, rhs, r -> + val lhsCondition = lhs != null && lhs.isNotEmpty() + val rhsCondition = rhs != null && rhs.isEmpty() + val connection = r.getOrNull() contentEquals lhs + + lhsCondition && rhsCondition && connection + }, + { lhs, rhs, r -> + val lhsCondition = lhs != null && lhs.isNotEmpty() + val rhsCondition = rhs != null && rhs.isNotEmpty() + val connection = lhs.last() < rhs.last() && r.getOrNull()?.toList() == (lhs + rhs).sorted() + + lhsCondition && rhsCondition && connection + }, + { lhs, rhs, r -> + val lhsCondition = lhs != null && lhs.isNotEmpty() + val rhsCondition = rhs != null && rhs.isNotEmpty() + val connection = lhs.last() >= rhs.last() && r.getOrNull()?.toList() == (lhs + rhs).sorted() + + lhsCondition && rhsCondition && connection + }, + ) + } + + @Test + fun testDefaultSort() { + val defaultSortSummary1 = listOf( + DocPreTagStatement( + listOf( + DocRegularStmt("Test "), + DocRegularStmt("\n"), + DocRegularStmt("throws NullPointerException in: array.length < 4"), + DocRegularStmt("\n") + ) + ) + ) + + val defaultSortSummary2 = listOf( + DocPreTagStatement( + listOf( + DocRegularStmt("Test "), + DocRegularStmt("executes conditions:\n"), + DocRegularStmt(" "), + DocCodeStmt("(array.length < 4): True"), + DocRegularStmt("\n"), + DocRegularStmt("\n"), + DocRegularStmt("throws IllegalArgumentException after condition: array.length < 4"), + DocRegularStmt("\n") + ) + ) + ) + val defaultSortSummary3 = listOf( + DocPreTagStatement( + listOf( + DocRegularStmt("Test "), + DocRegularStmt("executes conditions:\n"), + DocRegularStmt(" "), + DocCodeStmt("(array.length < 4): False"), + DocRegularStmt("\n"), + DocRegularStmt("invokes:\n"), + DocRegularStmt(" {@link java.util.Arrays#sort(int[])} once"), + DocRegularStmt("\n"), + DocRegularStmt("returns from: "), + DocCodeStmt("return array;"), + DocRegularStmt("\n") + ) + ) + ) + checkWithException( + Sort::defaultSort, + eq(3), + { a, r -> a == null && r.isException() }, + { a, r -> a != null && a.size < 4 && r.isException() }, + { a, r -> + val resultArray = intArrayOf(-100, 0, 100, 200) + a != null && r.getOrNull()!!.size >= 4 && r.getOrNull() contentEquals resultArray + }, + summaryTextChecks = listOf( + keyMatch(defaultSortSummary1), + keyMatch(defaultSortSummary2), + keyMatch(defaultSortSummary3), + ), + summaryNameChecks = listOf( + keyMatch("testDefaultSort_ThrowNullPointerException"), + keyMatch("testDefaultSort_ArrayLengthLessThan4"), + keyMatch("testDefaultSort_ArrayLengthGreaterOrEqual4"), + ), + summaryDisplayNameChecks = listOf( + keyMatch("array.length < 4 -> ThrowNullPointerException"), + keyMatch("array.length < 4 -> ThrowIllegalArgumentException"), + keyMatch("array.length < 4 : False -> return array"), + ) + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/NotNullAnnotationTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/NotNullAnnotationTest.kt new file mode 100644 index 0000000000..6ba1d8bf06 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/NotNullAnnotationTest.kt @@ -0,0 +1,101 @@ +package org.utbot.examples.annotations + +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker + +internal class NotNullAnnotationTest : UtValueTestCaseChecker(testClass = NotNullAnnotation::class) { + @Test + fun testDoesNotThrowNPE() { + check( + NotNullAnnotation::doesNotThrowNPE, + eq(1), + { value, r -> value == r } + ) + } + + @Test + fun testThrowsNPE() { + check( + NotNullAnnotation::throwsNPE, + eq(2), + { value, _ -> value == null }, + { value, r -> value == r } + ) + } + + @Test + fun testSeveralParameters() { + check( + NotNullAnnotation::severalParameters, + eq(2), + { _, second, _, _ -> second == null }, + { first, second, third, result -> first + second + third == result } + ) + } + + @Test + fun testUseNotNullableValue() { + check( + NotNullAnnotation::useNotNullableValue, + eq(1), + { value, r -> value == r } + ) + } + + @Test + @Disabled("Annotations for local variables are not supported yet") + fun testNotNullableVariable() { + check( + NotNullAnnotation::notNullableVariable, + eq(1), + { first, second, third, r -> first + second + third == r } + ) + } + + @Test + fun testNotNullField() { + check( + NotNullAnnotation::notNullField, + eq(1), + { value, result -> value.boxedInt == result } + ) + } + + @Test + fun testNotNullStaticField() { + checkStatics( + NotNullAnnotation::notNullStaticField, + eq(1), + { statics, result -> result == statics.values.single().value } + ) + } + + @Test + fun testJavaxValidationNotNull() { + check( + NotNullAnnotation::javaxValidationNotNull, + eq(1), + { value, r -> value == r } + ) + } + + @Test + fun testFindBugsNotNull() { + check( + NotNullAnnotation::findBugsNotNull, + eq(1), + { value, r -> value == r } + ) + } + + @Test + fun testJavaxNotNull() { + check( + NotNullAnnotation::javaxNotNull, + eq(1), + { value, r -> value == r } + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithAnnotationsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithAnnotationsTest.kt new file mode 100644 index 0000000000..b4c8097e10 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithAnnotationsTest.kt @@ -0,0 +1,25 @@ +package org.utbot.examples.annotations.lombok + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker + +/** + * Tests for Lombok annotations + * + * We do not calculate coverage here as Lombok always make it pure + * (see, i.e. https://stackoverflow.com/questions/44584487/improve-lombok-data-code-coverage) + * and Lombok code is considered to be already tested itself. + */ +internal class EnumWithAnnotationsTest : UtValueTestCaseChecker(testClass = EnumWithAnnotations::class) { + @Test + fun testGetterWithAnnotations() { + check( + EnumWithAnnotations::getConstant, + eq(1), + { r -> r == "Constant_1" }, + coverage = DoNotCalculate, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithoutAnnotationsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithoutAnnotationsTest.kt new file mode 100644 index 0000000000..c9977326d6 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithoutAnnotationsTest.kt @@ -0,0 +1,16 @@ +package org.utbot.examples.annotations.lombok + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker + +internal class EnumWithoutAnnotationsTest : UtValueTestCaseChecker(testClass = EnumWithoutAnnotations::class) { + @Test + fun testGetterWithoutAnnotations() { + check( + EnumWithoutAnnotations::getConstant, + eq(1), + { r -> r == "Constant_1" }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/NotNullAnnotationsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/NotNullAnnotationsTest.kt new file mode 100644 index 0000000000..1d3e95b33c --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/NotNullAnnotationsTest.kt @@ -0,0 +1,25 @@ +package org.utbot.examples.annotations.lombok + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker + +/** + * Tests for Lombok NonNull annotation + * + * We do not calculate coverage here as Lombok always make it pure + * (see, i.e. https://stackoverflow.com/questions/44584487/improve-lombok-data-code-coverage) + * and Lombok code is considered to be already tested itself. + */ +internal class NotNullAnnotationsTest : UtValueTestCaseChecker(testClass = NotNullAnnotations::class) { + @Test + fun testNonNullAnnotations() { + check( + NotNullAnnotations::lombokNonNull, + eq(1), + { value, r -> value == r }, + coverage = DoNotCalculate, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayOfArraysTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayOfArraysTest.kt new file mode 100644 index 0000000000..4aa433b0b7 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayOfArraysTest.kt @@ -0,0 +1,283 @@ +package org.utbot.examples.arrays + +import org.junit.jupiter.api.Disabled +import org.utbot.examples.casts.ColoredPoint +import org.utbot.examples.casts.Point +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testcheckers.withoutMinimization +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast +import org.utbot.testing.ignoreExecutionsNumber + +@Suppress("NestedLambdaShadowedImplicitParameter") +internal class ArrayOfArraysTest : UtValueTestCaseChecker(testClass = ArrayOfArrays::class) { + @Test + fun testDefaultValues() { + check( + ArrayOfArrays::defaultValues, + eq(1), + { r -> r != null && r.single() == null }, + coverage = atLeast(50) + ) + } + + @Test + fun testExample() { + check( + ArrayOfArrays::sizesWithoutTouchingTheElements, + eq(1), + { r -> r != null && r.size == 10 && r.all { it.size == 3 && it.all { it == 0 } } }, + ) + } + + @Test + fun testDefaultValuesWithoutLastDimension() { + check( + ArrayOfArrays::defaultValuesWithoutLastDimension, + eq(1), + { r -> r != null && r.all { it.size == 4 && it.all { it.size == 4 && it.all { it == null } } } }, + coverage = atLeast(50) + ) + } + + @Test + fun testCreateNewMultiDimensionalArray() { + withoutMinimization { // TODO: JIRA:1506 + check( + ArrayOfArrays::createNewMultiDimensionalArray, + eq(4), + { i, j, _ -> i < 0 || j < 0 }, + { i, j, r -> i == 0 && j >= 0 && r != null && r.size == 2 && r.all { it.isEmpty() } }, + { i, j, r -> + val indicesConstraint = i > 0 && j == 0 + val arrayPropertiesConstraint = r != null && r.size == 2 + val arrayContentConstraint = r?.all { it.size == i && it.all { it.isEmpty() } } ?: false + + indicesConstraint && arrayPropertiesConstraint && arrayContentConstraint + }, + { i, j, r -> + val indicesConstraint = i > 0 && j > 0 + val arrayPropertiesConstraint = r != null && r.size == 2 + val arrayContentConstraint = + r?.all { + it.size == i && it.all { + it.size == j && it.all { + it.size == 3 && it.all { it == 0 } + } + } + } + + indicesConstraint && arrayPropertiesConstraint && (arrayContentConstraint ?: false) + } + ) + } + } + + @Test + fun testDefaultValuesWithoutTwoDimensions() { + check( + ArrayOfArrays::defaultValuesWithoutTwoDimensions, + eq(2), + { i, r -> i < 2 && r == null }, + { i, r -> i >= 2 && r != null && r.all { it.size == i && it.all { it == null } } }, + coverage = atLeast(75) + ) + } + + @Test + fun testDefaultValuesNewMultiArray() { + check( + ArrayOfArrays::defaultValuesNewMultiArray, + eq(1), + { r -> r != null && r.single().single().single() == 0 }, + coverage = atLeast(50) + ) + } + + @Test + fun testSimpleExample() { + check( + ArrayOfArrays::simpleExample, + eq(7), + { m, r -> m.size >= 3 && m[1] === m[2] && r == null }, + { m, r -> m.size >= 3 && m[1] !== m[2] && m[0] === m[2] && r == null }, + { m, _ -> m.size >= 3 && m[1].size < 2 }, + { m, _ -> m.size >= 3 && m[1][1] == 1 && m[2].size < 3 }, + { m, r -> m.size >= 3 && m[1][1] == 1 && m[2].size >= 3 && r != null && r[2][2] == 2 }, + { m, _ -> m.size >= 3 && m[1][1] != 1 && m[2].size < 3 }, + { m, r -> m.size >= 3 && m[1][1] != 1 && m[2].size >= 3 && r != null && r[2][2] == -2 }, + coverage = DoNotCalculate // because of assumes + ) + } + + @Test + fun testSimpleExampleMutation() { + checkParamsMutations( + ArrayOfArrays::simpleExample, + eq(7), + { matrixBefore, matrixAfter -> matrixBefore[1][1] == 1 && matrixAfter[2][2] == 2 }, + { matrixBefore, matrixAfter -> matrixBefore[1][1] != 1 && matrixAfter[2][2] == -2 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testIsIdentityMatrix() { + withoutMinimization { + check( + ArrayOfArrays::isIdentityMatrix, + eq(9), + { m, _ -> m == null }, + { m, _ -> m.size < 3 }, + { m, _ -> m.size >= 3 && m.any { it == null } }, + { m, r -> m.size >= 3 && m.any { it.size != m.size } && r == false }, + { m, r -> m.size >= 3 && m.size == m[0].size && m[0][0] != 1 && r == false }, + { m, r -> m.size >= 3 && m.size == m[0].size && m[0][0] == 1 && m[0][1] != 0 && r == false }, + { m, r -> m.size >= 3 && m.size == m[0].size && m[0][0] == 1 && m[0][1] == 0 && m[0][2] != 0 && r == false }, + { m, r -> + val sizeConstraints = m.size >= 3 && m.size == m[0].size + val valueConstraint = m[0][0] == 1 && m[0].drop(1).all { it == 0 } + val resultCondition = (m[1] == null && r == null) || (m[1]?.size != m.size && r == false) + + sizeConstraints && valueConstraint && resultCondition + }, + { m, r -> + val sizeConstraint = m.size >= 3 && m.size == m.first().size + val contentConstraint = + m.indices.all { i -> + m.indices.all { j -> + (i == j && m[i][j] == 1) || (i != j && m[i][j] == 0) + } + } + + sizeConstraint && contentConstraint && r == true + }, + ) + } + } + + @Test + fun testCreateNewThreeDimensionalArray() { + check( + ArrayOfArrays::createNewThreeDimensionalArray, + eq(2), + { length, _, r -> length != 2 && r != null && r.isEmpty() }, + { length, constValue, r -> + val sizeConstraint = length == 2 && r != null && r.size == length + val contentConstraint = + r!!.all { + it.size == length && it.all { + it.size == length && it.all { it == constValue + 1 } + } + } + + sizeConstraint && contentConstraint + } + ) + } + + @Test + fun testReallyMultiDimensionalArray() { + check( + ArrayOfArrays::reallyMultiDimensionalArray, + eq(8), + { a, _ -> a == null }, + { a, _ -> a.size < 2 }, + { a, _ -> a.size >= 2 && a[1] == null }, + { a, _ -> a.size >= 2 && a[1].size < 3 }, + { a, _ -> a.size >= 2 && a[1].size >= 3 && a[1][2] == null }, + { a, _ -> a.size >= 2 && a[1].size >= 3 && a[1][2].size < 4 }, + { a, r -> + val sizeConstraint = a.size >= 2 && a[1].size >= 3 && a[1][2].size >= 4 + val valueConstraint = a[1][2][3] == 12345 && r != null && r[1][2][3] == -12345 + + sizeConstraint && valueConstraint + }, + { a, r -> + val sizeConstraint = a.size >= 2 && a[1].size >= 3 && a[1][2].size >= 4 + val valueConstraint = a[1][2][3] != 12345 && r != null && r[1][2][3] == 12345 + + sizeConstraint && valueConstraint + }, + ) + } + + @Test + fun testReallyMultiDimensionalArrayMutation() { + checkParamsMutations( + ArrayOfArrays::reallyMultiDimensionalArray, + ignoreExecutionsNumber, + { arrayBefore, arrayAfter -> arrayBefore[1][2][3] != 12345 && arrayAfter[1][2][3] == 12345 }, + { arrayBefore, arrayAfter -> arrayBefore[1][2][3] == 12345 && arrayAfter[1][2][3] == -12345 }, + ) + } + + @Test + fun testMultiDimensionalObjectsArray() { + check( + ArrayOfArrays::multiDimensionalObjectsArray, + eq(4), + { a, _ -> a == null }, + { a, _ -> a.isEmpty() }, + { a, _ -> a.size == 1 }, + { a, r -> + require(r != null && r[0] != null && r[1] != null) + + val propertiesConstraint = a.size > 1 + val zeroElementConstraints = r[0] is Array<*> && r[0].isArrayOf() && r[0].size == 2 + val firstElementConstraints = r[1] is Array<*> && r[1].isArrayOf() && r[1].size == 1 + + propertiesConstraint && zeroElementConstraints && firstElementConstraints + }, + ) + } + + @Test + fun testMultiDimensionalObjectsArrayMutation() { + checkParamsMutations( + ArrayOfArrays::multiDimensionalObjectsArray, + ignoreExecutionsNumber, + { _, arrayAfter -> + arrayAfter[0] is Array<*> && arrayAfter[0].isArrayOf() && arrayAfter[0].size == 2 + }, + { _, arrayAfter -> + arrayAfter[1] is Array<*> && arrayAfter[1].isArrayOf() && arrayAfter[1].size == 1 + }, + ) + } + + @Test + fun testFillMultiArrayWithArray() { + check( + ArrayOfArrays::fillMultiArrayWithArray, + eq(3), + { v, _ -> v == null }, + { v, r -> v.size < 2 && r != null && r.isEmpty() }, + { v, r -> v.size >= 2 && r != null && r.all { a -> a.toList() == v.mapIndexed { i, elem -> elem + i } } } + ) + } + + @Test + fun testFillMultiArrayWithArrayMutation() { + checkParamsMutations( + ArrayOfArrays::fillMultiArrayWithArray, + ignoreExecutionsNumber, + { valueBefore, valueAfter -> valueAfter.withIndex().all { it.value == valueBefore[it.index] + it.index } } + ) + } + + @Test + @Disabled("https://github.com/UnitTestBot/UTBotJava/issues/1267") + fun testArrayWithItselfAnAsElement() { + check( + ArrayOfArrays::arrayWithItselfAnAsElement, + eq(2), + { a, r -> a !== a[0] && r == null }, + { a, r -> a === a[0] && a.contentDeepEquals(r) }, + coverage = atLeast(percents = 94) + // because of the assumption + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt new file mode 100644 index 0000000000..f26c944212 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt @@ -0,0 +1,111 @@ +package org.utbot.examples.arrays + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testcheckers.ge + +// TODO failed Kotlin compilation SAT-1332 +internal class ArrayOfObjectsTest : UtValueTestCaseChecker( + testClass = ArrayOfObjects::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testDefaultValues() { + check( + ArrayOfObjects::defaultValues, + eq(1), + { r -> r != null && r.single() == null }, + coverage = atLeast(50) + ) + } + + @Test + fun testCreateArray() { + check( + ArrayOfObjects::createArray, + eq(2), + { _, _, length, _ -> length < 3 }, + { x, y, length, r -> + require(r != null) + + val sizeConstraint = length >= 3 && r.size == length + val contentConstraint = r.mapIndexed { i, elem -> elem.x == x + i && elem.y == y + i }.all { it } + + sizeConstraint && contentConstraint + } + ) + } + + @Test + fun testCopyArray() { + checkWithException( + ArrayOfObjects::copyArray, + ge(4), + { a, r -> a == null && r.isException() }, + { a, r -> a.size < 3 && r.isException() }, + { a, r -> a.size >= 3 && null in a && r.isException() }, + { a, r -> a.size >= 3 && r.getOrThrow().all { it.x == -1 && it.y == 1 } }, + ) + } + + @Test + fun testCopyArrayMutation() { + checkParamsMutations( + ArrayOfObjects::copyArray, + ignoreExecutionsNumber, + { _, arrayAfter -> arrayAfter.all { it.x == -1 && it.y == 1 } } + ) + } + + @Test + fun testArrayWithSucc() { + check( + ArrayOfObjects::arrayWithSucc, + eq(3), + { length, _ -> length < 0 }, + { length, r -> length < 2 && r != null && r.size == length && r.all { it == null } }, + { length, r -> + require(r != null) + + val sizeConstraint = length >= 2 && r.size == length + val zeroElementConstraint = r[0] is ObjectWithPrimitivesClass && r[0].x == 2 && r[0].y == 4 + val firstElementConstraint = r[1] is ObjectWithPrimitivesClassSucc && r[1].x == 3 + + sizeConstraint && zeroElementConstraint && firstElementConstraint + }, + ) + } + + @Test + fun testObjectArray() { + check( + ArrayOfObjects::objectArray, + eq(5), + { a, _, _ -> a == null }, + { a, _, r -> a != null && a.size != 2 && r == -1 }, + { a, o, _ -> a != null && a.size == 2 && o == null }, + { a, p, r -> a != null && a.size == 2 && p != null && p.x + 5 > 20 && r == 1 }, + { a, o, r -> a != null && a.size == 2 && o != null && o.x + 5 <= 20 && r == 0 }, + ) + } + + @Test + fun testArrayOfArrays() { + withEnabledTestingCodeGeneration(testCodeGeneration = false) { + check( + ArrayOfObjects::arrayOfArrays, + between(4..5), // might be two ClassCastExceptions + { a, _ -> a.any { it == null } }, + { a, _ -> a.any { it != null && it !is IntArray } }, + { a, r -> (a.all { it != null && it is IntArray && it.isEmpty() } || a.isEmpty()) && r == 0 }, + { a, r -> a.all { it is IntArray } && r == a.sumBy { (it as IntArray).sum() } }, + coverage = DoNotCalculate + ) + } + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayStoreExceptionExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayStoreExceptionExamplesTest.kt new file mode 100644 index 0000000000..dfd48eafad --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayStoreExceptionExamplesTest.kt @@ -0,0 +1,210 @@ +package org.utbot.examples.arrays + +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq + +class ArrayStoreExceptionExamplesTest : UtValueTestCaseChecker( + testClass = ArrayStoreExceptionExamples::class, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + // Type inference errors in generated Kotlin code + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testCorrectAssignmentSamePrimitiveType() { + checkWithException( + ArrayStoreExceptionExamples::correctAssignmentSamePrimitiveType, + eq(3), + { data, result -> result.isSuccess && result.getOrNull() == data?.isNotEmpty() } + ) + } + + @Test + fun testCorrectAssignmentIntToIntegerArray() { + checkWithException( + ArrayStoreExceptionExamples::correctAssignmentIntToIntegerArray, + eq(3), + { data, result -> result.isSuccess && result.getOrNull() == data?.isNotEmpty() } + ) + } + + @Test + fun testCorrectAssignmentSubtype() { + checkWithException( + ArrayStoreExceptionExamples::correctAssignmentSubtype, + eq(3), + { data, result -> result.isSuccess && result.getOrNull() == data?.isNotEmpty() } + ) + } + + @Test + fun testCorrectAssignmentToObjectArray() { + checkWithException( + ArrayStoreExceptionExamples::correctAssignmentToObjectArray, + eq(3), + { data, result -> result.isSuccess && result.getOrNull() == data?.isNotEmpty() } + ) + } + + @Test + fun testWrongAssignmentUnrelatedType() { + checkWithException( + ArrayStoreExceptionExamples::wrongAssignmentUnrelatedType, + eq(3), + { data, result -> data == null && result.isSuccess }, + { data, result -> data.isEmpty() && result.isSuccess }, + { data, result -> data.isNotEmpty() && result.isException() }, + coverage = AtLeast(91) // TODO: investigate + ) + } + + @Test + fun testCheckGenericAssignmentWithCorrectCast() { + checkWithException( + ArrayStoreExceptionExamples::checkGenericAssignmentWithCorrectCast, + eq(1), + { result -> result.isSuccess } + ) + } + + @Test + fun testCheckGenericAssignmentWithWrongCast() { + checkWithException( + ArrayStoreExceptionExamples::checkGenericAssignmentWithWrongCast, + eq(1), + { result -> result.isException() }, + coverage = AtLeast(87) // TODO: investigate + ) + } + + @Test + fun testCheckGenericAssignmentWithExtendsSubtype() { + checkWithException( + ArrayStoreExceptionExamples::checkGenericAssignmentWithExtendsSubtype, + eq(1), + { result -> result.isSuccess } + ) + } + + @Test + fun testCheckGenericAssignmentWithExtendsUnrelated() { + checkWithException( + ArrayStoreExceptionExamples::checkGenericAssignmentWithExtendsUnrelated, + eq(1), + { result -> result.isException() }, + coverage = AtLeast(87) // TODO: investigate + ) + } + + @Test + fun testCheckObjectAssignment() { + checkWithException( + ArrayStoreExceptionExamples::checkObjectAssignment, + eq(1), + { result -> result.isSuccess } + ) + } + + // Should this be allowed at all? + @Test + fun testCheckWrongAssignmentOfItself() { + checkWithException( + ArrayStoreExceptionExamples::checkWrongAssignmentOfItself, + eq(1), + { result -> result.isException() }, + coverage = AtLeast(87) + ) + } + + @Test + fun testCheckGoodAssignmentOfItself() { + checkWithException( + ArrayStoreExceptionExamples::checkGoodAssignmentOfItself, + eq(1), + { result -> result.isSuccess } + ) + } + + @Test + fun testCheckAssignmentToObjectArray() { + checkWithException( + ArrayStoreExceptionExamples::checkAssignmentToObjectArray, + eq(1), + { result -> result.isSuccess } + ) + } + + @Test + fun testArrayCopyForIncompatiblePrimitiveTypes() { + checkWithException( + ArrayStoreExceptionExamples::arrayCopyForIncompatiblePrimitiveTypes, + eq(3), + { data, result -> data == null && result.isSuccess && result.getOrNull() == null }, + { data, result -> data != null && data.isEmpty() && result.isSuccess && result.getOrNull()?.size == 0 }, + { data, result -> data != null && data.isNotEmpty() && result.isException() } + ) + } + + @Test + fun testFill2DPrimitiveArray() { + checkWithException( + ArrayStoreExceptionExamples::fill2DPrimitiveArray, + eq(1), + { result -> result.isSuccess } + ) + } + + @Test + fun testFillObjectArrayWithList() { + check( + ArrayStoreExceptionExamples::fillObjectArrayWithList, + eq(2), + { list, result -> list != null && result != null && result[0] != null }, + { list, result -> list == null && result == null } + ) + } + + @Test + fun testFillWithTreeSet() { + check( + ArrayStoreExceptionExamples::fillWithTreeSet, + eq(2), + { treeSet, result -> treeSet != null && result != null && result[0] != null }, + { treeSet, result -> treeSet == null && result == null } + ) + } + + @Test + fun testFillSomeInterfaceArrayWithSomeInterface() { + check( + ArrayStoreExceptionExamples::fillSomeInterfaceArrayWithSomeInterface, + eq(2), + { impl, result -> impl == null && result == null }, + { impl, result -> impl != null && result != null && result[0] != null } + ) + } + + @Test + @Disabled("TODO: Not null path is not found, need to investigate") + fun testFillObjectArrayWithSomeInterface() { + check( + ArrayStoreExceptionExamples::fillObjectArrayWithSomeInterface, + eq(2), + { impl, result -> impl == null && result == null }, + { impl, result -> impl != null && result != null && result[0] != null } + ) + } + + @Test + fun testFillWithSomeImplementation() { + check( + ArrayStoreExceptionExamples::fillWithSomeImplementation, + eq(2), + { impl, result -> impl == null && result == null }, + { impl, result -> impl != null && result != null && result[0] != null } + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArraysOverwriteValueTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArraysOverwriteValueTest.kt new file mode 100644 index 0000000000..6f6f5f3b23 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArraysOverwriteValueTest.kt @@ -0,0 +1,153 @@ +package org.utbot.examples.arrays + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker + +// TODO failed Kotlin compilation SAT-1332 +class ArraysOverwriteValueTest : UtValueTestCaseChecker( + testClass = ArraysOverwriteValue::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testByteArray() { + checkParamsMutationsAndResult( + ArraysOverwriteValue::byteArray, + eq(4), + { before, _, _ -> before == null }, + { before, _, r -> before != null && before.isEmpty() && r == 1.toByte() }, + { before, _, r -> before != null && before.isNotEmpty() && before[0] != 0.toByte() && r == 2.toByte() }, + { before, after, r -> + val precondition = before != null && before.isNotEmpty() && before[0] == 0.toByte() + val postcondition = after[0] == 1.toByte() && r == 3.toByte() + + precondition && postcondition + }, + ) + } + + @Test + fun testShortArray() { + checkParamsMutationsAndResult( + ArraysOverwriteValue::shortArray, + eq(4), + { before, _, _ -> before == null }, + { before, _, r -> before != null && before.isEmpty() && r == 1.toByte() }, + { before, _, r -> before != null && before.isNotEmpty() && before[0] != 0.toShort() && r == 2.toByte() }, + { before, after, r -> + val precondition = before != null && before.isNotEmpty() && before[0] == 0.toShort() + val postcondition = after[0] == 1.toShort() && r == 3.toByte() + + precondition && postcondition + }, + ) + } + + @Test + fun testCharArray() { + checkParamsMutationsAndResult( + ArraysOverwriteValue::charArray, + eq(4), + { before, _, _ -> before == null }, + { before, _, r -> before != null && before.isEmpty() && r == 1.toChar() }, + { before, _, r -> before != null && before.isNotEmpty() && before[0] != 0.toChar() && r == 2.toChar() }, + { before, after, r -> + val precondition = before != null && before.isNotEmpty() && before[0] == 0.toChar() + val postcondition = after[0] == 1.toChar() && r == 3.toChar() + + precondition && postcondition + }, + ) + } + + @Test + fun testIntArray() { + checkParamsMutationsAndResult( + ArraysOverwriteValue::intArray, + eq(4), + { before, _, _ -> before == null }, + { before, _, r -> before != null && before.isEmpty() && r == 1.toByte() }, + { before, _, r -> before != null && before.isNotEmpty() && before[0] != 0 && r == 2.toByte() }, + { before, after, r -> + before != null && before.isNotEmpty() && before[0] == 0 && after[0] == 1 && r == 3.toByte() + }, + ) + } + + @Test + fun testLongArray() { + checkParamsMutationsAndResult( + ArraysOverwriteValue::longArray, + eq(4), + { before, _, _ -> before == null }, + { before, _, r -> before != null && before.isEmpty() && r == 1.toLong() }, + { before, _, r -> before != null && before.isNotEmpty() && before[0] != 0.toLong() && r == 2.toLong() }, + { before, after, r -> + val precondition = before != null && before.isNotEmpty() && before[0] == 0.toLong() + val postcondition = after[0] == 1.toLong() && r == 3.toLong() + + precondition && postcondition + }, + ) + } + + @Test + fun testFloatArray() { + checkParamsMutationsAndResult( + ArraysOverwriteValue::floatArray, + eq(4), + { before, _, _ -> before == null }, + { before, _, r -> before != null && before.isEmpty() && r == 1.0f }, + { before, _, r -> before != null && before.isNotEmpty() && !before[0].isNaN() && r == 2.0f }, + { before, after, r -> + before != null && before.isNotEmpty() && before[0].isNaN() && after[0] == 1.0f && r == 3.0f + }, + ) + } + + @Test + fun testDoubleArray() { + checkParamsMutationsAndResult( + ArraysOverwriteValue::doubleArray, + eq(4), + { before, _, _ -> before == null }, + { before, _, r -> before != null && before.isEmpty() && r == 1.00 }, + { before, _, r -> before != null && before.isNotEmpty() && !before[0].isNaN() && r == 2.0 }, + { before, after, r -> + before != null && before.isNotEmpty() && before[0].isNaN() && after[0] == 1.toDouble() && r == 3.0 + }, + ) + } + + @Test + fun testBooleanArray() { + checkParamsMutationsAndResult( + ArraysOverwriteValue::booleanArray, + eq(4), + { before, _, _ -> before == null }, + { before, _, r -> before != null && before.isEmpty() && r == 1 }, + { before, _, r -> before != null && before.isNotEmpty() && before[0] && r == 2 }, + { before, after, r -> before != null && before.isNotEmpty() && !before[0] && after[0] && r == 3 }, + ) + } + + @Test + fun testObjectArray() { + checkParamsMutationsAndResult( + ArraysOverwriteValue::objectArray, + eq(4), + { before, _, _ -> before == null }, + { before, _, r -> before != null && before.isEmpty() && r == 1 }, + { before, _, r -> before != null && before.isNotEmpty() && before[0] == null && r == 2 }, + { before, after, r -> + before != null && before.isNotEmpty() && before[0] != null && after[0] == null && r == 3 + }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/FinalStaticFieldArrayTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/FinalStaticFieldArrayTest.kt new file mode 100644 index 0000000000..55b0d37eed --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/FinalStaticFieldArrayTest.kt @@ -0,0 +1,21 @@ +package org.utbot.examples.arrays + +import org.junit.jupiter.api.Test +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber + +internal class FinalStaticFieldArrayTest : UtValueTestCaseChecker(testClass = FinalStaticFieldArray::class) { + + @Test + fun testFactorial() { + checkStaticMethod( + FinalStaticFieldArray::factorial, + ignoreExecutionsNumber, + { n, r -> + (n as Int) >= 0 && n < FinalStaticFieldArray.MAX_FACTORIAL && r == FinalStaticFieldArray.factorial(n) + }, + { n, _ -> (n as Int) < 0 }, + { n, r -> (n as Int) > FinalStaticFieldArray.MAX_FACTORIAL && r == FinalStaticFieldArray.factorial(n) }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/IntArrayBasicsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/IntArrayBasicsTest.kt new file mode 100644 index 0000000000..aedb08e43a --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/IntArrayBasicsTest.kt @@ -0,0 +1,228 @@ +package org.utbot.examples.arrays + +import org.junit.jupiter.api.Disabled +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testcheckers.ge + +// TODO failed Kotlin compilation SAT-1332 +internal class IntArrayBasicsTest : UtValueTestCaseChecker( + testClass = IntArrayBasics::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testIntArrayWithAssumeOrExecuteConcretely() { + check( + IntArrayBasics::intArrayWithAssumeOrExecuteConcretely, + eq(4), + { x, n, r -> x > 0 && n < 20 && r?.size == 2 }, + { x, n, r -> x > 0 && n >= 20 && r?.size == 4 }, + { x, n, r -> x <= 0 && n < 20 && r?.size == 10 }, + { x, n, r -> x <= 0 && n >= 20 && r?.size == 20 }, + ) + } + + @Test + fun testInitArray() { + checkWithException( + IntArrayBasics::initAnArray, + eq(4), + { n, r -> n < 0 && r.isException() }, + { n, r -> n == 0 && r.isException() }, + { n, r -> n == 1 && r.isException() }, + { n, r -> + val resultArray = IntArray(n) { if (it == n - 1 || it == n - 2) it else 0 } + n > 1 && r.getOrNull() contentEquals resultArray + } + ) + } + + @Test + fun testIsValid() { + checkWithException( + IntArrayBasics::isValid, + ignoreExecutionsNumber, + { a, _, r -> a == null && r.isException() }, + { a, n, r -> a != null && (n < 0 || n >= a.size) && r.isException() }, + { a, n, r -> a != null && n in a.indices && a[n] == 9 && n == 5 && r.getOrNull() == true }, + { a, n, r -> a != null && n in a.indices && !(a[n] == 9 && n == 5) && r.getOrNull() == false }, + { a, n, r -> a != null && n in a.indices && a[n] > 9 && n == 5 && r.getOrNull() == true }, + { a, n, r -> a != null && n in a.indices && !(a[n] > 9 && n == 5) && r.getOrNull() == false }, + ) + } + + @Test + fun testGetValue() { + checkWithException( + IntArrayBasics::getValue, + ge(4), + { a, _, r -> a == null && r.isException() }, + { a, n, r -> a != null && a.size > 6 && (n < 0 || n >= a.size) && r.isException() }, + { a, n, r -> a != null && a.size > 6 && n < a.size && r.getOrNull() == a[n] }, + { a, _, r -> a != null && a.size <= 6 && r.getOrNull() == -1 } + ) + } + + @Test + fun testSetValue() { + checkWithException( + IntArrayBasics::setValue, + eq(5), + { _, x, r -> x <= 0 && r.getOrNull() == 0 }, + { a, x, r -> x > 0 && a == null && r.isException() }, + { a, x, r -> x > 0 && a != null && a.isEmpty() && r.getOrNull() == 0 }, + { a, x, r -> x in 1..2 && a != null && a.isNotEmpty() && r.getOrNull() == 1 }, + { a, x, r -> x > 2 && a != null && a.isNotEmpty() && r.getOrNull() == 2 } + ) + } + + @Test + fun testCheckFour() { + checkWithException( + IntArrayBasics::checkFour, + eq(7), + { a, r -> a == null && r.isException() }, + { a, r -> a != null && a.size < 4 && r.getOrNull() == -1 }, + { a, r -> a != null && a.size >= 4 && a[0] != 1 && r.getOrNull() == 0 }, + { a, r -> a != null && a.size >= 4 && a[0] == 1 && a[1] != 2 && r.getOrNull() == 0 }, + { a, r -> a != null && a.size >= 4 && a[0] == 1 && a[1] == 2 && a[2] != 3 && r.getOrNull() == 0 }, + { a, r -> a != null && a.size >= 4 && a[0] == 1 && a[1] == 2 && a[2] == 3 && a[3] != 4 && r.getOrNull() == 0 }, + { a, r -> + require(a != null) + + val precondition = a.size >= 4 && a[0] == 1 && a[1] == 2 && a[2] == 3 && a[3] == 4 + val postcondition = r.getOrNull() == IntArrayBasics().checkFour(a) + + precondition && postcondition + } + ) + } + + @Test + fun testNullability() { + check( + IntArrayBasics::nullability, + eq(3), + { a, r -> a == null && r == 1 }, + { a, r -> a != null && a.size > 1 && r == 2 }, + { a, r -> a != null && a.size in 0..1 && r == 3 }, + ) + } + + @Test + fun testEquality() { + check( + IntArrayBasics::equality, + eq(4), + { a, _, r -> a == null && r == 1 }, + { a, b, r -> a != null && b == null && r == 1 }, + { a, b, r -> a != null && b != null && a.size == b.size && r == 2 }, + { a, b, r -> a != null && b != null && a.size != b.size && r == 3 }, + ) + } + + @Test + fun testOverwrite() { + checkWithException( + IntArrayBasics::overwrite, + eq(5), + { a, _, r -> a == null && r.isException() }, + { a, _, r -> a != null && a.size != 1 && r.getOrNull() == 0 }, + { a, b, r -> a != null && a.size == 1 && a[0] > 0 && b < 0 && r.getOrNull() == 1 }, + { a, b, r -> a != null && a.size == 1 && a[0] > 0 && b >= 0 && r.getOrNull() == 2 }, + { a, _, r -> a != null && a.size == 1 && a[0] <= 0 && r.getOrNull() == 3 }, + ) + } + + @Test + fun testMergeArrays() { + check( + IntArrayBasics::mergeArrays, + ignoreExecutionsNumber, + { fst, _, _ -> fst == null }, + { fst, snd, _ -> fst != null && snd == null }, + { fst, snd, r -> fst != null && snd != null && fst.size < 2 && r == null }, + { fst, snd, r -> fst != null && snd != null && fst.size >= 2 && snd.size < 2 && r == null }, + { fst, snd, r -> + require(fst != null && snd != null && r != null) + + val sizeConstraint = fst.size >= 2 && snd.size >= 2 && r.size == fst.size + snd.size + val maxConstraint = fst.maxOrNull()!! < snd.maxOrNull()!! + val contentConstraint = r contentEquals (IntArrayBasics().mergeArrays(fst, snd)) + + sizeConstraint && maxConstraint && contentConstraint + }, + { fst, snd, r -> + require(fst != null && snd != null && r != null) + + val sizeConstraint = fst.size >= 2 && snd.size >= 2 && r.size == fst.size + snd.size + val maxConstraint = fst.maxOrNull()!! >= snd.maxOrNull()!! + val contentConstraint = r contentEquals (IntArrayBasics().mergeArrays(fst, snd)) + + sizeConstraint && maxConstraint && contentConstraint + } + ) + } + + @Test + fun testNewArrayInTheMiddle() { + check( + IntArrayBasics::newArrayInTheMiddle, + eq(5), + { a, _ -> a == null }, + { a, _ -> a != null && a.isEmpty() }, + { a, _ -> a != null && a.size < 2 }, + { a, _ -> a != null && a.size < 3 }, + { a, r -> a != null && a.size >= 3 && r != null && r[0] == 1 && r[1] == 2 && r[2] == 3 } + ) + } + + @Test + fun testNewArrayInTheMiddleMutation() { + checkParamsMutations( + IntArrayBasics::newArrayInTheMiddle, + ignoreExecutionsNumber, + { _, arrayAfter -> arrayAfter[0] == 1 && arrayAfter[1] == 2 && arrayAfter[2] == 3 } + ) + } + + @Test + fun testReversed() { + check( + IntArrayBasics::reversed, + eq(5), + { a, _ -> a == null }, + { a, _ -> a != null && a.size != 3 }, + { a, r -> a != null && a.size == 3 && a[0] <= a[1] && r == null }, + { a, r -> a != null && a.size == 3 && a[0] > a[1] && a[1] <= a[2] && r == null }, + { a, r -> a != null && a.size == 3 && a[0] > a[1] && a[1] > a[2] && r contentEquals a.reversedArray() }, + ) + } + + @Test + fun testUpdateCloned() { + check( + IntArrayBasics::updateCloned, + eq(3), + { a, _ -> a == null }, + { a, _ -> a.size != 3 }, + { a, r -> a.size == 3 && r != null && r.toList() == a.map { it * 2 } }, + ) + } + + @Test + @Disabled("Java 11 transition -- Sergei is looking into it") + fun testArraysEqualsExample() { + check( + IntArrayBasics::arrayEqualsExample, + eq(2), + { a, r -> a.size == 3 && a contentEquals intArrayOf(1, 2, 3) && r == 1 }, + { a, r -> !(a contentEquals intArrayOf(1, 2, 3)) && r == 2 } + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/PrimitiveArraysTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/PrimitiveArraysTest.kt new file mode 100644 index 0000000000..b1fc9d41db --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/PrimitiveArraysTest.kt @@ -0,0 +1,186 @@ +package org.utbot.examples.arrays + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast +import org.utbot.testing.isException + +// TODO failed Kotlin compilation SAT-1332 +internal class PrimitiveArraysTest : UtValueTestCaseChecker( + testClass = PrimitiveArrays::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testDefaultIntValues() { + check( + PrimitiveArrays::defaultIntValues, + eq(1), + { r -> r != null && r.all { it == 0 } }, + coverage = atLeast(50) + ) + } + + @Test + fun testDefaultDoubleValues() { + check( + PrimitiveArrays::defaultDoubleValues, + eq(1), + { r -> r != null && r.all { it == 0.0 } }, + coverage = atLeast(50) + ) + } + + @Test + fun testDefaultBooleanValues() { + check( + PrimitiveArrays::defaultBooleanValues, + eq(1), + { r -> r != null && r.none { it } }, + coverage = atLeast(50) + ) + } + + @Test + fun testByteArray() { + checkWithException( + PrimitiveArrays::byteArray, + eq(4), + { a, _, r -> a == null && r.isException() }, + { a, _, r -> a != null && a.size != 2 && r.getOrNull() == (-1).toByte() }, + { a, x, r -> a != null && a.size == 2 && x + 5 <= 20 && r.getOrNull() == 0.toByte() }, + { a, x, r -> a != null && a.size == 2 && x + 5 > 20 && r.getOrNull() == 1.toByte() } + ) + } + + @Test + fun testShortArray() { + checkWithException( + PrimitiveArrays::shortArray, + eq(4), + { a, _, r -> a == null && r.isException() }, + { a, _, r -> a != null && a.size != 2 && r.getOrNull() == (-1).toByte() }, + { a, x, r -> a != null && a.size == 2 && x + 5 <= 20 && r.getOrNull() == 0.toByte() }, + { a, x, r -> a != null && a.size == 2 && x + 5 > 20 && r.getOrNull() == 1.toByte() } + ) + } + + @Test + fun testCharArray() { + checkWithException( + PrimitiveArrays::charArray, + eq(4), + { a, _, r -> a == null && r.isException() }, + { a, _, r -> a != null && a.size != 2 && r.getOrNull() == (-1).toByte() }, + { a, x, r -> a != null && a.size == 2 && x + 5 <= 20.toChar() && r.getOrNull() == 0.toByte() }, + { a, x, r -> a != null && a.size == 2 && x + 5 > 20.toChar() && r.getOrNull() == 1.toByte() } + ) + } + + @Test + fun testIntArray() { + checkWithException( + PrimitiveArrays::intArray, + eq(4), + { a, _, r -> a == null && r.isException() }, + { a, _, r -> a != null && a.size != 2 && r.getOrNull() == (-1).toByte() }, + { a, x, r -> a != null && a.size == 2 && x + 5 <= 20 && r.getOrNull() == 0.toByte() }, + { a, x, r -> a != null && a.size == 2 && x + 5 > 20 && r.getOrNull() == 1.toByte() } + ) + } + + @Test + fun testLongArray() { + checkWithException( + PrimitiveArrays::longArray, + eq(4), + { a, _, r -> a == null && r.isException() }, + { a, _, r -> a != null && a.size != 2 && r.getOrNull() == (-1).toLong() }, + { a, x, r -> a != null && a.size == 2 && x + 5 <= 20 && r.getOrNull() == 0.toLong() }, + { a, x, r -> a != null && a.size == 2 && x + 5 > 20 && r.getOrNull() == 1.toLong() } + ) + } + + @Suppress("SimplifyNegatedBinaryExpression") + @Test + fun testFloatArray() { + checkWithException( + PrimitiveArrays::floatArray, + eq(4), + { a, _, r -> a == null && r.isException() }, + { a, _, r -> a != null && a.size != 2 && r.getOrNull() == (-1).toFloat() }, + { a, x, r -> a != null && a.size == 2 && !(x + 5 > 20) && r.getOrNull() == 0.toFloat() }, + { a, x, r -> a != null && a.size == 2 && x + 5 > 20 && r.getOrNull() == 1.toFloat() } + ) + } + + @Suppress("SimplifyNegatedBinaryExpression") + @Test + fun testDoubleArray() { + checkWithException( + PrimitiveArrays::doubleArray, + eq(4), + { a, _, r -> a == null && r.isException() }, + { a, _, r -> a != null && a.size != 2 && r.getOrNull() == (-1).toDouble() }, + { a, x, r -> a != null && a.size == 2 && !(x + 5 > 20) && r.getOrNull() == 0.toDouble() }, + { a, x, r -> a != null && a.size == 2 && x + 5 > 20 && r.getOrNull() == 1.toDouble() } + ) + } + + @Test + fun testBooleanArray() { + checkWithException( + PrimitiveArrays::booleanArray, + eq(4), + { a, _, _, r -> a == null && r.isException() }, + { a, _, _, r -> a != null && a.size != 2 && r.getOrNull() == -1 }, + { a, x, y, r -> a != null && a.size == 2 && !(x xor y) && r.getOrNull() == 0 }, + { a, x, y, r -> a != null && a.size == 2 && (x xor y) && r.getOrNull() == 1 } + ) + } + + @Test + fun testByteSizeAndIndex() { + check( + PrimitiveArrays::byteSizeAndIndex, + eq(5), + { a, _, r -> a == null && r == (-1).toByte() }, + { a, x, r -> a != null && a.size <= x.toInt() && r == (-1).toByte() }, + { a, x, r -> a != null && a.size > x.toInt() && x.toInt() < 1 && r == (-1).toByte() }, + { a, x, r -> a != null && a.size > x.toInt() && x.toInt() > 0 && x + 5 <= 7 && r == 0.toByte() }, + { a, x, r -> a != null && a.size > x.toInt() && x.toInt() > 0 && x + 5 > 7 && r == 1.toByte() } + ) + } + + @Test + fun testShortSizeAndIndex() { + check( + PrimitiveArrays::shortSizeAndIndex, + eq(5), + { a, _, r -> a == null && r == (-1).toByte() }, + { a, x, r -> a != null && a.size <= x.toInt() && r == (-1).toByte() }, + { a, x, r -> a != null && a.size > x.toInt() && x.toInt() < 1 && r == (-1).toByte() }, + { a, x, r -> a != null && a.size > x.toInt() && x.toInt() > 0 && x + 5 <= 7 && r == 0.toByte() }, + { a, x, r -> a != null && a.size > x.toInt() && x.toInt() > 0 && x + 5 > 7 && r == 1.toByte() } + ) + } + + @Test + fun testCharSizeAndIndex() { + check( + PrimitiveArrays::charSizeAndIndex, + eq(5), + { a, _, r -> a == null && r == (-1).toByte() }, + { a, x, r -> a != null && a.size <= x.toInt() && r == (-1).toByte() }, + { a, x, r -> a != null && a.size > x.toInt() && x.toInt() < 1 && r == (-1).toByte() }, + { a, x, r -> a != null && a.size > x.toInt() && x.toInt() > 0 && x + 5 <= 7.toChar() && r == 0.toByte() }, + { a, x, r -> a != null && a.size > x.toInt() && x.toInt() > 0 && x + 5 > 7.toChar() && r == 1.toByte() } + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/casts/ArrayCastExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/casts/ArrayCastExampleTest.kt new file mode 100644 index 0000000000..51c4c3123f --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/casts/ArrayCastExampleTest.kt @@ -0,0 +1,172 @@ +package org.utbot.examples.casts + +import org.junit.jupiter.api.Disabled +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +// TODO failed Kotlin compilation (generics) SAT-1332 +//TODO: SAT-1487 calculate coverage for all methods of this test class +internal class ArrayCastExampleTest : UtValueTestCaseChecker( + testClass = ArrayCastExample::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testCastToAncestor() { + check( + ArrayCastExample::castToAncestor, + eq(2), + { a, r -> a == null && r != null && r is Array }, + { a, r -> a != null && r != null && r.isArrayOf() } + ) + } + + @Test + fun testClassCastException() { + check( + ArrayCastExample::classCastException, + eq(3), + { a, r -> a == null && r != null && r.isEmpty() }, + { a, _ -> !a.isArrayOf() }, + { a, r -> a.isArrayOf() && r != null && r.isArrayOf() }, + ) + } + + @Test + fun testNullCast() { + check( + ArrayCastExample::nullCast, + eq(2), + { a, r -> a != null && r == null }, + { a, r -> a == null && r == null } + ) + } + + @Test + fun testNullArray() { + check( + ArrayCastExample::nullArray, + eq(1), + { r -> r == null } + ) + } + + @Test + fun testSuccessfulExampleFromJLS() { + check( + ArrayCastExample::successfulExampleFromJLS, + eq(1), + { r -> + require(r != null) + + val sizeConstraint = r.size == 4 + val typeConstraint = r[0] is ColoredPoint && r[1] is ColoredPoint + val zeroElementConstraint = r[0].x == 2 && r[0].y == 2 && r[0].color == 12 + val firstElementConstraint = r[1].x == 4 && r[1].y == 5 && r[1].color == 24 + + sizeConstraint && typeConstraint && zeroElementConstraint && firstElementConstraint + } + ) + } + + @Test + fun testCastAfterStore() { + check( + ArrayCastExample::castAfterStore, + eq(5), + { a, _ -> a == null }, + { a, _ -> a.isEmpty() }, + { a, _ -> a.isNotEmpty() && !a.isArrayOf() }, + { a, _ -> a.isArrayOf() && a.size == 1 }, + { a, r -> + require(r != null) + + val sizeConstraint = a.size >= 2 + val typeConstraint = a.isArrayOf() && r.isArrayOf() + val zeroElementConstraint = r[0].color == 12 && r[0].x == 1 && r[0].y == 2 + val firstElementConstraint = r[1].color == 14 && r[1].x == 2 && r[1].y == 3 + + sizeConstraint && typeConstraint && zeroElementConstraint && firstElementConstraint + } + ) + } + + @Test + fun testCastFromObject() { + check( + ArrayCastExample::castFromObject, + eq(3), + { a, _ -> a !is Array<*> || !a.isArrayOf() }, + { a, r -> a == null && r != null && r.isArrayOf() && r.isEmpty() }, + { a, r -> a is Array<*> && a.isArrayOf() && r != null && r.isArrayOf() }, + ) + } + + @Test + fun testCastFromObjectToPrimitivesArray() { + check( + ArrayCastExample::castFromObjectToPrimitivesArray, + eq(2), + { array, r -> array is IntArray && array.size > 0 && r is IntArray && array contentEquals r }, + { array, r -> array != null && array !is IntArray && r !is IntArray }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCastsChainFromObject() { + check( + ArrayCastExample::castsChainFromObject, + eq(8), + { a, r -> a == null && r == null }, + { a, _ -> a !is Array<*> || !a.isArrayOf() }, + { a, r -> a is Array<*> && a.isArrayOf() && a.isEmpty() && r == null }, + { a, _ -> a is Array<*> && a.isArrayOf() && a.isNotEmpty() && a[0] == null }, + { a, _ -> a is Array<*> && a.isArrayOf() && !a.isArrayOf() && (a[0] as Point).x == 1 }, + { a, _ -> a is Array<*> && a.isArrayOf() && !a.isArrayOf() && (a[0] as Point).x != 1 }, + { a, r -> a is Array<*> && a.isArrayOf() && (a[0] as Point).x == 1 && r != null && r[0].x == 10 }, + { a, r -> a is Array<*> && a.isArrayOf() && (a[0] as Point).x != 1 && r != null && r[0].x == 5 }, + ) + } + + @Test + fun testCastFromCollections() { + check( + ArrayCastExample::castFromCollections, + eq(3), + { c, r -> c == null && r == null }, + { c, r -> c != null && c is List<*> && r is List<*> }, + { c, _ -> c is Collection<*> && c !is List<*> }, + coverage = DoNotCalculate, + ) + } + + @Test + fun testCastFromIterable() { + check( + ArrayCastExample::castFromIterable, + eq(3), + { i, r -> i == null && r == null }, + { i, r -> i is List<*> && r is List<*> }, + { i, _ -> i is Iterable<*> && i !is List<*> }, + coverage = DoNotCalculate, + ) + } + + @Test + @Disabled("Fix Traverser.findInvocationTargets to exclude non-exported classes / provide good classes") + fun testCastFromIterableToCollection() { + check( + ArrayCastExample::castFromIterableToCollection, + eq(3), + { i, r -> i == null && r == null }, + { i, r -> i is Collection<*> && r is Collection<*> }, + { i, _ -> i is Iterable<*> && i !is Collection<*> }, + coverage = DoNotCalculate, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/casts/CastClassTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/casts/CastClassTest.kt new file mode 100644 index 0000000000..220e11cc33 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/casts/CastClassTest.kt @@ -0,0 +1,26 @@ +package org.utbot.examples.casts + +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker + +internal class CastClassTest : UtValueTestCaseChecker( + testClass = CastClass::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testThisTypeChoice() { + check( + CastClass::castToInheritor, + eq(0), + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/casts/CastExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/casts/CastExampleTest.kt new file mode 100644 index 0000000000..77747a3035 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/casts/CastExampleTest.kt @@ -0,0 +1,89 @@ +package org.utbot.examples.casts + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +// TODO failed Kotlin compilation SAT-1332 +internal class CastExampleTest : UtValueTestCaseChecker( + testClass = CastExample::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testSimpleCast() { + check( + CastExample::simpleCast, + eq(3), + { o, _ -> o != null && o !is CastClassFirstSucc }, + { o, r -> o != null && r is CastClassFirstSucc }, + { o, r -> o == null && r == null }, + ) + } + + @Test + fun testClassCastException() { + checkWithException( + CastExample::castClassException, + eq(3), + { o, r -> o == null && r.isException() }, + { o, r -> o != null && o !is CastClassFirstSucc && r.isException() }, + { o, r -> o != null && o is CastClassFirstSucc && r.isException() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCastUp() { + check( + CastExample::castUp, + eq(1) + ) + } + + @Test + fun testCastNullToDifferentTypes() { + check( + CastExample::castNullToDifferentTypes, + eq(1) + ) + } + + @Test + fun testFromObjectToPrimitive() { + check( + CastExample::fromObjectToPrimitive, + eq(3), + { obj, _ -> obj == null }, + { obj, _ -> obj != null && obj !is Int }, + { obj, r -> obj != null && obj is Int && r == obj } + ) + } + + @Test + fun testCastFromObjectToInterface() { + check( + CastExample::castFromObjectToInterface, + eq(2), + { obj, _ -> obj != null && obj !is Colorable }, + { obj, r -> obj != null && obj is Colorable && r == obj }, + coverage = DoNotCalculate + ) + } + + @Test + fun testComplicatedCast() { + withEnabledTestingCodeGeneration(testCodeGeneration = false) { // error: package sun.text is not visible + check( + CastExample::complicatedCast, + eq(2), + { i, a, _ -> i == 0 && a != null && a[i] != null && a[i] !is CastClassFirstSucc }, + { i, a, r -> i == 0 && a != null && a[i] != null && a[i] is CastClassFirstSucc && r is CastClassFirstSucc }, + coverage = DoNotCalculate + ) + } + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/casts/GenericCastExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/casts/GenericCastExampleTest.kt new file mode 100644 index 0000000000..e62fe49cbe --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/casts/GenericCastExampleTest.kt @@ -0,0 +1,77 @@ +package org.utbot.examples.casts + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +// TODO failed Kotlin compilation SAT-1332 +internal class GenericCastExampleTest : UtValueTestCaseChecker( + testClass = GenericCastExample::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testCompareTwoNumbers() { + check( + GenericCastExample::compareTwoNumbers, + eq(5), + { a, _, _ -> a == null }, + { _, b, _ -> b == null }, + { _, b, _ -> b.comparableGenericField == null }, + { a, b, r -> a >= b.comparableGenericField && r == 1 }, + { a, b, r -> a < b.comparableGenericField && r == -1 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetGenericFieldValue() { + check( + GenericCastExample::getGenericFieldValue, + eq(3), + { g, _ -> g == null }, + { g, _ -> g.genericField == null }, + { g, r -> g?.genericField != null && r == g.genericField }, + ) + } + + @Test + fun testCompareGenericField() { + check( + GenericCastExample::compareGenericField, + between(4..5), + { g, _, _ -> g == null }, + { g, v, _ -> g != null && v == null }, + { g, v, r -> v != null && v != g.comparableGenericField && r == -1 }, + { g, v, r -> g.comparableGenericField is Int && v != null && v == g.comparableGenericField && r == 1 }, + coverage = DoNotCalculate // TODO because of kryo exception: Buffer underflow. + ) + } + + @Test + fun testCreateNewGenericObject() { + check( + GenericCastExample::createNewGenericObject, + eq(1), + { r -> r is Int && r == 10 }, + ) + } + + @Test + fun testSumFromArrayOfGenerics() { + check( + GenericCastExample::sumFromArrayOfGenerics, + eq(7), + { g, _ -> g == null }, + { g, _ -> g.genericArray == null }, + { g, _ -> g.genericArray.isEmpty() }, + { g, _ -> g.genericArray.size == 1 }, + { g, _ -> g.genericArray[0] == null }, + { g, _ -> g.genericArray[0] != null && g.genericArray[1] == null }, + { g, r -> g.genericArray[0] != null && g.genericArray[1] != null && r == g.genericArray[0] + g.genericArray[1] }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/casts/InstanceOfExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/casts/InstanceOfExampleTest.kt new file mode 100644 index 0000000000..fe9fa10068 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/casts/InstanceOfExampleTest.kt @@ -0,0 +1,406 @@ +package org.utbot.examples.casts + +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 + +// TODO failed Kotlin compilation SAT-1332 +internal class InstanceOfExampleTest : UtValueTestCaseChecker( + testClass = InstanceOfExample::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testSimpleInstanceOf() { + check( + InstanceOfExample::simpleInstanceOf, + eq(2), + { o, r -> o is CastClassFirstSucc && r is CastClassFirstSucc }, + { o, r -> o !is CastClassFirstSucc && r == null }, + ) + } + + @Test + fun testNullPointerCheck() { + check( + InstanceOfExample::nullPointerCheck, + eq(3), + { o, _ -> o == null }, + { o, r -> o is CastClassFirstSucc && r == o.z }, + { o, r -> o !is CastClassFirstSucc && o != null && r == o.x }, + ) + } + + @Test + fun testVirtualCall() { + check( + InstanceOfExample::virtualCall, + eq(2), + { o, r -> o is CastClassFirstSucc && r == o.foo() }, + { o, r -> o !is CastClassFirstSucc && r == -1 }, + ) + } + + @Test + fun testVirtualFunctionCallWithCast() { + check( + InstanceOfExample::virtualFunctionCallWithCast, + eq(3), + { o, r -> o !is CastClassFirstSucc && r == -1 }, + { o, _ -> o is CastClass && o !is CastClassFirstSucc }, + { o, r -> o is CastClassFirstSucc && r == o.z }, + ) + } + + @Test + fun testVirtualCallWithoutOneInheritor() { + check( + InstanceOfExample::virtualCallWithoutOneInheritor, + eq(4), + { o, r -> o !is CastClassFirstSucc && o is CastClass && r == o.foo() }, + { o, r -> o is CastClassSecondSucc && r == o.foo() }, + { o, _ -> o == null }, + { o, r -> o is CastClassFirstSucc && r == o.foo() }, + ) + } + + @Test + fun testVirtualCallWithoutOneInheritorInverse() { + check( + InstanceOfExample::virtualCallWithoutOneInheritorInverse, + eq(4), + { o, r -> o !is CastClassFirstSucc && o is CastClass && r == o.foo() }, + { o, r -> o is CastClassSecondSucc && r == o.foo() }, + { o, _ -> o == null }, + { o, r -> o is CastClassFirstSucc && r == o.foo() }, + ) + } + + @Test + fun testWithoutOneInheritorOnArray() { + check( + InstanceOfExample::withoutOneInheritorOnArray, + eq(2), + { o, r -> o.isInstanceOfArray() && r == 0 }, + { o, r -> !o.isInstanceOfArray() && r == 1 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testWithoutOneInheritorOnArrayInverse() { + check( + InstanceOfExample::withoutOneInheritorOnArrayInverse, + eq(2), + { o, r -> !o.isInstanceOfArray() && r == 0 }, + { o, r -> o.isInstanceOfArray() && r == 1 }, + coverage = DoNotCalculate + ) + } + + + @Test + fun testInstanceOfAsPartOfInternalExpressions() { + check( + InstanceOfExample::instanceOfAsPartOfInternalExpressions, + branches = ignoreExecutionsNumber, + { o, r -> + val o0isFirst = o[0].isInstanceOfArray() + val o1isSecond = o[1].isInstanceOfArray() + val and = o0isFirst && o1isSecond + and && r == 1 + }, + { o, r -> + val o0isSecond = o[0].isInstanceOfArray() + val o1isFirst = o[1].isInstanceOfArray() + val or = o0isSecond || o1isFirst + or && r == 2 + }, + { o, r -> + val o0isFirst = o[0].isInstanceOfArray() + val o1isSecond = o[1].isInstanceOfArray() + + val o0isSecond = o[0].isInstanceOfArray() + val o1isFirst = o[1].isInstanceOfArray() + + val and = o0isFirst && o1isSecond + val or = o0isSecond || o1isFirst + + !and && !or && r == 3 + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testInstanceOfAsPartOfInternalExpressionsCastClass() { + check( + InstanceOfExample::instanceOfAsPartOfInternalExpressionsCastClass, + branches = ignoreExecutionsNumber, + { o, r -> + val o0isFirst = o[0].isInstanceOfArray() + val o1isSecond = o[1].isInstanceOfArray() + val and = o0isFirst && o1isSecond + !and && r == 1 + }, + { o, r -> + val o0isSecond = o[0].isInstanceOfArray() + val o1isFirst = o[1].isInstanceOfArray() + val or = o0isSecond || o1isFirst + !or && r == 2 + }, + { o, r -> + val o0isFirst = o[0].isInstanceOfArray() + val o1isSecond = o[1].isInstanceOfArray() + + val o0isSecond = o[0].isInstanceOfArray() + val o1isFirst = o[1].isInstanceOfArray() + + val and = o0isFirst && o1isSecond + val or = o0isSecond || o1isFirst + + and && or && r == 3 + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testInstanceOfAsPartOfInternalExpressionsXor() { + check( + InstanceOfExample::instanceOfAsPartOfInternalExpressionsXor, + eq(4), + { o, r -> + val o0isSecond = o[0].isInstanceOfArray() + val o1isFirst = o[1].isInstanceOfArray() + r == 1 && !o0isSecond && o1isFirst + }, + { o, r -> + val o0isSecond = o[0].isInstanceOfArray() + val o1isFirst = o[1].isInstanceOfArray() + r == 2 && o0isSecond && !o1isFirst + }, + { o, r -> + val o0isSecond = o[0].isInstanceOfArray() + val o1isFirst = o[1].isInstanceOfArray() + r == 3 && o0isSecond && o1isFirst + }, + { o, r -> + val o0isSecond = o[0].isInstanceOfArray() + val o1isFirst = o[1].isInstanceOfArray() + r == 4 && !o0isSecond && !o1isFirst + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testInstanceOfAsPartOfInternalExpressionsXorInverse() { + check( + InstanceOfExample::instanceOfAsPartOfInternalExpressionsXorInverse, + eq(4), + { o, r -> + val o0isSecond = o[0].isInstanceOfArray() + val o1isFirst = o[1].isInstanceOfArray() + r == 1 && o0isSecond && o1isFirst + }, + { o, r -> + val o0isSecond = o[0].isInstanceOfArray() + val o1isFirst = o[1].isInstanceOfArray() + r == 2 && !o0isSecond && !o1isFirst + }, + { o, r -> + val o0isSecond = o[0].isInstanceOfArray() + val o1isFirst = o[1].isInstanceOfArray() + r == 3 && o0isSecond && !o1isFirst + }, + { o, r -> + val o0isSecond = o[0].isInstanceOfArray() + val o1isFirst = o[1].isInstanceOfArray() + r == 4 && !o0isSecond && o1isFirst + }, + coverage = DoNotCalculate + ) + } + + @Test + @Disabled("TODO: Can't deal with complicated expressions") + fun testInstanceOfAsPartOfInternalExpressionsIntValue() { + check( + InstanceOfExample::instanceOfAsPartOfInternalExpressionsIntValue, + branches = ignoreExecutionsNumber, + { o, r -> + val t1 = o.isInstanceOfArray() + val t2 = !o.isInstanceOfArray() + val t3 = r == 1 + t1 && t2 && t3 + }, + { o, r -> o.isInstanceOfArray() && r == 2 }, + { o, r -> !o.isInstanceOfArray() && r == 3 }, + coverage = DoNotCalculate + ) + } + + @Test + @Disabled("TODO: Zero branches") + fun testInstanceOfAsInternalExpressionsMap() { + check( + InstanceOfExample::instanceOfAsInternalExpressionsMap, + ge(3), + coverage = DoNotCalculate + ) + } + + + @Test + fun testSymbolicInstanceOf() { + check( + InstanceOfExample::symbolicInstanceOf, + eq(6), + { _, i, r -> i < 1 && r == null }, + { _, i, r -> i > 3 && r == null }, + { o, _, _ -> o == null }, + { o, i, _ -> o != null && i > o.lastIndex }, + { o, i, r -> o != null && o[i] is CastClassFirstSucc && r is CastClassFirstSucc }, + { o, i, r -> o != null && o[i] !is CastClassFirstSucc && r is CastClassSecondSucc }, + ) + } + + @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 + ) + } + + @Test + fun testInstanceOfFromArray() { + check( + InstanceOfExample::instanceOfFromArray, + eq(5), + { a, _ -> a == null }, + { a, r -> a.size != 3 && r == null }, + { a, r -> a.size == 3 && a[0] is CastClassFirstSucc && r != null && r[0] is CastClassFirstSucc }, + { a, r -> a.size == 3 && a[0] is CastClassSecondSucc && r != null && r[0] == null }, + { a, r -> a.size == 3 && a[0] !is CastClassFirstSucc && a[0] !is CastClassSecondSucc && r != null }, + ) + } + + @Test + fun testInstanceOfFromArrayWithReadingAnotherElement() { + check( + InstanceOfExample::instanceOfFromArrayWithReadingAnotherElement, + eq(4), + { a, _ -> a == null }, + { a, r -> a != null && a.size < 2 && r == null }, + { a, r -> a != null && a.size >= 2 && a[0] is CastClassFirstSucc && r is CastClassFirstSucc }, + { a, r -> a != null && a.size >= 2 && a[0] !is CastClassFirstSucc && r == null }, + ) + } + + @Test + fun testInstanceOfFromArrayWithReadingSameElement() { + check( + InstanceOfExample::instanceOfFromArrayWithReadingSameElement, + eq(4), + { a, _ -> a == null }, + { a, r -> a != null && a.size < 2 && r == null }, + { a, r -> a != null && a.size >= 2 && a[0] is CastClassFirstSucc && r is CastClassFirstSucc }, + { a, r -> a != null && a.size >= 2 && a[0] !is CastClassFirstSucc && r == null }, + ) + } + + @Test + fun testIsNull() { + check( + InstanceOfExample::isNull, + eq(2), + { a, r -> a is Array<*> && a.isArrayOf() && r == 1 }, + { a, r -> a == null && r == 2 }, + ) + } + + @Test + fun testArrayInstanceOfArray() { + check( + InstanceOfExample::arrayInstanceOfArray, + eq(4), + { a, r -> a == null && r == null }, + { a, r -> a is Array<*> && a.isArrayOf() && r is Array<*> && r.isArrayOf() }, + { a, r -> a is Array<*> && a.isArrayOf() && r is Array<*> && r.isArrayOf() }, + { a, r -> + a is Array<*> && a.isArrayOf() && !a.isArrayOf() && + !a.isArrayOf() && r is Array<*> && a contentDeepEquals r + }, + ) + } + + @Test + fun testObjectInstanceOfArray() { + check( + InstanceOfExample::objectInstanceOfArray, + eq(3), + { a, r -> a is IntArray && r is IntArray && a contentEquals r }, + { a, r -> a is BooleanArray && r is BooleanArray && a contentEquals r }, + { a, r -> (a == null && r == null) || (!(a is IntArray || a is BooleanArray) && a.equals(r)) }, + ) + } + + @Test + fun testInstanceOfObjectArray() { + check( + InstanceOfExample::instanceOfObjectArray, + eq(3), + { a, r -> a == null && r == null }, + { a, r -> a is Array<*> && a.isArrayOf>() && r is Array<*> && r contentDeepEquals a }, + { a, r -> a is Array<*> && !a.isArrayOf>() && r!!::class == a::class }, + ) + } + + + private inline fun Any?.isInstanceOfArray() = + (this as? Array<*>)?.run { T::class.java.isAssignableFrom(this::class.java.componentType) } == true +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/ClassWithStaticAndInnerClassesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/ClassWithStaticAndInnerClassesTest.kt new file mode 100644 index 0000000000..a2576397ee --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/ClassWithStaticAndInnerClassesTest.kt @@ -0,0 +1,129 @@ +package org.utbot.examples.codegen + +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq + +@Suppress("INACCESSIBLE_TYPE") +internal class ClassWithStaticAndInnerClassesTest : UtValueTestCaseChecker( + testClass = ClassWithStaticAndInnerClasses::class, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA, lastStage = TestExecution, parameterizedModeLastStage = Compilation), + TestLastStage(CodegenLanguage.KOTLIN, lastStage = TestExecution) + ) +) { + @Test + fun testUsePrivateStaticClassWithPrivateField() { + check( + ClassWithStaticAndInnerClasses::usePrivateStaticClassWithPrivateField, + eq(2), + coverage = DoNotCalculate + ) + } + + @Test + fun testUsePrivateStaticClassWithPublicField() { + check( + ClassWithStaticAndInnerClasses::usePrivateStaticClassWithPublicField, + eq(2), + coverage = DoNotCalculate + ) + } + + @Test + fun testUsePublicStaticClassWithPrivateField() { + check( + ClassWithStaticAndInnerClasses::usePublicStaticClassWithPrivateField, + eq(2), + coverage = DoNotCalculate + ) + } + + @Test + fun testUsePublicStaticClassWithPublicField() { + check( + ClassWithStaticAndInnerClasses::usePublicStaticClassWithPublicField, + eq(2), + coverage = DoNotCalculate + ) + } + + @Test + fun testUsePrivateInnerClassWithPrivateField() { + check( + ClassWithStaticAndInnerClasses::usePrivateInnerClassWithPrivateField, + eq(2), + coverage = DoNotCalculate + ) + } + + @Test + fun testUsePrivateInnerClassWithPublicField() { + check( + ClassWithStaticAndInnerClasses::usePrivateInnerClassWithPublicField, + eq(2), + coverage = DoNotCalculate + ) + } + + @Test + fun testUsePublicInnerClassWithPrivateField() { + check( + ClassWithStaticAndInnerClasses::usePublicInnerClassWithPrivateField, + eq(2), + coverage = DoNotCalculate + ) + } + + @Test + fun testUsePublicInnerClassWithPublicField() { + check( + ClassWithStaticAndInnerClasses::usePublicInnerClassWithPublicField, + eq(2), + coverage = DoNotCalculate + ) + } + + @Test + fun testUsePackagePrivateFinalStaticClassWithPackagePrivateField() { + check( + ClassWithStaticAndInnerClasses::usePackagePrivateFinalStaticClassWithPackagePrivateField, + eq(2), + coverage = DoNotCalculate + ) + } + + @Test + fun testUsePackagePrivateFinalInnerClassWithPackagePrivateField() { + check( + ClassWithStaticAndInnerClasses::usePackagePrivateFinalInnerClassWithPackagePrivateField, + eq(2), + coverage = DoNotCalculate + ) + } + + @Test + fun testGetValueFromPublicFieldWithPrivateType() { + check( + ClassWithStaticAndInnerClasses::getValueFromPublicFieldWithPrivateType, + eq(2), + coverage = DoNotCalculate + ) + } + + @Test + fun testPublicStaticClassWithPrivateField_DeepNestedStatic_g() { + checkAllCombinations( + ClassWithStaticAndInnerClasses.PublicStaticClassWithPrivateField.DeepNestedStatic::g, + generateWithNested = true + ) + } + + @Test + fun testPublicStaticClassWithPrivateField_DeepNested_h() { + checkAllCombinations( + ClassWithStaticAndInnerClasses.PublicStaticClassWithPrivateField.DeepNested::h, + generateWithNested = true + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/CodegenExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/CodegenExampleTest.kt new file mode 100644 index 0000000000..ce9b6b757f --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/CodegenExampleTest.kt @@ -0,0 +1,56 @@ +package org.utbot.examples.codegen + +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, + ) + } + } + + @Test + fun innerClassTest() { + val innerClass = CodegenExample::class.nestedClasses.single { it.simpleName == "InnerClass" } + val fooMethod = innerClass.functions.single { it.name == "foo" } + + checkAllCombinations(fooMethod) + } + + @Test + @Disabled("TODO static initializers JIRA:1483") + fun staticClassTest() { + val staticClass = CodegenExample::class.nestedClasses.single { it.simpleName == "StaticClass" } + val barMethod = staticClass.functions.single { it.name == "bar" } + + checkAllCombinations(barMethod) + } + + @Test + fun randomAsLocalVariableTest() { + checkAllCombinations( + MockRandomExamples::randomAsLocalVariable, + ) + } + + @Test + fun randomAsFieldTest() { + checkAllCombinations( + MockRandomExamples::randomAsField, + ) + } + + @Test + fun randomAsParameterTest() { + checkAllCombinations( + MockRandomExamples::randomAsParameter, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/FileWithTopLevelFunctionsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/FileWithTopLevelFunctionsTest.kt new file mode 100644 index 0000000000..6af41eb6d4 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/FileWithTopLevelFunctionsTest.kt @@ -0,0 +1,43 @@ +package org.utbot.examples.codegen + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker +import kotlin.reflect.KFunction3 + +@Suppress("UNCHECKED_CAST") +internal class FileWithTopLevelFunctionsTest : UtValueTestCaseChecker(testClass = FileWithTopLevelFunctionsReflectHelper.clazz.kotlin) { + @Test + fun topLevelSumTest() { + check( + ::topLevelSum, + eq(1), + ) + } + + @Test + fun extensionOnBasicTypeTest() { + check( + Int::extensionOnBasicType, + eq(1), + ) + } + + @Test + fun extensionOnCustomClassTest() { + check( + // NB: cast is important here because we need to treat receiver as an argument to be able to check its content in matchers + CustomClass::extensionOnCustomClass as KFunction3<*, CustomClass, CustomClass, Boolean>, + eq(2), + { receiver, argument, result -> receiver === argument && result == true }, + { receiver, argument, result -> receiver !== argument && result == false }, + additionalDependencies = dependenciesForClassExtensions + ) + } + + companion object { + // Compilation of extension methods for ref objects produces call to + // `kotlin.jvm.internal.Intrinsics::checkNotNullParameter`, so we need to add it to dependencies + val dependenciesForClassExtensions = arrayOf>(kotlin.jvm.internal.Intrinsics::class.java) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt new file mode 100644 index 0000000000..2133cf2ef8 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt @@ -0,0 +1,21 @@ +package org.utbot.examples.codegen + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException + +class JavaAssertTest : UtValueTestCaseChecker( + testClass = JavaAssert::class, + testCodeGeneration = false +) { + @Test + fun testAssertPositive() { + checkWithException( + JavaAssert::assertPositive, + eq(2), + { value, result -> value > 0 && result.isSuccess && result.getOrNull() == value }, + { value, result -> value <= 0 && result.isException() } + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/VoidStaticMethodsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/VoidStaticMethodsTest.kt new file mode 100644 index 0000000000..42af7ff925 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/VoidStaticMethodsTest.kt @@ -0,0 +1,36 @@ +package org.utbot.examples.codegen + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker + +class VoidStaticMethodsTest : UtValueTestCaseChecker( + testClass = VoidStaticMethodsTestingClass::class) { + @Test + fun testInvokeChangeStaticFieldMethod() { + check( + VoidStaticMethodsTestingClass::invokeChangeStaticFieldMethod, + eq(2), + coverage = DoNotCalculate + ) + } + + @Test + fun testInvokeThrowExceptionMethod() { + check( + VoidStaticMethodsTestingClass::invokeThrowExceptionMethod, + eq(3), + coverage = DoNotCalculate + ) + } + + @Test + fun testInvokeAnotherThrowExceptionMethod() { + check( + VoidStaticMethodsTestingClass::invokeAnotherThrowExceptionMethod, + eq(2), + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithCrossReferenceRelationshipTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithCrossReferenceRelationshipTest.kt new file mode 100644 index 0000000000..1e962818ed --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithCrossReferenceRelationshipTest.kt @@ -0,0 +1,26 @@ +package org.utbot.examples.codegen.deepequals + +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker + +class ClassWithCrossReferenceRelationshipTest : UtValueTestCaseChecker( + testClass = ClassWithCrossReferenceRelationship::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testClassWithCrossReferenceRelationship() { + check( + ClassWithCrossReferenceRelationship::returnFirstClass, + eq(2), + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithNullableFieldTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithNullableFieldTest.kt new file mode 100644 index 0000000000..4dbf645bd8 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithNullableFieldTest.kt @@ -0,0 +1,32 @@ +package org.utbot.examples.codegen.deepequals + +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq + +class ClassWithNullableFieldTest : UtValueTestCaseChecker( + testClass = ClassWithNullableField::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testClassWithNullableFieldInCompound() { + check( + ClassWithNullableField::returnCompoundWithNullableField, + eq(2), + coverage = DoNotCalculate + ) + } + + @Test + fun testClassWithNullableFieldInGreatCompound() { + check( + ClassWithNullableField::returnGreatCompoundWithNullableField, + eq(3), + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/DeepEqualsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/DeepEqualsTest.kt new file mode 100644 index 0000000000..9d206c61d4 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/DeepEqualsTest.kt @@ -0,0 +1,164 @@ +package org.utbot.examples.codegen.deepequals + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +// TODO failed Kotlin compilation (generics) SAT-1332 +class DeepEqualsTest : UtValueTestCaseChecker( + testClass = DeepEqualsTestingClass::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testReturnList() { + check( + DeepEqualsTestingClass::returnList, + eq(1), + coverage = DoNotCalculate + ) + } + + @Test + fun testReturnSet() { + check( + DeepEqualsTestingClass::returnSet, + eq(1), + coverage = DoNotCalculate + ) + } + + @Test + fun testReturnMap() { + check( + DeepEqualsTestingClass::returnMap, + eq(1), + coverage = DoNotCalculate + ) + } + + @Test + fun testReturnArray() { + check( + DeepEqualsTestingClass::returnArray, + eq(1), + coverage = DoNotCalculate + ) + } + + @Test + @Disabled("We do not support 2d generics containers right now") + fun testReturn2DList() { + check( + DeepEqualsTestingClass::return2DList, + eq(1), + coverage = DoNotCalculate + ) + } + + @Test + @Disabled("We do not support 2d generics containers right now") + fun testReturn2DSet() { + check( + DeepEqualsTestingClass::return2DSet, + eq(1), + coverage = DoNotCalculate + ) + } + + @Test + @Disabled("We do not support 2d generics containers right now") + fun testReturn2DMap() { + check( + DeepEqualsTestingClass::return2DMap, + eq(1), + coverage = DoNotCalculate + ) + } + + @Test + @Disabled("We do not support 2d generics containers right now") + fun testIntegers2DList() { + check( + DeepEqualsTestingClass::returnIntegers2DList, + eq(1), + coverage = DoNotCalculate + ) + } + + @Test + fun testReturn2DArray() { + check( + DeepEqualsTestingClass::return2DArray, + eq(1), + coverage = DoNotCalculate + ) + } + + @Test + fun testReturnCommonClass() { + check( + DeepEqualsTestingClass::returnCommonClass, + eq(1), + coverage = DoNotCalculate + ) + } + + @Test + fun testTriangle() { + check( + DeepEqualsTestingClass::returnTriangle, + eq(1), + coverage = DoNotCalculate + ) + } + + @Test + fun testQuadrilateral() { + check( + DeepEqualsTestingClass::returnQuadrilateralFromNode, + eq(1), + coverage = DoNotCalculate + ) + } + + @Test + fun testIntMultiArray() { + check( + DeepEqualsTestingClass::fillIntMultiArrayWithConstValue, + eq(3), + coverage = DoNotCalculate + ) + } + + @Test + fun testDoubleMultiArray() { + check( + DeepEqualsTestingClass::fillDoubleMultiArrayWithConstValue, + eq(3), + coverage = DoNotCalculate + ) + } + + @Test + fun testIntegerWrapperMultiArray() { + check( + DeepEqualsTestingClass::fillIntegerWrapperMultiArrayWithConstValue, + eq(3), + coverage = DoNotCalculate + ) + } + + @Test + fun testDoubleWrapperMultiArray() { + check( + DeepEqualsTestingClass::fillDoubleWrapperMultiArrayWithConstValue, + eq(3), + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt new file mode 100644 index 0000000000..200047ea44 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt @@ -0,0 +1,41 @@ +package org.utbot.examples.codegen.modifiers + +import org.junit.jupiter.api.Test +import org.utbot.common.withAccessibility +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.framework.plugin.api.FieldId +import org.utbot.framework.plugin.api.util.id +import org.utbot.framework.plugin.api.util.jField +import org.utbot.testcheckers.eq +import org.utbot.testing.Compilation +import org.utbot.testing.UtValueTestCaseChecker + +// TODO failed Kotlin tests execution with non-nullable expected field +class ClassWithPrivateMutableFieldOfPrivateTypeTest : UtValueTestCaseChecker( + testClass = ClassWithPrivateMutableFieldOfPrivateType::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, Compilation) + ) +) { + @Test + fun testChangePrivateMutableFieldWithPrivateType() { + checkAllMutationsWithThis( + ClassWithPrivateMutableFieldOfPrivateType::changePrivateMutableFieldWithPrivateType, + eq(1), + { thisBefore, _, thisAfter, _, r -> + val privateMutableField = FieldId( + ClassWithPrivateMutableFieldOfPrivateType::class.id, + "privateMutableField" + ).jField + + val (privateFieldBeforeValue, privateFieldAfterValue) = privateMutableField.withAccessibility { + privateMutableField.get(thisBefore) to privateMutableField.get(thisAfter) + } + + privateFieldBeforeValue == null && privateFieldAfterValue != null && r == 0 + } + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt new file mode 100644 index 0000000000..bcc5df047d --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt @@ -0,0 +1,76 @@ +package org.utbot.examples.collections + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.framework.plugin.api.FieldId +import org.utbot.framework.plugin.api.UtConcreteValue +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class CustomerExamplesTest: UtValueTestCaseChecker( + testClass = CustomerExamples::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA, lastStage = TestExecution, parameterizedModeLastStage = Compilation), + TestLastStage(CodegenLanguage.KOTLIN, lastStage = CodeGeneration) + ) +) { + @Test + fun testSimpleExample() { + checkStatics( + CustomerExamples::simpleExample, + eq(2), + { key, statics, r -> + val hashMap = statics.extractSingleStaticMap() + key !in hashMap && r == 2 + }, + { key, statics, r -> + val hashMap = statics.extractSingleStaticMap() + key in hashMap && r == 1 + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testStaticMap() { + checkStaticsWithThis( + CustomerExamples::staticMap, + ignoreExecutionsNumber, + { _, a, _, _, _, _ -> a == null }, + { t, _, _, _, _, _ -> t.c == null }, + { _, a, _, _, _, _ -> a.b == null }, + { t, a, _, _, _, r -> a.foo() > 1 && t.c.x < 3 && r == 1 }, + { t, a, key, _, statics, r -> + val hashMap = statics.extractSingleStaticMap() + + val firstConditionNegation = !(a.foo() > 1 && t.c.x < 3) + val secondCondition = a.b.bar() < 3 && key in hashMap + + firstConditionNegation && secondCondition && r == 2 + }, + { t, a, key, x, statics, r -> + val hashMap = statics.extractSingleStaticMap() + + val firstConditionNegation = !(a.foo() > 1 && t.c.x < 3) + val secondConditionNegation = !(a.b.bar() < 3 && key in hashMap) + val thirdCondition = t.c.x > 5 && t.foo(x) < 10 + + firstConditionNegation && secondConditionNegation && thirdCondition && r == 3 + }, + { t, a, key, x, statics, r -> + val hashMap = statics.extractSingleStaticMap() + + val firstConditionNegation = !(a.foo() > 1 && t.c.x < 3) + val secondConditionNegation = !(a.b.bar() < 3 && key in hashMap) + val thirdConditionNegation = !(t.c.x > 5 && t.foo(x) < 10) + + firstConditionNegation && secondConditionNegation && thirdConditionNegation && r == 4 + }, + // TODO JIRA:1588 + coverage = DoNotCalculate + ) + } + + private fun Map>.extractSingleStaticMap() = + values.singleOrNull()?.value as? HashMap<*, *> ?: emptyMap() +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/GenericListsExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/GenericListsExampleTest.kt new file mode 100644 index 0000000000..fbabf6523c --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/GenericListsExampleTest.kt @@ -0,0 +1,160 @@ +package org.utbot.examples.collections + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +// TODO disabled tests should be fixes with SAT-1441 +internal class GenericListsExampleTest : UtValueTestCaseChecker( + testClass = GenericListsExample::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + @Disabled("Doesn't find branches without NPE") + fun testListOfListsOfT() { + check( + GenericListsExample::listOfListsOfT, + eq(-1) + ) + } + + @Test + @Disabled("Problems with memory") + fun testListOfComparable() { + check( + GenericListsExample::listOfComparable, + eq(1), + { v, r -> v != null && v.size > 1 && v[0] != null && v.all { it is Comparable<*> || it == null } && v == r }, + coverage = DoNotCalculate + ) + } + + @Test + fun testListOfT() { + check( + GenericListsExample::listOfT, + eq(1), + { v, r -> v != null && v.size >= 2 && v[0] != null && v == r }, + coverage = DoNotCalculate + ) + } + + @Test + @Disabled("Wrong number of matchers") + fun testListOfTArray() { + check( + GenericListsExample::listOfTArray, + eq(1) + ) + } + + @Test + @Disabled("JIRA:1446") + fun testListOfExtendsTArray() { + check( + GenericListsExample::listOfExtendsTArray, + eq(-1) + ) + } + + @Test + @Disabled("java.lang.ClassCastException: java.util.ArraysParallelSortHelpers\$FJShort\$Merger cannot be cast to [I") + fun testListOfPrimitiveArrayInheritors() { + check( + GenericListsExample::listOfPrimitiveArrayInheritors, + eq(-1) + ) + } + + @Test + @Disabled("JIRA:1620") + fun createWildcard() { + check( + GenericListsExample<*>::wildcard, + eq(4), + { v, r -> v == null && r?.isEmpty() == true }, + { v, r -> v != null && v.size == 1 && v[0] != null && v == r && v.all { it is Number || it == null } }, + { v, r -> v != null && (v.size != 1 || v[0] == null) && v == r && v.all { it is Number || it == null } }, + coverage = DoNotCalculate + ) + } + + @Suppress("NestedLambdaShadowedImplicitParameter") + @Test + @Disabled("unexpected empty nested list") + fun createListOfLists() { + check( + GenericListsExample<*>::listOfLists, + eq(1), + { v, r -> + val valueCondition = v != null && v[0] != null && v[0].isNotEmpty() + val typeCondition = v.all { (it is List<*> && it.all { it is Int || it == null }) || it == null } + + valueCondition && typeCondition && v == r + }, + coverage = DoNotCalculate + ) + } + + @Test + fun createWildcardWithOnlyQuestionMark() { + check( + GenericListsExample<*>::wildcardWithOnlyQuestionMark, + eq(3), + { v, r -> v == null && r?.isEmpty() == true }, + { v, r -> v.size == 1 && v == r }, + { v, r -> v.size != 1 && v == r }, + coverage = DoNotCalculate + ) + } + + + @Test + fun testGenericWithArrayOfPrimitives() { + check( + GenericListsExample<*>::genericWithArrayOfPrimitives, + eq(1), + { v, _ -> + val valueCondition = v != null && v.size >= 2 && v[0] != null && v[0].isNotEmpty() && v[0][0] != 0L + val typeCondition = v.all { it is LongArray || it == null } + + valueCondition && typeCondition + }, + coverage = DoNotCalculate + ) + } + + + @Test + fun testGenericWithObject() { + check( + GenericListsExample<*>::genericWithObject, + eq(1), + { v, r -> v != null && v.size >= 2 && v[0] != null && v[0] is Long && v == r }, + coverage = DoNotCalculate + ) + } + + + @Test + fun testGenericWithArrayOfArrays() { + check( + GenericListsExample<*>::genericWithArrayOfArrays, + eq(1), + { v, _ -> + val valueCondition = v != null && v.size >= 2 && v[0] != null && v[0].isNotEmpty() && v[0][0] != null + val typeCondition = v.all { + (it is Array<*> && it.isArrayOf>() && it.all { it.isArrayOf() || it == null}) || it == null + } + + valueCondition && typeCondition + }, + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/LinkedListsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/LinkedListsTest.kt new file mode 100644 index 0000000000..ca667af7e9 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/LinkedListsTest.kt @@ -0,0 +1,261 @@ +package org.utbot.examples.collections + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +// TODO failed Kotlin compilation (generics) SAT-1332 +internal class LinkedListsTest : UtValueTestCaseChecker( + testClass = LinkedLists::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + + @Test + fun testSet() { + check( + LinkedLists::set, + eq(3), + { l, _ -> l == null }, + { l, _ -> l.size <= 2 }, + { l, r -> l.size > 2 && r == 1 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testOffer() { + check( + LinkedLists::offer, + eq(3), + { l, _ -> l == null }, + { l, r -> l != null && l.size <= 1 && r == l }, + { l, r -> l != null && l.size > 1 && r == l + 1 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testOfferLast() { + check( + LinkedLists::offerLast, + eq(3), + { l, _ -> l == null }, + { l, r -> l != null && l.size <= 1 && r == l }, + { l, r -> l != null && l.size > 1 && r == l + 1 }, + coverage = DoNotCalculate + ) + } + + + @Test + fun testAddLast() { + check( + LinkedLists::addLast, + eq(3), + { l, _ -> l == null }, + { l, r -> l != null && l.size <= 1 && r == l }, + { l, r -> l != null && l.size > 1 && (r == l + 1) }, + coverage = DoNotCalculate + ) + } + + @Test + fun testPush() { + check( + LinkedLists::push, + eq(3), + { l, _ -> l == null }, + { l, r -> l != null && l.size <= 1 && r == l }, + { l, r -> l != null && l.size > 1 && r == listOf(1) + l }, + coverage = DoNotCalculate + ) + } + + @Test + fun testOfferFirst() { + check( + LinkedLists::offerFirst, + eq(3), + { l, _ -> l == null }, + { l, r -> l != null && l.size <= 1 && r == l }, + { l, r -> l != null && l.size > 1 && r == listOf(1) + l }, + coverage = DoNotCalculate + ) + } + + @Test + fun testAddFirst() { + check( + LinkedLists::addFirst, + eq(3), + { l, _ -> l == null }, + { l, r -> l != null && l.size <= 1 && r == l }, + { l, r -> l != null && l.size > 1 && r!!.size == l.size + 1 && r[0] == 1 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testPeek() { + checkWithException( + LinkedLists::peek, + eq(3), + { l, _ -> l == null }, + { l, r -> l != null && (l.isEmpty() || l.first() == null) && r.isException() }, + { l, r -> l != null && l.isNotEmpty() && r.getOrNull() == l[0] }, + coverage = DoNotCalculate + ) + } + + @Test + fun testPeekFirst() { + checkWithException( + LinkedLists::peekFirst, + eq(3), + { l, _ -> l == null }, + { l, r -> l != null && (l.isEmpty() || l.first() == null) && r.isException() }, + { l, r -> l != null && l.isNotEmpty() && r.getOrNull() == l[0] }, + coverage = DoNotCalculate + ) + } + + @Test + fun testPeekLast() { + checkWithException( + LinkedLists::peekLast, + eq(3), + { l, _ -> l == null }, + { l, r -> l != null && (l.isEmpty() || l.last() == null) && r.isException() }, + { l, r -> l != null && l.isNotEmpty() && r.getOrNull() == l.last() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testElement() { + checkWithException( + LinkedLists::element, + eq(4), + { l, _ -> l == null }, + { l, r -> l != null && l.isEmpty() && r.isException() }, + { l, r -> l != null && l.isNotEmpty() && l[0] == null && r.isException() }, + { l, r -> l != null && l.isNotEmpty() && l[0] != null && r.getOrNull() == l[0] }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetFirst() { + checkWithException( + LinkedLists::getFirst, + eq(4), + { l, _ -> l == null }, + { l, r -> l != null && l.isEmpty() && r.isException() }, + { l, _ -> l != null && l.isNotEmpty() && l[0] == null }, + { l, r -> l != null && l.isNotEmpty() && r.getOrNull() == l[0] }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetLast() { + checkWithException( + LinkedLists::getLast, + eq(4), + { l, _ -> l == null }, + { l, r -> l != null && l.isEmpty() && r.isException() }, + { l, _ -> l != null && l.isNotEmpty() && l.last() == null }, + { l, r -> l != null && l.isNotEmpty() && r.getOrNull() == l.last() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testPoll() { + checkWithException( + LinkedLists::poll, + eq(5), + { l, _ -> l == null }, + { l, r -> l != null && l.isEmpty() && r.isException() }, + { l, r -> l != null && l.size == 1 && r.getOrNull() == l }, + { l, _ -> l != null && l.size > 1 && l.first() == null }, + { l, r -> l != null && l.size > 1 && r.getOrNull() == l.subList(1, l.size) }, + coverage = DoNotCalculate + ) + } + + @Test + fun testPollFirst() { + checkWithException( + LinkedLists::pollFirst, + eq(5), + { l, _ -> l == null }, + { l, r -> l != null && l.isEmpty() && r.isException() }, + { l, r -> l != null && l.size == 1 && r.getOrNull() == l }, + { l, _ -> l != null && l.size > 1 && l.first() == null }, + { l, r -> l != null && l.size > 1 && r.getOrNull() == l.subList(1, l.size) }, + coverage = DoNotCalculate + ) + } + + @Test + fun testPollLast() { + checkWithException( + LinkedLists::pollLast, + eq(5), + { l, _ -> l == null }, + { l, r -> l != null && l.isEmpty() && r.isException() }, + { l, r -> l != null && l.size == 1 && r.getOrNull() == l }, + { l, _ -> l != null && l.size > 1 && l.last() == null }, + { l, r -> l != null && l.size > 1 && r.getOrNull() == l.subList(0, l.size - 1) }, + coverage = DoNotCalculate + ) + } + + @Test + fun testRemove() { + checkWithException( + LinkedLists::removeFirst, + eq(5), + { l, _ -> l == null }, + { l, r -> l != null && l.isEmpty() && r.isException() }, + { l, r -> l != null && l.size == 1 && r.getOrNull() == l }, + { l, _ -> l != null && l.size > 1 && l.first() == null }, + { l, r -> l != null && l.size > 1 && r.getOrNull() == l.subList(1, l.size) }, + coverage = DoNotCalculate + ) + } + + @Test + fun testRemoveFirst() { + checkWithException( + LinkedLists::removeFirst, + eq(5), + { l, _ -> l == null }, + { l, r -> l != null && l.isEmpty() && r.isException() }, + { l, r -> l != null && l.size == 1 && r.getOrNull() == l }, + { l, _ -> l != null && l.size > 1 && l.first() == null }, + { l, r -> l != null && l.size > 1 && r.getOrNull() == l.subList(1, l.size) }, + coverage = DoNotCalculate + ) + } + + @Test + fun testRemoveLast() { + checkWithException( + LinkedLists::removeLast, + eq(5), + { l, _ -> l == null }, + { l, r -> l != null && l.isEmpty() && r.isException() }, + { l, r -> l != null && l.size == 1 && r.getOrNull() == l }, + { l, _ -> l != null && l.size > 1 && l.last() == null }, + { l, r -> l != null && l.size > 1 && r.getOrNull() == l.subList(0, l.size - 1) }, + coverage = DoNotCalculate + ) + } + +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListAlgorithmsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListAlgorithmsTest.kt new file mode 100644 index 0000000000..ef1083217e --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListAlgorithmsTest.kt @@ -0,0 +1,32 @@ +package org.utbot.examples.collections + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast + +// TODO failed Kotlin compilation SAT-1332 +class ListAlgorithmsTest : UtValueTestCaseChecker( + testClass = ListAlgorithms::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + + @Test + fun testMergeLists() { + check( + ListAlgorithms::mergeListsInplace, + eq(4), + { a, b, r -> b.subList(0, b.size - 1).any { a.last() < it } && r != null && r == r.sorted() }, + { a, b, r -> (a.subList(0, a.size - 1).any { b.last() <= it } || a.any { ai -> b.any { ai < it } }) && r != null && r == r.sorted() }, + { a, b, r -> a[0] < b[0] && r != null && r == r.sorted() }, + { a, b, r -> a[0] >= b[0] && r != null && r == r.sorted() }, + coverage = atLeast(94) + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListIteratorsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListIteratorsTest.kt new file mode 100644 index 0000000000..a8274f04df --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListIteratorsTest.kt @@ -0,0 +1,108 @@ +package org.utbot.examples.collections + +import org.junit.jupiter.api.Disabled +import org.utbot.framework.plugin.api.CodegenLanguage +import kotlin.math.min +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +// TODO failed Kotlin compilation (generics) SAT-1332 +internal class ListIteratorsTest : UtValueTestCaseChecker( + testClass = ListIterators::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + + @Test + fun testIterate() { + check( + ListIterators::iterate, + eq(3), + { l, _ -> l == null }, + { l, result -> l.isEmpty() && result == l }, + { l, result -> l.isNotEmpty() && result == l }, + coverage = DoNotCalculate + ) + } + + @Test + fun testIterateReversed() { + check( + ListIterators::iterateReversed, + eq(3), + { l, _ -> l == null }, + { l, result -> l.isEmpty() && result == l }, + { l, result -> l.isNotEmpty() && result == l.reversed() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testIterateForEach() { + check( + ListIterators::iterateForEach, + eq(4), + { l, _ -> l == null }, + { l, result -> l.isEmpty() && result == 0 }, + { l, _ -> l.isNotEmpty() && l.any { it == null } }, + { l, result -> l.isNotEmpty() && result == l.sum() }, + coverage = DoNotCalculate + ) + } + + @Test + @Disabled("Java 11 transition") + fun testAddElements() { + check( + ListIterators::addElements, + eq(5), + { l, _, _ -> l == null }, + { l, _, result -> l != null && l.isEmpty() && result == l }, + { l, arr, _ -> l != null && l.size > 0 && arr == null }, + { l, arr, _ -> l != null && arr != null && l.isNotEmpty() && arr.isEmpty() }, + { l, arr, _ -> l != null && arr != null && l.size > arr.size }, + coverage = DoNotCalculate + ) + } + + @Test + fun testSetElements() { + check( + ListIterators::setElements, + eq(5), + { l, _, _ -> l == null }, + { l, _, result -> l != null && l.isEmpty() && result == l }, + { l, arr, _ -> l != null && arr != null && l.size > arr.size }, + { l, arr, _ -> l != null && l.size > 0 && arr == null }, + { l, arr, result -> l != null && arr != null && l.size <= arr.size && result == arr.asList().take(l.size) }, + coverage = DoNotCalculate + ) + } + + @Test + fun testRemoveElements() { + check( + ListIterators::removeElements, + ignoreExecutionsNumber, // the exact number of the executions depends on the decisions made by PathSelector + // so we can have either six results or seven, depending on the [pathSelectorType] + // from UtSettings + { l, _, _ -> l == null }, + { l, i, _ -> l != null && i <= 0 }, + { l, i, _ -> l != null && l.isEmpty() && i > 0 }, + { l, i, _ -> l != null && i > 0 && l.subList(0, min(i, l.size)).any { it !is Int } }, + { l, i, _ -> l != null && i > 0 && l.subList(0, min(i, l.size)).any { it == null } }, + { l, i, _ -> l != null && l.isNotEmpty() && i > 0 }, + { l, i, result -> + require(l != null) + + val precondition = l.isNotEmpty() && i > 0 && l.subList(0, i).all { it is Int } + val postcondition = result == (l.subList(0, i - 1) + l.subList(min(l.size, i), l.size)) + + precondition && postcondition + }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListWrapperReturnsVoidTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListWrapperReturnsVoidTest.kt new file mode 100644 index 0000000000..d4c5cae8dc --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListWrapperReturnsVoidTest.kt @@ -0,0 +1,43 @@ +package org.utbot.examples.collections + +import org.junit.jupiter.api.Disabled +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +// TODO failed Kotlin compilation ($ in function names, generics) SAT-1220 SAT-1332 +@Disabled("Java 11 transition") +internal class ListWrapperReturnsVoidTest : UtValueTestCaseChecker( + testClass = ListWrapperReturnsVoidExample::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testRunForEach() { + checkWithException( + ListWrapperReturnsVoidExample::runForEach, + eq(4), + { l, r -> l == null && r.isException() }, + { l, r -> l.isEmpty() && r.getOrThrow() == 0 }, + { l, r -> l.isNotEmpty() && l.all { it != null } && r.getOrThrow() == 0 }, + { l, r -> l.isNotEmpty() && l.any { it == null } && r.getOrThrow() > 0 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testSumPositiveForEach() { + checkWithException( + ListWrapperReturnsVoidExample::sumPositiveForEach, + eq(5), + { l, r -> l == null && r.isException() }, + { l, r -> l.isEmpty() && r.getOrThrow() == 0 }, + { l, r -> l.isNotEmpty() && l.any { it == null } && r.isException() }, + { l, r -> l.isNotEmpty() && l.any { it <= 0 } && r.getOrThrow() == l.filter { it > 0 }.sum() }, + { l, r -> l.isNotEmpty() && l.any { it > 0 } && r.getOrThrow() == l.filter { it > 0 }.sum() } + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart1Test.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart1Test.kt new file mode 100644 index 0000000000..397276453e --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart1Test.kt @@ -0,0 +1,30 @@ +package org.utbot.examples.collections + +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber + +// TODO failed Kotlin compilation SAT-1332 +@Disabled +internal class ListsPart1Test : UtValueTestCaseChecker( + testClass = Lists::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testIterableContains() { + check( + Lists::iterableContains, + ignoreExecutionsNumber, + { iterable, _ -> iterable == null }, + { iterable, r -> 1 in iterable && r == true }, + { iterable, r -> 1 !in iterable && r == false }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart2Test.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart2Test.kt new file mode 100644 index 0000000000..616ec2e4a7 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart2Test.kt @@ -0,0 +1,27 @@ +package org.utbot.examples.collections + +import org.junit.jupiter.api.Disabled +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test + +// TODO failed Kotlin compilation SAT-1332 +@Disabled +internal class ListsPart2Test : UtValueTestCaseChecker( + testClass = Lists::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testCollectionContains() { + check( + Lists::collectionContains, + ignoreExecutionsNumber, + { collection, _ -> collection == null }, + { collection, r -> 1 in collection && r == true }, + { collection, r -> 1 !in collection && r == false }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart3Test.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart3Test.kt new file mode 100644 index 0000000000..d7ac68b90a --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart3Test.kt @@ -0,0 +1,246 @@ +package org.utbot.examples.collections + +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 + +// TODO failed Kotlin compilation SAT-1332 +internal class ListsPart3Test : UtValueTestCaseChecker( + testClass = Lists::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun createTest() { + check( + Lists::create, + 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 + ) + } + + @Test + fun testBigListFromParameters() { + check( + Lists::bigListFromParameters, + eq(1), + { list, r -> list.size == r && list.size == 11 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetNonEmptyCollection() { + check( + Lists::getNonEmptyCollection, + eq(3), + { collection, _ -> collection == null }, + { collection, r -> collection.isEmpty() && r == null }, + { collection, r -> collection.isNotEmpty() && collection == r }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetFromAnotherListToArray() { + check( + Lists::getFromAnotherListToArray, + eq(4), + { l, _ -> l == null }, + { 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 + ) + } + + @Test + fun addElementsTest() { + check( + Lists::addElements, + eq(5), + { list, _, _ -> list == null }, + { list, a, _ -> list != null && list.size >= 2 && a == null }, + { list, _, r -> list.size < 2 && r == list }, + { list, a, r -> list.size >= 2 && a.size < 2 && r == list }, + { list, a, r -> + require(r != null) + + val sizeConstraint = list.size >= 2 && a.size >= 2 && r.size == list.size + a.size + val content = r.mapIndexed { i, it -> if (i < r.size) it == r[i] else it == a[i - r.size] }.all { it } + + sizeConstraint && content + }, + coverage = DoNotCalculate + ) + } + + @Test + fun removeElementsTest() { + checkWithException( + Lists::removeElements, + between(7..8), + { 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() }, + { list, i, j, r -> + require(list != null && list[i] != null) + + val listConstraints = i >= 0 && list.size > i && (list.size <= j + 1 || j < 0) + val resultConstraint = r.isException() + + listConstraints && resultConstraint + }, + { list, i, j, r -> + require(list != null && list[i] != null) + + val k = j + if (i <= j) 1 else 0 + val indicesConstraint = i >= 0 && list.size > i && j >= 0 && list.size > j + 1 + val contentConstraint = list[i] != null && list[k] == null + val resultConstraint = r.isException() + + indicesConstraint && contentConstraint && resultConstraint + }, + { list, i, j, r -> + require(list != null) + + val k = j + if (i <= j) 1 else 0 + + val precondition = i >= 0 && list.size > i && j >= 0 && list.size > j + 1 && list[i] < list[k] + val postcondition = r.getOrNull() == list[i] + + precondition && postcondition + }, + { list, i, j, r -> + require(list != null) + + val k = j + if (i <= j) 1 else 0 + + val precondition = i >= 0 && list.size > i && j >= 0 && list.size > j + 1 && list[i] >= list[k] + val postcondition = r.getOrNull() == list[k] + + precondition && postcondition + }, + coverage = DoNotCalculate + ) + } + + @Test + fun createArrayWithDifferentTypeTest() { + check( + Lists::createWithDifferentType, + 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 + ) + } + + @Test + fun getElementsTest() { + check( + Lists::getElements, + eq(4), + { x, _ -> x == null }, + { 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 + ) + } + + @Test + fun setElementsTest() { + check( + Lists::setElements, + eq(3), + { 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 + ) + } + + @Test + fun testClear() { + check( + Lists::clear, + eq(3), + { list, _ -> list == null }, + { list, r -> list.size >= 2 && r == emptyList() }, + { list, r -> list.size < 2 && r == emptyList() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testAddAll() { + check( + Lists::addAll, + eq(3), + { list, _, _ -> list == null }, + { list, i, r -> + list != null && list.isEmpty() && r != null && r.size == 1 && r[0] == i + }, + { list, i, r -> + list != null && list.isNotEmpty() && r != null && r.size == 1 + list.size && r == listOf(i) + list + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testAddAllInIndex() { + check( + Lists::addAllByIndex, + eq(4), + { list, i, _ -> list == null && i >= 0 }, + { list, i, _ -> list == null && i < 0 }, + { list, i, r -> list != null && i >= list.size && r == list }, + { list, i, r -> + list != null && i in 0..list.lastIndex && r == list.toMutableList().apply { addAll(i, listOf(0, 1)) } + }, + coverage = DoNotCalculate + ) + } + + @Test + @Disabled("TODO: add choosing proper type in list wrapper") + fun testRemoveFromList() { + checkWithException( + Lists::removeFromList, + ge(4), + { list, _, r -> list == null && r.isException() }, + { list, _, r -> list != null && list.isEmpty() && r.isException() }, + { list, i, r -> + require(list != null && list.lastOrNull() != null) + + list.isNotEmpty() && (i < 0 || i >= list.size) && r.isException() + }, + { list, i, r -> + require(list != null && list.lastOrNull() != null) + + val changedList = list.toMutableList().apply { + set(i, last()) + removeLast() + } + + val precondition = list.isNotEmpty() && i >= 0 && i < list.size + val postcondition = changedList == r.getOrNull() + + precondition && postcondition + }, + // TODO: add branches with conditions (list is LinkedList) and (list !is ArrayList && list !is LinkedList) + coverage = DoNotCalculate + ) + } + +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapEntrySetTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapEntrySetTest.kt new file mode 100644 index 0000000000..4c9bd82989 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapEntrySetTest.kt @@ -0,0 +1,172 @@ +package org.utbot.examples.collections + +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 + +// TODO failed Kotlin compilation SAT-1332 +class MapEntrySetTest : UtValueTestCaseChecker( + testClass = MapEntrySet::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + @Disabled("JIRA:1443") + fun testRemoveFromEntrySet() { + checkWithException( + MapEntrySet::removeFromEntrySet, + between(3..7), + { map, _, _, result -> map == null && result.isException() }, + { map, i, j, result -> map.entries.none { it.key == i && it.value == j } && result.getOrNull() == map }, + { map, i, j, result -> + val resultMap = result.getOrNull()!! + val mapContainsIJ = map.entries.any { it.key == i && it.value == j } + val mapContainsAllEntriesFromResult = map.entries.containsAll(resultMap.entries) + val resultDoesntContainIJ = + resultMap.entries.size == map.entries.size - 1 && resultMap.entries.none { it.key == i && it.value == j } + mapContainsIJ && mapContainsAllEntriesFromResult && resultDoesntContainIJ + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testAddToEntrySet() { + checkWithException( + MapEntrySet::addToEntrySet, + between(2..4), + { map, result -> map == null && result.isException() }, + { map, result -> map != null && result.isException() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetFromEntrySet() { + check( + MapEntrySet::getFromEntrySet, + between(3..7), + { 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 + ) + } + + @Test + fun testIteratorHasNext() { + check( + MapEntrySet::iteratorHasNext, + between(3..4), + { map, _ -> map == null }, + { map, result -> map.entries.isEmpty() && result == 0 }, + { map, result -> map.entries.isNotEmpty() && result == map.entries.size }, + coverage = DoNotCalculate + ) + } + + @Test + fun testIteratorNext() { + checkWithException( + MapEntrySet::iteratorNext, + between(3..5), + { 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 + { map, result -> + val resultEntry = result.getOrNull()!! + val (entryKey, entryValue) = map.entries.first() + val (resultKey, resultValue) = resultEntry + map.entries.isNotEmpty() && entryKey == resultKey && entryValue == resultValue + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testIteratorRemove() { + checkWithException( + MapEntrySet::iteratorRemove, + between(3..4), + { 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 + { map, result -> + val resultMap = result.getOrNull()!! + val mapContainsAllEntriesInResult = map.entries.containsAll(resultMap.entries) + val resultDoesntContainFirstEntry = + resultMap.entries.size == map.entries.size - 1 && map.entries.first() !in resultMap.entries + map.entries.isNotEmpty() && mapContainsAllEntriesInResult && resultDoesntContainFirstEntry + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testIteratorRemoveOnIndex() { + checkWithException( + MapEntrySet::iteratorRemoveOnIndex, + ge(5), + { _, i, result -> i == 0 && result.isSuccess && result.getOrNull() == null }, + { map, _, result -> map == null && result.isException() }, + { map, i, result -> map != null && i < 0 && result.isException() }, + { map, i, result -> i > map.entries.size && result.isException() }, + // test should work as long as default class for map is LinkedHashMap + { map, i, result -> + val resultMap = result.getOrNull()!! + val iInIndexRange = i in 0..map.entries.size + val mapContainsAllEntriesInResult = map.entries.containsAll(resultMap.entries) + val resultDoesntContainIthEntry = map.entries.toList()[i - 1] !in resultMap.entries + iInIndexRange && mapContainsAllEntriesInResult && resultDoesntContainIthEntry + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testIterateForEach() { + check( + MapEntrySet::iterateForEach, + between(3..5), + { map, _ -> map == null }, + { map, _ -> null in map.values }, + { map, result -> result!![0] == map.keys.sum() && result[1] == map.values.sum() }, + coverage = DoNotCalculate + ) + } + + + @Test + fun testIterateWithIterator() { + withPushingStateFromPathSelectorForConcrete { + checkWithException( + MapEntrySet::iterateWithIterator, + ignoreExecutionsNumber, + { map, result -> map == null && result.isException() }, + { map, result -> map.isEmpty() && result.getOrThrow().contentEquals(intArrayOf(0, 0)) }, + { map, result -> map.size % 2 == 1 && result.isException() }, + { map, result -> + val evenEntryHasNullKey = map.keys.indexOf(null) % 2 == 0 + evenEntryHasNullKey && result.isException() + }, + { map, result -> + val twoElementsOrMore = map.size > 1 + val oddEntryHasNullKey = map.values.indexOf(null) % 2 == 1 + twoElementsOrMore && oddEntryHasNullKey && result.isException() + }, + { 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 } + mapIsNotEmptyAndSizeIsEven && arrayResult[0] == evenKeysSum && arrayResult[1] == oddValuesSum + }, + ) + } + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapKeySetTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapKeySetTest.kt new file mode 100644 index 0000000000..92aa202c2e --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapKeySetTest.kt @@ -0,0 +1,161 @@ +package org.utbot.examples.collections + +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.testcheckers.withPushingStateFromPathSelectorForConcrete +import org.utbot.testcheckers.withoutMinimization + +// TODO failed Kotlin compilation SAT-1332 +class MapKeySetTest : UtValueTestCaseChecker( + testClass = MapKeySet::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testRemoveFromKeySet() { + withoutMinimization { // TODO: JIRA:1506 + checkWithException( + MapKeySet::removeFromKeySet, + ignoreExecutionsNumber, + { map, _, result -> map == null && result.isException() }, + { map, i, result -> i !in map.keys && result.getOrNull() == map }, // one of these will be minimized + { map, i, result -> // one of these will be minimized + val resultMap = result.getOrNull()!! + val mapKeysContainsI = i in map.keys + val mapContainsAllKeysInResult = map.keys.containsAll(resultMap.keys) + val resultDoesntContainI = resultMap.keys.size == map.keys.size - 1 && i !in resultMap.keys + mapKeysContainsI && mapContainsAllKeysInResult && resultDoesntContainI + }, + ) + } + } + + @Test + fun testAddToKeySet() { + checkWithException( + MapKeySet::addToKeySet, + between(2..4), + { map, result -> map == null && result.isException() }, + { map, result -> map != null && result.isException() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetFromKeySet() { + withoutMinimization { // TODO: JIRA:1506 + check( + MapKeySet::getFromKeySet, + ignoreExecutionsNumber, // branches with null keys may appear + { 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 + ) + } + } + + @Test + fun testIteratorHasNext() { + check( + MapKeySet::iteratorHasNext, + between(3..4), + { map, _ -> map == null }, + { map, result -> map.keys.isEmpty() && result == 0 }, + { map, result -> map.keys.isNotEmpty() && result == map.keys.size }, + coverage = DoNotCalculate + ) + } + + @Test + fun testIteratorNext() { + withPushingStateFromPathSelectorForConcrete { + checkWithException( + MapKeySet::iteratorNext, + between(3..4), + { 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 + ) + } + } + + @Test + fun testIteratorRemove() { + checkWithException( + MapKeySet::iteratorRemove, + between(3..4), + { 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 -> + val resultMap = result.getOrNull()!! + val mapContainsAllKeysInResult = map.keys.isNotEmpty() && map.keys.containsAll(resultMap.keys) + val resultDoesntContainFirstKey = resultMap.keys.size == map.keys.size - 1 && map.keys.first() !in resultMap.keys + mapContainsAllKeysInResult && resultDoesntContainFirstKey + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testIteratorRemoveOnIndex() { + checkWithException( + MapKeySet::iteratorRemoveOnIndex, + ge(5), + { _, i, result -> i == 0 && result.isSuccess && result.getOrNull() == null }, + { map, _, result -> map == null && result.isException() }, + { map, i, result -> map != null && i < 0 && result.isException() }, + { map, i, result -> i > map.keys.size && result.isException() }, + // test should work as long as default class for map is LinkedHashMap + { map, i, result -> + val resultMap = result.getOrNull()!! + val iInIndexRange = i in 0..map.keys.size + val mapContainsAllKeysInResult = map.keys.containsAll(resultMap.keys) + val resultDoesntContainIthKey = map.keys.toList()[i - 1] !in resultMap.keys + iInIndexRange && mapContainsAllKeysInResult && resultDoesntContainIthKey + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testIterateForEach() { + check( + MapKeySet::iterateForEach, + ignoreExecutionsNumber, + { map, _ -> map == null }, + { map, _ -> map != null && null in map.keys }, + { map, result -> map != null && result == map.keys.sum() }, + ) + } + + @Test + fun testIterateWithIterator() { + check( + MapKeySet::iterateWithIterator, + ignoreExecutionsNumber, + { map, _ -> map == null }, + { map, _ -> map != null && null in map.keys }, + { map, result -> map != null && result == map.keys.sum() }, + ) + } + + @Test + fun testNullKey() { + check( + MapKeySet::nullKey, + eq(3), + { map, _ -> map == null }, + { map, result -> map != null && null in map.keys && map[null] == result }, + { map, _ -> map != null && null !in map.keys } + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapValuesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapValuesTest.kt new file mode 100644 index 0000000000..cd92dfb0b8 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapValuesTest.kt @@ -0,0 +1,179 @@ +package org.utbot.examples.collections + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.ge +import org.utbot.testcheckers.withoutMinimization + +// TODO failed Kotlin compilation SAT-1332 +class MapValuesTest : UtValueTestCaseChecker( + testClass = MapValues::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testRemoveFromValues() { + withoutMinimization { // TODO: JIRA:1506 + checkWithException( + MapValues::removeFromValues, + ignoreExecutionsNumber, + { map, _, result -> map == null && result.isException() }, + { map, i, result -> i !in map.values && result.getOrNull() == map }, + { map, i, result -> + val resultMap = result.getOrNull()!! + + val iInMapValues = i in map.values + val iWasDeletedFromValues = + resultMap.values.filter { it == i }.size == map.values.filter { it == i }.size - 1 + + val firstKeyAssociatedWithI = map.keys.first { map[it] == i } + val firstKeyAssociatedWIthIWasDeleted = firstKeyAssociatedWithI !in resultMap.keys + + val getCountExceptI: Collection.() -> Map = + { this.filter { it != i }.filterNotNull().groupingBy { it }.eachCount() } + val mapContainsAllValuesFromResult = + map.values.getCountExceptI() == resultMap.values.getCountExceptI() + + iInMapValues && iWasDeletedFromValues && firstKeyAssociatedWIthIWasDeleted && mapContainsAllValuesFromResult + }, + ) + } + } + + @Test + fun testAddToValues() { + checkWithException( + MapValues::addToValues, + between(2..4), + { map, result -> map == null && result.isException() }, + { map, result -> map != null && result.isException() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetFromValues() { + withoutMinimization { + check( + MapValues::getFromValues, + ignoreExecutionsNumber, + { map, _, _ -> map == null }, + { map, i, result -> i !in map.values && result == 1 }, + { map, i, result -> i in map.values && result == 1 }, + coverage = AtLeast(90) // unreachable else branch in MUT + ) + } + } + + @Test + fun testIteratorHasNext() { + check( + MapValues::iteratorHasNext, + between(3..4), + { map, _ -> map == null }, + { map, result -> map.values.isEmpty() && result == 0 }, + { map, result -> map.values.isNotEmpty() && result == map.values.size }, + coverage = DoNotCalculate + ) + } + + @Test + fun testIteratorNext() { + checkWithException( + MapValues::iteratorNext, + between(3..4), + { 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 + // { map, result -> map != null && map.values.isEmpty() && result.isException() }, + { map, result -> map != null && map.values.first() == null && result.isException() }, + // as map is LinkedHashmap by default this matcher would be correct + { map, result -> map != null && map.values.isNotEmpty() && result.getOrNull() == map.values.first() }, + ) + } + + @Test + fun testIteratorRemove() { + checkWithException( + MapValues::iteratorRemove, + between(3..4), + { 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 + { map, result -> + val resultMap = result.getOrNull()!! + val firstValue = map.values.first() + + val getCountsExceptFirstValue: Collection.() -> Map = + { this.filter { it != firstValue }.filterNotNull().groupingBy { it }.eachCount() } + val mapContainsAllValuesFromResult = + map.values.getCountsExceptFirstValue() == resultMap.values.getCountsExceptFirstValue() + + val firstValueWasDeleted = + resultMap.values.filter { it == firstValue }.size == map.values.filter { it == firstValue }.size - 1 + + val keyAssociatedWithFirstValueWasDeleted = + map.keys.first { map[it] == firstValue } !in resultMap.keys + + mapContainsAllValuesFromResult && firstValueWasDeleted && keyAssociatedWithFirstValueWasDeleted + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testIteratorRemoveOnIndex() { + checkWithException( + MapValues::iteratorRemoveOnIndex, + ge(5), + { _, i, result -> i == 0 && result.isSuccess && result.getOrNull() == null }, + { map, _, result -> map == null && result.isException() }, + { map, i, result -> map != null && i < 0 && result.isException() }, + { map, i, result -> i > map.values.size && result.isException() }, + { map, i, result -> + val iInIndexRange = i in 1..map.size + val ithValue = map.values.toList()[i - 1] + val resultMap = result.getOrNull()!! + + val getCountsExceptIthValue: Collection.() -> Map = + { this.filter { it != ithValue }.filterNotNull().groupingBy { it }.eachCount() } + val mapContainsAllValuesFromResult = + map.values.getCountsExceptIthValue() == resultMap.values.getCountsExceptIthValue() + val ithValueWasDeleted = + resultMap.values.filter { it == ithValue }.size == map.values.filter { it == ithValue }.size - 1 + val keyAssociatedWIthIthValueWasDeleted = + map.keys.filter { map[it] == ithValue }.any { it !in resultMap.keys } + + iInIndexRange && mapContainsAllValuesFromResult && ithValueWasDeleted && keyAssociatedWIthIthValueWasDeleted + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testIterateForEach() { + check( + MapValues::iterateForEach, + between(3..5), + { map, _ -> map == null }, + { map, _ -> null in map.values }, + { map, result -> map != null && result == map.values.sum() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testIterateWithIterator() { + check( + MapValues::iterateWithIterator, + between(3..5), + { 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-testing/src/test/kotlin/org/utbot/examples/collections/MapsPart1Test.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapsPart1Test.kt new file mode 100644 index 0000000000..4f73aec84b --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapsPart1Test.kt @@ -0,0 +1,382 @@ +package org.utbot.examples.collections + +import org.junit.jupiter.api.Tag +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.withoutMinimization + +// TODO failed Kotlin compilation ($ in names, generics) SAT-1220 SAT-1332 +internal class MapsPart1Test : UtValueTestCaseChecker( + testClass = Maps::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testPutElementIfAbsent() { + withoutMinimization { // TODO: JIRA:1506 + check( + Maps::putElementIfAbsent, + ignoreExecutionsNumber, + { map, _, _, _ -> map == null }, + { 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 + }, + coverage = AtLeast(90) // unreachable else branch in MUT + ) + } + } + + @Test + fun testReplaceEntry() { + check( + Maps::replaceEntry, + between(3..6), + { 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 + }, + coverage = DoNotCalculate + ) + } + + @Test + fun createTest() { + check( + Maps::create, + 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, 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 { + 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 }, + ) + } + } + + // 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 + ) + } + } + + @Test + fun testFindAllChars() { + check( + Maps::countChars, + eq(3), + { s, _ -> s == null }, + { s, result -> s == "" && result!!.isEmpty() }, + { s, result -> s != "" && result == s.groupingBy { it }.eachCount() }, + coverage = DoNotCalculate + ) + } + + @Test + fun putElementsTest() { + check( + Maps::putElements, + ge(5), + { 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() + && result == map.toMutableMap().apply { putAll(array.map { it to it }) } + }, + coverage = DoNotCalculate + ) + } + + @Test + fun removeEntries() { + check( + Maps::removeElements, + ge(6), + { 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 + ) + } + + @Test + fun createWithDifferentTypeTest() { + check( + Maps::createWithDifferentType, + 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 + ) + } + + @Test + fun removeCustomObjectTest() { + check( + Maps::removeCustomObject, + ge(3), + { 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 + ) + } + + @Test + @Tag("slow") // it takes about 20 minutes to execute this test + fun testMapOperator() { + withPushingStateFromPathSelectorForConcrete { + check( + Maps::mapOperator, + ignoreExecutionsNumber + ) + } + } + + @Test + fun testComputeValue() { + check( + Maps::computeValue, + between(3..5), + { 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 + }, + { 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 + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testComputeValueWithMocks() { + check( + Maps::computeValue, + between(3..5), + { 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 + }, + { 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 + }, + mockStrategy = MockStrategyApi.OTHER_PACKAGES, // checks that we do not generate mocks for lambda classes + coverage = DoNotCalculate + ) + } + + @Test + fun testComputeValueIfAbsent() { + check( + Maps::computeValueIfAbsent, + between(3..5), + { 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 + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testComputeValueIfPresent() { + check( + Maps::computeValueIfPresent, + between(3..5), + { 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 + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testClearEntries() { + check( + Maps::clearEntries, + between(3..4), + { map, _ -> map == null }, + { map, result -> map.isEmpty() && result == 0 }, + { map, result -> map.isNotEmpty() && result == 1 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testContainsKey() { + check( + Maps::containsKey, + between(3..5), + { map, _, _ -> map == null }, + { map, key, result -> key !in map && result == 0 }, + { map, key, result -> key in map && result == 1 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testContainsValue() { + check( + Maps::containsValue, + between(3..6), + { map, _, _ -> map == null }, + { map, value, result -> value !in map.values && result == 0 }, + { map, value, result -> value in map.values && result == 1 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetOrDefaultElement() { + check( + Maps::getOrDefaultElement, + between(4..6), + { 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 + ) + } + + @Test + fun testRemoveKeyWithValue() { + check( + Maps::removeKeyWithValue, + ge(6), + { 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 + ) + } + + @Test + fun testReplaceAllEntries() { + check( + Maps::replaceAllEntries, + between(5..6), + { map, _ -> map == null }, + { map, result -> map.isEmpty() && result == null }, + { map, _ -> map.isNotEmpty() && map.containsValue(null) }, + { map, result -> + val precondition = map.isNotEmpty() && !map.containsValue(null) + val firstBranchInLambdaExists = map.entries.any { it.key > it.value } + val valuesWereReplaced = + result == map.mapValues { if (it.key > it.value) it.value + 1 else it.value - 1 } + precondition && firstBranchInLambdaExists && valuesWereReplaced + }, + { map, result -> + val precondition = map.isNotEmpty() && !map.containsValue(null) + val secondBranchInLambdaExists = map.entries.any { it.key <= it.value } + val valuesWereReplaced = + 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() } + ) + } + } + @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 } + ) + } + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapsPart2Test.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapsPart2Test.kt new file mode 100644 index 0000000000..12a0c585e4 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapsPart2Test.kt @@ -0,0 +1,87 @@ +package org.utbot.examples.collections + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.ge +import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete +import org.utbot.testcheckers.withoutMinimization + +// TODO failed Kotlin compilation ($ in names, generics) SAT-1220 SAT-1332 +internal class MapsPart2Test : UtValueTestCaseChecker( + testClass = Maps::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testReplaceEntryWithValue() { + withPushingStateFromPathSelectorForConcrete { + check( + Maps::replaceEntryWithValue, + ge(6), + { 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 + ) + } + } + + @Test + fun testMerge() { + withoutMinimization { // TODO: JIRA:1506 + checkWithException( + Maps::merge, + ge(5), + { map, _, _, result -> map == null && result.isException() }, + { map, _, value, result -> map != null && value == null && result.isException() }, + { map, key, value, result -> + val resultMap = result.getOrNull()!! + val entryWasPut = resultMap.entries.all { it.key == key && it.value == value || it in map.entries } + key !in map && value != null && entryWasPut + }, + { map, key, value, result -> + val resultMap = result.getOrNull()!! + val valueInMapIsNull = key in map && map[key] == null + val valueWasReplaced = resultMap[key] == value + val otherValuesWerentTouched = resultMap.entries.all { it.key == key || it in map.entries } + value != null && valueInMapIsNull && valueWasReplaced && otherValuesWerentTouched + }, + { map, key, value, result -> + val resultMap = result.getOrNull()!! + val valueInMapIsNotNull = map[key] != null + val valueWasMerged = resultMap[key] == map[key]!! + value + val otherValuesWerentTouched = resultMap.entries.all { it.key == key || it in map.entries } + value != null && valueInMapIsNotNull && valueWasMerged && otherValuesWerentTouched + }, + coverage = DoNotCalculate + ) + } + } + + @Test + fun testPutAllEntries() { + withPushingStateFromPathSelectorForConcrete { + check( + Maps::putAllEntries, + ge(5), + { map, _, _ -> map == null }, + { map, other, _ -> map != null && other == null }, + { map, other, result -> map != null && other != null && map.keys.containsAll(other.keys) && result == 0 }, + { map, other, result -> map != null && other != null && other.keys.all { it !in map.keys } && result == 1 }, + { map, other, result -> + val notNull = map != null && other != null + val mapContainsAtLeastOneKeyOfOther = other.keys.any { it in map.keys } + val mapDoesNotContainAllKeysOfOther = !map.keys.containsAll(other.keys) + notNull && mapContainsAtLeastOneKeyOfOther && mapDoesNotContainAllKeysOfOther && result == 2 + }, + coverage = DoNotCalculate + ) + } + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt new file mode 100644 index 0000000000..fab2ca1d57 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt @@ -0,0 +1,489 @@ +package org.utbot.examples.collections + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import java.util.* + +class OptionalsTest : UtValueTestCaseChecker( + Optionals::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + + + @Test + fun testCreate() { + checkWithException( + Optionals::create, + eq(2), + { value, result -> value == null && result.isException() }, + { value, result -> value != null && result.getOrNull()!!.get() == value }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCreateInt() { + check( + Optionals::createInt, + eq(1), + { value, result -> result!!.asInt == value }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCreateLong() { + check( + Optionals::createLong, + eq(1), + { value, result -> result!!.asLong == value }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCreateDouble() { + check( + Optionals::createDouble, + eq(1), + { value, result -> result!!.asDouble == value || result.asDouble.isNaN() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCreateNullable() { + checkStatics( + Optionals::createNullable, + eq(2), + { value, _, result -> value == null && result === Optional.empty() }, + { value, _, result -> value != null && result!!.get() == value }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCreateEmpty() { + checkStatics( + Optionals::createEmpty, + eq(1), + { _, result -> result === Optional.empty() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCreateIntEmpty() { + checkStatics( + Optionals::createIntEmpty, + eq(1), + { _, result -> result === OptionalInt.empty() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCreateLongEmpty() { + checkStatics( + Optionals::createLongEmpty, + eq(1), + { _, result -> result === OptionalLong.empty() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCreateDoubleEmpty() { + checkStatics( + Optionals::createDoubleEmpty, + eq(1), + { _, result -> result === OptionalDouble.empty() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetValue() { + checkStatics( + Optionals::getValue, + eq(3), + { optional, _, _ -> optional == null }, + { optional, _, result -> optional != null && optional === Optional.empty() && result == null }, + { optional, _, result -> optional != null && result == optional.get() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetIntValue() { + checkStatics( + Optionals::getIntValue, + eq(3), + { optional, _, _ -> optional == null }, + { optional, _, result -> optional != null && optional === OptionalInt.empty() && result == null }, + { optional, _, result -> optional != null && result == optional.asInt }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetLongValue() { + checkStatics( + Optionals::getLongValue, + eq(3), + { optional, _, _ -> optional == null }, + { optional, _, result -> optional != null && optional === OptionalLong.empty() && result == null }, + { optional, _, result -> optional != null && result == optional.asLong }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetDoubleValue() { + checkStatics( + Optionals::getDoubleValue, + eq(3), + { optional, _, _ -> optional == null }, + { optional, _, result -> optional != null && optional === OptionalDouble.empty() && result == null }, + { optional, _, result -> optional != null && result == optional.asDouble }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetWithIsPresent() { + checkStatics( + Optionals::getWithIsPresent, + eq(3), + { optional, _, _ -> optional == null }, + { optional, _, result -> optional === Optional.empty() && result == null }, + { optional, _, result -> optional.get() == result }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCountIfPresent() { + checkStatics( + Optionals::countIfPresent, + eq(3), + { optional, _, _ -> optional == null }, + { optional, _, result -> optional === Optional.empty() && result == 0 }, + { optional, _, result -> optional.get() == result }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCountIntIfPresent() { + checkStatics( + Optionals::countIntIfPresent, + ignoreExecutionsNumber, + { optional, _, _ -> optional == null }, + { optional, _, result -> optional === OptionalInt.empty() && result == 0 }, + { optional, _, result -> optional.asInt == result }, + ) + } + + @Test + fun testCountLongIfPresent() { + checkStatics( + Optionals::countLongIfPresent, + ignoreExecutionsNumber, + { optional, _, _ -> optional == null }, + { optional, _, result -> optional === OptionalLong.empty() && result == 0L }, + { optional, _, result -> optional.asLong == result }, + ) + } + + @Test + fun testCountDoubleIfPresent() { + checkStatics( + Optionals::countDoubleIfPresent, + ignoreExecutionsNumber, + { optional, _, _ -> optional == null }, + { optional, _, result -> optional === OptionalDouble.empty() && result == 0.0 }, + { optional, _, result -> optional.asDouble == result }, + ) + } + + @Test + fun testFilterLessThanZero() { + checkStatics( + Optionals::filterLessThanZero, + eq(4), + { optional, _, _ -> optional == null }, + { optional, _, result -> optional === Optional.empty() && result === optional }, + { optional, _, result -> optional.get() >= 0 && result == optional }, + { optional, _, result -> optional.get() < 0 && result === Optional.empty() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testAbsNotNull() { + checkStatics( + Optionals::absNotNull, + eq(4), + { optional, _, _ -> optional == null }, + { optional, _, result -> optional === Optional.empty() && result === optional }, + { optional, _, result -> optional.get() < 0 && result!!.get() == -optional.get() }, + { optional, _, result -> optional.get() >= 0 && result == optional }, + coverage = DoNotCalculate + ) + } + + @Test + fun testMapLessThanZeroToNull() { + checkStatics( + Optionals::mapLessThanZeroToNull, + eq(4), + { optional, _, _ -> optional == null }, + { optional, _, result -> optional === Optional.empty() && result === optional }, + { optional, _, result -> optional.get() < 0 && result === Optional.empty() }, + { optional, _, result -> optional.get() >= 0 && result == optional }, + coverage = DoNotCalculate + ) + } + + @Test + fun testFlatAbsNotNull() { + checkStatics( + Optionals::flatAbsNotNull, + eq(4), + { optional, _, _ -> optional == null }, + { optional, _, result -> optional === Optional.empty() && result === optional }, + { optional, _, result -> optional.get() < 0 && result!!.get() == -optional.get() }, + { optional, _, result -> optional.get() >= 0 && result == optional }, + coverage = DoNotCalculate + ) + } + + @Test + fun testFlatMapWithNull() { + checkStatics( + Optionals::flatMapWithNull, + eq(5), + { optional, _, _ -> optional == null }, + { optional, _, result -> optional === Optional.empty() && result === optional }, + { optional, _, result -> optional.get() < 0 && result === Optional.empty() }, + { optional, _, result -> optional.get() > 0 && result == optional }, + { optional, _, result -> optional.get() == 0 && result == null }, + coverage = DoNotCalculate + ) + } + + @Test + fun testLeftOrElseRight() { + checkStatics( + Optionals::leftOrElseRight, + eq(3), + { left, _, _, _ -> left == null }, + { left, right, _, result -> left === Optional.empty() && result == right }, + { left, _, _, result -> left.isPresent && result == left.get() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testLeftIntOrElseRight() { + checkStatics( + Optionals::leftIntOrElseRight, + eq(3), + { left, _, _, _ -> left == null }, + { left, right, _, result -> left === OptionalInt.empty() && result == right }, + { left, _, _, result -> left.isPresent && result == left.asInt }, + coverage = DoNotCalculate + ) + } + + + @Test + fun testLeftLongOrElseRight() { + checkStatics( + Optionals::leftLongOrElseRight, + eq(3), + { left, _, _, _ -> left == null }, + { left, right, _, result -> left === OptionalLong.empty() && result == right }, + { left, _, _, result -> left.isPresent && result == left.asLong }, + coverage = DoNotCalculate + ) + } + + + @Test + fun testLeftDoubleOrElseRight() { + checkStatics( + Optionals::leftDoubleOrElseRight, + eq(3), + { left, _, _, _ -> left == null }, + { left, right, _, result -> left === OptionalDouble.empty() && (result == right || result!!.isNaN() && right.isNaN()) }, + { left, _, _, result -> left.isPresent && (result == left.asDouble || result!!.isNaN() && left.asDouble.isNaN()) }, + coverage = DoNotCalculate + ) + } + + + @Test + fun testLeftOrElseGetOne() { + checkStatics( + Optionals::leftOrElseGetOne, + eq(3), + { left, _, _ -> left == null }, + { left, _, result -> left === Optional.empty() && result == 1 }, + { left, _, result -> left.isPresent && result == left.get() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testLeftIntOrElseGetOne() { + checkStatics( + Optionals::leftIntOrElseGetOne, + eq(3), + { left, _, _ -> left == null }, + { left, _, result -> left === OptionalInt.empty() && result == 1 }, + { left, _, result -> left.isPresent && result == left.asInt }, + coverage = DoNotCalculate + ) + } + + @Test + fun testLeftLongOrElseGetOne() { + checkStatics( + Optionals::leftLongOrElseGetOne, + eq(3), + { left, _, _ -> left == null }, + { left, _, result -> left === OptionalLong.empty() && result == 1L }, + { left, _, result -> left.isPresent && result == left.asLong }, + coverage = DoNotCalculate + ) + } + + @Test + fun testLeftDoubleOrElseGetOne() { + checkStatics( + Optionals::leftDoubleOrElseGetOne, + eq(3), + { left, _, _ -> left == null }, + { left, _, result -> left === OptionalDouble.empty() && result == 1.0 }, + { left, _, result -> left.isPresent && result == left.asDouble }, + coverage = DoNotCalculate + ) + } + + @Test + fun testLeftOrElseThrow() { + checkStatics( + Optionals::leftOrElseThrow, + eq(3), + { left, _, _ -> left == null }, + { left, _, result -> left === Optional.empty() && result == null }, + { left, _, result -> left.isPresent && result == left.get() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testLeftIntOrElseThrow() { + checkStatics( + Optionals::leftIntOrElseThrow, + eq(3), + { left, _, _ -> left == null }, + { left, _, result -> left === OptionalInt.empty() && result == null }, + { left, _, result -> left.isPresent && result == left.asInt }, + coverage = DoNotCalculate + ) + } + + @Test + fun testLeftLongOrElseThrow() { + checkStatics( + Optionals::leftLongOrElseThrow, + eq(3), + { left, _, _ -> left == null }, + { left, _, result -> left === OptionalLong.empty() && result == null }, + { left, _, result -> left.isPresent && result == left.asLong }, + coverage = DoNotCalculate + ) + } + + @Test + fun testLeftDoubleOrElseThrow() { + checkStatics( + Optionals::leftDoubleOrElseThrow, + eq(3), + { left, _, _ -> left == null }, + { left, _, result -> left === OptionalDouble.empty() && result == null }, + { left, _, result -> left.isPresent && result == left.asDouble }, + coverage = DoNotCalculate + ) + } + + @Test + fun testEqualOptionals() { + check( + Optionals::equalOptionals, + between(4..7), + { left, _, result -> left == null && result == null }, + { left, right, result -> left != null && left != right && !result!! }, + { left, right, result -> left != null && left === right && !left.isPresent && !right.isPresent && result!! }, + { left, right, result -> left != null && left == right && left.isPresent && right.isPresent && result!! }, + coverage = DoNotCalculate + ) + } + + @Test + fun testEqualOptionalsInt() { + check( + Optionals::equalOptionalsInt, + between(4..8), + { left, _, result -> left == null && result == null }, + { left, right, result -> left != null && left != right && !result!! }, + { left, right, result -> left != null && left === right && !left.isPresent && !right.isPresent && result!! }, + { left, right, result -> left != null && left == right && left.isPresent && right.isPresent && result!! }, + coverage = DoNotCalculate + ) + } + + @Test + fun testEqualOptionalsLong() { + check( + Optionals::equalOptionalsLong, + between(4..8), + { left, _, result -> left == null && result == null }, + { left, right, result -> left != null && left != right && !result!! }, + { left, right, result -> left != null && left === right && !left.isPresent && !right.isPresent && result!! }, + { left, right, result -> left != null && left == right && left.isPresent && right.isPresent && result!! }, + coverage = DoNotCalculate + ) + } + + @Test + fun testEqualOptionalsDouble() { + check( + Optionals::equalOptionalsDouble, + between(4..8), + { left, _, result -> left == null && result == null }, + { left, right, result -> left != null && left != right && !result!! }, + { left, right, result -> left != null && left === right && !left.isPresent && !right.isPresent && result!! }, + { left, right, result -> left != null && left == right && left.isPresent && right.isPresent && result!! }, + coverage = DoNotCalculate + ) + } + + @Test + fun testOptionalOfPositive() { + check( + Optionals::optionalOfPositive, + eq(2), + { value, result -> value > 0 && result != null && result.isPresent && result.get() == value }, + { value, result -> value <= 0 && result != null && !result.isPresent } + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/QueueUsagesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/QueueUsagesTest.kt new file mode 100644 index 0000000000..8822b05365 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/QueueUsagesTest.kt @@ -0,0 +1,127 @@ +package org.utbot.examples.collections + +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException + +class QueueUsagesTest : UtValueTestCaseChecker( + testClass = QueueUsages::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testCreateArrayDeque() { + checkWithException( + QueueUsages::createArrayDeque, + eq(3), + { init, next, r -> init == null && next == null && r.isException() }, + { init, next, r -> init != null && next == null && r.isException() }, + { init, next, r -> init != null && next != null && r.getOrNull() == 2 }, + ) + } + + @Test + fun testCreateLinkedList() { + checkWithException( + QueueUsages::createLinkedList, + eq(1), + { _, _, r -> r.getOrNull()!! == 2 }, + ) + } + + @Test + fun testCreateLinkedBlockingDeque() { + checkWithException( + QueueUsages::createLinkedBlockingDeque, + eq(3), + { init, next, r -> init == null && next == null && r.isException() }, + { init, next, r -> init != null && next == null && r.isException() }, + { init, next, r -> init != null && next != null && r.getOrNull() == 2 }, + ) + } + + @Test + fun testContainsQueue() { + checkWithException( + QueueUsages::containsQueue, + eq(3), + { q, _, r -> q == null && r.isException() }, + { q, x, r -> x in q && r.getOrNull() == 1 }, + { q, x, r -> x !in q && r.getOrNull() == 0 }, + ) + } + + @Test + fun testAddQueue() { + checkWithException( + QueueUsages::addQueue, + eq(3), + { q, _, r -> q == null && r.isException() }, + { q, x, r -> q != null && x in r.getOrNull()!! }, + { q, x, r -> q != null && x == null && r.isException() }, ) + } + + @Test + fun testAddAllQueue() { + checkWithException( + QueueUsages::addAllQueue, + eq(3), + { q, _, r -> q == null && r.isException() }, + { q, x, r -> q != null && x in r.getOrNull()!! }, // we can cover this line with x == null or x != null + { q, x, r -> q != null && x == null && r.isException() }, + ) + } + + @Test + fun testCastQueueToDeque() { + check( + QueueUsages::castQueueToDeque, + eq(2), + { q, r -> q !is java.util.Deque<*> && r == null }, + { q, r -> q is java.util.Deque<*> && r is java.util.Deque<*> }, + ) + } + + @Test + fun testCheckSubtypesOfQueue() { + check( + QueueUsages::checkSubtypesOfQueue, + eq(4), + { q, r -> q == null && r == 0 }, + { q, r -> q is java.util.LinkedList<*> && r == 1 }, + { q, r -> q is java.util.ArrayDeque<*> && r == 2 }, + { q, r -> q !is java.util.LinkedList<*> && q !is java.util.ArrayDeque && r == 3 } + ) + } + + @Test + @Disabled("TODO: Related to https://github.com/UnitTestBot/UTBotJava/issues/820") + fun testCheckSubtypesOfQueueWithUsage() { + check( + QueueUsages::checkSubtypesOfQueueWithUsage, + eq(4), + { q, r -> q == null && r == 0 }, + { q, r -> q is java.util.LinkedList<*> && r == 1 }, + { q, r -> q is java.util.ArrayDeque<*> && r == 2 }, + { q, r -> q !is java.util.LinkedList<*> && q !is java.util.ArrayDeque && r == 3 } // this is uncovered + ) + } + + @Test + fun testAddConcurrentLinkedQueue() { + checkWithException( + QueueUsages::addConcurrentLinkedQueue, + eq(3), + { q, _, r -> q == null && r.isException() }, + { q, x, r -> q != null && x != null && x in r.getOrNull()!! }, + { q, x, r -> q != null && x == null && r.isException() }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/SetIteratorsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/SetIteratorsTest.kt new file mode 100644 index 0000000000..21c9945b94 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/SetIteratorsTest.kt @@ -0,0 +1,98 @@ +package org.utbot.examples.collections + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.ge + +// TODO failed Kotlin compilation SAT-1332 +class SetIteratorsTest : UtValueTestCaseChecker( + testClass = SetIterators::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testIteratorHasNext() { + check( + SetIterators::iteratorHasNext, + between(3..4), + { set, _ -> set == null }, + { set, result -> set.isEmpty() && result == 0 }, + { set, result -> set.isNotEmpty() && result == set.size }, + ) + } + + @Test + fun testIteratorNext() { + checkWithException( + SetIterators::iteratorNext, + between(3..4), + { 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 + { set, result -> set != null && set.isNotEmpty() && result.getOrNull() == set.first() }, + ) + } + + @Test + fun testIteratorRemove() { + checkWithException( + SetIterators::iteratorRemove, + between(3..4), + { set, result -> set == null && result.isException() }, + { set, result -> set.isEmpty() && result.isException() }, + // test should work as long as default class for set is LinkedHashSet + { set, result -> + val firstElement = set.first() + val resultSet = result.getOrNull()!! + val resultDoesntContainFirstElement = resultSet.size == set.size - 1 && firstElement !in resultSet + set.isNotEmpty() && set.containsAll(resultSet) && resultDoesntContainFirstElement + }, + ) + } + + @Test + fun testIteratorRemoveOnIndex() { + checkWithException( + SetIterators::iteratorRemoveOnIndex, + ge(5), + { _, i, result -> i == 0 && result.isSuccess && result.getOrNull() == null }, + { set, _, result -> set == null && result.isException() }, + { set, i, result -> set != null && i < 0 && result.isException() }, + { set, i, result -> i > set.size && result.isException() }, + // test should work as long as default class for set is LinkedHashSet + { set, i, result -> + val ithElement = set.toList()[i - 1] + val resultSet = result.getOrNull()!! + val iInIndexRange = i in 0..set.size + val resultDoesntContainIthElement = resultSet.size == set.size - 1 && ithElement !in resultSet + iInIndexRange && set.containsAll(resultSet) && resultDoesntContainIthElement + }, + ) + } + + @Test + fun testIterateForEach() { + check( + SetIterators::iterateForEach, + ignoreExecutionsNumber, + { set, _ -> set == null }, + { set, _ -> set != null && null in set }, + { set, result -> set != null && result == set.sum() }, + ) + } + + + @Test + fun testIterateWithIterator() { + check( + SetIterators::iterateWithIterator, + ignoreExecutionsNumber, + { set, _ -> set == null }, + { set, _ -> set != null && null in set }, + { set, result -> set != null && result == set.sum() }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/SetsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/SetsTest.kt new file mode 100644 index 0000000000..4e368f8085 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/SetsTest.kt @@ -0,0 +1,239 @@ +package org.utbot.examples.collections + +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 + +// TODO failed Kotlin compilation SAT-1332 +internal class SetsTest : UtValueTestCaseChecker( + testClass = Sets::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun createTest() { + check( + Sets::create, + 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()) }, + ) + } + + @Test + fun testSetContainsInteger() { + check( + Sets::setContainsInteger, + ignoreExecutionsNumber, + { set, _, _, _ -> set == null }, + { set, a, _, r -> 1 + a in set && r != null && 1 + a !in r && set.remove(1 + a) && r == set }, + { set, a, _, r -> 1 + a !in set && set.isEmpty() && r == null }, + { set, a, b, r -> 1 + a !in set && set.isNotEmpty() && r != null && r == set && 4 + a + b !in r }, + ) + } + + @Test + @Disabled("Does not find positive branches JIRA:1529") + fun testSetContains() { + check( + Sets::setContains, + eq(-1), + ) + } + + @Test + fun testSimpleContains() { + check( + Sets::simpleContains, + ignoreExecutionsNumber, + { set, _ -> set == null }, + { set, r -> set != null && "aaa" in set && r == true }, + { set, r -> set != null && "aaa" !in set && r == false } + ) + } + + @Test + @Disabled("Same problem from testSetContains JIRA:1529") + fun testMoreComplicatedContains() { + check( + Sets::moreComplicatedContains, + eq(-1), // TODO how many branches do we have? + ) + } + + + @Test + fun testFindAllChars() { + check( + Sets::findAllChars, + eq(3), + { s, _ -> s == null }, + { s, result -> s == "" && result!!.isEmpty() }, + { s, result -> s != "" && result == s.toCollection(mutableSetOf()) }, + ) + } + + @Test + fun testRemoveSpace() { + val resultFun = { set: Set -> listOf(' ', '\t', '\r', '\n').intersect(set).size } + check( + Sets::removeSpace, + ge(3), + { set, _ -> set == null }, + { set, res -> ' ' in set && resultFun(set) == res }, + { set, res -> '\t' in set && resultFun(set) == res }, + { set, res -> '\n' in set && resultFun(set) == res }, + { set, res -> '\r' in set && resultFun(set) == res }, + { set, res -> ' ' !in set && resultFun(set) == res }, + { set, res -> '\t' !in set && resultFun(set) == res }, + { set, res -> '\n' !in set && resultFun(set) == res }, + { set, res -> '\r' !in set && resultFun(set) == res }, + ) + } + + @Test + fun addElementsTest() { + check( + Sets::addElements, + ge(5), + { set, _, _ -> set == null }, + { set, a, _ -> set != null && set.isNotEmpty() && a == null }, + { set, _, r -> set.isEmpty() && r == set }, + { set, a, r -> set.isNotEmpty() && a.isEmpty() && r == set }, + { set, a, r -> + set.size >= 1 && a.isNotEmpty() && r == set.toMutableSet().apply { addAll(a.toTypedArray()) } + }, + ) + } + + @Test + fun removeElementsTest() { + check( + Sets::removeElements, + between(6..8), + { 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 }, + { set, i, j, res -> set != null && set.size >= 1 && i in set && (j !in set || j == i) && res == 3 }, + { set, i, j, res -> set != null && set.size >= 2 && i in set && j in set && i > j && res == 2 }, + { set, i, j, res -> set != null && set.size >= 2 && i in set && j in set && i < j && res == 1 }, + coverage = AtLeast(94) // unreachable branch + ) + } + + @Test + fun createWithDifferentTypeTest() { + check( + Sets::createWithDifferentType, + eq(2), + { seed, r -> seed % 2 != 0 && r is java.util.LinkedHashSet }, + { seed, r -> seed % 2 == 0 && r !is java.util.LinkedHashSet && r is java.util.HashSet }, + ) + } + + @Test + fun removeCustomObjectTest() { + withoutMinimization { // TODO: JIRA:1506 + check( + Sets::removeCustomObject, + ge(4), + { set, _, _ -> set == null }, + { set, _, result -> set.isEmpty() && result == 0 }, + { set, i, result -> set.isNotEmpty() && CustomClass(i) !in set && result == 0 }, + { set, i, result -> set.isNotEmpty() && CustomClass(i) in set && result == 1 }, + ) + } + } + + @Test + fun testAddAllElements() { + withPushingStateFromPathSelectorForConcrete { + check( + Sets::addAllElements, + ignoreExecutionsNumber, + { set, _, _ -> set == null }, + { set, other, _ -> set != null && other == null }, + { set, other, result -> set.containsAll(other) && result == 0 }, + { set, other, result -> !set.containsAll(other) && result == 1 }, + // TODO: Cannot find branch with result == 2 + { set, other, result -> !set.containsAll(other) && other.any { it in set } && result == 2 }, + ) + } + } + + @Test + fun testRemoveAllElements() { + withPushingStateFromPathSelectorForConcrete { + check( + Sets::removeAllElements, + ignoreExecutionsNumber, + { set, _, _ -> set == null }, + { set, other, _ -> set != null && other == null }, + { set, other, result -> other.all { it !in set } && result == 0 }, + { set, other, result -> set.containsAll(other) && result == 1 }, + //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 + ) + } + } + + @Test + fun testRetainAllElements() { + check( + Sets::retainAllElements, + ge(4), + { set, _, _ -> set == null }, + { set, other, _ -> set != null && other == null }, + { set, other, result -> other.containsAll(set) && result == 1 }, + { set, other, result -> set.any { it !in other } && result == 0 }, + ) + } + + @Test + fun testContainsAllElements() { + check( + Sets::containsAllElements, + ge(5), + { set, _, _ -> set == null }, + { set, other, _ -> set != null && other == null }, + { set, other, result -> set.isEmpty() || other.isEmpty() && result == -1 }, + { set, other, result -> set.isNotEmpty() && other.isNotEmpty() && set.containsAll(other) && result == 1 }, + { set, other, result -> set.isNotEmpty() && other.isNotEmpty() && !set.containsAll(other) && result == 0 }, + ) + } + + + @Test + fun testClearElements() { + check( + Sets::clearElements, + eq(3), + { set, _ -> set == null }, + { set, result -> set.isEmpty() && result == 0 }, + { set, result -> set.isNotEmpty() && result == 1 }, + coverage = AtLeast(85) // unreachable final return + ) + } + + + @Test + fun testContainsElement() { + check( + Sets::containsElement, + between(3..5), + { set, _, _ -> set == null }, + { set, i, result -> i !in set && result == 0 }, + { set, i, result -> i in set && result == 1 }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/ConditionsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/ConditionsTest.kt new file mode 100644 index 0000000000..4cd9376ef9 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/ConditionsTest.kt @@ -0,0 +1,55 @@ +package org.utbot.examples.controlflow + +import org.utbot.framework.plugin.api.DocCodeStmt +import org.utbot.framework.plugin.api.DocPreTagStatement +import org.utbot.framework.plugin.api.DocRegularStmt +import org.utbot.framework.plugin.api.DocStatement +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class ConditionsTest : UtValueTestCaseChecker(testClass = Conditions::class) { + @Test + fun testSimpleCondition() { + val conditionSummary = listOf( + DocPreTagStatement( + listOf( + DocRegularStmt("Test "), + DocRegularStmt("executes conditions:\n"), + DocRegularStmt(" "), + DocCodeStmt("(condition): True"), + DocRegularStmt("\n"), + DocRegularStmt("returns from: "), + DocCodeStmt("return 1;"), + DocRegularStmt("\n"), + ) + ) + ) + check( + Conditions::simpleCondition, + eq(2), + { condition, r -> !condition && r == 0 }, + { condition, r -> condition && r == 1 }, + summaryTextChecks = listOf( + keyContain(DocCodeStmt("(condition): True")), + keyContain(DocCodeStmt("(condition): False")), + keyMatch(conditionSummary) + ), + summaryNameChecks = listOf( + keyMatch("testSimpleCondition_Condition"), + keyMatch("testSimpleCondition_NotCondition"), + ), + summaryDisplayNameChecks = listOf( + keyContain("condition : True"), + keyContain("condition : False"), + ) + ) + } + + @Test + fun testIfLastStatement() { + checkWithException( + Conditions::emptyBranches, + ignoreExecutionsNumber, + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/CycleDependedConditionTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/CycleDependedConditionTest.kt new file mode 100644 index 0000000000..c0dc060e96 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/CycleDependedConditionTest.kt @@ -0,0 +1,117 @@ +package org.utbot.examples.controlflow + +import org.utbot.framework.plugin.api.DocCodeStmt +import org.utbot.framework.plugin.api.DocPreTagStatement +import org.utbot.framework.plugin.api.DocRegularStmt +import org.utbot.framework.plugin.api.DocStatement +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class CycleDependedConditionTest : UtValueTestCaseChecker(testClass = CycleDependedCondition::class) { + @Test + fun testCycleDependedOneCondition() { + val conditionSummary = listOf( + DocPreTagStatement( + listOf( + DocRegularStmt("Test "), + DocRegularStmt("does not iterate "), + DocCodeStmt("for(int i = 0; i < x; i++)"), + DocRegularStmt(", "), + DocRegularStmt("returns from: "), + DocCodeStmt("return 0;"), + DocRegularStmt("\n"), + ) + ) + ) + check( + CycleDependedCondition::oneCondition, + eq(3), + { x, r -> x <= 0 && r == 0 }, + { x, r -> x in 1..2 && r == 0 }, + { x, r -> x > 2 && r == 1 }, + summaryTextChecks = listOf( + keyContain(DocCodeStmt("(i == 2): True")), + keyContain(DocCodeStmt("(i == 2): False")), + keyMatch(conditionSummary) + ), + summaryNameChecks = listOf( + keyMatch("testOneCondition_IEquals2"), + keyMatch("testOneCondition_INotEquals2"), + keyMatch("testOneCondition_ReturnZero"), + ), + summaryDisplayNameChecks = listOf( + keyContain("i == 2 : True"), + keyContain("i == 2 : False"), + keyContain("return 0"), + ) + ) + } + + @Test + fun testCycleDependedTwoCondition() { + val conditionSummary = listOf( + DocPreTagStatement( + listOf( + DocRegularStmt("Test "), + DocRegularStmt("does not iterate "), + DocCodeStmt("for(int i = 0; i < x; i++)"), + DocRegularStmt(", "), + DocRegularStmt("returns from: "), + DocCodeStmt("return 0;"), + DocRegularStmt("\n"), + ) + ) + ) + check( + CycleDependedCondition::twoCondition, + eq(4), + { x, r -> x <= 0 && r == 0 }, + { x, r -> x in 1..3 && r == 0 }, + { x, r -> x == 4 && r == 1 }, + { x, r -> x >= 5 && r == 0 }, + summaryTextChecks = listOf( + keyContain(DocCodeStmt("(x == 4): False")), + keyContain(DocCodeStmt("(i > 2): True")), + keyContain(DocCodeStmt("(i > 2): False")), + keyMatch(conditionSummary) + ), + summaryNameChecks = listOf( + keyMatch("testTwoCondition_XNotEquals4"), + keyMatch("testTwoCondition_XEquals4"), + keyMatch("testTwoCondition_ILessOrEqual2"), + keyMatch("testTwoCondition_ReturnZero"), + ), + summaryDisplayNameChecks = listOf( + keyContain("x == 4 : False"), + keyContain("x == 4 : True"), + keyContain("i > 2 : False"), + keyContain("return 0"), + ) + ) + } + + + @Test + fun testCycleDependedThreeCondition() { + check( + CycleDependedCondition::threeCondition, + eq(4), + { x, r -> x <= 0 && r == 0 }, + { x, r -> x in 1..5 && r == 0 }, + { x, r -> x == 6 || x > 8 && r == 1 }, + { x, r -> x == 7 && r == 0 } + ) + } + + + @Test + fun testCycleDependedOneConditionHigherNumber() { + check( + CycleDependedCondition::oneConditionHigherNumber, + eq(3), + { x, r -> x <= 0 && r == 0 }, + { x, r -> x in 1..100 && r == 0 }, + { x, r -> x > 100 && r == 1 && r == 1 } + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt new file mode 100644 index 0000000000..878ecb6ca5 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt @@ -0,0 +1,216 @@ +package org.utbot.examples.controlflow + +import org.utbot.framework.plugin.api.DocCodeStmt +import org.utbot.framework.plugin.api.DocPreTagStatement +import org.utbot.framework.plugin.api.DocRegularStmt +import org.utbot.framework.plugin.api.DocStatement +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class CyclesTest : UtValueTestCaseChecker(testClass = Cycles::class) { + @Test + fun testForCycle() { + check( + Cycles::forCycle, + eq(3), + { x, r -> x <= 0 && r == -1 }, + { x, r -> x in 1..5 && r == -1 }, + { x, r -> x > 5 && r == 1 } + ) + } + + @Test + fun testForCycleFour() { + val cycleSummary = listOf( + DocPreTagStatement( + listOf( + DocRegularStmt("Test "), + DocRegularStmt("does not iterate "), + DocCodeStmt("for(int i = 0; i < x; i++)"), + DocRegularStmt(", "), + DocRegularStmt("returns from: "), + DocCodeStmt("return -1;"), + DocRegularStmt("\n"), + ) + ) + ) + check( + Cycles::forCycleFour, + eq(3), + { x, r -> x <= 0 && r == -1 }, + { x, r -> x in 1..4 && r == -1 }, + { x, r -> x > 4 && r == 1 }, + summaryTextChecks = listOf( + keyContain(DocCodeStmt("(i > 4): True")), + keyContain(DocCodeStmt("(i > 4): False")), + keyMatch(cycleSummary) + ), + summaryNameChecks = listOf( + keyMatch("testForCycleFour_IGreaterThan4"), + keyMatch("testForCycleFour_ILessOrEqual4"), + keyMatch("testForCycleFour_ReturnNegative1") + ), + summaryDisplayNameChecks = listOf( + keyContain("i > 4 : True"), + keyContain("i > 4 : False"), + keyContain("return -1") + ) + ) + } + + @Test + fun testForCycleJayHorn() { + check( + Cycles::forCycleFromJayHorn, + eq(2), + { x, r -> x <= 0 && r == 0 }, + { x, r -> x > 0 && r == 2 * x } + ) + } + + @Test + fun testFiniteCycle() { + check( + Cycles::finiteCycle, + eq(2), + { x, r -> x % 519 == 0 && (r as Int) % 519 == 0 }, + { x, r -> x % 519 != 0 && (r as Int) % 519 == 0 } + ) + } + + @Test + fun testWhileCycle() { + check( + Cycles::whileCycle, + eq(2), + { x, r -> x <= 0 && r == 0 }, + { x, r -> x > 0 && r == (0 until x).sum() } + ) + } + + @Test + fun testCallInnerWhile() { + check( + Cycles::callInnerWhile, + between(1..2), + { x, r -> x >= 42 && r == Cycles().callInnerWhile(x) }, + summaryTextChecks = listOf( + keyContain(DocCodeStmt("return innerWhile(value, 42);")), + ), + summaryNameChecks = listOf( + keyMatch("testCallInnerWhile_IterateWhileLoop") + ) + ) + } + + @Test + fun testInnerLoop() { + val innerLoopSummary1 = arrayOf( + DocRegularStmt("Test "), + DocRegularStmt("calls "), + DocRegularStmt("CycleDependedCondition::twoCondition"), + DocRegularStmt(",\n there it "), + DocRegularStmt("iterates the loop "), + DocRegularStmt(""), + DocCodeStmt("for(int i = 0; i < x; i++)"), + DocRegularStmt(" "), + DocRegularStmt("once"), + DocRegularStmt(""), + DocRegularStmt(". "), + DocRegularStmt("\n Test "), +// DocRegularStmt("afterwards "), + DocRegularStmt("returns from: "), + DocCodeStmt("return 0;"), + DocRegularStmt("\n "), + DocRegularStmt("\nTest "), +// DocRegularStmt("afterwards "), + DocRegularStmt("returns from: "), + DocCodeStmt("return cycleDependedCondition.twoCondition(value);"), + DocRegularStmt("\n"), + ) + val innerLoopSummary2 = arrayOf( + DocRegularStmt("Test "), + DocRegularStmt("calls "), + DocRegularStmt("CycleDependedCondition::twoCondition"), + DocRegularStmt(",\n there it "), + DocRegularStmt("iterates the loop "), + DocRegularStmt(""), + DocCodeStmt("for(int i = 0; i < x; i++)"), + DocRegularStmt(" "), + DocRegularStmt("4 times"), + DocRegularStmt(""), + DocRegularStmt(",\n "), + DocRegularStmt(" "), + DocRegularStmt("inside this loop, the test "), + DocRegularStmt("executes conditions:\n "), + DocRegularStmt(""), + DocCodeStmt("(i > 2): True"), + DocRegularStmt(",\n "), + DocCodeStmt("(x == 4): True"), + DocRegularStmt("\n returns from: "), + DocCodeStmt("return 1;"), + DocRegularStmt("\nTest "), +// DocRegularStmt("afterwards "), + DocRegularStmt("returns from: "), + DocCodeStmt("return cycleDependedCondition.twoCondition(value);"), + DocRegularStmt("\n"), + ) + val innerLoopSummary3 = arrayOf( + DocRegularStmt("Test "), + DocRegularStmt("calls "), + DocRegularStmt("CycleDependedCondition::twoCondition"), + DocRegularStmt(",\n there it "), + DocRegularStmt("iterates the loop "), + DocCodeStmt("for(int i = 0; i < x; i++)"), + DocRegularStmt("5 times"), + DocRegularStmt("inside this loop, the test "), + DocRegularStmt("executes conditions:\n "), + DocCodeStmt("(x == 4): False"), + DocRegularStmt("\n Test "), + DocRegularStmt("returns from: "), + DocCodeStmt("return 0;"), + DocCodeStmt("return cycleDependedCondition.twoCondition(value);"), + ) + check( + Cycles::innerLoop, + ignoreExecutionsNumber, + { x, r -> x in 1..3 && r == 0 }, + { x, r -> x == 4 && r == 1 }, + { x, r -> x >= 5 && r == 0 }, + // TODO JIRA:1442 +/* summaryTextChecks = listOf( + keyContain(*innerLoopSummary1), + keyContain(*innerLoopSummary2), + keyContain(*innerLoopSummary3) + ), + summaryNameChecks = listOf( + keyMatch("testInnerLoop_ReturnZero"), + keyMatch("testInnerLoop_XEquals4"), + keyMatch("testInnerLoop_XNotEquals4") + )*/ + ) + } + + @Test + fun testDivideByZeroCheckWithCycles() { + checkWithException( + Cycles::divideByZeroCheckWithCycles, + eq(3), + { n, _, r -> n < 5 && r.isException() }, + { n, x, r -> n >= 5 && x == 0 && r.isException() }, + { n, x, r -> n >= 5 && x != 0 && r.getOrNull() == Cycles().divideByZeroCheckWithCycles(n, x) } + ) + } + + @Test + fun moveToExceptionTest() { + checkWithException( + Cycles::moveToException, + eq(3), + { x, r -> x < 400 && r.isException() }, + { x, r -> x > 400 && r.isException() }, + { x, r -> x == 400 && r.isException() }, + coverage = atLeast(85) + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/SwitchTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/SwitchTest.kt new file mode 100644 index 0000000000..381c097be9 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/SwitchTest.kt @@ -0,0 +1,88 @@ +package org.utbot.examples.controlflow + +import org.utbot.framework.plugin.api.DocCodeStmt +import org.utbot.framework.plugin.api.DocPreTagStatement +import org.utbot.framework.plugin.api.DocRegularStmt +import org.utbot.framework.plugin.api.DocStatement +import java.math.RoundingMode.CEILING +import java.math.RoundingMode.DOWN +import java.math.RoundingMode.HALF_DOWN +import java.math.RoundingMode.HALF_EVEN +import java.math.RoundingMode.HALF_UP +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testcheckers.ge +import org.utbot.testcheckers.withoutMinimization + +internal class SwitchTest : UtValueTestCaseChecker(testClass = Switch::class) { + @Test + fun testSimpleSwitch() { + val switchCaseSummary = listOf( + DocPreTagStatement( + listOf( + DocRegularStmt("Test "), + DocRegularStmt("activates switch case: "), + DocCodeStmt("default"), + DocRegularStmt(", "), + DocRegularStmt("returns from: "), + DocCodeStmt("return -1;"), + DocRegularStmt("\n"), + ) + ) + ) + check( + Switch::simpleSwitch, + ge(4), + { x, r -> x == 10 && r == 10 }, + { x, r -> (x == 11 || x == 12) && r == 12 }, // fall-through has it's own branch + { x, r -> x == 13 && r == 13 }, + { x, r -> x !in 10..13 && r == -1 }, // one for default is enough + summaryTextChecks = listOf( + keyContain(DocCodeStmt("return 10;")), + keyContain(DocCodeStmt("return 12;")), + keyContain(DocCodeStmt("return 12;")), + keyContain(DocCodeStmt("return 13;")), + keyMatch(switchCaseSummary) + ), + summaryNameChecks = listOf( + keyMatch("testSimpleSwitch_Return10"), + keyMatch("testSimpleSwitch_Return13"), + keyMatch("testSimpleSwitch_ReturnNegative1"), + ), + summaryDisplayNameChecks = listOf( + keyMatch("switch(x) case: 10 -> return 10"), + keyMatch("switch(x) case: 13 -> return 13"), + keyMatch("switch(x) case: Default -> return -1"), + ) + ) + } + + @Test + fun testLookupSwitch() { + check( + Switch::lookupSwitch, + ge(4), + { x, r -> x == 0 && r == 0 }, + { x, r -> (x == 10 || x == 20) && r == 20 }, // fall-through has it's own branch + { x, r -> x == 30 && r == 30 }, + { x, r -> x !in setOf(0, 10, 20, 30) && r == -1 } // one for default is enough + ) + } + + @Test + fun testEnumSwitch() { + withoutMinimization { // TODO: JIRA:1506 + check( + Switch::enumSwitch, + eq(7), + { m, r -> m == null && r == null }, // NPE + { m, r -> m == HALF_DOWN && r == 1 }, // We will minimize two of these branches + { m, r -> m == HALF_EVEN && r == 1 }, // We will minimize two of these branches + { m, r -> m == HALF_UP && r == 1 }, // We will minimize two of these branches + { m, r -> m == DOWN && r == 2 }, + { m, r -> m == CEILING && r == 3 }, + { m, r -> m !in setOf(HALF_DOWN, HALF_EVEN, HALF_UP, DOWN, CEILING) && r == -1 }, + ) + } + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/enums/ClassWithEnumTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/enums/ClassWithEnumTest.kt new file mode 100644 index 0000000000..a6d62721ca --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/enums/ClassWithEnumTest.kt @@ -0,0 +1,194 @@ +package org.utbot.examples.enums + +import org.utbot.examples.enums.ClassWithEnum.StatusEnum.ERROR +import org.utbot.examples.enums.ClassWithEnum.StatusEnum.READY +import org.utbot.framework.plugin.api.FieldId +import org.utbot.framework.plugin.api.util.id +import org.junit.jupiter.api.Disabled +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 + +class ClassWithEnumTest : UtValueTestCaseChecker(testClass = ClassWithEnum::class) { + @Test + fun testOrdinal() { + withoutConcrete { + checkAllCombinations(ClassWithEnum::useOrdinal) + } + } + + @Test + fun testGetter() { + check( + ClassWithEnum::useGetter, + eq(2), + { s, r -> s == null && r == -1 }, + { s, r -> s != null && r == 0 }, + ) + } + + @Test + fun testDifficultIfBranch() { + check( + ClassWithEnum::useEnumInDifficultIf, + eq(2), + { s, r -> s.equals("TRYIF", ignoreCase = true) && r == 1 }, + { s, r -> !s.equals("TRYIF", ignoreCase = true) && r == 2 }, + ) + } + + @Test + @Disabled("TODO JIRA:1686") + fun testNullParameter() { + check( + ClassWithEnum::nullEnumAsParameter, + eq(3), + { e, _ -> e == null }, + { e, r -> e == READY && r == 0 }, + { e, r -> e == ERROR && r == -1 }, + ) + } + + @Test + @Disabled("TODO JIRA:1686") + fun testNullField() { + checkWithException( + ClassWithEnum::nullField, + eq(3), + { e, r -> e == null && r.isException() }, + { e, r -> e == ERROR && r.isException() }, + { e, r -> e == READY && r.getOrNull()!! == 3 && READY.s.length == 3 }, + ) + } + + @Test + @Disabled("TODO JIRA:1686") + fun testChangeEnum() { + checkWithException( + ClassWithEnum::changeEnum, + eq(3), + { e, r -> e == null && r.isException() }, + { e, r -> e == READY && r.getOrNull()!! == ERROR.ordinal }, + { e, r -> e == ERROR && r.getOrNull()!! == READY.ordinal }, + ) + } + + @Test + fun testChangeMutableField() { + // TODO testing code generation for this method is disabled because we need to restore original field state + // should be enabled after solving JIRA:1648 + withEnabledTestingCodeGeneration(testCodeGeneration = false) { + checkWithException( + ClassWithEnum::changeMutableField, + eq(2), + { e, r -> e == READY && r.getOrNull()!! == 2 }, + { e, r -> (e == null || e == ERROR) && r.getOrNull()!! == -2 }, + ) + } + } + + @Test + @Disabled("TODO JIRA:1686") + fun testCheckName() { + check( + ClassWithEnum::checkName, + eq(3), + { s, _ -> s == null }, + { s, r -> s == READY.name && r == ERROR.name }, + { s, r -> s != READY.name && r == READY.name }, + ) + } + + @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 + } + ) + } + + @Test + fun testEnumValues() { + checkStaticMethod( + ClassWithEnum.StatusEnum::values, + eq(1), + { r -> r.contentEquals(arrayOf(READY, ERROR)) }, + ) + } + + @Test + fun testFromCode() { + checkStaticMethod( + ClassWithEnum.StatusEnum::fromCode, + eq(3), + { code, r -> code == 10 && r == READY }, + { code, r -> code == -10 && r == ERROR }, + { code, r -> code !in setOf(10, -10) && r == null }, // IllegalArgumentException + ) + } + + @Test + fun testFromIsReady() { + checkStaticMethod( + ClassWithEnum.StatusEnum::fromIsReady, + eq(2), + { isFirst, r -> isFirst && r == READY }, + { isFirst, r -> !isFirst && r == ERROR }, + ) + } + + @Test + @Disabled("TODO JIRA:1450") + fun testPublicGetCodeMethod() { + checkWithThis( + ClassWithEnum.StatusEnum::publicGetCode, + eq(2), + { enumInstance, r -> enumInstance == READY && r == 10 }, + { enumInstance, r -> enumInstance == ERROR && r == -10 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testImplementingInterfaceEnumInDifficultBranch() { + withPushingStateFromPathSelectorForConcrete { + check( + ClassWithEnum::implementingInterfaceEnumInDifficultBranch, + eq(2), + { s, r -> s.equals("SUCCESS", ignoreCase = true) && r == 0 }, + { s, r -> !s.equals("SUCCESS", ignoreCase = true) && r == 2 }, + ) + } + } + + @Test + fun testAffectSystemStaticAndUseInitEnumFromIt() { + check( + ClassWithEnum::affectSystemStaticAndInitEnumFromItAndReturnField, + eq(1), + { r -> r == true }, + coverage = DoNotCalculate + ) + } + + @Test + fun testAffectSystemStaticAndInitEnumFromItAndGetItFromEnumFun() { + check( + ClassWithEnum::affectSystemStaticAndInitEnumFromItAndGetItFromEnumFun, + eq(1), + { r -> r == true }, + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/enums/ComplexEnumExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/enums/ComplexEnumExamplesTest.kt new file mode 100644 index 0000000000..e0d35726a4 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/enums/ComplexEnumExamplesTest.kt @@ -0,0 +1,106 @@ +package org.utbot.examples.enums + +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.examples.enums.ComplexEnumExamples.Color +import org.utbot.examples.enums.ComplexEnumExamples.Color.BLUE +import org.utbot.examples.enums.ComplexEnumExamples.Color.GREEN +import org.utbot.examples.enums.ComplexEnumExamples.Color.RED +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq + +class ComplexEnumExamplesTest : UtValueTestCaseChecker( + testClass = ComplexEnumExamples::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testEnumToEnumMapCountValues() { + check( + ComplexEnumExamples::enumToEnumMapCountValues, + ignoreExecutionsNumber, + { m, r -> m.isEmpty() && r == 0 }, + { m, r -> m.isNotEmpty() && !m.values.contains(RED) && r == 0 }, + { m, r -> m.isNotEmpty() && m.values.contains(RED) && m.values.count { it == RED } == r } + ) + } + + @Test + fun testEnumToEnumMapCountKeys() { + check( + ComplexEnumExamples::enumToEnumMapCountKeys, + ignoreExecutionsNumber, + { m, r -> m.isEmpty() && r == 0 }, + { m, r -> m.isNotEmpty() && !m.keys.contains(GREEN) && !m.keys.contains(BLUE) && r == 0 }, + { m, r -> m.isNotEmpty() && m.keys.intersect(setOf(BLUE, GREEN)).isNotEmpty() && m.keys.count { it == BLUE || it == GREEN } == r } + ) + } + + @Test + fun testEnumToEnumMapCountMatches() { + check( + ComplexEnumExamples::enumToEnumMapCountMatches, + ignoreExecutionsNumber, + { m, r -> m.isEmpty() && r == 0 }, + { m, r -> m.entries.count { it.key == it.value } == r } + ) + } + + @Test + fun testCountEqualColors() { + check( + ComplexEnumExamples::countEqualColors, + ignoreExecutionsNumber, + { a, b, c, r -> a == b && a == c && r == 3 }, + { a, b, c, r -> setOf(a, b, c).size == 2 && r == 2 }, + { a, b, c, r -> a != b && b != c && a != c && r == 1 } + ) + } + + @Test + fun testCountNullColors() { + check( + ComplexEnumExamples::countNullColors, + eq(3), + { a, b, r -> a == null && b == null && r == 2 }, + { a, b, r -> (a == null) != (b == null) && r == 1 }, + { a, b, r -> a != null && b != null && r == 0 }, + ) + } + + @Test + @Disabled("TODO: nested anonymous classes are not supported: https://github.com/UnitTestBot/UTBotJava/issues/617") + fun testFindState() { + check( + ComplexEnumExamples::findState, + ignoreExecutionsNumber, + { c, r -> c in setOf(0, 127, 255) && r != null && r.code == c } + ) + } + + @Test + fun testCountValuesInArray() { + fun Color.isCorrectlyCounted(inputs: Array, counts: Map): Boolean = + inputs.count { it == this } == (counts[this] ?: 0) + + check( + ComplexEnumExamples::countValuesInArray, + ignoreExecutionsNumber, + { cs, r -> cs.isEmpty() && r != null && r.isEmpty() }, + { cs, r -> cs.toList().isEmpty() && r != null && r.isEmpty() }, + { cs, r -> cs.toList().isNotEmpty() && r != null && Color.values().all { it.isCorrectlyCounted(cs, r) } } + ) + } + + @Test + fun testCountRedInArray() { + check( + ComplexEnumExamples::countRedInArray, + eq(3), + { colors, result -> colors.count { it == RED } == result } + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/ExceptionClusteringChecker.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/ExceptionClusteringChecker.kt new file mode 100644 index 0000000000..4e67505768 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/ExceptionClusteringChecker.kt @@ -0,0 +1,57 @@ +package org.utbot.examples.exceptions + +import org.utbot.framework.plugin.api.UtExecutionSuccess +import org.utbot.framework.plugin.api.UtExplicitlyThrownException +import org.utbot.framework.plugin.api.UtImplicitlyThrownException +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.UtTimeoutException +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.ge +import org.utbot.testing.UtModelTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.primitiveValue + +internal class ExceptionClusteringChecker : + UtModelTestCaseChecker(testClass = ExceptionClusteringExamples::class) { + /** + * Difference is in throwing unchecked exceptions - for method under test is [UtExpectedCheckedThrow]. + */ + @Test + fun testDifferentExceptions() { + check( + ExceptionClusteringExamples::differentExceptions, + ignoreExecutionsNumber, + { i, r -> i.int() == 0 && r is UtImplicitlyThrownException && r.exception is ArithmeticException }, + { i, r -> i.int() == 1 && r is UtExplicitlyThrownException && r.exception is MyCheckedException }, + { i, r -> i.int() == 2 && r is UtExplicitlyThrownException && r.exception is IllegalArgumentException }, + { i, r -> i.int() !in 0..2 && r is UtExecutionSuccess && r.model.int() == 2 * i.int() }, + ) + } + + /** + * Difference is in throwing unchecked exceptions - for nested call it is [UtUnexpectedUncheckedThrow]. + */ + @Test + fun testDifferentExceptionsInNestedCall() { + check( + ExceptionClusteringExamples::differentExceptionsInNestedCall, + ignoreExecutionsNumber, + { i, r -> i.int() == 0 && r is UtImplicitlyThrownException && r.exception is ArithmeticException }, + { i, r -> i.int() == 1 && r is UtExplicitlyThrownException && r.exception is MyCheckedException }, + { i, r -> i.int() == 2 && r is UtExplicitlyThrownException && r.exception is IllegalArgumentException }, + { i, r -> i.int() !in 0..2 && r is UtExecutionSuccess && r.model.int() == 2 * i.int() }, + ) + } + + @Test + fun testSleepingMoreThanDefaultTimeout() { + check( + ExceptionClusteringExamples::sleepingMoreThanDefaultTimeout, + ge(1), + { _, r -> r is UtTimeoutException }, // we will minimize one of these: i <= 0 or i > 0 + ) + } +} + +private fun UtModel.int(): Int = this.primitiveValue() + diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/ExceptionExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/ExceptionExamplesTest.kt new file mode 100644 index 0000000000..29b62857fa --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/ExceptionExamplesTest.kt @@ -0,0 +1,135 @@ +package org.utbot.examples.exceptions + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testcheckers.withoutConcrete + +internal class ExceptionExamplesTest : UtValueTestCaseChecker( + testClass = ExceptionExamples::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) // TODO: fails because we construct lists with generics + ) +) { + @Test + fun testInitAnArray() { + check( + ExceptionExamples::initAnArray, + ignoreExecutionsNumber, + { n, r -> n < 0 && r == -2 }, + { n, r -> n == 0 || n == 1 && r == -3 }, + { n, r -> n > 1 && r == 2 * n + 3 }, + coverage = atLeast(80) + ) + } + + @Test + fun testNestedExceptions() { + check( + ExceptionExamples::nestedExceptions, + eq(3), + { i, r -> i < 0 && r == -100 }, + { i, r -> i > 0 && r == 100 }, + { i, r -> i == 0 && r == 0 }, + ) + } + + @Test + fun testDoNotCatchNested() { + checkWithException( + ExceptionExamples::doNotCatchNested, + eq(3), + { i, r -> i < 0 && r.isException() }, + { i, r -> i > 0 && r.isException() }, + { i, r -> i == 0 && r.getOrThrow() == 0 }, + ) + } + + @Test + fun testFinallyThrowing() { + checkWithException( + ExceptionExamples::finallyThrowing, + eq(2), + { i, r -> i <= 0 && r.isException() }, + { i, r -> i > 0 && r.isException() }, + ) + } + + @Test + fun testFinallyChanging() { + check( + ExceptionExamples::finallyChanging, + eq(2), + { i, r -> i * 2 <= 0 && r == i * 2 + 10 }, + { i, r -> i * 2 > 0 && r == i * 2 + 110 }, + coverage = atLeast(80) // differs from JaCoCo + ) + } + + @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 + ) + } + + @Test + fun testCreateException() { + check( + ExceptionExamples::createException, + eq(1), + { r -> r is java.lang.IllegalArgumentException }, + ) + } + + /** + * Used for path generation check in [org.utbot.engine.Traverser.fullPath] + */ + @Test + fun testCatchDeepNestedThrow() { + checkWithException( + ExceptionExamples::catchDeepNestedThrow, + eq(2), + { i, r -> i < 0 && r.isException() }, + { i, r -> i >= 0 && r.getOrThrow() == i }, + coverage = atLeast(66) // because of unexpected exception thrown + ) + } + + /** + * Covers [#656](https://github.com/UnitTestBot/UTBotJava/issues/656). + */ + @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) + ) + } + } + + /** + * Used for path generation check in [org.utbot.engine.Traverser.fullPath] + */ + @Test + fun testDontCatchDeepNestedThrow() { + checkWithException( + ExceptionExamples::dontCatchDeepNestedThrow, + eq(2), + { i, r -> i < 0 && r.isException() }, + { i, r -> i >= 0 && r.getOrThrow() == i }, + coverage = atLeast(66) // because of unexpected exception thrown + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/JvmCrashExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/JvmCrashExamplesTest.kt new file mode 100644 index 0000000000..6a9449d4f7 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/JvmCrashExamplesTest.kt @@ -0,0 +1,41 @@ +package org.utbot.examples.exceptions + +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testcheckers.withoutSandbox +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker + +internal class JvmCrashExamplesTest : UtValueTestCaseChecker(testClass = JvmCrashExamples::class) { + @Test + @Disabled("JIRA:1527") + fun testExit() { + check( + JvmCrashExamples::exit, + eq(2) + ) + } + + @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 + ) + } + } + + @Test + fun testCrashPrivileged() { + check( + JvmCrashExamples::crashPrivileged, + 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-testing/src/test/kotlin/org/utbot/examples/invokes/InvokeExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/InvokeExampleTest.kt new file mode 100644 index 0000000000..44ec7ceb69 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/InvokeExampleTest.kt @@ -0,0 +1,212 @@ +package org.utbot.examples.invokes + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class InvokeExampleTest : UtValueTestCaseChecker(testClass = InvokeExample::class) { + @Test + fun testSimpleFormula() { + check( + InvokeExample::simpleFormula, + eq(3), + { fst, _, _ -> fst < 100 }, + { _, snd, _ -> snd < 100 }, + { fst, snd, r -> fst >= 100 && snd >= 100 && r == (fst + 5) * (snd / 2) }, + ) + } + + @Test + fun testChangeObjectValueByMethod() { + check( + InvokeExample::changeObjectValueByMethod, + eq(2), + { o, _ -> o == null }, + { o, r -> o != null && r?.value == 4 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testParticularValue() { + check( + InvokeExample::particularValue, + eq(3), + { o, _ -> o == null }, + { o, _ -> o != null && o.value < 0 }, + { o, r -> o != null && o.value >= 0 && r?.value == 12 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCreateObjectFromValue() { + check( + InvokeExample::createObjectFromValue, + eq(2), + { value, r -> value == 0 && r?.value == 1 }, + { value, r -> value != 0 && r?.value == value } + ) + } + + @Test + fun testGetNullOrValue() { + check( + InvokeExample::getNullOrValue, + eq(3), + { o, _ -> o == null }, + { o, r -> o != null && o.value < 100 && r == null }, + { o, r -> o != null && o.value >= 100 && r?.value == 5 }, + coverage = DoNotCalculate + ) + } + + + @Test + fun testConstraintsFromOutside() { + check( + InvokeExample::constraintsFromOutside, + eq(3), + { value, r -> value >= 0 && r == value }, + { value, r -> value == Int.MIN_VALUE && r == 0 }, + { value, r -> value < 0 && value != Int.MIN_VALUE && r == -value }, + coverage = DoNotCalculate + ) + } + + + @Test + fun testConstraintsFromInside() { + check( + InvokeExample::constraintsFromInside, + eq(3), + { value, r -> value >= 0 && r == 1 }, + { value, r -> value == Int.MIN_VALUE && r == 1 }, + { value, r -> value < 0 && value != Int.MIN_VALUE && r == 1 }, + ) + } + + @Test + fun testAlwaysNPE() { + checkWithException( + InvokeExample::alwaysNPE, + eq(4), + { o, r -> o == null && r.isException() }, + { o, r -> o != null && o.value == 0 && r.isException() }, + { o, r -> o != null && o.value < 0 && r.isException() }, + { o, r -> o != null && o.value > 0 && r.isException() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testExceptionInNestedMethod() { + checkWithException( + InvokeExample::exceptionInNestedMethod, + eq(3), + { o, _, r -> o == null && r.isException() }, + { o, value, r -> o != null && value < 0 && r.isException() }, + { o, value, r -> o != null && value >= 0 && value == (r.getOrNull() as InvokeClass).value }, + coverage = DoNotCalculate + ) + } + + @Test + fun testFewNestedExceptions() { + checkWithException( + InvokeExample::fewNestedException, + eq(5), + { o, _, r -> o == null && r.isException() }, + { o, value, r -> o != null && value < 10 && r.isException() }, + { o, value, r -> o != null && value in 10..99 && r.isException() }, + { o, value, r -> o != null && value in 100..9999 && r.isException() }, + { o, value, r -> o != null && value >= 10000 && value == (r.getOrNull() as InvokeClass).value }, + coverage = DoNotCalculate + ) + } + + @Test + fun testDivBy() { + checkWithException( + InvokeExample::divBy, + eq(4), + { o, _, r -> o == null && r.isException() }, + { o, _, r -> o != null && o.value < 1000 && r.isException() }, + { o, den, r -> o != null && o.value >= 1000 && den == 0 && r.isException() }, + { o, den, r -> o != null && o.value >= 1000 && den != 0 && r.getOrNull() == o.value / den }, + coverage = DoNotCalculate + ) + } + + @Test + fun testUpdateValue() { + check( + InvokeExample::updateValue, + eq(4), + { o, _, _ -> o == null }, + { o, _, r -> o != null && o.value > 0 && r != null && r.value > 0 }, + { o, value, r -> o != null && o.value <= 0 && value > 0 && r?.value == value }, + { o, value, _ -> o != null && o.value <= 0 && value <= 0 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testNullAsParameter() { + check( + InvokeExample::nullAsParameter, + eq(1), + coverage = DoNotCalculate + ) + } + + @Test + fun testChangeArrayWithAssignFromMethod() { + check( + InvokeExample::changeArrayWithAssignFromMethod, + eq(3), + { a, _ -> a == null }, + { a, r -> a != null && a.isEmpty() && r != null && r.isEmpty() }, + { a, r -> + require(a != null && r != null) + a.isNotEmpty() && r.size == a.size && a.map { it + 5 } == r.toList() && !a.contentEquals(r) + } + ) + } + + @Test + fun testChangeArrayByMethod() { + check( + InvokeExample::changeArrayByMethod, + ignoreExecutionsNumber, + { a, _ -> a == null }, + { a, r -> a != null && a.isNotEmpty() && r != null && r.size == a.size && a.map { it + 5 } == r.toList() } + ) + } + + @Test + fun testArrayCopyExample() { + check( + InvokeExample::arrayCopyExample, + eq(5), + { a, _ -> a == null }, + { a, _ -> a != null && a.size < 3 }, + { a, r -> a != null && a.size >= 3 && a[0] <= a[1] && r == null }, + { a, r -> a != null && a.size >= 3 && a[0] > a[1] && a[1] <= a[2] && r == null }, + { a, r -> a != null && a.size >= 3 && a[0] > a[1] && a[1] > a[2] && r.contentEquals(a) }, + coverage = DoNotCalculate + ) + } + + @Test + fun testUpdateValues() { + check( + InvokeExample::updateValues, + eq(4), + { fst, _, _ -> fst == null }, + { fst, snd, _ -> fst != null && snd == null }, + { fst, snd, r -> fst != null && snd != null && fst !== snd && r == 1 }, + { fst, snd, _ -> fst != null && snd != null && fst === snd }, + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/NativeExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/NativeExampleTest.kt new file mode 100644 index 0000000000..9949638cb1 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/NativeExampleTest.kt @@ -0,0 +1,52 @@ +package org.utbot.examples.invokes + +import kotlin.math.ln +import kotlin.math.sqrt +import org.junit.jupiter.api.Tag +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testcheckers.ge + +internal class NativeExampleTest : UtValueTestCaseChecker(testClass = NativeExample::class) { + @Test + fun testPartialEx() { + check( + NativeExample::partialExecution, + ge(1), + coverage = atLeast(50) + ) + } + + @Test + fun testUnreachableNativeCall() { + check( + NativeExample::unreachableNativeCall, + eq(2), + { d, r -> !d.isNaN() && r == 1 }, + { d, r -> d.isNaN() && r == 2 }, + coverage = atLeast(50) + ) + } + + @Test + @Tag("slow") + fun testSubstitution() { + check( + NativeExample::substitution, + ignoreExecutionsNumber, + { x, r -> x > 4 && r == 1 }, + { x, r -> sqrt(x) <= 2 && r == 0 } + ) + } + + @Test + fun testUnreachableBranch() { + check( + NativeExample::unreachableBranch, + ge(2), + { x, r -> x.isNaN() && r == 1 }, + { x, r -> (!ln(x).isNaN() || x < 0) && r == 2 }, + coverage = atLeast(66) + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/SimpleInterfaceExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/SimpleInterfaceExampleTest.kt new file mode 100644 index 0000000000..98e19a19b8 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/SimpleInterfaceExampleTest.kt @@ -0,0 +1,40 @@ +package org.utbot.examples.invokes + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker + +internal class SimpleInterfaceExampleTest : UtValueTestCaseChecker( + testClass = SimpleInterfaceExample::class +) { + @Test + fun testOverrideMethod() { + check( + SimpleInterfaceExample::overrideMethod, + eq(3), + { o, _, _ -> o == null }, + { o, v, r -> o is SimpleInterfaceImpl && r == v + 2 }, + { o, v, r -> o is Realization && r == v + 5 } + ) + } + + @Test + fun testDefaultMethod() { + check( + SimpleInterfaceExample::defaultMethod, + eq(2), + { o, _, _ -> o == null }, + { o, v, r -> o != null && r == v - 5 } + ) + } + + @Test + fun testInvokeMethodFromImplementor() { + check( + SimpleInterfaceExample::invokeMethodFromImplementor, + eq(2), + { o, _ -> o == null }, + { o, r -> o != null && r == 10 }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/StaticInvokeExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/StaticInvokeExampleTest.kt new file mode 100644 index 0000000000..5c75b0f0cb --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/StaticInvokeExampleTest.kt @@ -0,0 +1,22 @@ +package org.utbot.examples.invokes + +import kotlin.math.max +import org.junit.jupiter.api.Test +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.between + +internal class StaticInvokeExampleTest : UtValueTestCaseChecker(testClass = StaticInvokeExample::class) { + // TODO: inline local variables when types inference bug in Kotlin fixed + @Test + fun testMaxForThree() { + val method = StaticInvokeExample::maxForThree + checkStaticMethod( + method, + between(2..3), // two executions can cover all branches + { x, y, _, _ -> x > y }, + { x, y, _, _ -> x <= y }, + { x, y, z, _ -> max(x, y.toInt()) > z }, + { x, y, z, _ -> max(x, y.toInt()) <= z }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/VirtualInvokeExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/VirtualInvokeExampleTest.kt new file mode 100644 index 0000000000..05f4395083 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/VirtualInvokeExampleTest.kt @@ -0,0 +1,145 @@ +@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") + +package org.utbot.examples.invokes + +import java.lang.Boolean +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class VirtualInvokeExampleTest : UtValueTestCaseChecker(testClass = VirtualInvokeExample::class) { + @Test + fun testSimpleVirtualInvoke() { + checkWithException( + VirtualInvokeExample::simpleVirtualInvoke, + eq(3), + { v, r -> v < 0 && r.getOrNull() == -2 }, + { v, r -> v == 0 && r.isException() }, + { v, r -> v > 0 && r.getOrNull() == 1 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testVirtualNative() { + check( + VirtualInvokeExample::virtualNative, + eq(1), + { r -> r == Boolean::class.java.modifiers } + ) + } + + @Test + fun testGetSigners() { + check( + VirtualInvokeExample::virtualNativeArray, + eq(1), + ) + } + + @Test + fun testObjectFromOutside() { + checkWithException( + VirtualInvokeExample::objectFromOutside, + eq(7), + { o, _, r -> o == null && r.isException() }, + { o, v, r -> o != null && o is VirtualInvokeClassSucc && v < 0 && r.getOrNull() == -1 }, + { o, v, r -> o != null && o is VirtualInvokeClassSucc && v == 0 && r.getOrNull() == 0 }, + { o, v, r -> o != null && o is VirtualInvokeClassSucc && v > 0 && r.getOrNull() == 1 }, + { o, v, r -> o != null && o !is VirtualInvokeClassSucc && v < 0 && r.getOrNull() == 2 }, + { o, v, r -> o != null && o !is VirtualInvokeClassSucc && v == 0 && r.isException() }, + { o, v, r -> o != null && o !is VirtualInvokeClassSucc && v > 0 && r.getOrNull() == 1 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testDoubleCall() { + check( + VirtualInvokeExample::doubleCall, + eq(2), + { obj, _ -> obj == null }, + { obj, r -> obj != null && obj.returnX(obj) == r }, + coverage = DoNotCalculate + ) + } + + @Test + fun testYetAnotherObjectFromOutside() { + checkWithException( + VirtualInvokeExample::yetAnotherObjectFromOutside, + eq(3), + { o, r -> o == null && r.isException() }, + { o, r -> o != null && o !is VirtualInvokeClassSucc && r.getOrNull() == 1 }, + { o, r -> o != null && o is VirtualInvokeClassSucc && r.getOrNull() == 2 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testTwoObjects() { + checkWithException( + VirtualInvokeExample::twoObjects, + eq(3), + { o, r -> o == null && r.isException() }, + { o, r -> o != null && o is VirtualInvokeClassSucc && r.getOrNull() == 1 }, + { o, r -> o != null && o !is VirtualInvokeClassSucc && r.getOrNull() == 2 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testNestedVirtualInvoke() { + checkWithException( + VirtualInvokeExample::nestedVirtualInvoke, + eq(3), + { o, r -> o == null && r.isException() }, + { o, r -> o != null && o !is VirtualInvokeClassSucc && r.getOrNull() == 1 }, + { o, r -> o != null && o is VirtualInvokeClassSucc && r.getOrNull() == 2 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testAbstractClassInstanceFromOutsideWithoutOverrideMethods() { + check( + VirtualInvokeExample::abstractClassInstanceFromOutsideWithoutOverrideMethods, + eq(2), + { o, _ -> o == null }, + { o, r -> o is VirtualInvokeAbstractClassSucc && r == 1 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testAbstractClassInstanceFromOutside() { + check( + VirtualInvokeExample::abstractClassInstanceFromOutside, + eq(2), + { o, _ -> o == null }, + { o, r -> o is VirtualInvokeAbstractClassSucc && r == 2 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testNullValueInReturnValue() { + check( + VirtualInvokeExample::nullValueInReturnValue, + eq(3), + { o, _ -> o == null }, + { o, _ -> o is VirtualInvokeClassSucc }, + { o, r -> o is VirtualInvokeClass && r == 10L }, + coverage = DoNotCalculate + ) + } + + @Test + fun testQuasiImplementationInvoke() { + check( + VirtualInvokeExample::quasiImplementationInvoke, + eq(1), + { result -> result == 0 }, + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/CustomPredicateExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/CustomPredicateExampleTest.kt new file mode 100644 index 0000000000..868273353e --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/CustomPredicateExampleTest.kt @@ -0,0 +1,77 @@ +package org.utbot.examples.lambda + +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq + +class CustomPredicateExampleTest : UtValueTestCaseChecker( + testClass = CustomPredicateExample::class, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + // TODO: https://github.com/UnitTestBot/UTBotJava/issues/88 (generics in Kotlin) + // At the moment, when we create an instance of a functional interface via lambda (through reflection), + // we need to do a type cast (e.g. `obj as Predicate`), but since generics are not supported yet, + // we use a raw type (e.g. `Predicate`) instead (which is not allowed in Kotlin). + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testNoCapturedValuesPredicateCheck() { + checkWithException( + CustomPredicateExample::noCapturedValuesPredicateCheck, + 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 + ) + } + + @Test + fun testCapturedLocalVariablePredicateCheck() { + checkWithException( + CustomPredicateExample::capturedLocalVariablePredicateCheck, + 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 + ) + } + + @Test + fun testCapturedParameterPredicateCheck() { + checkWithException( + CustomPredicateExample::capturedParameterPredicateCheck, + 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 + ) + } + + @Test + fun testCapturedStaticFieldPredicateCheck() { + checkWithException( + 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() }, + 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 + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/PredicateNotExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/PredicateNotExampleTest.kt new file mode 100644 index 0000000000..739cff5964 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/PredicateNotExampleTest.kt @@ -0,0 +1,19 @@ +package org.utbot.examples.lambda + +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker + +class PredicateNotExampleTest : UtValueTestCaseChecker(testClass = PredicateNotExample::class) { + @Test + @Disabled("TODO flaky 0 executions at GitHub runners https://github.com/UnitTestBot/UTBotJava/issues/999") + fun testPredicateNotExample() { + check( + PredicateNotExample::predicateNotExample, + eq(2), + { a, r -> a == 5 && r == false }, + { a, r -> a != 5 && r == true }, + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt new file mode 100644 index 0000000000..2c893b55b6 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt @@ -0,0 +1,35 @@ +package org.utbot.examples.lambda + +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq + +// TODO failed Kotlin compilation (generics) SAT-1332 +class SimpleLambdaExamplesTest : UtValueTestCaseChecker( + testClass = SimpleLambdaExamples::class, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration), + ) +) { + @Test + fun testBiFunctionLambdaExample() { + checkWithException( + SimpleLambdaExamples::biFunctionLambdaExample, + eq(2), + { _, b, r -> b == 0 && r.isException() }, + { a, b, r -> b != 0 && r.getOrThrow() == a / b }, + ) + } + + @Test + fun testChoosePredicate() { + check( + SimpleLambdaExamples::choosePredicate, + eq(2), + { b, r -> b && !r!!.test(null) && r.test(0) }, + { b, r -> !b && r!!.test(null) && !r.test(0) }, + coverage = DoNotCalculate // coverage could not be calculated since method result is lambda + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/make/symbolic/ClassWithComplicatedMethodsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/make/symbolic/ClassWithComplicatedMethodsTest.kt new file mode 100644 index 0000000000..083220f4c5 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/make/symbolic/ClassWithComplicatedMethodsTest.kt @@ -0,0 +1,95 @@ +package org.utbot.examples.make.symbolic + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.framework.plugin.api.MockStrategyApi +import kotlin.math.abs +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 + +// This class is substituted with ComplicatedMethodsSubstitutionsStorage +// but we cannot do in code generation. +// For this reason code generation executions are disabled +internal class ClassWithComplicatedMethodsTest : UtValueTestCaseChecker( + testClass = ClassWithComplicatedMethods::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA, Compilation), + TestLastStage(CodegenLanguage.KOTLIN, Compilation) + ) +) { + @Test + @Disabled("[SAT-1419]") + fun testApplyMethodWithSideEffectAndReturn() { + checkMocksAndInstrumentation( + ClassWithComplicatedMethods::applyMethodWithSideEffectAndReturn, + eq(2), + { x, mocks, instr, r -> + x > 0 && mocks.isEmpty() && instr.isEmpty() && sqrt(x.toDouble()) == x.toDouble() && r!!.a == 2821 + }, + { x, mocks, instr, r -> + x > 0 && mocks.isEmpty() && instr.isEmpty() && sqrt(x.toDouble()) != x.toDouble() && r!!.a == 10 + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCreateWithOriginalConstructor() { + checkMocksAndInstrumentation( + ClassWithComplicatedMethods::createWithOriginalConstructor, + eq(1), + { a, b, mocks, instr, r -> a > 10 && b > 10 && r!!.a == a + b && mocks.isEmpty() && instr.isEmpty() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCreateWithSubstitutedConstructor() { + withoutConcrete { // TODO: concrete execution can't handle this + checkMocksAndInstrumentation( + ClassWithComplicatedMethods::createWithSubstitutedConstructor, + eq(1), + { a, b, mocks, instr, r -> a < 0 && b < 0 && r!!.a == (a + b).toInt() && mocks.isEmpty() && instr.isEmpty() }, + coverage = DoNotCalculate + ) + } + } + + @Test + fun testSqrt2() { + 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 + checkMocksAndInstrumentation( + ClassWithComplicatedMethods::returnSubstitutedMethod, + eq(1), + { x, mocks, instr, r -> x > 100 && mocks.isEmpty() && instr.isEmpty() && r != null && r.a == x }, + coverage = DoNotCalculate + ) + } + } + + @Test + fun testAssumesWithMocks() { + checkMocksAndInstrumentation( + ClassWithComplicatedMethods::assumesWithMocks, + eq(1), + { x, mocks, instr, r -> x in 6..7 && r == 1 && mocks.isEmpty() && instr.isEmpty() }, + coverage = DoNotCalculate, + mockStrategy = MockStrategyApi.OTHER_CLASSES + ) + } + + private val eps = 1e-8 +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/math/BitOperatorsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/math/BitOperatorsTest.kt new file mode 100644 index 0000000000..a54b0146dc --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/math/BitOperatorsTest.kt @@ -0,0 +1,175 @@ +package org.utbot.examples.math + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class BitOperatorsTest : UtValueTestCaseChecker(testClass = BitOperators::class) { + @Test + fun testComplement() { + check( + BitOperators::complement, + eq(2), + { x, r -> x == -2 && r == true }, + { x, r -> x != -2 && r == false } + ) + } + + @Test + fun testXor() { + check( + BitOperators::xor, + eq(2), + { x, y, r -> x == y && r == true }, + { x, y, r -> x != y && r == false } + ) + } + + @Test + fun testOr() { + check( + BitOperators::or, + eq(2), + { x, r -> x < 16 && (x and 0xfffffff8.toInt()) == 8 && r == true }, + { x, r -> x >= 16 || (x and 0xfffffff8.toInt()) != 8 && r == false } + ) + } + + @Test + @kotlin.ExperimentalStdlibApi + fun testAnd() { + check( + BitOperators::and, + eq(2), + { x, r -> x.countOneBits() <= 1 && r == true }, + { x, r -> x.countOneBits() > 1 && r == false } + ) + } + + @Test + fun testBooleanNot() { + check( + BitOperators::booleanNot, + eq(3), + { a, b, r -> a && b && r == 100 }, + { a, b, r -> a && !b && r == 200 }, + { a, b, r -> !a && !b && r == 200 }, + coverage = atLeast(91) + ) + } + + @Test + fun testBooleanXor() { + check( + BitOperators::booleanXor, + eq(1) + ) + } + + @Test + fun testBooleanOr() { + check( + BitOperators::booleanOr, + eq(1) + ) + } + + @Test + fun testBooleanAnd() { + check( + BitOperators::booleanAnd, + eq(1) + ) + } + + @Test + fun testBooleanXorCompare() { + check( + BitOperators::booleanXorCompare, + eq(2), + { a, b, r -> a != b && r == 1 }, + { a, b, r -> a == b && r == 0 } + ) + } + + @Test + fun testShl() { + check( + BitOperators::shl, + eq(2), + { x, r -> x == 1 && r == true }, + { x, r -> x != 1 && r == false } + ) + } + + @Test + fun testShlLong() { + check( + BitOperators::shlLong, + eq(2), + { x, r -> x == 1L && r == true }, + { x, r -> x != 1L && r == false } + ) + } + + @Test + fun testShlWithBigLongShift() { + check( + BitOperators::shlWithBigLongShift, + eq(3), + { shift, r -> shift < 40 && r == 1 }, + { shift, r -> shift >= 40 && shift and 0b11111 == 4L && r == 2 }, + { shift, r -> shift >= 40 && shift and 0b11111 != 4L && r == 3 }, + ) + } + + @Test + fun testShr() { + check( + BitOperators::shr, + eq(2), + { x, r -> x shr 1 == 1 && r == true }, + { x, r -> x shr 1 != 1 && r == false } + ) + } + + @Test + fun testShrLong() { + check( + BitOperators::shrLong, + eq(2), + { x, r -> x shr 1 == 1L && r == true }, + { x, r -> x shr 1 != 1L && r == false } + ) + } + + @Test + fun testUshr() { + check( + BitOperators::ushr, + eq(2), + { x, r -> x ushr 1 == 1 && r == true }, + { x, r -> x ushr 1 != 1 && r == false } + ) + } + + @Test + fun testUshrLong() { + check( + BitOperators::ushrLong, + eq(2), + { x, r -> x ushr 1 == 1L && r == true }, + { x, r -> x ushr 1 != 1L && r == false } + ) + } + + @Test + fun testSign() { + check( + BitOperators::sign, + eq(3), + { x, r -> x > 0 && r == 1 }, + { x, r -> x == 0 && r == 0 }, + { x, r -> x < 0 && r == -1 } + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/math/DivRemExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/math/DivRemExamplesTest.kt new file mode 100644 index 0000000000..acd9124d5d --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/math/DivRemExamplesTest.kt @@ -0,0 +1,78 @@ +package org.utbot.examples.math + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException + +internal class DivRemExamplesTest : UtValueTestCaseChecker(testClass = DivRemExamples::class) { + @Test + fun testDiv() { + checkWithException( + DivRemExamples::div, + eq(2), + { _, y, r -> y == 0 && r.isException() }, + { x, y, r -> y != 0 && r.getOrNull() == x / y } + ) + } + + @Test + fun testRem() { + checkWithException( + DivRemExamples::rem, + eq(2), + { _, y, r -> y == 0 && r.isException() }, + { x, y, r -> y != 0 && r.getOrNull() == x % y } + ) + } + + @Test + fun testRemPositiveConditional() { + checkWithException( + DivRemExamples::remPositiveConditional, + eq(3), + { d, r -> d == 0 && r.isException() }, + { d, r -> d != 0 && 11 % d == 2 && r.getOrNull() == true }, + { d, r -> d != 0 && 11 % d != 2 && r.getOrNull() == false } + ) + } + + @Test + fun testRemNegativeConditional() { + checkWithException( + DivRemExamples::remNegativeConditional, + eq(3), + { d, r -> d == 0 && r.isException() }, + { d, r -> d != 0 && -11 % d == -2 && r.getOrNull() == true }, + { d, r -> d != 0 && -11 % d != -2 && r.getOrNull() == false } + ) + } + + @Test + fun testRemWithConditions() { + checkWithException( + DivRemExamples::remWithConditions, + eq(4), + { d, r -> d < 0 && r.getOrNull() == false }, + { d, r -> d == 0 && r.isException() }, + { d, r -> d > 0 && -11 % d == -2 && r.getOrNull() == true }, + { d, r -> d > 0 && -11 % d != -2 && r.getOrNull() == false } + ) + } + + @Test + fun testRemDoubles() { + check( + DivRemExamples::remDoubles, + eq(1) + ) + } + + @Test + fun testRemDoubleInt() { + check( + DivRemExamples::remDoubleInt, + eq(1) + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/math/DoubleFunctionsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/math/DoubleFunctionsTest.kt new file mode 100644 index 0000000000..a69f6565f2 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/math/DoubleFunctionsTest.kt @@ -0,0 +1,61 @@ +package org.utbot.examples.math + +import kotlin.math.abs +import kotlin.math.hypot +import org.junit.jupiter.api.Tag +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException + +@Suppress("SimplifyNegatedBinaryExpression") +internal class DoubleFunctionsTest : UtValueTestCaseChecker(testClass = DoubleFunctions::class) { + @Test + @Tag("slow") + fun testHypo() { + check( + DoubleFunctions::hypo, + eq(1), + { a, b, r -> a > 1 && a < 10 && b > 1 && b < 10 && abs(r!! - hypot(a, b)) < 1e-5 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testMax() { + check( + DoubleFunctions::max, + eq(2), + { a, b, r -> a > b && r == a }, + { a, b, r -> !(a > b) && (r == b || r!!.isNaN()) } + ) + } + + @Test + @Tag("slow") + fun testCircleSquare() { + checkWithException( + DoubleFunctions::circleSquare, + eq(5), + { radius, r -> radius < 0 && r.isException() }, + { radius, r -> radius > 10000 && r.isException() }, + { radius, r -> radius.isNaN() && r.isException() }, + { radius, r -> Math.PI * radius * radius <= 777.85 && r.getOrNull() == 0.0 }, + { radius, r -> Math.PI * radius * radius > 777.85 && abs(777.85 - r.getOrNull()!!) >= 1e-5 } + ) + } + + @Test + @Tag("slow") + fun testNumberOfRootsInSquareFunction() { + check( + DoubleFunctions::numberOfRootsInSquareFunction, + eq(3), // sometimes solver substitutes a = nan || b = nan || c = nan || some combination of 0 and inf + { a, b, c, r -> !(b * b - 4 * a * c >= 0) && r == 0 }, + { a, b, c, r -> b * b - 4 * a * c == 0.0 && r == 1 }, + { a, b, c, r -> b * b - 4 * a * c > 0 && r == 2 }, + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt new file mode 100644 index 0000000000..4adc79d13b --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt @@ -0,0 +1,282 @@ +package org.utbot.examples.math + +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.examples.algorithms.Sort +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq +import org.utbot.testcheckers.withSolverTimeoutInMillis +import org.utbot.testcheckers.withTreatingOverflowAsError +import kotlin.math.floor +import kotlin.math.sqrt + +internal class OverflowAsErrorTest : UtValueTestCaseChecker( + testClass = OverflowExamples::class, + testCodeGeneration = true, + // Don't launch tests, because ArithmeticException will be expected, but it is not supposed to be actually thrown. + // ArithmeticException acts as a sign of Overflow. + listOf( + TestLastStage(CodegenLanguage.JAVA, Compilation), + TestLastStage(CodegenLanguage.KOTLIN, Compilation), + ) +) { + @Test + fun testIntOverflow() { + withTreatingOverflowAsError { + checkWithException( + OverflowExamples::intOverflow, + eq(5), + { x, _, r -> x * x * x <= 0 && x > 0 && r.isException() }, // through overflow + { x, _, r -> x * x * x <= 0 && x > 0 && r.isException() }, // through overflow (2nd '*') + { x, _, r -> x * x * x >= 0 && x >= 0 && r.getOrNull() == 0 }, + { x, y, r -> x * x * x > 0 && x > 0 && y == 10 && r.getOrNull() == 1 }, + { x, y, r -> x * x * x > 0 && x > 0 && y != 10 && r.getOrNull() == 0 }, + coverage = AtLeast(90), + ) + } + } + + @Test + fun testByteAddOverflow() { + withTreatingOverflowAsError { + checkWithException( + OverflowExamples::byteAddOverflow, + eq(2), + { _, _, r -> !r.isException() }, + { x, y, r -> + val negOverflow = ((x + y).toByte() >= 0 && x < 0 && y < 0) + val posOverflow = ((x + y).toByte() <= 0 && x > 0 && y > 0) + (negOverflow || posOverflow) && r.isException() + }, // through overflow + ) + } + } + + @Test + fun testByteSubOverflow() { + withTreatingOverflowAsError { + checkWithException( + OverflowExamples::byteSubOverflow, + eq(2), + { _, _, r -> !r.isException() }, + { x, y, r -> + val negOverflow = ((x - y).toByte() >= 0 && x < 0 && y > 0) + val posOverflow = ((x - y).toByte() <= 0 && x > 0 && y < 0) + (negOverflow || posOverflow) && r.isException() + }, // through overflow + ) + } + } + + @Test + fun testByteMulOverflow() { + withTreatingOverflowAsError { + checkWithException( + OverflowExamples::byteMulOverflow, + eq(2), + { _, _, r -> !r.isException() }, + { _, _, r -> r.isException() }, // through overflow + ) + } + } + + @Test + fun testShortAddOverflow() { + withTreatingOverflowAsError { + checkWithException( + OverflowExamples::shortAddOverflow, + eq(2), + { _, _, r -> !r.isException() }, + { x, y, r -> + val negOverflow = ((x + y).toShort() >= 0 && x < 0 && y < 0) + val posOverflow = ((x + y).toShort() <= 0 && x > 0 && y > 0) + (negOverflow || posOverflow) && r.isException() + }, // through overflow + ) + } + } + + @Test + fun testShortSubOverflow() { + withTreatingOverflowAsError { + checkWithException( + OverflowExamples::shortSubOverflow, + eq(2), + { _, _, r -> !r.isException() }, + { x, y, r -> + val negOverflow = ((x - y).toShort() >= 0 && x < 0 && y > 0) + val posOverflow = ((x - y).toShort() <= 0 && x > 0 && y < 0) + (negOverflow || posOverflow) && r.isException() + }, // through overflow + ) + } + } + + @Test + fun testShortMulOverflow() { + withTreatingOverflowAsError { + checkWithException( + OverflowExamples::shortMulOverflow, + eq(2), + { _, _, r -> !r.isException() }, + { _, _, r -> r.isException() }, // through overflow + ) + } + } + + @Test + fun testIntAddOverflow() { + withTreatingOverflowAsError { + checkWithException( + OverflowExamples::intAddOverflow, + eq(2), + { _, _, r -> !r.isException() }, + { x, y, r -> + val negOverflow = ((x + y) >= 0 && x < 0 && y < 0) + val posOverflow = ((x + y) <= 0 && x > 0 && y > 0) + (negOverflow || posOverflow) && r.isException() + }, // through overflow + ) + } + } + + @Test + fun testIntSubOverflow() { + withTreatingOverflowAsError { + checkWithException( + OverflowExamples::intSubOverflow, + eq(2), + { _, _, r -> !r.isException() }, + { x, y, r -> + val negOverflow = ((x - y) >= 0 && x < 0 && y > 0) + val posOverflow = ((x - y) <= 0 && x > 0 && y < 0) + (negOverflow || posOverflow) && r.isException() + }, // through overflow + ) + } + } + + @Test + fun testIntMulOverflow() { + // This test has solver timeout. + // Reason: softConstraints, containing limits for Int values, hang solver. + // With solver timeout softConstraints are dropped and hard constraints are SAT for overflow. + withSolverTimeoutInMillis(timeoutInMillis = 1000) { + withTreatingOverflowAsError { + checkWithException( + OverflowExamples::intMulOverflow, + eq(2), + { _, _, r -> !r.isException() }, + { _, _, r -> r.isException() }, // through overflow + ) + } + } + } + + @Test + fun testLongAddOverflow() { + withTreatingOverflowAsError { + checkWithException( + OverflowExamples::longAddOverflow, + eq(2), + { _, _, r -> !r.isException() }, + { x, y, r -> + val negOverflow = ((x + y) >= 0 && x < 0 && y < 0) + val posOverflow = ((x + y) <= 0 && x > 0 && y > 0) + (negOverflow || posOverflow) && r.isException() + }, // through overflow + ) + } + } + + @Test + fun testLongSubOverflow() { + withTreatingOverflowAsError { + checkWithException( + OverflowExamples::longSubOverflow, + eq(2), + { _, _, r -> !r.isException() }, + { x, y, r -> + val negOverflow = ((x - y) >= 0 && x < 0 && y > 0) + val posOverflow = ((x - y) <= 0 && x > 0 && y < 0) + (negOverflow || posOverflow) && r.isException() + }, // through overflow + ) + } + } + + @Test + @Disabled("Flaky branch count mismatch (1 instead of 2)") + fun testLongMulOverflow() { + // This test has solver timeout. + // Reason: softConstraints, containing limits for Int values, hang solver. + // With solver timeout softConstraints are dropped and hard constraints are SAT for overflow. + withSolverTimeoutInMillis(timeoutInMillis = 2000) { + withTreatingOverflowAsError { + checkWithException( + OverflowExamples::longMulOverflow, + eq(2), + { _, _, r -> !r.isException() }, + { _, _, r -> r.isException() }, // through overflow + ) + } + } + } + + @Test + fun testIncOverflow() { + withTreatingOverflowAsError { + checkWithException( + OverflowExamples::incOverflow, + eq(2), + { _, r -> !r.isException() }, + { _, r -> r.isException() }, // through overflow + ) + } + } + + @Test + fun testIntCubeOverflow() { + val sqrtIntMax = floor(sqrt(Int.MAX_VALUE.toDouble())).toInt() + withTreatingOverflowAsError { + checkWithException( + OverflowExamples::intCubeOverflow, + eq(3), + { _, r -> !r.isException() }, + // Can't use abs(x) below, because abs(Int.MIN_VALUE) == Int.MIN_VALUE. + // (Int.MAX_VALUE shr 16) is the border of square overflow and cube overflow. + // Int.MAX_VALUE.toDouble().pow(1/3.toDouble()) + { x, r -> (x > -sqrtIntMax && x < sqrtIntMax) && r.isException() }, // through overflow + { x, r -> (x <= -sqrtIntMax || x >= sqrtIntMax) && r.isException() }, // through overflow + ) + } + } + +// Generated Kotlin code does not compile, so disabled for now + @Test + @Disabled + fun testQuickSort() { + withTreatingOverflowAsError { + checkWithException( + Sort::quickSort, + ignoreExecutionsNumber, + { _, _, _, r -> !r.isException() }, + { _, _, _, r -> r.isException() }, // through overflow + ) + } + } + + @Test + fun testIntOverflowWithoutError() { + check( + OverflowExamples::intOverflow, + eq(6), + { x, _, r -> x * x * x <= 0 && x <= 0 && r == 0 }, + { x, _, r -> x * x * x > 0 && x <= 0 && r == 0 }, // through overflow + { x, y, r -> x * x * x > 0 && x > 0 && y != 10 && r == 0 }, + { x, y, r -> x * x * x > 0 && x > 0 && y == 10 && r == 1 }, + { x, y, r -> x * x * x <= 0 && x > 0 && y != 20 && r == 0 }, // through overflow + { x, y, r -> x * x * x <= 0 && x > 0 && y == 20 && r == 2 } // through overflow + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/LoggerExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/LoggerExampleTest.kt new file mode 100644 index 0000000000..9655f9119a --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/LoggerExampleTest.kt @@ -0,0 +1,58 @@ +package org.utbot.examples.mixed + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.framework.plugin.api.UtConcreteValue +import org.utbot.framework.plugin.api.UtInstrumentation +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.UtStaticMethodInstrumentation +import org.utbot.framework.plugin.api.isNull +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker + +internal class LoggerExampleTest : UtValueTestCaseChecker( + testClass = LoggerExample::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testExample() { + checkMocksAndInstrumentation( + LoggerExample::example, + eq(2), + { _, instrumentation, _ -> theOnlyStaticMockValue(instrumentation).isNull() }, + { mocks, instrumentation, r -> mocks.size == 3 && instrumentation.size == 1 && r == 15 }, + additionalDependencies = arrayOf(org.slf4j.Logger::class.java), + coverage = DoNotCalculate + ) + } + + @Test + fun testLoggerUsage() { + checkMocksAndInstrumentation( + LoggerExample::loggerUsage, + eq(3), + { _, instrumentation, _ -> theOnlyStaticMockValue(instrumentation).isNull() }, + { mocks, instrumentation, r -> + (mocks.single().values.single() as UtConcreteValue<*>).value == false && instrumentation.size == 1 && r == 2 + }, + { mocks, instrumentation, r -> + (mocks.single().values.single() as UtConcreteValue<*>).value == true && instrumentation.size == 1 && r == 1 + }, + additionalDependencies = arrayOf(org.slf4j.Logger::class.java), + coverage = DoNotCalculate + ) + } + + private fun theOnlyStaticMockValue(instrumentation: List): UtModel = + instrumentation + .filterIsInstance() + .single() + .values + .single() +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/MonitorUsageTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/MonitorUsageTest.kt new file mode 100644 index 0000000000..09974c3c22 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/MonitorUsageTest.kt @@ -0,0 +1,19 @@ +package org.utbot.examples.mixed + +import org.junit.jupiter.api.Test +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast +import org.utbot.testing.ignoreExecutionsNumber + +internal class MonitorUsageTest : UtValueTestCaseChecker(testClass = MonitorUsage::class) { + @Test + fun testSimpleMonitor() { + check( + MonitorUsage::simpleMonitor, + ignoreExecutionsNumber, + { x, r -> x <= 0 && r == 0 }, + { x, r -> x > 0 && x <= Int.MAX_VALUE - 1 && r == 1 }, + coverage = atLeast(81) // differs from JaCoCo + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/OverloadTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/OverloadTest.kt new file mode 100644 index 0000000000..b6012d8d8b --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/OverloadTest.kt @@ -0,0 +1,29 @@ +package org.utbot.examples.mixed + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker + +internal class OverloadTest : UtValueTestCaseChecker(testClass = Overload::class) { + @Test + fun testSignOneParam() { + check( + Overload::sign, + eq(3), + { x, r -> x < 0 && r == -1 }, + { x, r -> x == 0 && r == 0 }, + { x, r -> x > 0 && r == 1 } + ) + } + + @Test + fun testSignTwoParams() { + check( + Overload::sign, + eq(3), + { x, y, r -> x + y < 0 && r == -1 }, + { x, y, r -> x + y == 0 && r == 0 }, + { x, y, r -> x + y > 0 && r == 1 } + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt new file mode 100644 index 0000000000..9e6f07c623 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt @@ -0,0 +1,39 @@ +package org.utbot.examples.mixed + +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq + +// TODO parameterized tests disabled due to https://github.com/UnitTestBot/UTBotJava/issues/1266 +internal class PrivateConstructorExampleTest : UtValueTestCaseChecker( + testClass = PrivateConstructorExample::class, + pipelines = listOf( + TestLastStage( + CodegenLanguage.JAVA, + parameterizedModeLastStage = Compilation + ), + TestLastStage( + CodegenLanguage.KOTLIN, + parameterizedModeLastStage = Compilation + ) + ) +) { + + /** + * Two branches need to be covered: + * 1. argument must be <= a - b, + * 2. argument must be > a - b + * + * a and b are fields of the class under test + */ + @Test + fun testLimitedSub() { + checkWithThis( + PrivateConstructorExample::limitedSub, + eq(2), + { caller, limit, r -> caller.a - caller.b >= limit && r == caller.a - caller.b }, + { caller, limit, r -> caller.a - caller.b < limit && r == limit }, + coverage = DoNotCalculate // TODO: Method coverage with `this` parameter isn't supported + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/SimpleNoConditionTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/SimpleNoConditionTest.kt new file mode 100644 index 0000000000..8bddaa3e66 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/SimpleNoConditionTest.kt @@ -0,0 +1,32 @@ +package org.utbot.examples.mixed + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker + +internal class SimpleNoConditionTest : UtValueTestCaseChecker(testClass = SimpleNoCondition::class) { + + @Test + fun testNoConditionAdd() { + check( + SimpleNoCondition::basicAdd, + eq(1) + ) + } + + @Test + fun testNoConditionPow() { + check( + SimpleNoCondition::basicXorInt, + eq(1) + ) + } + + @Test + fun testNoConditionPowBoolean() { + check( + SimpleNoCondition::basicXorBoolean, + eq(1) + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/SimplifierTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/SimplifierTest.kt new file mode 100644 index 0000000000..0092e68eab --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/SimplifierTest.kt @@ -0,0 +1,20 @@ +package org.utbot.examples.mixed + + + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker + +internal class SimplifierTest: UtValueTestCaseChecker(testClass = Simplifier::class) { + @Test + fun testSimplifyAdditionWithZero() { + check( + Simplifier::simplifyAdditionWithZero, + eq(1), + { fst, r -> r != null && r.x == fst.shortValue.toInt() }, + coverage = DoNotCalculate // because of assumes + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/StaticInitializerExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/StaticInitializerExampleTest.kt new file mode 100644 index 0000000000..e5b15f10fa --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/StaticInitializerExampleTest.kt @@ -0,0 +1,31 @@ +package org.utbot.examples.mixed + +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.examples.StaticInitializerExample + +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker + +@Disabled("Unknown build failure") +internal class StaticInitializerExampleTest : UtValueTestCaseChecker(testClass = StaticInitializerExample::class) { + @Test + fun testPositive() { + check( + StaticInitializerExample::positive, + eq(2), + { i, r -> i > 0 && r == true }, + { i, r -> i <= 0 && r == false }, + ) + } + + @Test + fun testNegative() { + check( + StaticInitializerExample::negative, + eq(2), + { i, r -> i < 0 && r == true }, + { i, r -> i >= 0 && r == false }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt new file mode 100644 index 0000000000..40cfd0945d --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt @@ -0,0 +1,42 @@ +package org.utbot.examples.mixed + + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class StaticMethodExamplesTest : UtValueTestCaseChecker(testClass = StaticMethodExamples::class) { + // TODO: inline local variables when types inference bug in Kotlin fixed + @Test + fun testComplement() { + val method = StaticMethodExamples::complement + checkStaticMethod( + method, + eq(2), + { x, r -> x == -2 && r == true }, + { x, r -> x != -2 && r == false } + ) + } + + @Test + fun testMax2() { + val method = StaticMethodExamples::max2 + checkStaticMethod( + method, + eq(2), + { x, y, r -> x > y && r == x }, + { x, y, r -> x <= y && r == y.toInt() } + ) + } + + @Test + fun testSum() { + val method = StaticMethodExamples::sum + checkStaticMethod( + method, + eq(3), + { x, y, z, r -> x + y + z < -20 && r == (x + y + z).toLong() * 2 }, + { x, y, z, r -> x + y + z > 20 && r == (x + y + z).toLong() * 2 }, + { x, y, z, r -> x + y + z in -20..20 && r == (x + y + z).toLong() } + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt new file mode 100644 index 0000000000..5fa176228b --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt @@ -0,0 +1,363 @@ +package org.utbot.examples.mock + + + + + +import org.utbot.examples.mock.provider.Provider +import org.utbot.examples.mock.service.impl.ExampleClass +import org.utbot.examples.mock.service.impl.ServiceWithArguments + + +import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class ArgumentsMockTest : UtValueTestCaseChecker(testClass = ServiceWithArguments::class) { + @Test + fun testMockForArguments_callMultipleMethods() { + checkMocksAndInstrumentation( + ServiceWithArguments::callMultipleMethods, + eq(3), + { provider, _, _, _ -> provider == null }, + { _, mocks, _, r -> + val firstMockConstraint = mocks[0].mocksMethod(Provider::provideInteger) + val secondMockConstraint = mocks[1].mocksMethod(Provider::provideLong) + val valueConstraint = mocks[0].value() < mocks[1].value() + val mockedValues = mocks.all { it.isParameter(1) } + + firstMockConstraint && secondMockConstraint && valueConstraint && mockedValues && r == 1 + }, + { _, mocks, _, r -> + val firstMockConstraint = mocks[0].mocksMethod(Provider::provideInteger) + val secondMockConstraint = mocks[1].mocksMethod(Provider::provideLong) + val valueConstraint = mocks[0].value() >= mocks[1].value() + val mockedValue = mocks.all { it.isParameter(1) } + + firstMockConstraint && secondMockConstraint && valueConstraint && mockedValue && r == 0 + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForArguments_IntArgument() { + checkMocksAndInstrumentation( + ServiceWithArguments::calculateBasedOnIntArgument, + eq(3), + { provider, _, _, _, _ -> provider == null }, + { _, _, mocks, _, r -> + val singleMock = mocks.single() + + val mocksMethod = singleMock.mocksMethod(Provider::provideGiven) + val valueConstraint = singleMock.value(0) < singleMock.value(1) + val paramConstraint = singleMock.isParameter(1) + + mocksMethod && valueConstraint && paramConstraint && r == 1 + }, + { _, _, mocks, _, r -> + val singleMock = mocks.single() + + val mocksMethod = singleMock.mocksMethod(Provider::provideGiven) + val valueConstraint = singleMock.value(0) >= singleMock.value(1) + val paramConstraint = singleMock.isParameter(1) + + mocksMethod && valueConstraint && paramConstraint && r == 0 + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForArguments_BooleanPrimitive() { + checkMocksAndInstrumentation( + ServiceWithArguments::calculateBasedOnBoolean, + eq(3), + { provider, _, _, _ -> provider == null }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideBoolean) && value() && isParameter(1) && r == 1 + } + }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideBoolean) && !value() && isParameter(1) && r == 0 + } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForArguments_inconsistentBoolean() { + checkMocksAndInstrumentation( + ServiceWithArguments::inconsistentBoolean, + eq(4), + { provider, _, _, _ -> provider == null }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideBoolean) && !value() && isParameter(1) && r == 0 + } + }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideBoolean) && value(0) && value(1) && isParameter(1) && r == 0 + } + }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideBoolean) && value(0) && !value(1) && isParameter(1) && r == 1 + } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + + @Test + fun testMockForArguments_CharacterPrimitive() { + checkMocksAndInstrumentation( + ServiceWithArguments::calculateBasedOnCharacter, + eq(3), + { provider, _, _, _ -> provider == null }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideCharacter) && value() > 'a' && isParameter(1) && r == 1 + } + }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideCharacter) && value() <= 'a' && isParameter(1) && r == 0 + } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForArguments_BytePrimitive() { + checkMocksAndInstrumentation( + ServiceWithArguments::calculateBasedOnByte, + eq(3), + { provider, _, _, _ -> provider == null }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideByte) && value() > 5 && isParameter(1) && r == 1 + } + }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideByte) && value() <= 5 && isParameter(1) && r == 0 + } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForArguments_ShortPrimitive() { + checkMocksAndInstrumentation( + ServiceWithArguments::calculateBasedOnShort, + eq(3), + { provider, _, _, _ -> provider == null }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideShort) && value() > 5 && isParameter(1) && r == 1 + } + }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideShort) && value() <= 5 && isParameter(1) && r == 0 + } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForArguments_IntPrimitive() { + checkMocksAndInstrumentation( + ServiceWithArguments::calculateBasedOnInteger, + eq(3), + { provider, _, _, _ -> provider == null }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideInteger) && value() > 5 && isParameter(1) && r == 1 + } + }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideInteger) && value() <= 5 && isParameter(1) && r == 0 + } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForArguments_LongPrimitive() { + checkMocksAndInstrumentation( + ServiceWithArguments::calculateBasedOnLong, + eq(3), + { provider, _, _, _ -> provider == null }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideLong) && value() > 5 && isParameter(1) && r == 1 + } + }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideLong) && value() <= 5 && isParameter(1) && r == 0 + } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Suppress("SimplifyNegatedBinaryExpression") + @Test + fun testMockForArguments_FloatPrimitive() { + checkMocksAndInstrumentation( + ServiceWithArguments::calculateBasedOnFloat, + eq(3), + { provider, _, _, _ -> provider == null }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideFloat) && value() > 1f && isParameter(1) && r == 1 + } + }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideFloat) && !(value() > 1f) && isParameter(1) && r == 0 + } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Suppress("SimplifyNegatedBinaryExpression") + @Test + fun testMockForArguments_DoublePrimitive() { + checkMocksAndInstrumentation( + ServiceWithArguments::calculateBasedOnDouble, + eq(3), + { provider, _, _, _ -> provider == null }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideDouble) && value() > 1.0 && isParameter(1) && r == 1 + } + }, + { _, mocks, _, r -> + mocks.single().run { + mocksMethod(Provider::provideDouble) && !(value() > 1.0) && isParameter(1) && r == 0 + } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForArguments_returnObject() { + checkMocksAndInstrumentation( + ServiceWithArguments::calculateBasedOnObject, + eq(4), + { provider, _, _, _ -> provider == null }, + { _, mocks, _, _ -> + mocks.single().run { + mocksMethod(Provider::provideObject) && value() == null && isParameter(1) + } + }, + { _, mocks, _, r -> + val mockConstraint = mocks.single().run { + mocksMethod(Provider::provideObject) && value().field == 0 && isParameter(1) + } + + mockConstraint && r == 1 + }, + { _, mocks, _, r -> + val mockConstraint = mocks.single().run { + mocksMethod(Provider::provideObject) && value().field != 0 && isParameter(1) + } + + mockConstraint && r == 0 + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForArguments_overloadedMethods() { + checkMocksAndInstrumentation( + ServiceWithArguments::calculateBasedOnOverloadedMethods, + eq(3), + { provider, _, _, _, r -> provider == null && r == null }, + { _, _, mocks, _, r -> + val zeroMockConstraint = mocks[0].run { + val mockFunc: Provider.() -> Int = Provider::provideOverloaded + val overloadedFunc: Provider.(Int) -> Int = Provider::provideOverloaded + mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) && isParameter(1) + } + val firstMockConstraint = mocks[1].run { + val mockFunc: Provider.(Int) -> Int = Provider::provideOverloaded + val overloadedFunc: Provider.() -> Int = Provider::provideOverloaded + mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) && isParameter(1) + } + + zeroMockConstraint && firstMockConstraint && mocks[0].value() < mocks[1].value() && r == 1 + }, + + { _, _, mocks, _, r -> + val zeroMockConstraint = mocks[0].run { + val mockFunc: Provider.() -> Int = Provider::provideOverloaded + val overloadedFunc: Provider.(Int) -> Int = Provider::provideOverloaded + mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) && isParameter(1) + } + val firstMockConstraint = mocks[1].run { + val mockFunc: Provider.(Int) -> Int = Provider::provideOverloaded + val overloadedFunc: Provider.() -> Int = Provider::provideOverloaded + mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) && isParameter(1) + } + + zeroMockConstraint && firstMockConstraint && mocks[0].value() >= mocks[1].value() && r == 0 + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForArguments_objectArguments() { + checkMocksAndInstrumentation( + ServiceWithArguments::calculateBasedOnObjectArgument, + between(3..4), + { provider, _, mocks, _, r -> provider == null && mocks.isEmpty() && r == null }, // NPE + { _, obj, _, _, _ -> obj != null }, + { _, _, mocks, _, r -> + val mockConstraint = mocks.single().run { + mocksMethod(Provider::provideGivenObject) && value() < 1 && isParameter(1) + } + mockConstraint && r == 1 + }, + { _, _, mocks, _, r -> + val mockConstraint = mocks.single().run { + mocksMethod(Provider::provideGivenObject) && value() >= 1 && isParameter(1) + } + mockConstraint && r == 0 + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt new file mode 100644 index 0000000000..5c4a3a24d0 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt @@ -0,0 +1,59 @@ +package org.utbot.examples.mock + + + +import org.utbot.framework.plugin.api.MockStrategyApi +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class CommonMocksExampleTest: UtValueTestCaseChecker(testClass = CommonMocksExample::class) { + @Test + fun testMockInterfaceWithoutImplementors() { + checkMocks( + CommonMocksExample::mockInterfaceWithoutImplementors, + eq(2), + { v, mocks, _ -> v == null && mocks.isEmpty() }, + { _, mocks, _ -> mocks.singleOrNull() != null }, + coverage = DoNotCalculate + ) + } + + // TODO JIRA:1449 + @Test + fun testDoNotMockEquals() { + checkMocks( + CommonMocksExample::doNotMockEquals, + eq(2), + { fst, _, mocks, _ -> fst == null && mocks.isEmpty() }, + { _, _, mocks, _ -> mocks.isEmpty() }, // should be changed to not null fst when 1449 will be finished + mockStrategy = MockStrategyApi.OTHER_PACKAGES, + coverage = DoNotCalculate + ) + } + + // TODO JIRA:1449 + @Test + fun testNextValue() { + checkMocks( + CommonMocksExample::nextValue, + eq(4), + // node == null -> NPE + // node.next == null -> NPE + // node == node.next + // node.next.value == node.value + 1 + mockStrategy = MockStrategyApi.OTHER_CLASSES, + coverage = DoNotCalculate + ) + } + + @Test + fun testClinitMockExample() { + check( + CommonMocksExample::clinitMockExample, + eq(1), + { r -> r == -420 }, + mockStrategy = MockStrategyApi.OTHER_CLASSES, + coverage = DoNotCalculate + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt new file mode 100644 index 0000000000..14a4c754d7 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt @@ -0,0 +1,290 @@ +package org.utbot.examples.mock + +import org.utbot.examples.mock.provider.Provider +import org.utbot.examples.mock.service.impl.ExampleClass +import org.utbot.examples.mock.service.impl.ServiceWithField +import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq + +internal class FieldMockTest : UtValueTestCaseChecker( + testClass = ServiceWithField::class, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA, lastStage = TestExecution, parameterizedModeLastStage = Compilation), + TestLastStage(CodegenLanguage.KOTLIN, lastStage = TestExecution) + ) +) { + @Test + fun testMockForField_callMultipleMethods() { + checkMocksAndInstrumentation( + ServiceWithField::callMultipleMethods, + eq(3), + { _, _, r -> r == null }, + { mocks, _, r -> + val zeroMock = mocks[0].mocksMethod(Provider::provideInteger) + val firstMock = mocks[1].mocksMethod(Provider::provideLong) + val valueConstraint = mocks[0].value() < mocks[1].value() + + zeroMock && firstMock && valueConstraint && r == 1 + }, + { mocks, _, r -> + val zeroMock = mocks[0].mocksMethod(Provider::provideInteger) + val firstMock = mocks[1].mocksMethod(Provider::provideLong) + val valueConstraint = mocks[0].value() >= mocks[1].value() + + zeroMock && firstMock && valueConstraint && r == 0 + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForField_IntArgument() { + checkMocksAndInstrumentation( + ServiceWithField::calculateBasedOnIntArgument, + eq(3), + { _, _, _, r -> r == null }, + { _, mocks, _, _ -> + mocks.single().run { + mocksMethod(Provider::provideGiven) && value(0) < value(1) + } + }, + { _, mocks, _, _ -> + mocks.single().run { + mocksMethod(Provider::provideGiven) && value(0) >= value(1) + } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForField_BooleanPrimitive() { + checkMocksAndInstrumentation( + ServiceWithField::calculateBasedOnBoolean, + eq(3), + { _, _, r -> r == null }, + { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideBoolean) && value() } }, + { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideBoolean) && !value() } }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForField_inconsistentBoolean() { + checkMocksAndInstrumentation( + ServiceWithField::inconsistentBoolean, + eq(4), + { _, _, r -> r == null }, + { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideBoolean) && !value() } }, + { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideBoolean) && value(0) && value(1) } }, + { mocks, _, _ -> + mocks.single().run { mocksMethod(Provider::provideBoolean) && value(0) && !value(1) } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + + @Test + fun testMockForField_CharacterPrimitive() { + checkMocksAndInstrumentation( + ServiceWithField::calculateBasedOnCharacter, + eq(3), + { _, _, r -> r == null }, + { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideCharacter) && value() > 'a' } }, + { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideCharacter) && value() <= 'a' } }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForField_BytePrimitive() { + checkMocksAndInstrumentation( + ServiceWithField::calculateBasedOnByte, + eq(3), + { _, _, r -> r == null }, + { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideByte) && value() > 5 } }, + { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideByte) && value() <= 5 } }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForField_ShortPrimitive() { + checkMocksAndInstrumentation( + ServiceWithField::calculateBasedOnShort, + eq(3), + { _, _, r -> r == null }, + { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideShort) && value() > 5 } }, + { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideShort) && value() <= 5 } }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForField_IntPrimitive() { + checkMocksAndInstrumentation( + ServiceWithField::calculateBasedOnInteger, + eq(3), + { _, _, r -> r == null }, + { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideInteger) && value() > 5 } }, + { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideInteger) && value() <= 5 } }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForField_LongPrimitive() { + checkMocksAndInstrumentation( + ServiceWithField::calculateBasedOnLong, + eq(3), + { _, _, r -> r == null }, + { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideLong) && value() > 5 } }, + { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideLong) && value() <= 5 } }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForField_FloatPrimitive() { + checkMocksAndInstrumentation( + ServiceWithField::calculateBasedOnFloat, + eq(3), + { _, _, r -> r == null }, + { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideFloat) && value() > 1f } }, + { mocks, _, _ -> + mocks.single().run { + mocksMethod(Provider::provideFloat) && value().isNaN() || value() <= 1f + } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForField_DoublePrimitive() { + checkMocksAndInstrumentation( + ServiceWithField::calculateBasedOnDouble, + eq(3), + { _, _, r -> r == null }, + { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideDouble) && value() > 1.0 } }, + { mocks, _, _ -> + mocks.single().run { + mocksMethod(Provider::provideDouble) && value().isNaN() || value() <= 1.0 + } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForField_returnObject() { + checkMocksAndInstrumentation( + ServiceWithField::calculateBasedOnObject, + eq(4), + { _, _, r -> r == null }, + { mocks, _, _ -> + mocks.single().run { + mocksMethod(Provider::provideObject) && value() == null + } + }, + { mocks, _, result -> + val mockConstraint = mocks.single().run { + mocksMethod(Provider::provideObject) && value().field == 0 + } + + mockConstraint && result == 1 + }, + { mocks, _, result -> + val mockConstraint = mocks.single().run { + mocksMethod(Provider::provideObject) && + value().field != 0 + } + + mockConstraint && result == 0 + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForField_overloadedMethods() { + checkMocksAndInstrumentation( + ServiceWithField::calculateBasedOnOverloadedMethods, + eq(3), + { _, _, _, r -> r == null }, + { _, mocks, _, result -> + val zeroMockConstraint = mocks[0].run { + val mockFunc: Provider.() -> Int = Provider::provideOverloaded + val overloadedFunc: Provider.(Int) -> Int = Provider::provideOverloaded + mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) + } + val firstMockConstraint = mocks[1].run { + val mockFunc: Provider.(Int) -> Int = Provider::provideOverloaded + val overloadedFunc: Provider.() -> Int = Provider::provideOverloaded + mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) + } + val valueConstraint = mocks[0].value() < mocks[1].value() + + zeroMockConstraint && firstMockConstraint && valueConstraint && result == 1 + }, + { _, mocks, _, result -> + val zeroMockConstraint = mocks[0].run { + val mockFunc: Provider.() -> Int = Provider::provideOverloaded + val overloadedFunc: Provider.(Int) -> Int = Provider::provideOverloaded + mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) + } + val firstMockConstraint = mocks[1].run { + val mockFunc: Provider.(Int) -> Int = Provider::provideOverloaded + val overloadedFunc: Provider.() -> Int = Provider::provideOverloaded + mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) + } + val valueConstraint = mocks[0].value() >= mocks[1].value() + + zeroMockConstraint && firstMockConstraint && valueConstraint && result == 0 + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForField_objectArguments() { + checkMocksAndInstrumentation( + ServiceWithField::calculateBasedOnObjectArgument, + between(3..4), + { _, _, _, r -> r == null }, + { obj, _, _, _ -> obj == null }, + { obj, _, _, _ -> obj != null }, + { _, mocks, _, r -> + val mockConstraint = mocks.single().run { + mocksMethod(Provider::provideGivenObject) && value() < 1 + } + mockConstraint && r == 1 + }, + { _, mocks, _, r -> + val mockConstraint = mocks.single().run { + mocksMethod(Provider::provideGivenObject) && value() >= 1 + } + + mockConstraint && r == 0 + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/InnerMockWithFieldChecker.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/InnerMockWithFieldChecker.kt new file mode 100644 index 0000000000..30a746e0c1 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/InnerMockWithFieldChecker.kt @@ -0,0 +1,52 @@ +package org.utbot.examples.mock + +import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.isMockModel +import org.utbot.framework.plugin.api.isNotNull +import org.utbot.framework.plugin.api.isNull +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtModelTestCaseChecker +import org.utbot.testing.getOrThrow +import org.utbot.testing.primitiveValue + +internal class InnerMockWithFieldChecker : UtModelTestCaseChecker(testClass = InnerMockWithFieldExample::class) { + @Test + fun testCheckAndUpdate() { + checkStatic( + InnerMockWithFieldExample::checkAndUpdate, + eq(4), + { example, r -> example.isNull() && r.isException() }, + { example, r -> example.isNotNull() && example.stamp.isNull() && r.isException() }, + { example, r -> + val result = r.getOrThrow() + val isMockModels = example.stamp.isMockModel() && result.isMockModel() + val stampConstraint = example.stamp.initial > example.stamp.version + val postcondition = result.initial == example.stamp.initial && result.version == result.initial + + isMockModels && stampConstraint && postcondition + }, + { example, r -> + val result = r.getOrThrow() + val stamp = example.stamp + + val isMockModels = stamp.isMockModel() && result.isMockModel() + val stampConstraint = stamp.initial <= stamp.version + val postcondition = result.initial == stamp.initial && result.version == stamp.version + 1 + + isMockModels && stampConstraint && postcondition + }, + mockStrategy = OTHER_PACKAGES + ) + } + + private val UtModel.stamp: UtModel + get() = findField("stamp") + + private val UtModel.initial: Int + get() = findField("initial").primitiveValue() + + private val UtModel.version: Int + get() = findField("version").primitiveValue() +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockFinalClassTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockFinalClassTest.kt new file mode 100644 index 0000000000..72165ec696 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockFinalClassTest.kt @@ -0,0 +1,34 @@ +package org.utbot.examples.mock + +import org.utbot.examples.mock.others.FinalClass +import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_CLASSES +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.ge +import org.utbot.testing.* + +internal class MockFinalClassTest : UtValueTestCaseChecker( + testClass = MockFinalClassExample::class, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA, lastStage = TestExecution, parameterizedModeLastStage = Compilation), + TestLastStage(CodegenLanguage.KOTLIN, lastStage = TestExecution) + ) +) { + @Test + fun testFinalClass() { + checkMocks( + MockFinalClassExample::useFinalClass, + ge(2), + { mocks, r -> + val intProvider = mocks.singleMock("intProvider", FinalClass::provideInt) + intProvider.value(0) == 1 && r == 1 + }, + { mocks, r -> + val intProvider = mocks.singleMock("intProvider", FinalClass::provideInt) + intProvider.value(0) != 1 && r == 2 + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_CLASSES + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt new file mode 100644 index 0000000000..7b5662bd82 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt @@ -0,0 +1,146 @@ +package org.utbot.examples.mock + +import org.utbot.framework.plugin.api.UtCompositeModel +import org.utbot.framework.plugin.api.UtNewInstanceInstrumentation +import java.util.Random +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq + +// TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 +internal class MockRandomTest : UtValueTestCaseChecker( + testClass = MockRandomExamples::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA, lastStage = TestExecution, parameterizedModeLastStage = Compilation), + TestLastStage(CodegenLanguage.KOTLIN, lastStage = CodeGeneration) + ) +) { + @Test + fun testRandomAsParameter() { + val method: Random.() -> Int = Random::nextInt + checkMocks( + MockRandomExamples::randomAsParameter, + eq(3), + { random, _, _, r -> random == null && r == null }, // NPE + { random, threshold, mocks, r -> + val mock = mocks.single() + assert(mock.isParameter(1) && mock.mocksMethod(method)) + val nextInt = mock.value() + + random == null && nextInt > threshold && r == threshold + 1 + }, + { random, threshold, mocks, r -> + val mock = mocks.single() + assert(mock.isParameter(1) && mock.mocksMethod(method)) + val nextInt = mock.value() + + random == null && nextInt <= threshold && r == nextInt + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testRandomAsField() { + val method: Random.() -> Int = Random::nextInt + checkMocks( + MockRandomExamples::randomAsField, + eq(3), + { _, _, r -> r == null }, // NPE + { threshold, mocks, r -> + val mock = mocks.singleMock("random", method) + val nextInt = mock.value() + + nextInt > threshold && r == threshold + 1 + }, + { threshold, mocks, r -> + val mock = mocks.singleMock("random", method) + val nextInt = mock.value() + + nextInt <= threshold && r == nextInt + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testRandomAsLocalVariable() { + checkMocksAndInstrumentation( + MockRandomExamples::randomAsLocalVariable, + eq(2), + { _, instrumentation, r -> + val mockInstances = instrumentation + .filterIsInstance() + .single { it.classId.name == "java.util.Random" } + .instances + //TODO: support any UtModel here after SAT-1135 is completed + .filterIsInstance() + + assert(mockInstances.size == 2) + + val firstMockValues = mockInstances[0].mockValues("nextInt") + val secondMockValues = mockInstances[1].mockValues("nextInt") + + val sizes = firstMockValues.size == 2 && secondMockValues.size == 2 + val valueConstraint = firstMockValues[0] + firstMockValues[1] + secondMockValues[0] > 1000 + val resultConstraint = r == secondMockValues[1] + + sizes && valueConstraint && resultConstraint + }, + { _, instrumentation, r -> + val mockInstances = instrumentation + .filterIsInstance() + .single { it.classId.name == "java.util.Random" } + .instances + .filterIsInstance() + + assert(mockInstances.size == 3) + + val firstMockValues = mockInstances[0].mockValues("nextInt") + val secondMockValues = mockInstances[1].mockValues("nextInt") + val thirdMockValues = mockInstances[2].mockValues("nextInt") + + val sizes = firstMockValues.size == 2 && secondMockValues.size == 1 && thirdMockValues.size == 1 + val valueConstraint = firstMockValues[0] + firstMockValues[1] + secondMockValues[0] <= 1000 + val resultConstraint = r == thirdMockValues[0] + + sizes && valueConstraint && resultConstraint + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testUseSecureRandom() { + checkMocksAndInstrumentation( + MockRandomExamples::useSecureRandom, + eq(2), + { _, instrumentation, r -> + val mock = instrumentation + .filterIsInstance() + .single { it.classId.name == "java.security.SecureRandom" } + .instances + .filterIsInstance() + .single() + + val values = mock.mockValues("nextInt") + + values.size == 1 && values[0] > 1000 && r == 1 + }, + { _, instrumentation, r -> + val mock = instrumentation + .filterIsInstance() + .single { it.classId.name == "java.security.SecureRandom" } + .instances + .filterIsInstance() + .single() + + val values = mock.mockValues("nextInt") + + values.size == 2 && values[0] <= 1000 && r == values[1] + }, + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockReturnObjectExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockReturnObjectExampleTest.kt new file mode 100644 index 0000000000..3120626749 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockReturnObjectExampleTest.kt @@ -0,0 +1,69 @@ +package org.utbot.examples.mock + +import org.junit.jupiter.api.Disabled +import org.utbot.examples.mock.others.Generator +import org.utbot.examples.mock.others.Locator +import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.* + +internal class MockReturnObjectExampleTest : UtValueTestCaseChecker(testClass = MockReturnObjectExample::class) { + @Test + @Disabled("Java 11 transition") + fun testMockReturnObject() { + checkMocks( + MockReturnObjectExample::calculate, + eq(6), // 4 NPE + // NPE, privateLocator is null + { _, mocks, r -> + val privateLocator = mocks.singleMockOrNull("privateLocator", Locator::locate) + privateLocator == null && r == null + }, + // NPE, privateLocator.locate() returns null + { _, mocks, r -> + val generator = mocks.singleMock("privateLocator", Locator::locate).value() + generator == null && r == null + }, + // NPE, publicLocator is null + { _, mocks, r -> + val publicLocator = mocks.singleMockOrNull("publicLocator", Locator::locate) + publicLocator == null && r == null + }, + // NPE, publicLocator.locate() returns null + { _, mocks, r -> + val generator = mocks.singleMock("publicLocator", Locator::locate).value() + generator == null && r == null + }, + { threshold, mocks, r -> + val mockId1 = mocks.singleMock("privateLocator", Locator::locate).mockValue().id + val mockId2 = mocks.singleMock("publicLocator", Locator::locate).mockValue().id + + val mock1 = mocks.singleMock(mockId1, Generator::generateInt) + val mock2 = mocks.singleMock(mockId2, Generator::generateInt) + + val (index1, index2) = if (mock1.values.size > 1) 0 to 1 else 0 to 0 + val value1 = mock1.value(index1) + val value2 = mock2.value(index2) + + + threshold < value1 + value2 && r == threshold + }, + { threshold, mocks, r -> + val mockId1 = mocks.singleMock("privateLocator", Locator::locate).mockValue().id + val mockId2 = mocks.singleMock("publicLocator", Locator::locate).mockValue().id + + val mock1 = mocks.singleMock(mockId1, Generator::generateInt) + val mock2 = mocks.singleMock(mockId2, Generator::generateInt) + + val (index1, index2) = if (mock1.values.size > 1) 0 to 1 else 0 to 0 + val value1 = mock1.value(index1) + val value2 = mock2.value(index2) + + threshold >= value1 + value2 && r == value1 + value2 + 1 + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockStaticFieldExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockStaticFieldExampleTest.kt new file mode 100644 index 0000000000..2c1188af36 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockStaticFieldExampleTest.kt @@ -0,0 +1,71 @@ +package org.utbot.examples.mock + +import org.utbot.examples.mock.others.Generator +import org.utbot.framework.plugin.api.FieldMockTarget +import org.utbot.framework.plugin.api.MockInfo +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.testing.* + +internal class MockStaticFieldExampleTest : UtValueTestCaseChecker(testClass = MockStaticFieldExample::class) { + + @Test + fun testMockStaticField() { + withoutConcrete { // TODO JIRA:1420 + checkMocks( + MockStaticFieldExample::calculate, + eq(4), // 2 NPE + // NPE, privateGenerator is null + { _, mocks, r -> + val privateGenerator = mocks.singleMockOrNull("privateGenerator", Generator::generateInt) + privateGenerator == null && r == null + }, + // NPE, publicGenerator is null + { _, mocks, r -> + val publicGenerator = mocks.singleMockOrNull("publicGenerator", Generator::generateInt) + publicGenerator == null && r == null + }, + { threshold, mocks, r -> + val mock1 = mocks.singleMock("privateGenerator", Generator::generateInt) + val mock2 = mocks.singleMock("publicGenerator", Generator::generateInt) + + val (index1, index2) = if (mock1.values.size > 1) 0 to 1 else 0 to 0 + + val value1 = mock1.value(index1) + val value2 = mock2.value(index2) + + val firstMockConstraint = mock1.mocksStaticField(MockStaticFieldExample::class) + val secondMockConstraint = mock2.mocksStaticField(MockStaticFieldExample::class) + val resultConstraint = threshold < value1 + value2 && r == threshold + + firstMockConstraint && secondMockConstraint && resultConstraint + }, + { threshold, mocks, r -> + val mock1 = mocks.singleMock("privateGenerator", Generator::generateInt) + val mock2 = mocks.singleMock("publicGenerator", Generator::generateInt) + + val (index1, index2) = if (mock1.values.size > 1) 0 to 1 else 0 to 0 + + val value1 = mock1.value(index1) + val value2 = mock2.value(index2) + + val firstMockConstraint = mock1.mocksStaticField(MockStaticFieldExample::class) + val secondMockConstraint = mock2.mocksStaticField(MockStaticFieldExample::class) + val resultConstraint = threshold >= value1 + value2 && r == value1 + value2 + 1 + + firstMockConstraint && secondMockConstraint && resultConstraint + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + } + + private fun MockInfo.mocksStaticField(kClass: KClass<*>) = when (val mock = mock) { + is FieldMockTarget -> mock.ownerClassName == kClass.qualifiedName && mock.owner == null + else -> false + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt new file mode 100644 index 0000000000..821435ca21 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt @@ -0,0 +1,46 @@ +package org.utbot.examples.mock + +import org.utbot.framework.plugin.api.MockStrategyApi +import org.utbot.framework.plugin.api.UtPrimitiveModel +import org.utbot.framework.util.singleModel +import org.utbot.framework.util.singleStaticMethod +import org.utbot.framework.util.singleValue +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq + +// TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 +internal class MockStaticMethodExampleTest : UtValueTestCaseChecker( + testClass = MockStaticMethodExample::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA, lastStage = TestExecution, parameterizedModeLastStage = Compilation), + TestLastStage(CodegenLanguage.KOTLIN, lastStage = CodeGeneration) + ) +) { + @Test + fun testUseStaticMethod() { + checkMocksAndInstrumentation( + MockStaticMethodExample::useStaticMethod, + eq(2), + { _, instrumentation, r -> + val mockValue = instrumentation + .singleStaticMethod("nextRandomInt") + .singleModel() + .singleValue() as Int + + mockValue > 50 && r == 100 + }, + { _, instrumentation, r -> + val mockValue = instrumentation + .singleStaticMethod("nextRandomInt") + .singleModel() + .singleValue() as Int + + mockValue <= 50 && r == 0 + }, + coverage = DoNotCalculate, + mockStrategy = MockStrategyApi.OTHER_PACKAGES + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockWithFieldChecker.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockWithFieldChecker.kt new file mode 100644 index 0000000000..397981d54e --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockWithFieldChecker.kt @@ -0,0 +1,47 @@ +package org.utbot.examples.mock + +import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.isMockModel +import org.utbot.framework.plugin.api.isNull +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtModelTestCaseChecker +import org.utbot.testing.getOrThrow +import org.utbot.testing.primitiveValue + +internal class MockWithFieldChecker : UtModelTestCaseChecker(testClass = MockWithFieldExample::class) { + @Test + fun testCheckAndUpdate() { + check( + MockWithFieldExample::checkAndUpdate, + eq(3), + { stamp, r -> stamp.isNull() && r.isException() }, + { stamp, r -> + val result = r.getOrThrow() + + val mockModels = stamp.isMockModel() && result.isMockModel() + val stampValues = stamp.initial > stamp.version + val resultConstraint = result.initial == stamp.initial && result.version == result.initial + + mockModels && stampValues && resultConstraint + }, + { stamp, r -> + val result = r.getOrThrow() + + val mockModels = stamp.isMockModel() && result.isMockModel() + val stampValues = stamp.initial <= stamp.version + val resultConstraint = result.initial == stamp.initial && result.version == stamp.version + 1 + + mockModels && stampValues && resultConstraint + }, + mockStrategy = OTHER_PACKAGES + ) + } + + private val UtModel.initial: Int + get() = findField("initial").primitiveValue() + + private val UtModel.version: Int + get() = findField("version").primitiveValue() +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockWithSideEffectExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockWithSideEffectExampleTest.kt new file mode 100644 index 0000000000..1fba9e414b --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockWithSideEffectExampleTest.kt @@ -0,0 +1,66 @@ +package org.utbot.examples.mock + +import org.utbot.framework.plugin.api.MockStrategyApi +import org.junit.Test +import org.utbot.testcheckers.eq + +internal class MockWithSideEffectExampleTest : UtValueTestCaseChecker(testClass = MockWithSideEffectExample::class) { + @Test + fun testSideEffect() { + checkWithException( + MockWithSideEffectExample::checkSideEffect, + eq(3), + { _, r -> r.isException() }, + { _, r -> r.getOrNull() == false }, + { _, r -> r.getOrNull() == true }, + coverage = DoNotCalculate, + mockStrategy = MockStrategyApi.OTHER_PACKAGES + ) + } + + @Test + fun testSideEffectWithoutMocks() { + checkWithException( + MockWithSideEffectExample::checkSideEffect, + eq(2), + { _, r -> r.isException() }, + { _, r -> r.getOrNull() == true }, + coverage = DoNotCalculate, + mockStrategy = MockStrategyApi.NO_MOCKS + ) + } + + @Test + fun testSideEffectElimination() { + checkWithException( + MockWithSideEffectExample::checkSideEffectElimination, + eq(1), + { _, r -> r.getOrNull() == true }, + coverage = DoNotCalculate, + mockStrategy = MockStrategyApi.OTHER_PACKAGES + ) + } + + @Test + fun testStaticMethodSideEffectElimination() { + checkWithException( + MockWithSideEffectExample::checkStaticMethodSideEffectElimination, + eq(1), + { _, r -> r.getOrNull() == true }, + coverage = DoNotCalculate, + mockStrategy = MockStrategyApi.OTHER_PACKAGES + ) + } + + @Test + fun testStaticMethodSideEffectEliminationWithoutMocks() { + checkWithException( + MockWithSideEffectExample::checkStaticMethodSideEffectElimination, + eq(1), + { _, r -> r.getOrNull() == false }, + coverage = DoNotCalculate, + mockStrategy = MockStrategyApi.NO_MOCKS + ) + } + +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt new file mode 100644 index 0000000000..9246daad57 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt @@ -0,0 +1,277 @@ +package org.utbot.examples.mock + +import org.utbot.examples.mock.provider.Provider +import org.utbot.examples.mock.service.impl.ExampleClass +import org.utbot.examples.mock.service.impl.ServiceWithStaticField + + +import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class StaticFieldMockTest : UtValueTestCaseChecker(testClass = ServiceWithStaticField::class) { + + @Test + fun testMockForStaticField_callMultipleMethods() { + checkMocks( + ServiceWithStaticField::callMultipleMethods, + eq(3), + { _, r -> r == null }, + { mocks, _ -> + val firstMockConstraint = mocks[0].mocksMethod(Provider::provideInteger) + val secondMockConstraint = mocks[1].mocksMethod(Provider::provideLong) + val resultConstraint = mocks[0].value() < mocks[1].value() + + firstMockConstraint && secondMockConstraint && resultConstraint + }, + { mocks, _ -> + val firstMockConstraint = mocks[0].mocksMethod(Provider::provideInteger) + val secondMockConstraint = mocks[1].mocksMethod(Provider::provideLong) + val resultConstraint = mocks[0].value() >= mocks[1].value() + + firstMockConstraint && secondMockConstraint && resultConstraint + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForStaticField_IntArgument() { + checkMocks( + ServiceWithStaticField::calculateBasedOnIntArgument, + eq(3), + { _, _, r -> r == null }, + { _, mocks, _ -> + mocks.single().run { + mocksMethod(Provider::provideGiven) && value(0) < value(1) + } + }, + { _, mocks, _ -> + mocks.single().run { + mocksMethod(Provider::provideGiven) && value(0) >= value(1) + } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForStaticField_BooleanPrimitive() { + checkMocks( + ServiceWithStaticField::calculateBasedOnBoolean, + eq(3), + { _, r -> r == null }, + { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideBoolean) && value() } }, + { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideBoolean) && !value() } }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForStaticField_inconsistentBoolean() { + checkMocks( + ServiceWithStaticField::inconsistentBoolean, + eq(4), + { _, r -> r == null }, + { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideBoolean) && !value() } }, + { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideBoolean) && value(0) && value(1) } }, + { mocks, _ -> + mocks.single().run { mocksMethod(Provider::provideBoolean) && value(0) && !value(1) } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + + @Test + fun testMockForStaticField_CharacterPrimitive() { + checkMocks( + ServiceWithStaticField::calculateBasedOnCharacter, + eq(3), + { _, r -> r == null }, + { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideCharacter) && value() > 'a' } }, + { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideCharacter) && value() <= 'a' } }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForStaticField_BytePrimitive() { + checkMocks( + ServiceWithStaticField::calculateBasedOnByte, + eq(3), + { _, r -> r == null }, + { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideByte) && value() > 5 } }, + { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideByte) && value() <= 5 } }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForStaticField_ShortPrimitive() { + checkMocks( + ServiceWithStaticField::calculateBasedOnShort, + eq(3), + { _, r -> r == null }, + { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideShort) && value() > 5 } }, + { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideShort) && value() <= 5 } }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForStaticField_IntPrimitive() { + checkMocks( + ServiceWithStaticField::calculateBasedOnInteger, + eq(3), + { _, r -> r == null }, + { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideInteger) && value() > 5 } }, + { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideInteger) && value() <= 5 } }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForStaticField_LongPrimitive() { + checkMocks( + ServiceWithStaticField::calculateBasedOnLong, + eq(3), + { _, r -> r == null }, + { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideLong) && value() > 5 } }, + { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideLong) && value() <= 5 } }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForStaticField_FloatPrimitive() { + checkMocks( + ServiceWithStaticField::calculateBasedOnFloat, + eq(3), + { _, r -> r == null }, + { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideFloat) && value() > 1f } }, + { mocks, _ -> + mocks.single().run { + mocksMethod(Provider::provideFloat) && value().isNaN() || value() <= 1f + } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForStaticField_DoublePrimitive() { + checkMocks( + ServiceWithStaticField::calculateBasedOnDouble, + eq(3), + { _, r -> r == null }, + { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideDouble) && value() > 1.0 } }, + { mocks, _ -> + mocks.single().run { + mocksMethod(Provider::provideDouble) && value().isNaN() || value() <= 1.0 + } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForStaticField_returnObject() { + checkMocks( + ServiceWithStaticField::calculateBasedOnObject, + eq(4), + { _, r -> r == null }, + { mocks, _ -> + mocks.single().run { + mocksMethod(Provider::provideObject) && value() == null + } + }, + { mocks, result -> + val mockConstraint = mocks.single().run { + mocksMethod(Provider::provideObject) && value().field == 0 + } + mockConstraint && result == 1 + }, + { mocks, result -> + val mockConstraint = mocks.single().run { + mocksMethod(Provider::provideObject) && value().field != 0 + } + mockConstraint && result == 0 + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForStaticField_overloadedMethods() { + checkMocks( + ServiceWithStaticField::calculateBasedOnOverloadedMethods, + eq(3), + { _, _, r -> r == null }, + { _, mocks, result -> + val zeroMockConstraint = mocks[0].run { + val mockFunc: Provider.() -> Int = Provider::provideOverloaded + val overloadedFunc: Provider.(Int) -> Int = Provider::provideOverloaded + mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) + } + val firstMockConstraint = mocks[1].run { + val mockFunc: Provider.(Int) -> Int = Provider::provideOverloaded + val overloadedFunc: Provider.() -> Int = Provider::provideOverloaded + mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) + } + val valueConstraint = mocks[0].value() < mocks[1].value() + + zeroMockConstraint && firstMockConstraint && valueConstraint && result == 1 + }, + + { _, mocks, result -> + val zeroMockConstraint = mocks[0].run { + val mockFunc: Provider.() -> Int = Provider::provideOverloaded + val overloadedFunc: Provider.(Int) -> Int = Provider::provideOverloaded + mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) + } + val firstMockConstraint = mocks[1].run { + val mockFunc: Provider.(Int) -> Int = Provider::provideOverloaded + val overloadedFunc: Provider.() -> Int = Provider::provideOverloaded + mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) + } + val valueConstraint = mocks[0].value() >= mocks[1].value() + + zeroMockConstraint && firstMockConstraint && valueConstraint && result == 0 + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } + + @Test + fun testMockForStaticField_objectArguments() { + checkMocks( + ServiceWithStaticField::calculateBasedOnObjectArgument, + eq(4), + { _, _, r -> r == null }, + { obj, _, _ -> obj == null }, + { obj, _, _ -> obj != null }, + { _, mocks, _ -> + mocks.single().run { mocksMethod(Provider::provideGivenObject) && value() < 1 } + }, + { _, mocks, _ -> + mocks.single().run { mocksMethod(Provider::provideGivenObject) && value() >= 1 } + }, + coverage = DoNotCalculate, + mockStrategy = OTHER_PACKAGES + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/UseNetworkTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/UseNetworkTest.kt new file mode 100644 index 0000000000..f481cb78be --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/UseNetworkTest.kt @@ -0,0 +1,57 @@ +package org.utbot.examples.mock + +import org.utbot.framework.plugin.api.MockStrategyApi +import org.utbot.framework.plugin.api.UtConcreteValue +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq + +internal class UseNetworkTest : UtValueTestCaseChecker(testClass = UseNetwork::class) { + @Test + fun testReadBytes() { + val method = UseNetwork::readBytes + checkStaticMethodWithException( + method, + eq(5), + { _, network, r -> network == null && r.isException() }, + { _, _, r -> r.getOrNull() == 0 }, + { pkg, _, r -> pkg == null && r.isException() }, + { pkg, _, r -> pkg.isEmpty() && r.isException() }, + { pkg, _, r -> pkg.isNotEmpty() && (r.isException() || r.getOrNull()!! > 0) }, + mockStrategy = MockStrategyApi.OTHER_PACKAGES, + coverage = DoNotCalculate + ) + } + + @Test + fun testReadBytesWithMocks() { + val method = UseNetwork::readBytes + checkMocksInStaticMethod( + method, + eq(5), + { packet, _, _, _ -> packet == null }, + { _, network, _, _ -> network == null }, + { _, _, mocks, r -> (mocks.single().values.single() as UtConcreteValue<*>).value == -1 && r == 0 }, + { packet, _, mocks, _ -> + require(packet != null) + + val mockConstraint = (mocks.single().values.single() as UtConcreteValue<*>).value != -1 + val sizeConstraint = packet.isEmpty() + + mockConstraint && sizeConstraint + }, + { packet, _, mocks, r -> + require(packet != null) + + val values = mocks.single().values.map { (it as UtConcreteValue<*>).value } + val mockConstraint = values.dropLast(1).all { it != -1 } && values.last() == -1 + val sizeConstraint = packet.size >= values.lastIndex + + mockConstraint && sizeConstraint && r == values.lastIndex + + }, + mockStrategy = MockStrategyApi.OTHER_PACKAGES, + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/aliasing/AliasingInParamsExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/aliasing/AliasingInParamsExampleTest.kt new file mode 100644 index 0000000000..c0ce27528f --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/aliasing/AliasingInParamsExampleTest.kt @@ -0,0 +1,31 @@ +package org.utbot.examples.mock.aliasing + +import org.utbot.framework.plugin.api.MockStrategyApi +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class AliasingInParamsExampleTest : UtValueTestCaseChecker(testClass = AliasingInParamsExample::class) { + @Test + fun testExamplePackageBased() { + check( + AliasingInParamsExample::example, + eq(1), + { fst, snd, x, r -> fst != snd && x == r }, + coverage = DoNotCalculate, + mockStrategy = MockStrategyApi.OTHER_PACKAGES + ) + } + + @Test + fun testExample() { + check( + AliasingInParamsExample::example, + eq(2), + { fst, snd, x, r -> fst == snd && x == r }, + { fst, snd, x, r -> fst != snd && x == r }, + coverage = DoNotCalculate, + mockStrategy = MockStrategyApi.NO_MOCKS + ) + } + +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt new file mode 100644 index 0000000000..2499893bf3 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt @@ -0,0 +1,38 @@ +package org.utbot.examples.mock.model + +import org.utbot.examples.mock.provider.impl.ProviderImpl +import org.utbot.examples.mock.service.impl.ServiceWithField + +import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.isNotNull +import org.utbot.framework.plugin.api.isNull +import org.junit.jupiter.api.Test + +import org.utbot.testcheckers.eq + +internal class FieldMockChecker : UtModelTestCaseChecker(testClass = ServiceWithField::class) { + @Test + fun testMockForField_IntPrimitive() { + checkStatic( + ServiceWithField::staticCalculateBasedOnInteger, + eq(4), + { service, r -> service.isNull() && r.isException() }, + { service, r -> service.provider.isNull() && r.isException() }, + { service, r -> + service.provider.isNotNull() && + service.provider.mocksMethod(ProviderImpl::provideInteger)!!.single() + .primitiveValue() > 5 && r.primitiveValue() == 1 + }, + { service, r -> + service.provider.isNotNull() && + service.provider.mocksMethod(ProviderImpl::provideInteger)!!.single() + .primitiveValue() <= 5 && r.primitiveValue() == 0 + }, + mockStrategy = OTHER_PACKAGES + ) + } + + private val UtModel.provider: UtModel + get() = this.findField("provider") +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/model/UseNetworkModelBasedTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/model/UseNetworkModelBasedTest.kt new file mode 100644 index 0000000000..dcdd58e4d0 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/model/UseNetworkModelBasedTest.kt @@ -0,0 +1,28 @@ +package org.utbot.examples.mock.model + + +import org.utbot.examples.mock.UseNetwork +import org.utbot.framework.plugin.api.MockStrategyApi +import org.utbot.framework.plugin.api.UtCompositeModel +import org.utbot.framework.plugin.api.UtVoidModel +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtModelTestCaseChecker + +internal class UseNetworkModelBasedTest : UtModelTestCaseChecker(testClass = UseNetwork::class) { + @Test + fun testMockVoidMethod() { + check( + UseNetwork::mockVoidMethod, + eq(1), + { network, _ -> + require(network is UtCompositeModel) + + val mock = network.mocks.values.single().single() + + mock is UtVoidModel + }, + mockStrategy = MockStrategyApi.OTHER_PACKAGES + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/models/CompositeModelMinimizationChecker.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/models/CompositeModelMinimizationChecker.kt new file mode 100644 index 0000000000..cb2556af49 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/models/CompositeModelMinimizationChecker.kt @@ -0,0 +1,78 @@ +package org.utbot.examples.models + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.framework.plugin.api.FieldId +import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtCompositeModel +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.UtReferenceModel +import org.junit.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtModelTestCaseChecker + +internal class CompositeModelMinimizationChecker : UtModelTestCaseChecker( + testClass = CompositeModelMinimizationExample::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + private fun UtModel.getFieldsOrNull(): Map? = when(this) { + is UtAssembleModel -> origin?.fields + is UtCompositeModel -> fields + else -> null + } + + private fun UtModel.hasInitializedFields(): Boolean = getFieldsOrNull()?.isNotEmpty() == true + private fun UtModel.isNotInitialized(): Boolean = getFieldsOrNull()?.isEmpty() == true + + @Test + fun singleNotNullArgumentInitializationRequiredTest() { + check( + CompositeModelMinimizationExample::singleNotNullArgumentInitializationRequired, + eq(2), + { o, _ -> o.hasInitializedFields() } + ) + } + + @Test + fun sameArgumentsInitializationRequiredTest() { + check( + CompositeModelMinimizationExample::sameArgumentsInitializationRequired, + eq(3), + { a, b, _ -> + a as UtReferenceModel + b as UtReferenceModel + a.id == b.id && a.hasInitializedFields() && b.hasInitializedFields() + } + ) + } + + @Test + fun distinctNotNullArgumentsSecondInitializationNotExpected() { + check( + CompositeModelMinimizationExample::distinctNotNullArgumentsSecondInitializationNotExpected, + eq(2), + { a, b, _ -> + a as UtReferenceModel + b as UtReferenceModel + a.hasInitializedFields() && b.isNotInitialized() + } + ) + } + + @Test + fun distinctNotNullArgumentsInitializationRequired() { + check( + CompositeModelMinimizationExample::distinctNotNullArgumentsInitializationRequired, + eq(2), + { a, b, _ -> + a as UtReferenceModel + b as UtReferenceModel + a.hasInitializedFields() && b.hasInitializedFields() + } + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/models/ModelsIdEqualityChecker.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/models/ModelsIdEqualityChecker.kt new file mode 100644 index 0000000000..8e50a4b48b --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/models/ModelsIdEqualityChecker.kt @@ -0,0 +1,143 @@ +package org.utbot.examples.models + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.framework.plugin.api.UtArrayModel +import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtDirectSetFieldModel +import org.utbot.framework.plugin.api.UtExecutionSuccess +import org.utbot.framework.plugin.api.UtReferenceModel +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +// TODO failed Kotlin compilation SAT-1332 +internal class ModelsIdEqualityChecker : UtModelTestCaseChecker( + testClass = ModelsIdEqualityExample::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testObjectItself() { + check( + ModelsIdEqualityExample::objectItself, + eq(1), + { o, r -> (o as UtReferenceModel).id == ((r as UtExecutionSuccess).model as UtReferenceModel).id } + ) + } + + @Test + fun testRefField() { + check( + ModelsIdEqualityExample::refField, + eq(1), + { o, r -> + val resultId = ((r as UtExecutionSuccess).model as UtReferenceModel).id + val fieldId = (o as UtAssembleModel).findFieldId() + fieldId == resultId + } + ) + } + + @Test + fun testArrayField() { + check( + ModelsIdEqualityExample::arrayField, + eq(1), + { o, r -> + val resultId = ((r as UtExecutionSuccess).model as UtReferenceModel).id + val fieldId = (o as UtAssembleModel).findFieldId() + fieldId == resultId + } + ) + } + + @Test + fun testArrayItself() { + check( + ModelsIdEqualityExample::arrayItself, + eq(1), + { o, r -> (o as? UtReferenceModel)?.id == ((r as UtExecutionSuccess).model as? UtReferenceModel)?.id } + ) + } + + @Test + fun testSubArray() { + check( + ModelsIdEqualityExample::subArray, + eq(1), + { array, r -> + val resultId = ((r as UtExecutionSuccess).model as UtReferenceModel).id + val arrayId = (array as UtArrayModel).findElementId(0) + resultId == arrayId + } + ) + } + + @Test + fun testSubRefArray() { + check( + ModelsIdEqualityExample::subRefArray, + eq(1), + { array, r -> + val resultId = ((r as UtExecutionSuccess).model as UtReferenceModel).id + val arrayId = (array as UtArrayModel).findElementId(0) + resultId == arrayId + } + ) + } + + @Test + fun testWrapperExample() { + check( + ModelsIdEqualityExample::wrapperExample, + eq(1), + { o, r -> (o as? UtReferenceModel)?.id == ((r as UtExecutionSuccess).model as? UtReferenceModel)?.id } + ) + } + + @Test + fun testObjectFromArray() { + check( + ModelsIdEqualityExample::objectFromArray, + eq(1), + { array, r -> + val resultId = ((r as UtExecutionSuccess).model as UtReferenceModel).id + val objectId = (array as UtArrayModel).findElementId(0) + resultId == objectId + } + ) + } + + @Test + fun testObjectAndStatic() { + checkStaticsAfter( + ModelsIdEqualityExample::staticSetter, + eq(1), + { obj, statics, r -> + val resultId = ((r as UtExecutionSuccess).model as UtReferenceModel).id + val objectId = (obj as UtReferenceModel).id + val staticId = (statics.values.single() as UtReferenceModel).id + resultId == objectId && resultId == staticId + } + ) + + } + + private fun UtReferenceModel.findFieldId(): Int? { + this as UtAssembleModel + val fieldModel = this.modificationsChain + .filterIsInstance() + .single() + .fieldModel + return (fieldModel as UtReferenceModel).id + } + + private fun UtArrayModel.findElementId(index: Int) = + if (index in stores.keys) { + (stores[index] as UtReferenceModel).id + } else { + (constModel as UtReferenceModel).id + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/natives/NativeExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/natives/NativeExamplesTest.kt new file mode 100644 index 0000000000..4b7bd42a9e --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/natives/NativeExamplesTest.kt @@ -0,0 +1,39 @@ +package org.utbot.examples.natives + +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq +import org.utbot.testcheckers.ge +import org.utbot.testcheckers.withSolverTimeoutInMillis + +// TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 +internal class NativeExamplesTest : UtValueTestCaseChecker( + testClass = NativeExamples::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + + @Test + fun testFindAndPrintSum() { + // TODO related to the https://github.com/UnitTestBot/UTBotJava/issues/131 + withSolverTimeoutInMillis(5000) { + check( + NativeExamples::findAndPrintSum, + ge(1), + coverage = DoNotCalculate, + ) + } + } + + @Test + fun testFindSumWithMathRandom() { + check( + NativeExamples::findSumWithMathRandom, + eq(1), + coverage = DoNotCalculate, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt new file mode 100644 index 0000000000..efab9304b1 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt @@ -0,0 +1,57 @@ +package org.utbot.examples.objects + +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq + +class AnonymousClassesExampleTest : UtValueTestCaseChecker( + testClass = AnonymousClassesExample::class, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA, lastStage = TestExecution, parameterizedModeLastStage = Compilation), + TestLastStage(CodegenLanguage.KOTLIN, lastStage = TestExecution) + ) +) { + @Test + fun testAnonymousClassAsParam() { + checkWithException( + AnonymousClassesExample::anonymousClassAsParam, + eq(3), + { abstractAnonymousClass, r -> abstractAnonymousClass == null && r.isException() }, + { abstractAnonymousClass, r -> abstractAnonymousClass != null && r.getOrNull() == 0 }, + { abstractAnonymousClass, r -> abstractAnonymousClass != null && abstractAnonymousClass::class.java.isAnonymousClass && r.getOrNull() == 42 }, + coverage = Full + ) + } + + @Test + fun testNonFinalAnonymousStatic() { + checkStaticsAndException( + AnonymousClassesExample::nonFinalAnonymousStatic, + eq(3), + { statics, r -> statics.values.single().value == null && r.isException() }, + { _, r -> r.getOrNull() == 0 }, + { _, r -> r.getOrNull() == 42 }, + coverage = Full + ) + } + + @Test + fun testAnonymousClassAsStatic() { + check( + AnonymousClassesExample::anonymousClassAsStatic, + eq(1), + { r -> r == 42 }, + coverage = Full + ) + } + + @Test + fun testAnonymousClassAsResult() { + check( + AnonymousClassesExample::anonymousClassAsResult, + eq(1), + { abstractAnonymousClass -> abstractAnonymousClass != null && abstractAnonymousClass::class.java.isAnonymousClass }, + coverage = Full + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ClassRefTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ClassRefTest.kt new file mode 100644 index 0000000000..6382bc09c5 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ClassRefTest.kt @@ -0,0 +1,137 @@ +@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") + +package org.utbot.examples.objects + +import org.utbot.framework.plugin.api.CodegenLanguage +import java.lang.Boolean +import kotlin.Array +import kotlin.Suppress +import kotlin.arrayOf +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class ClassRefTest : UtValueTestCaseChecker( + testClass = ClassRef::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + // TODO: SAT-1457 Restore Kotlin codegen for a group of tests with type casts + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testTakeBooleanClassRef() { + check( + ClassRef::takeBooleanClassRef, + eq(1), + { r -> r == Boolean.TYPE } + ) + } + + @Test + fun testTakeClassRef() { + check( + ClassRef::takeClassRef, + eq(1), + { r -> r == ClassRef::class.java } + ) + } + + @Test + fun testTakeClassRefFromParam() { + check( + ClassRef::takeClassRefFromParam, + eq(2), + { classRef, _ -> classRef == null }, + { classRef, r -> r == classRef.javaClass } + ) + } + + + @Test + fun testTakeArrayClassRef() { + check( + ClassRef::takeArrayClassRef, + eq(1), + { r -> r == arrayOf()::class.java } + ) + } + + @Test + fun testTwoDimArrayClassRef() { + check( + ClassRef::twoDimArrayClassRef, + eq(1), + { r -> r == arrayOf>()::class.java } + ) + } + + @Test + fun testTwoDimArrayClassRefFromParam() { + check( + ClassRef::twoDimArrayClassRefFromParam, + eq(2), + { array, _ -> array == null }, + { array, r -> r == array::class.java } + ) + } + + @Test + fun testTakeConstantClassRef() { + check( + ClassRef::takeConstantClassRef, + eq(1), + { r -> r == ClassRef::class.java } + ) + } + + @Test + fun testEqualityOnClassRef() { + check( + ClassRef::equalityOnClassRef, + eq(1), + { r -> r == true }, + coverage = atLeast(50) // we cannot find a way to have different class references + ) + } + + @Test + fun testEqualityOnStringClassRef() { + check( + ClassRef::equalityOnStringClassRef, + eq(1), + { r -> r == true }, + coverage = atLeast(50) // we cannot find a way to have different class references + ) + } + + @Test + fun testEqualityOnArrayClassRef() { + check( + ClassRef::equalityOnArrayClassRef, + eq(1), + { r -> r == true }, + coverage = atLeast(50) // we cannot find a way to have different class references + ) + } + + @Test + fun testTwoDimensionalArrayClassRef() { + check( + ClassRef::twoDimensionalArrayClassRef, + eq(1), + { r -> r == true }, + coverage = atLeast(50) + ) + } + + @Test + fun testEqualityOnGenericClassRef() { + check( + ClassRef::equalityOnGenericClassRef, + eq(1), + { r -> r == true }, + coverage = atLeast(50) // we cannot find a way to have different class references + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ClassWithClassRefTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ClassWithClassRefTest.kt new file mode 100644 index 0000000000..d081c8c0a3 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ClassWithClassRefTest.kt @@ -0,0 +1,32 @@ +package org.utbot.examples.objects + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testcheckers.withoutConcrete + +// TODO Kotlin compilation SAT-1332 +// Code generation executions fail due we cannot analyze strings properly for now +internal class ClassWithClassRefTest : UtValueTestCaseChecker( + testClass = ClassWithClassRef::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA, Compilation), // TODO JIRA:1479 + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + // 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" + checkWithThisAndException( + ClassWithClassRef::classRefName, + eq(2), + { instance, r -> instance.someListClass == null && r.isException() }, + { instance, r -> instance.someListClass != null && r.getOrNull() == "" }, + coverage = DoNotCalculate // TODO: Method coverage with `this` parameter isn't supported + ) + } + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/HiddenFieldAccessModifiersTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/HiddenFieldAccessModifiersTest.kt new file mode 100644 index 0000000000..c9ef29e55e --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/HiddenFieldAccessModifiersTest.kt @@ -0,0 +1,20 @@ +package org.utbot.examples.objects + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker + +internal class HiddenFieldAccessModifiersTest : UtValueTestCaseChecker(testClass = HiddenFieldAccessModifiersExample::class) { + @Test + fun testCheckSuperFieldEqualsOne() { + withEnabledTestingCodeGeneration(testCodeGeneration = true) { + check( + HiddenFieldAccessModifiersExample::checkSuperFieldEqualsOne, + eq(3), + { o, _ -> o == null }, + { _, r -> r == true }, + { _, r -> r == false }, + ) + } + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt new file mode 100644 index 0000000000..41d2edfbfb --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt @@ -0,0 +1,34 @@ +package org.utbot.examples.objects + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class HiddenFieldExampleTest : UtValueTestCaseChecker(testClass = HiddenFieldExample::class) { + @Test + fun testCheckHiddenField() { + check( + HiddenFieldExample::checkHiddenField, + eq(4), + { o, _ -> o == null }, + { o, r -> o != null && o.a != 1 && r == 2 }, + { o, r -> o != null && o.a == 1 && o.b != 2 && r == 2 }, + { o, r -> o != null && o.a == 1 && o.b == 2 && r == 1 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCheckSuccField() { + withEnabledTestingCodeGeneration(testCodeGeneration = true) { + check( + HiddenFieldExample::checkSuccField, + eq(5), + { o, _ -> o == null }, + { o, r -> o.a == 1 && r == 1 }, + { o, r -> o.a != 1 && o.b == 2.0 && r == 2 }, + { o, r -> o.a != 1 && o.b != 2.0 && (o as HiddenFieldSuperClass).b == 3 && r == 3 }, + { o, r -> o.a != 1 && o.b != 2.0 && (o as HiddenFieldSuperClass).b != 3 && r == 4 }, + ) + } + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ModelMinimizationExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ModelMinimizationExamplesTest.kt new file mode 100644 index 0000000000..80ab112c2b --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ModelMinimizationExamplesTest.kt @@ -0,0 +1,131 @@ +package org.utbot.examples.objects + +import org.junit.Test +import org.utbot.testcheckers.eq + +internal class ModelMinimizationExamplesTest : UtValueTestCaseChecker(testClass = ModelMinimizationExamples::class) { + @Test + fun singleValueComparisonTest() { + check( + ModelMinimizationExamples::singleValueComparison, + eq(4), + { quad, _ -> quad == null }, // NPE + { quad, _ -> quad.a == null }, // NPE + { quad, r -> quad.a.value == 0 && r == true }, + { quad, r -> quad.a.value != 0 && r == false } + ) + } + + @Test + fun singleValueComparisonNotNullTest() { + check( + ModelMinimizationExamples::singleValueComparisonNotNull, + eq(2), + { quad, r -> quad.a.value == 0 && r == true }, + { quad, r -> quad.a.value != 0 && r == false }, + coverage = DoNotCalculate // TODO: JIRA:1688 + ) + } + + @Test + fun conditionCheckANeTest() { + // Parameters `a` and `b` should be not null. + // Parameters `a` and `b` should be distinct instances. + // The field `a.value` is used and should be initialized. + // The field `b.value` is not used and should not be initialized to avoid redundancy. + check( + ModelMinimizationExamples::conditionCheckANe, + eq(3), + { a, _, r -> a.value == 42 && r == true }, + { a, _, r -> a.value <= 0 && r == true }, + { a, _, r -> a.value > 0 && a.value != 42 && r == false}, + coverage = DoNotCalculate // TODO: JIRA:1688 + ) + } + + @Test + fun conditionCheckAEqTest() { + // Parameters `a` and `b` should be not null. + // Parameters `a` and `b` should refer to the same instance. + // The field `a.value` is used and should be initialized. + // The field `b.value` is not used but should be implicitly initialized, as `b` is `a` restored from cache. + check( + ModelMinimizationExamples::conditionCheckAEq, + eq(3), + { a, _, r -> a.value == 42 && r == true }, + { a, _, r -> a.value <= 0 && r == true }, + { a, _, r -> a.value > 0 && a.value != 42 && r == false}, + coverage = DoNotCalculate // TODO: JIRA:1688 + ) + } + + @Test + fun conditionCheckBNeTest() { + // Parameters `a` and `b` should be not null. + // Parameters `a` and `b` should be distinct instances. + // The field `a.value` is not used and should not be initialized to avoid redundancy. + // The field `b.value` is used and should be initialized. + check( + ModelMinimizationExamples::conditionCheckBNe, + eq(3), + { _, b, r -> b.value == 42 && r == true }, + { _, b, r -> b.value <= 0 && r == true }, + { _, b, r -> b.value > 0 && b.value != 42 && r == false}, + coverage = DoNotCalculate // TODO: JIRA:1688 + ) + } + + @Test + fun conditionCheckBEqTest() { + // Parameters `a` and `b` should be not null. + // Parameters `a` and `b` should refer to the same instance. + // The field `a.value` is not used but should be initialized, as `b.value` is used, and `a === b`. + // The field `b.value` is used and should be initialized. + // `a` should be initialized even if its model is created first and stored in the cache. + // Note: `a` and `b` might have different `addr` but they will have the same `concreteAddr`. + check( + ModelMinimizationExamples::conditionCheckBEq, + eq(3), + { _, b, r -> b.value == 42 && r == true }, + { _, b, r -> b.value <= 0 && r == true }, + { _, b, r -> b.value > 0 && b.value != 42 && r == false}, + coverage = DoNotCalculate // TODO: JIRA:1688 + ) + } + + @Test + fun conditionCheckNoNullabilityConstraintTest() { + // Note: in this test we have no constraints on the second argument, so it becomes `null`. + check( + ModelMinimizationExamples::conditionCheckNoNullabilityConstraintExample, + eq(4), + { a, _, _ -> a == null }, // NPE + { a, _, r -> a.value == 42 && r == true }, + { a, _, r -> a.value <= 0 && r == true }, + { a, _, r -> a.value > 0 && a.value != 42 && r == false} + ) + } + + @Test + fun firstArrayElementContainsSentinelTest() { + check( + ModelMinimizationExamples::firstArrayElementContainsSentinel, + eq(2), + { values, r -> values[0].value == 42 && r == true }, + { values, r -> values[0].value != 42 && r == false }, + coverage = DoNotCalculate // TODO: JIRA:1688 + ) + } + + @Test + fun multipleConstraintsTest() { + check( + ModelMinimizationExamples::multipleConstraintsExample, + eq(3), + { a, _, _, r -> a.value == 42 && r == 1 }, + { a, b, _, r -> a.value != 42 && b.value == 73 && r == 2 }, + { a, b, _, r -> a.value != 42 && b.value != 73 && r == 3 }, + coverage = DoNotCalculate // TODO: JIRA:1688 + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithFinalStaticTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithFinalStaticTest.kt new file mode 100644 index 0000000000..4f2e04c94c --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithFinalStaticTest.kt @@ -0,0 +1,26 @@ +package org.utbot.examples.objects + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +class ObjectWithFinalStaticTest : UtValueTestCaseChecker( + testClass = ObjectWithFinalStatic::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testParameterEqualsFinalStatic() { + checkStatics( + ObjectWithFinalStatic::parameterEqualsFinalStatic, + eq(2), + { key, _, statics, result -> key != statics.singleValue() as Int && result == -420 }, + // matcher checks equality by value, but branch is executed if objects are equal by reference + { key, i, statics, result -> key == statics.singleValue() && i == result }, + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesClassTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesClassTest.kt new file mode 100644 index 0000000000..aa568046f5 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesClassTest.kt @@ -0,0 +1,34 @@ +package org.utbot.examples.objects + +import kotlin.reflect.KFunction0 +import kotlin.reflect.KFunction3 +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class ObjectWithPrimitivesClassTest : UtValueTestCaseChecker(testClass = ObjectWithPrimitivesClass::class) { + @Test + fun testDefaultConstructor() { + val method: KFunction0 = ::ObjectWithPrimitivesClass + checkStaticMethod( + method, + eq(1), + // TODO: SAT-933 Add support for constructor testing") + // { instance -> instance is ObjectWithPrimitivesClass }, + coverage = DoNotCalculate + ) + } + + @Test + fun testConstructorWithParams() { + val method: KFunction3 = ::ObjectWithPrimitivesClass + checkStaticMethod( + method, + eq(1), + // TODO: SAT-933 Add support for constructor testing") +// { x, y, weight, instance -> +// instance is ObjectWithPrimitivesClass && instance.x == x && instance.y == y && instance.weight == weight +// }, + coverage = DoNotCalculate + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt new file mode 100644 index 0000000000..bff483ad3f --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt @@ -0,0 +1,266 @@ +package org.utbot.examples.objects + +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class ObjectWithPrimitivesExampleTest : UtValueTestCaseChecker(testClass = ObjectWithPrimitivesExample::class) { + @Test + fun testMax() { + checkWithException( + ObjectWithPrimitivesExample::max, + eq(7), + { fst, _, r -> fst == null && r.isException() }, + { _, snd, r -> snd == null && r.isException() }, + { fst, snd, r -> fst != null && snd != null && fst.x > snd.x && fst.y > snd.y && r.getOrNull()!! == fst }, + { fst, snd, r -> fst != null && snd != null && fst.x > snd.x && fst.y <= snd.y && r.getOrNull()!! == fst }, + { fst, snd, r -> fst != null && snd != null && fst.x < snd.x && fst.y < snd.y && r.getOrNull()!! == snd }, + { fst, snd, r -> fst != null && snd != null && fst.x == snd.x && r.getOrNull()!! == fst }, + { fst, snd, r -> fst != null && snd != null && fst.y == snd.y && r.getOrNull()!! == fst }, + coverage = DoNotCalculate + ) + } + + @Test + fun testIgnoredInputParameters() { + check( + ObjectWithPrimitivesExample::ignoredInputParameters, + eq(1), + { fst, snd, r -> fst == null && snd == null && r != null } + ) + } + + @Test + fun testExample() { + check( + ObjectWithPrimitivesExample::example, + eq(3), + { v, _ -> v == null }, + { v, r -> v != null && v.x == 1 && r?.x == 1 }, + { v, r -> v != null && v.x != 1 && r?.x == 1 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testExampleMutation() { + checkParamsMutations( + ObjectWithPrimitivesExample::example, + ignoreExecutionsNumber, + { valueBefore, valueAfter -> valueBefore.x != 0 && valueAfter.x == 1 } + ) + } + + @Test + fun testDefaultValueForSuperclassFields() { + check( + ObjectWithPrimitivesExample::defaultValueForSuperclassFields, + eq(1), + { r -> r != null && r.x == 0 && r.y == 0 && r.weight == 0.0 && r.valueByDefault == 5 && r.anotherX == 0 }, + coverage = atLeast(50) + ) + } + + @Test + @Disabled("TODO JIRA:1594") + fun testCreateObject() { + checkWithException( + ObjectWithPrimitivesExample::createObject, + eq(3), + { _, _, o, r -> o == null && r.isException() }, + { _, _, o, r -> o != null && o.weight < 0 && r.isException() }, + { a, b, o, r -> + val result = r.getOrNull()!! + + val objectConstraint = o != null && (o.weight >= 0 || o.weight.isNaN()) + val resultConstraint = result.x == a + 5 && result.y == b + 6 + val postcondition = result.weight == o.weight || result.weight.isNaN() && o.weight.isNaN() + + objectConstraint && resultConstraint && postcondition + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testMemory() { + checkWithException( + ObjectWithPrimitivesExample::memory, + eq(4), + { o, v, r -> o == null && v > 0 && r.isException() }, + { o, v, r -> + val resultValue = r.getOrNull() + val objectToCompare = if (resultValue is ObjectWithPrimitivesClassSucc) { + ObjectWithPrimitivesClassSucc(1, 2, 1.2, resultValue.anotherX) + } else { + ObjectWithPrimitivesClass(1, 2, 1.2) + } + objectToCompare.valueByDefault = resultValue!!.valueByDefault + + o != null && v > 0 && resultValue == objectToCompare + }, + { o, v, r -> o == null && v <= 0 && r.isException() }, + { o, v, r -> + val resultValue = r.getOrNull() + val objectToCompare = if (resultValue is ObjectWithPrimitivesClassSucc) { + ObjectWithPrimitivesClassSucc(-1, -2, -1.2, resultValue.anotherX) + } else { + ObjectWithPrimitivesClass(-1, -2, -1.2) + } + objectToCompare.valueByDefault = resultValue!!.valueByDefault + + o != null && v <= 0 && resultValue == objectToCompare + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCompareWithNull() { + check( + ObjectWithPrimitivesExample::compareWithNull, + eq(3), + { fst, _, r -> fst == null && r == 1 }, + { fst, snd, r -> fst != null && snd == null && r == 2 }, + { fst, snd, r -> fst != null && snd != null && r == 3 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCompareTwoNullObjects() { + check( + ObjectWithPrimitivesExample::compareTwoNullObjects, + eq(1), + coverage = DoNotCalculate + ) + } + + @Test + fun testNullExample() { + check( + ObjectWithPrimitivesExample::nullExample, + eq(4), + { o, _ -> o == null }, + { o, r -> o != null && o.x != 0 && r != null }, + { o, r -> o != null && o.x == 0 && o.y != 0 && r != null }, + { o, r -> o != null && o.x == 0 && o.y == 0 && r == null }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCompareTwoOuterObjects() { + checkWithException( + ObjectWithPrimitivesExample::compareTwoOuterObjects, + eq(4), + { x, _, r -> x == null && r.isException() }, + { x, y, r -> x != null && y == null && r.isException() }, + { x, y, r -> x != null && y != null && x === y && r.getOrNull() == true }, + { x, y, r -> x != null && y != null && x !== y && r.getOrNull() == false } + ) + } + + @Test + fun testCompareObjectWithArgument() { + check( + ObjectWithPrimitivesExample::compareObjectWithArgument, + eq(1), + coverage = DoNotCalculate + ) + } + + @Test + fun testCompareTwoDifferentObjects() { + check( + ObjectWithPrimitivesExample::compareTwoDifferentObjects, + eq(1), + coverage = DoNotCalculate + ) + } + + + @Test + fun testCompareTwoIdenticalObjectsFromArguments() { + checkWithException( + ObjectWithPrimitivesExample::compareTwoIdenticalObjectsFromArguments, + eq(4), + { fst, _, r -> fst == null && r.isException() }, + { _, snd, r -> snd == null && r.isException() }, + { fst, snd, r -> fst != null && snd != null && r.getOrNull() == 1 }, + { fst, snd, r -> fst != null && snd != null && r.getOrNull() == 2 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCompareTwoRefEqualObjects() { + check( + ObjectWithPrimitivesExample::compareTwoRefEqualObjects, + eq(1), + coverage = DoNotCalculate + ) + } + + @Test + fun testGetOrDefault() { + checkWithException( + ObjectWithPrimitivesExample::getOrDefault, + ignoreExecutionsNumber, + { _, d, r -> d == null && r.isException() }, + { _, d, r -> d != null && d.x == 0 && d.y == 0 && r.isException() }, + { o, d, r -> o == null && (d.x != 0 || d.y != 0) && r.getOrNull() == d }, + { o, d, r -> o != null && (d.x != 0 || d.y != 0) && r.getOrNull() == o }, + ) + } + + @Test + fun testInheritorsFields() { + checkWithException( + ObjectWithPrimitivesExample::inheritorsFields, + eq(3), + { fst, _, r -> fst == null && r.isException() }, + { fst, snd, r -> fst != null && snd == null && r.isException() }, + { fst, snd, r -> fst != null && snd != null && r.getOrNull() == 1 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCreateWithConstructor() { + check( + ObjectWithPrimitivesExample::createWithConstructor, + eq(1), + { x, y, r -> r != null && r.x == x + 1 && r.y == y + 2 && r.weight == 3.3 } + ) + } + + @Test + fun testCreateWithSuperConstructor() { + check( + ObjectWithPrimitivesExample::createWithSuperConstructor, + eq(1), + { x, y, anotherX, r -> + r != null && r.x == x + 1 && r.y == y + 2 && r.weight == 3.3 && r.anotherX == anotherX + 4 + } + ) + } + + @Test + fun testFieldWithDefaultValue() { + check( + ObjectWithPrimitivesExample::fieldWithDefaultValue, + eq(1), + { x, y, r -> r != null && r.x == x && r.y == y && r.weight == 3.3 && r.valueByDefault == 5 } + ) + } + + @Test + fun testValueByDefault() { + check( + ObjectWithPrimitivesExample::valueByDefault, + eq(1), + { r -> r == 5 } + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt new file mode 100644 index 0000000000..1d331f9d0d --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt @@ -0,0 +1,154 @@ +package org.utbot.examples.objects + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class ObjectWithRefFieldsExampleTest : UtValueTestCaseChecker(testClass = ObjectWithRefFieldExample::class) { + @Test + fun testDefaultValue() { + check( + ObjectWithRefFieldExample::defaultValue, + eq(1), + { r -> r != null && r.x == 0 && r.y == 0 && r.weight == 0.0 && r.arrayField == null && r.refField == null }, + coverage = atLeast(50) + ) + } + + @Test + fun testWriteToRefTypeField() { + check( + ObjectWithRefFieldExample::writeToRefTypeField, + eq(4), + { _, v, _ -> v != 42 }, + { o, v, _ -> v == 42 && o == null }, + { o, v, _ -> v == 42 && o != null && o.refField != null }, + { o, v, r -> + v == 42 && o != null && o.refField == null && r != null && r.refField.a == v && r.refField.b == 2 * v + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testDefaultFieldValues() { + check( + ObjectWithRefFieldExample::defaultFieldValues, + eq(1), + { r -> + r != null && r.x == 0 && r.y == 0 && r.weight == 0.0 && r.refField == null && r.arrayField == null + } + ) + } + + @Test + fun testReadFromRefTypeField() { + check( + ObjectWithRefFieldExample::readFromRefTypeField, + eq(4), + { o, _ -> o == null }, + { o, _ -> o != null && o.refField == null }, + { o, r -> o?.refField != null && o.refField.a <= 0 && r == -1 }, + { o, r -> o?.refField != null && o.refField.a > 0 && o.refField.a == r } + ) + } + + @Test + fun testWriteToArrayField() { + check( + ObjectWithRefFieldExample::writeToArrayField, + eq(3), + { _, length, _ -> length < 3 }, + { o, length, _ -> length >= 3 && o == null }, + { o, length, r -> + require(r != null) + + val array = r.arrayField + + val preconditions = length >= 3 && o != null + val contentConstraint = array.dropLast(1) == (1 until length).toList() && array.last() == 100 + + preconditions && contentConstraint + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testReadFromArrayField() { + check( + ObjectWithRefFieldExample::readFromArrayField, + eq(5), + { o, _, _ -> o == null }, + { o, _, _ -> o != null && o.arrayField == null }, + { o, _, _ -> o?.arrayField != null && o.arrayField.size < 3 }, + { o, v, r -> o?.arrayField != null && o.arrayField.size >= 3 && o.arrayField[2] == v && r == 1 }, + { o, v, r -> o?.arrayField != null && o.arrayField.size >= 3 && o.arrayField[2] != v && r == 2 } + ) + } + + @Test + fun testCompareTwoDifferentObjectsFromArguments() { + check( + ObjectWithRefFieldExample::compareTwoDifferentObjectsFromArguments, + ignoreExecutionsNumber, + { fst, _, _ -> fst == null }, + { fst, snd, _ -> fst != null && fst.x > 0 && snd == null }, + { fst, snd, _ -> fst != null && fst.x <= 0 && snd == null }, + { fst, snd, r -> fst != null && snd != null && fst.x > 0 && snd.x < 0 && r == 1 }, + { fst, snd, r -> fst != null && snd != null && ((fst.x > 0 && snd.x >= 0) || fst.x <= 0) && fst === snd && r == 2 }, + { fst, snd, r -> fst != null && snd != null && (fst.x <= 0 || (fst.x > 0 && snd.x >= 0)) && fst !== snd && r == 3 }, + coverage = atLeast(87) + ) + } + + @Test + fun testCompareTwoObjectsWithNullRefField() { + checkWithException( + ObjectWithRefFieldExample::compareTwoObjectsWithNullRefField, + eq(4), + { fst, _, r -> fst == null && r.isException() }, + { fst, snd, r -> fst != null && snd == null && r.isException() }, + { fst, snd, r -> fst != null && snd != null && r.getOrNull() == 1 /* && fst == snd by ref */ }, + { fst, snd, r -> fst != null && snd != null && r.getOrNull() == 2 /* && fst != snd by ref */ }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCompareTwoObjectsWithDifferentRefField() { + checkWithException( + ObjectWithRefFieldExample::compareTwoObjectsWithDifferentRefField, + eq(4), + { fst, _, _, r -> fst == null && r.isException() }, + { fst, snd, _, r -> fst != null && snd == null && r.isException() }, + { fst, snd, _, r -> fst != null && snd != null && r.getOrNull() == 1 /* fst == snd by ref */ }, + { fst, snd, _, r -> fst != null && snd != null && r.getOrNull() == 2 /* fst != snd by ref */ }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCompareTwoObjectsWithTheDifferentRefField() { + checkWithException( + ObjectWithRefFieldExample::compareTwoObjectsWithDifferentRefField, + eq(4), + { fst, _, r -> fst == null && r.isException() }, + { fst, snd, r -> fst != null && snd == null && r.isException() }, + { fst, snd, r -> fst != null && snd != null && fst.refField === snd.refField && r.getOrNull() == true }, + { fst, snd, r -> fst != null && snd != null && fst.refField !== snd.refField && r.getOrNull() == false } + ) + } + + @Test + fun testCompareTwoObjectsWithTheSameRefField() { + checkWithException( + ObjectWithRefFieldExample::compareTwoObjectsWithTheSameRefField, + eq(4), + { fst, _, r -> fst == null && r.isException() }, + { fst, snd, r -> fst != null && snd == null && r.isException() }, + { fst, snd, r -> fst != null && snd != null && r.getOrNull() == 1 /* && fst == snd by ref */ }, + { fst, snd, r -> fst != null && snd != null && r.getOrNull() == 2 /* && fst != snd by ref */ }, + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt new file mode 100644 index 0000000000..6af50704af --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt @@ -0,0 +1,186 @@ +package org.utbot.examples.objects + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class ObjectWithStaticFieldsExampleTest : UtValueTestCaseChecker(testClass = ObjectWithStaticFieldsExample::class) { + @Test + fun testReadFromStaticArray() { + checkStatics( + ObjectWithStaticFieldsExample::readFromStaticArray, + eq(6), + { _, statics, _ -> statics.singleValue() == null }, + { _, statics, _ -> (statics.singleValue() as IntArray).size < 5 }, + { _, statics, _ -> (statics.singleValue() as IntArray)[1] != 1 }, + { _, statics, _ -> + val array = statics.singleValue() as IntArray + array[1] == 1 && array[2] != 2 + }, + { o, statics, _ -> + val array = statics.singleValue() as IntArray + o == null && array[1] == 1 && array[2] == 2 + }, + { o, statics, r -> + val array = statics.singleValue() as IntArray + r as ObjectWithStaticFieldsClass + o != null && array[1] == 1 && array[2] == 2 && r.x == array[1] && r.y == array[2] + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testSetStaticField() { + checkStaticsAfter( + ObjectWithStaticFieldsExample::setStaticField, + eq(4), + { o, _, _ -> o == null }, + { o, _, _ -> o != null && o.x < 100 }, + { o, _, _ -> o != null && o.x >= 100 && o.y < 150 }, + { o, staticsAfter, r -> + val staticValue = staticsAfter.singleValue() as Int + + val objectCondition = o != null && o.x >= 100 && o.y >= 150 && r?.x == o.x * o.y && r.y == o.y + val staticCondition = staticValue == o.y * o.x + val connection = r!!.x == staticValue + + objectCondition && staticCondition && connection + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetStaticField() { + checkStatics( + ObjectWithStaticFieldsExample::getStaticField, + eq(3), + { o, _, _ -> o == null }, + { o, statics, _ -> o != null && statics.singleValue() as Int != 3 }, + { o, statics, r -> o != null && statics.singleValue() as Int == 3 && r != null && r.x == 3 }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetStaticFieldWithDefaultValue() { + checkStatics( + ObjectWithStaticFieldsExample::getStaticFieldWithDefaultValue, + eq(1), + { statics, r -> statics.singleValue() == r } + ) + } + + @Test + fun testStaticFieldInInvoke() { + checkMutationsAndResult( + ObjectWithStaticFieldsExample::staticFieldInInvoke, + eq(1), + { staticsBefore, staticsAfter, r -> + val defaultValue = staticsBefore.findByName("defaultValue") + staticsAfter.findByName("staticValue") == defaultValue && r == defaultValue + } + ) + } + + @Test + fun testStaticFieldAfterStateInInvoke() { + checkMutationsAndResult( + ObjectWithStaticFieldsExample::staticFieldInInvoke, + eq(1), + { staticsBefore, staticsAfter, r -> + val defaultValue = staticsBefore.findByName("defaultValue") + val staticValue = staticsAfter.findByName("staticValue") + + defaultValue == staticValue && r == defaultValue + } + ) + } + + @Test + fun testStaticFieldArrayMax() { + checkMutationsAndResult( + ObjectWithStaticFieldsExample::staticFieldArrayMax, + eq(4), + { staticsBefore, _, _ -> (staticsBefore.values.single().value as Int) < 0 }, + { staticsBefore, staticsAfter, _ -> + val defaultValue = staticsBefore.findByName("defaultValue") as Int + val staticArray = staticsAfter.findByName("staticArrayValue") as IntArray + + defaultValue == 0 && staticArray.isEmpty() + }, + { staticsBefore, staticsAfter, r -> + val defaultValue = staticsBefore.findByName("defaultValue") as Int + val staticArray = staticsAfter.findByName("staticArrayValue") as IntArray + + val contentCondition = staticArray.zip(staticArray.indices).all { it.first == defaultValue + it.second } + val maxValue = staticArray.maxOrNull() + + staticArray.size == 1 && contentCondition && maxValue == r + }, + { staticsBefore, staticsAfter, r -> + val defaultValue = staticsBefore.findByName("defaultValue") as Int + val staticArray = staticsAfter.findByName("staticArrayValue") as IntArray + + val contentCondition = staticArray.zip(staticArray.indices).all { it.first == defaultValue + it.second } + val maxValue = staticArray.maxOrNull() + + staticArray.size > 1 && contentCondition && maxValue == r + }, + ) + } + + @Test + fun testInitializedArrayWithCycle() { + checkStatics( + ObjectWithStaticFieldsExample::initializedArrayWithCycle, + ignoreExecutionsNumber, + { n, _, r -> n < 0 && r == Double.NEGATIVE_INFINITY }, + { _, statics, _ -> statics.singleValue() == null }, + { n, statics, _ -> n > 0 && (statics.singleValue() as IntArray).lastIndex < n }, + { n, statics, r -> + r!!.toInt() == (1 until n).fold(1) { a, b -> a * b } * (statics.singleValue() as IntArray)[n] + }, + ) + } + + @Test + fun testBigStaticArray() { + checkStatics( + ObjectWithStaticFieldsExample::bigStaticArray, + eq(3), + { statics, _ -> statics.singleValue() == null }, + { statics, _ -> (statics.singleValue() as IntArray).lastIndex < 10 }, + { statics, r -> (statics.singleValue() as IntArray)[10] == r } + ) + } + + @Test + fun testModifyStatic() { + checkStaticMethodMutationAndResult( + ObjectWithStaticFieldsExample::modifyStatic, + eq(2), + { staticsBefore, staticsAfter, _ -> staticsBefore.singleValue() == 41 && staticsAfter.singleValue() == 42 }, + { staticsBefore, staticsAfter, _ -> + staticsBefore.singleValue() != 41 && staticsAfter.singleValue() == staticsBefore.singleValue() + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testResetNonFinalFields() { + checkMutationsAndResult( + ObjectWithStaticFieldsExample::resetNonFinalFields, + eq(2), + { staticsBefore, staticsAfter, r -> + staticsBefore.singleValue() == 42 && staticsAfter.singleValue() == 43 && r == 43 + }, + { staticsBefore, staticsAfter, r -> + val value = staticsBefore.singleValue() + value !in 42..43 && staticsAfter.singleValue() == value && r == value + }, + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithThrowableConstructorTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithThrowableConstructorTest.kt new file mode 100644 index 0000000000..297bf4c932 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithThrowableConstructorTest.kt @@ -0,0 +1,22 @@ +package org.utbot.examples.objects + +import kotlin.reflect.KFunction2 +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker + +internal class ObjectWithThrowableConstructorTest : UtValueTestCaseChecker(testClass = ObjectWithThrowableConstructor::class) { + @Test + @Disabled("SAT-1500 Support verification of UtAssembleModel for possible exceptions") + fun testThrowableConstructor() { + val method: KFunction2 = ::ObjectWithThrowableConstructor + checkStaticMethod( + method, + eq(2), + // TODO: SAT-933 Add support for constructor testing + coverage = DoNotCalculate + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt new file mode 100644 index 0000000000..985bc1ee4e --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt @@ -0,0 +1,21 @@ +package org.utbot.examples.objects + + + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException + +internal class PrivateFieldsTest : UtValueTestCaseChecker(testClass = PrivateFields::class) { + @Test + fun testAccessWithGetter() { + checkWithException( + PrivateFields::accessWithGetter, + eq(3), + { x, r -> x == null && r.isException() }, + { x, r -> x.a == 1 && r.getOrNull() == true }, + { x, r -> x.a != 1 && r.getOrNull() == false }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/RecursiveTypeTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/RecursiveTypeTest.kt new file mode 100644 index 0000000000..e1dc21ad88 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/RecursiveTypeTest.kt @@ -0,0 +1,36 @@ +package org.utbot.examples.objects + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker + +internal class RecursiveTypeTest : UtValueTestCaseChecker(testClass = RecursiveType::class) { + @Test + fun testNextValue() { + check( + RecursiveType::nextValue, + eq(5), + { _, value, _ -> value == 0 }, + { node, _, _ -> node == null }, + { node, _, _ -> node != null && node.next == null }, + { node, value, r -> node?.next != null && node.next.value != value && r == null }, + { node, value, r -> node?.next != null && node.next.value == value && r != null && r.value == value }, + coverage = DoNotCalculate + ) + } + + @Test + fun testWriteObjectFieldTest() { + check( + RecursiveType::writeObjectField, + eq(3), + { node, _ -> node == null }, + { node, r -> + node != null && node.next == null && r?.next != null && r.next.value == RecursiveTypeClass().value + 1 + }, + { node, r -> node?.next != null && r?.next != null && node.next.value + 1 == r.next.value }, + coverage = DoNotCalculate + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt new file mode 100644 index 0000000000..67bad2c9f3 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt @@ -0,0 +1,100 @@ +package org.utbot.examples.objects + +import org.utbot.framework.plugin.api.DocCodeStmt +import org.utbot.framework.plugin.api.DocPreTagStatement +import org.utbot.framework.plugin.api.DocRegularStmt +import org.utbot.framework.plugin.api.DocStatement +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class SimpleClassExampleTest : UtValueTestCaseChecker(testClass = SimpleClassExample::class) { + @Test + fun simpleConditionTest() { + check( + SimpleClassExample::simpleCondition, + eq(4), + { c, _ -> c == null }, // NPE + { c, r -> c.a >= 5 && r == 3 }, + { c, r -> c.a < 5 && c.b <= 10 && r == 3 }, + { c, r -> c.a < 5 && c.b > 10 && r == 0 }, + coverage = DoNotCalculate // otherwise we overwrite original values + ) + } + + /** + * Additional bytecode instructions between IFs, because of random, makes different order of executing the branches, + * that affects their number. Changing random seed in PathSelector can explore 6th branch + * + * @see multipleFieldAccessesTest + */ + @Test + fun singleFieldAccessTest() { + check( + SimpleClassExample::singleFieldAccess, + between(5..6), // could be 6 + { c, _ -> c == null }, // NPE + { c, r -> c.a == 3 && c.b != 5 && r == 2 }, + { c, r -> c.a == 3 && c.b == 5 && r == 1 }, + { c, r -> c.a == 2 && c.b != 3 && r == 2 }, + { c, r -> c.a == 2 && c.b == 3 && r == 0 } + ) + } + + /** + * Additional bytecode instructions between IFs, because of random, makes different order of executing the branches, + * that affects their number + */ + @Test + fun multipleFieldAccessesTest() { + check( + SimpleClassExample::multipleFieldAccesses, + eq(6), + { c, _ -> c == null }, // NPE + { c, r -> c.a != 2 && c.a != 3 && r == 2 }, // this one appears + { c, r -> c.a == 3 && c.b != 5 && r == 2 }, + { c, r -> c.a == 3 && c.b == 5 && r == 1 }, + { c, r -> c.a == 2 && c.b != 3 && r == 2 }, + { c, r -> c.a == 2 && c.b == 3 && r == 0 } + ) + } + + @Test + fun immutableFieldAccessTest() { + val immutableFieldAccessSummary = listOf( + DocPreTagStatement( + listOf( + DocRegularStmt("Test "), + DocRegularStmt("executes conditions:\n"), + DocRegularStmt(" "), + DocCodeStmt("(c.b == 10): True"), + DocRegularStmt("\n"), + DocRegularStmt("returns from: "), + DocCodeStmt("return 0;"), + DocRegularStmt("\n"), + ) + ) + ) + checkWithException( + SimpleClassExample::immutableFieldAccess, + eq(3), + { c, r -> c == null && r.isException() }, + { c, r -> c.b == 10 && r.getOrNull() == 0 }, + { c, r -> c.b != 10 && r.getOrNull() == 1 }, + summaryTextChecks = listOf( + keyContain(DocRegularStmt("throws NullPointerException in: c.b == 10")), + keyContain(DocCodeStmt("(c.b == 10): False")), + keyMatch(immutableFieldAccessSummary) + ), + summaryNameChecks = listOf( + keyMatch("testImmutableFieldAccess_ThrowNullPointerException"), + keyMatch("testImmutableFieldAccess_CBNotEquals10"), + keyMatch("testImmutableFieldAccess_CBEquals10") + ), + summaryDisplayNameChecks = listOf( + keyContain("NullPointerException", "c.b == 10"), + keyContain("c.b == 10 : False"), + keyContain("c.b == 10 : True") + ) + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/SimpleClassMultiInstanceExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/SimpleClassMultiInstanceExampleTest.kt new file mode 100644 index 0000000000..d7d427cd5e --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/SimpleClassMultiInstanceExampleTest.kt @@ -0,0 +1,22 @@ +package org.utbot.examples.objects + +import org.junit.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker + +internal class SimpleClassMultiInstanceExampleTest : UtValueTestCaseChecker(testClass = + SimpleClassMultiInstanceExample::class) { + @Test + fun singleObjectChangeTest() { + check( + SimpleClassMultiInstanceExample::singleObjectChange, + eq(3), + { first, _, _ -> first == null }, // NPE + { first, _, r -> first.a < 5 && r == 3 }, + { first, _, r -> first.a >= 5 && r == first.b }, + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/ByteExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/ByteExamplesTest.kt new file mode 100644 index 0000000000..4b709e11f5 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/ByteExamplesTest.kt @@ -0,0 +1,39 @@ +package org.utbot.examples.primitives + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker + +internal class ByteExamplesTest : UtValueTestCaseChecker(testClass = ByteExamples::class) { + @Test + fun testNegByte() { + check( + ByteExamples::negByte, + eq(2), + { b, r -> b > 0 && r == 0 }, + { b, r -> b <= 0 && r == 1 }, + ) + } + + @Test + fun testNegConstByte() { + check( + ByteExamples::negConstByte, + eq(3), + { b, r -> b <= -10 && r == 1 }, + { b, r -> b in -9..9 && r == 0 }, + { b, r -> b >= 10 && r == 1 }, + ) + } + + @Test + fun testSumTwoBytes() { + check( + ByteExamples::sumTwoBytes, + eq(3), + { a, b, r -> a + b > Byte.MAX_VALUE && r == 1 }, + { a, b, r -> a + b < Byte.MIN_VALUE && r == 2 }, + { a, b, r -> a + b in Byte.MIN_VALUE..Byte.MAX_VALUE && r == 3 }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/CharExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/CharExamplesTest.kt new file mode 100644 index 0000000000..c93b615eb9 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/CharExamplesTest.kt @@ -0,0 +1,52 @@ +package org.utbot.examples.primitives + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException + +internal class CharExamplesTest : UtValueTestCaseChecker(testClass = CharExamples::class) { + @Test + fun testCharDiv() { + checkWithException( + CharExamples::charDiv, + eq(2), + { _, b, r -> b == '\u0000' && r.isException() }, + { a, b, r -> b != '\u0000' && r.getOrNull() == a.toInt() / b.toInt() } + ) + } + + @Test + fun testCharNeg() { + check( + CharExamples::charNeg, + eq(2), + { c, r -> c !in '\u0000'..'\uC350' && r == 1 }, + { c, r -> c in '\u0000'..'\uC350' && r == 2 }, + ) + } + + @Test + fun testByteToChar() { + check( + CharExamples::byteToChar, + eq(5), + { b, r -> b == (-1).toByte() && r == -1 }, + { b, r -> b == (-128).toByte() && r == -128 }, + { b, r -> b == 0.toByte() && r == 0 }, + { b, r -> b == 127.toByte() && r == 127 }, + { b, r -> b != (-1).toByte() && b != (-128).toByte() && b != 0.toByte() && b != 127.toByte() && r == 200 }, + ) + } + + @Test + fun testUpdateObject() { + checkWithException( + CharExamples::updateObject, + eq(3), + { obj, _, r -> obj == null && r.isException() }, + { obj, i, r -> obj != null && i <= 50000 && r.getOrNull()!!.c == '\u0444' }, + { obj, i, r -> obj != null && i.toChar() > 50000.toChar() && r.getOrNull()?.c == i.toChar() }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/DoubleExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/DoubleExamplesTest.kt new file mode 100644 index 0000000000..157d5be275 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/DoubleExamplesTest.kt @@ -0,0 +1,161 @@ +package org.utbot.examples.primitives + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker + +@Suppress("SimplifyNegatedBinaryExpression") +internal class DoubleExamplesTest : UtValueTestCaseChecker(testClass = DoubleExamples::class) { + @Test + fun testCompareSum() { + check( + DoubleExamples::compareSum, + eq(2), + { a, b, r -> a + b > 5.6 && r == 1.0 }, + { a, b, r -> (a + b).isNaN() || a + b <= 5.6 && r == 0.0 } + ) + } + + @Test + fun testCompare() { + check( + DoubleExamples::compare, + eq(2), + { a, b, r -> a > b && r == 1.0 }, + { a, b, r -> !(a > b) && r == 0.0 } + ) + } + + @Test + fun testCompareWithDiv() { + check( + DoubleExamples::compareWithDiv, + eq(2), // only two branches because division by zero is not an error with doubles + { a, b, r -> a / (a + 0.5) > b && r == 1.0 }, + { a, b, r -> !(a / (a + 0.5) > b) && r == 0.0 } + ) + } + + @Test + fun testSimpleSum() { + check( + DoubleExamples::simpleSum, + eq(4), + { a, b, r -> (a + b).isNaN() && r == 0.0 }, + { a, b, r -> a + 1.1 + b > 10.1 && a + 1.1 + b < 11.125 && r == 1.1 }, + { a, b, r -> a + 1.1 + b <= 10.1 && r == 1.2 }, + { a, b, r -> a + 1.1 + b >= 11.125 && r == 1.2 } + ) + } + + @Test + fun testSum() { + check( + DoubleExamples::sum, + eq(4), + { a, b, r -> (a + b).isNaN() && r == 0.0 }, + { a, b, r -> a + 0.123124 + b > 11.123124 && a + b + 0.123124 < 11.125 && r == 1.1 }, + { a, b, r -> a + 0.123124 + b <= 11.123124 && r == 1.2 }, + { a, b, r -> a + 0.123124 + b >= 11.125 && r == 1.2 } + ) + } + + @Test + fun testSimpleMul() { + check( + DoubleExamples::simpleMul, + eq(4), + { a, b, r -> (a * b).isNaN() && r == 0.0 }, + { a, b, r -> a * b > 33.1 && a * b < 33.875 && r == 1.1 }, + { a, b, r -> a * b <= 33.1 && r == 1.2 }, + { a, b, r -> a * b >= 33.875 && r == 1.2 } + ) + } + + @Test + fun testMul() { + check( + DoubleExamples::mul, + eq(6), + { a, b, r -> (a * b).isNaN() && r == 0.0 }, // 0 * inf || a == nan || b == nan + { a, b, r -> !(a * b > 33.32) && !(a * b > 33.333) && r == 1.3 }, // 1.3, 1-1 false, 2-1 false + { a, b, r -> a * b == 33.333 && r == 1.3 }, // 1.3, 1-1 true, 1-2 false, 2-1 false + { a, b, r -> a * b > 33.32 && a * b < 33.333 && r == 1.1 }, // 1.1, 1st true + { a, b, r -> a * b > 33.333 && a * b < 33.7592 && r == 1.2 }, // 1.2, 1st false, 2nd true + { a, b, r -> a * b >= 33.7592 && r == 1.3 } // 1.3, 1-1 false, 2-1 true, 2-2 false + ) + } + + @Test + fun testCheckNonInteger() { + check( + DoubleExamples::checkNonInteger, + eq(3), + { a, r -> !(a > 0.1) && r == 0.0 }, + { a, r -> a > 0.1 && !(a < 0.9) && r == 0.0 }, + { a, r -> a > 0.1 && a < 0.9 && r == 1.0 } + ) + } + + @Test + fun testDiv() { + check( + DoubleExamples::div, + eq(1), + { a, b, c, r -> r == (a + b) / c || (r!!.isNaN() && (a + b + c).isNaN()) } + ) + } + + @Test + fun testSimpleEquation() { + check( + DoubleExamples::simpleEquation, + eq(2), + { x, r -> x + x + x - 9 == x + 3 && r == 0 }, + { x, r -> x + x + x - 9 != x + 3 && r == 1 } + ) + } + + @Test + fun testSimpleNonLinearEquation() { + check( + DoubleExamples::simpleNonLinearEquation, + eq(2), + { x, r -> 3 * x - 9 == x + 3 && r == 0 }, + { x, r -> 3 * x - 9 != x + 3 && r == 1 } + ) + } + + @Test + fun testCheckNaN() { + check( + DoubleExamples::checkNaN, + eq(4), + { d, r -> !d.isNaN() && d < 0 && r == -1 }, + { d, r -> !d.isNaN() && d == 0.0 && r == 0 }, + { d, r -> !d.isNaN() && d > 0 && r == 1 }, + { d, r -> d.isNaN() && r == 100 } + ) + } + + @Test + fun testUnaryMinus() { + check( + DoubleExamples::unaryMinus, + eq(2), + { d, r -> !d.isNaN() && -d < 0 && r == -1 }, + { d, r -> d.isNaN() || -d >= 0 && r == 0 } + ) + } + + @Test + fun testDoubleInfinity() { + check( + DoubleExamples::doubleInfinity, + eq(3), + { d, r -> d == Double.POSITIVE_INFINITY && r == 1 }, + { d, r -> d == Double.NEGATIVE_INFINITY && r == 2 }, + { d, r -> !d.isInfinite() && r == 3 }, + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/FloatExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/FloatExamplesTest.kt new file mode 100644 index 0000000000..87baa7a2a3 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/FloatExamplesTest.kt @@ -0,0 +1,18 @@ +package org.utbot.examples.primitives + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker + +internal class FloatExamplesTest : UtValueTestCaseChecker(testClass = FloatExamples::class) { + @Test + fun testFloatInfinity() { + check( + FloatExamples::floatInfinity, + eq(3), + { f, r -> f == Float.POSITIVE_INFINITY && r == 1 }, + { f, r -> f == Float.NEGATIVE_INFINITY && r == 2 }, + { f, r -> !f.isInfinite() && r == 3 }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt new file mode 100644 index 0000000000..ba51507276 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt @@ -0,0 +1,119 @@ +package org.utbot.examples.primitives + +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +import org.utbot.testcheckers.eq + +@Suppress("ConvertTwoComparisonsToRangeCheck") +internal class IntExamplesTest : UtValueTestCaseChecker(testClass = IntExamples::class) { + @Test + @Disabled("SAT-1009 [JAVA] Engine can't analyze isInteger") + fun testIsInteger() { + val method = IntExamples::isInteger + checkStaticMethod( + method, + eq(2), + { value, r -> runCatching { Integer.valueOf(value) }.isSuccess && r == true }, + { value, r -> runCatching { Integer.valueOf(value) }.isFailure && r == false }, + ) + } + + @Test + fun testMax() { + check( + IntExamples::max, + eq(2), + { x, y, r -> x > y && r == x }, + { x, y, r -> x <= y && r == y } + ) + } + + @Test + fun testPreferableLt() { + check( + IntExamples::preferableLt, + eq(2), + { x, r -> x == 41 && r == 41 }, + { x, r -> x == 42 && r == 42 } + ) + } + + @Test + fun testPreferableLe() { + check( + IntExamples::preferableLe, + eq(2), + { x, r -> x == 42 && r == 42 }, + { x, r -> x == 43 && r == 43 } + ) + } + + @Test + fun testPreferableGe() { + check( + IntExamples::preferableGe, + eq(2), + { x, r -> x == 42 && r == 42 }, + { x, r -> x == 41 && r == 41 } + ) + } + + @Test + fun testPreferableGt() { + check( + IntExamples::preferableGt, + eq(2), + { x, r -> x == 43 && r == 43 }, + { x, r -> x == 42 && r == 42 } + ) + } + + + @Test + fun testCompare() { + check( + IntExamples::complexCompare, + eq(6), + { a, b, r -> a < b && b < 11 && r == 0 }, + { a, b, r -> a < b && b > 11 && r == 1 }, + { a, b, r -> a == b && b == 11 && r == 3 }, + { a, b, r -> a == b && b != 11 && r == 6 }, + { a, b, r -> a < b && b == 11 && r == 6 }, + { a, b, r -> a > b && r == 6 } + ) + } + + @Test + fun testComplexCondition() { + check( + IntExamples::complexCondition, + eq(3), + { _, b, r -> b + 10 >= b + 22 && r == 0 }, // negative overflow, result = 1 + { a, b, r -> b + 10 < b + 22 && b + 22 >= a + b + 10 && r == 0 }, + { a, b, r -> b + 10 < b + 22 && b + 22 < a + b + 10 && r == 1 } // overflow involved + ) + } + + @Test + fun testOrderCheck() { + check( + IntExamples::orderCheck, + eq(3), + { first, second, _, r -> first >= second && r == false }, + { first, second, third, r -> first < second && second >= third && r == false }, + { first, second, third, r -> first < second && second < third && r == true } + ) + } + + @Test + fun testOrderCheckWithMethods() { + check( + IntExamples::orderCheckWithMethods, + eq(3), + { first, second, _, r -> first >= second && r == false }, + { first, second, third, r -> first < second && second >= third && r == false }, + { first, second, third, r -> first < second && second < third && r == true } + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt new file mode 100644 index 0000000000..a5ee5eda7e --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt @@ -0,0 +1,138 @@ +package org.utbot.examples.recursion + +import org.utbot.framework.plugin.api.DocCodeStmt +import org.utbot.framework.plugin.api.DocPreTagStatement +import org.utbot.framework.plugin.api.DocRegularStmt +import org.utbot.framework.plugin.api.DocStatement +import kotlin.math.pow +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq +import org.utbot.testcheckers.ge + +// TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 +internal class RecursionTest : UtValueTestCaseChecker( + testClass = Recursion::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testFactorial() { + val factorialSummary = listOf( + DocPreTagStatement( + listOf( + DocRegularStmt("Test "), + DocRegularStmt("returns from: "), + DocCodeStmt("return 1;"), + DocRegularStmt("\n"), + ) + ) + ) + + checkWithException( + Recursion::factorial, + eq(3), + { x, r -> x < 0 && r.isException() }, + { x, r -> x == 0 && r.getOrNull() == 1 }, + { x, r -> x > 0 && r.getOrNull() == (1..x).reduce { a, b -> a * b } }, + summaryTextChecks = listOf( + keyContain(DocCodeStmt("(n < 0): True")), + keyMatch(factorialSummary), + keyContain(DocCodeStmt("(n == 0): False")) + ), + summaryNameChecks = listOf( + keyMatch("testFactorial_NLessThanZero"), + keyMatch("testFactorial_Return1"), + keyMatch("testFactorial_NNotEqualsZero") + ), + summaryDisplayNameChecks = listOf( + keyMatch("-> return 1"), + keyMatch("n < 0 -> ThrowIllegalArgumentException"), + keyMatch("-> return 1") + ) + ) + } + + @Test + fun testFib() { + checkWithException( + Recursion::fib, + eq(4), + { x, r -> x < 0 && r.isException() }, + { x, r -> x == 0 && r.getOrNull() == 0 }, + { x, r -> x == 1 && r.getOrNull() == 1 }, + { x, r -> x > 1 && r.getOrNull() == Recursion().fib(x) } + ) + } + + @Test + @Disabled("Freezes the execution when snd != 0 JIRA:1293") + fun testSum() { + check( + Recursion::sum, + eq(2), + { x, y, r -> y == 0 && r == x }, + { x, y, r -> y != 0 && r == x + y } + ) + } + + @Test + fun testPow() { + checkWithException( + Recursion::pow, + eq(4), + { _, y, r -> y < 0 && r.isException() }, + { _, y, r -> y == 0 && r.getOrNull() == 1 }, + { x, y, r -> y % 2 == 1 && r.getOrNull() == x.toDouble().pow(y.toDouble()).toInt() }, + { x, y, r -> y % 2 != 1 && r.getOrNull() == x.toDouble().pow(y.toDouble()).toInt() } + ) + } + + @Test + fun infiniteRecursionTest() { + checkWithException( + Recursion::infiniteRecursion, + eq(2), + { x, r -> x > 10000 && r.isException() }, + { x, r -> x <= 10000 && r.isException() }, + coverage = atLeast(50) + ) + } + + @Test + fun vertexSumTest() { + check( + Recursion::vertexSum, + between(2..3), + { x, _ -> x <= 10 }, + { x, _ -> x > 10 } + ) + } + + @Test + fun recursionWithExceptionTest() { + checkWithException( + Recursion::recursionWithException, + ge(3), + { x, r -> x < 42 && r.isException() }, + { x, r -> x == 42 && r.isException() }, + { x, r -> x > 42 && r.isException() }, + coverage = atLeast(50) + ) + } + + @Test + fun recursionLoopTest() { + check( + Recursion::firstMethod, + eq(2), + { x, _ -> x < 4 }, + { x, _ -> x >= 4 }, + coverage = atLeast(50) + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/statics/substitution/StaticsSubstitutionTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/statics/substitution/StaticsSubstitutionTest.kt new file mode 100644 index 0000000000..0b97f4e0c7 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/statics/substitution/StaticsSubstitutionTest.kt @@ -0,0 +1,30 @@ +package org.utbot.examples.statics.substitution + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testcheckers.withoutSubstituteStaticsWithSymbolicVariable + +class StaticsSubstitutionTest : UtValueTestCaseChecker(testClass = StaticSubstitutionExamples::class) { + + @Test + fun lessThanZeroWithSubstitution() { + check( + StaticSubstitutionExamples::lessThanZero, + eq(2), + { r -> r != 0 }, + { r -> r == 0 }, + ) + } + + @Test + fun lessThanZeroWithoutSubstitution() { + withoutSubstituteStaticsWithSymbolicVariable { + checkWithoutStaticsSubstitution( + StaticSubstitutionExamples::lessThanZero, + eq(1), + { r -> r != 0 }, + coverage = DoNotCalculate, + ) + } + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt new file mode 100644 index 0000000000..ddbe69d720 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt @@ -0,0 +1,67 @@ +package org.utbot.examples.stdlib + +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Tag +import org.junit.jupiter.api.Test + + +import org.utbot.testcheckers.eq +import org.utbot.testcheckers.withUsingReflectionForMaximizingCoverage +import java.util.Date + +@Disabled("Java 11 transition -- these tests seems to take too much time and memory") +class DateExampleTest : UtValueTestCaseChecker(testClass = DateExample::class) { + @Suppress("SpellCheckingInspection") + @Tag("slow") + @Test + fun testGetTimeWithNpeChecksForNonPublicFields() { + withUsingReflectionForMaximizingCoverage(maximizeCoverage = true) { + checkWithException( + DateExample::getTime, + eq(5), + *commonMatchers, + { date: Date?, r: Result -> + val cdate = date!!.getDeclaredFieldValue("cdate") + val calendarDate = cdate!!.getDeclaredFieldValue("date") + + calendarDate == null && r.isException() + }, + { date: Date?, r: Result -> + val cdate = date!!.getDeclaredFieldValue("cdate") + val calendarDate = cdate!!.getDeclaredFieldValue("date") + + val gcal = date.getDeclaredFieldValue("gcal") + + val normalized = calendarDate!!.getDeclaredFieldValue("normalized") as Boolean + val gregorianYear = calendarDate.getDeclaredFieldValue("gregorianYear") as Int + + gcal == null && !normalized && gregorianYear >= 1582 && r.isException() + } + ) + } + } + + @Test + fun testGetTimeWithoutReflection() { + withUsingReflectionForMaximizingCoverage(maximizeCoverage = false) { + checkWithException( + DateExample::getTime, + eq(3), + *commonMatchers + ) + } + } + + private val commonMatchers = arrayOf( + { date: Date?, r: Result -> date == null && r.isException() }, + { date: Date?, r: Result -> date != null && date.time == 100L && r.getOrThrow() }, + { date: Date?, r: Result -> date != null && date.time != 100L && !r.getOrThrow() } + ) + + private fun Any.getDeclaredFieldValue(fieldName: String): Any? { + val declaredField = javaClass.getDeclaredField(fieldName) + declaredField.isAccessible = true + + return declaredField.get(this) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt new file mode 100644 index 0000000000..b3bed63f70 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt @@ -0,0 +1,462 @@ +package org.utbot.examples.stream + +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Tag +import org.junit.jupiter.api.Test + + + + + + + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq +import org.utbot.testcheckers.withoutConcrete + + +import java.util.Optional +import java.util.stream.Stream +import kotlin.streams.toList + +// TODO 1 instruction is always uncovered https://github.com/UnitTestBot/UTBotJava/issues/193 +// TODO failed Kotlin compilation (generics) JIRA:1332 +class BaseStreamExampleTest : UtValueTestCaseChecker( + testClass = BaseStreamExample::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testReturningStreamAsParameterExample() { + withoutConcrete { + check( + BaseStreamExample::returningStreamAsParameterExample, + eq(1), + { s, r -> s != null && s.toList() == r!!.toList() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + } + + @Test + fun testFilterExample() { + check( + BaseStreamExample::filterExample, + ignoreExecutionsNumber, + { c, r -> null !in c && r == false }, + { c, r -> null in c && r == true }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMapExample() { + checkWithException( + BaseStreamExample::mapExample, + ignoreExecutionsNumber, + { c, r -> null in c && r.isException() }, + { c, r -> r.getOrThrow().contentEquals(c.map { it * 2 }.toTypedArray()) }, + coverage = AtLeast(90) + ) + } + + @Test + @Tag("slow") + fun testMapToIntExample() { + checkWithException( + BaseStreamExample::mapToIntExample, + ignoreExecutionsNumber, + { c, r -> null in c && r.isException() }, + { c, r -> r.getOrThrow().contentEquals(c.map { it.toInt() }.toIntArray()) }, + coverage = AtLeast(90) + ) + } + + @Test + @Tag("slow") + fun testMapToLongExample() { + checkWithException( + BaseStreamExample::mapToLongExample, + ignoreExecutionsNumber, + { c, r -> null in c && r.isException() }, + { c, r -> r.getOrThrow().contentEquals(c.map { it.toLong() }.toLongArray()) }, + coverage = AtLeast(90) + ) + } + + @Test + @Tag("slow") + fun testMapToDoubleExample() { + checkWithException( + BaseStreamExample::mapToDoubleExample, + ignoreExecutionsNumber, + { c, r -> null in c && r.isException() }, + { c, r -> r.getOrThrow().contentEquals(c.map { it.toDouble() }.toDoubleArray()) }, + coverage = AtLeast(90) + ) + } + + @Test + fun testFlatMapExample() { + check( + BaseStreamExample::flatMapExample, + ignoreExecutionsNumber, + { c, r -> r.contentEquals(c.flatMap { listOf(it, it) }.toTypedArray()) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + @Tag("slow") + fun testFlatMapToIntExample() { + check( + BaseStreamExample::flatMapToIntExample, + ignoreExecutionsNumber, + { c, r -> r.contentEquals(c.flatMap { listOf(it?.toInt() ?: 0, it?.toInt() ?: 0) }.toIntArray()) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testFlatMapToLongExample() { + check( + BaseStreamExample::flatMapToLongExample, + ignoreExecutionsNumber, + { c, r -> r.contentEquals(c.flatMap { listOf(it?.toLong() ?: 0L, it?.toLong() ?: 0L) }.toLongArray()) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testFlatMapToDoubleExample() { + check( + BaseStreamExample::flatMapToDoubleExample, + ignoreExecutionsNumber, + { c, r -> r.contentEquals(c.flatMap { listOf(it?.toDouble() ?: 0.0, it?.toDouble() ?: 0.0) }.toDoubleArray()) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + @Tag("slow") + fun testDistinctExample() { + check( + BaseStreamExample::distinctExample, + ignoreExecutionsNumber, + { c, r -> c == c.distinct() && r == false }, + { c, r -> c != c.distinct() && r == true }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + @Tag("slow") + // TODO slow sorting https://github.com/UnitTestBot/UTBotJava/issues/188 + fun testSortedExample() { + check( + BaseStreamExample::sortedExample, + ignoreExecutionsNumber, + { c, r -> c.last() < c.first() && r!!.asSequence().isSorted() }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + + @Test + fun testPeekExample() { + checkThisAndStaticsAfter( + BaseStreamExample::peekExample, + ignoreExecutionsNumber, + *streamConsumerStaticsMatchers, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testLimitExample() { + check( + BaseStreamExample::limitExample, + ignoreExecutionsNumber, + { c, r -> c.size <= 5 && c.toTypedArray().contentEquals(r) }, + { c, r -> c.size > 5 && c.take(5).toTypedArray().contentEquals(r) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testSkipExample() { + check( + BaseStreamExample::skipExample, + ignoreExecutionsNumber, + { c, r -> c.size > 5 && c.drop(5).toTypedArray().contentEquals(r) }, + { c, r -> c.size <= 5 && r!!.isEmpty() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testForEachExample() { + checkThisAndStaticsAfter( + BaseStreamExample::forEachExample, + ignoreExecutionsNumber, + *streamConsumerStaticsMatchers, + coverage = AtLeast(92) + ) + } + + @Test + fun testToArrayExample() { + check( + BaseStreamExample::toArrayExample, + eq(2), + { c, r -> c.toTypedArray().contentEquals(r) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testReduceExample() { + check( + BaseStreamExample::reduceExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == 42 }, + { c, r -> c.isNotEmpty() && r == c.sum() + 42 }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testOptionalReduceExample() { + checkWithException( + BaseStreamExample::optionalReduceExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r.getOrThrow() == Optional.empty() }, + { c, r -> c.isNotEmpty() && c.single() == null && r.isException() }, + { c, r -> c.isNotEmpty() && r.getOrThrow() == Optional.of(c.sum()) }, + coverage = DoNotCalculate // TODO 2 instructions are uncovered https://github.com/UnitTestBot/UTBotJava/issues/193 + ) + } + + @Test + fun testComplexReduceExample() { + check( + BaseStreamExample::complexReduceExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && c.sumOf { it.toDouble() } + 42.0 == r }, + { c: List, r -> c.isNotEmpty() && c.sumOf { it?.toDouble() ?: 0.0 } + 42.0 == r }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + @Disabled("TODO zero executions https://github.com/UnitTestBot/UTBotJava/issues/207") + fun testCollectorExample() { + check( + BaseStreamExample::collectorExample, + ignoreExecutionsNumber, + { c, r -> c.toSet() == r }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testCollectExample() { + checkWithException( + BaseStreamExample::collectExample, + ignoreExecutionsNumber, // 3 executions instead of 2 expected + { c, r -> null in c && r.isException() }, + { c, r -> null !in c && c.sum() == r.getOrThrow() }, + coverage = DoNotCalculate // TODO 2 instructions are uncovered https://github.com/UnitTestBot/UTBotJava/issues/193 + ) + } + + @Test + fun testMinExample() { + checkWithException( + BaseStreamExample::minExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r.getOrThrow() == Optional.empty() }, + { c, r -> c.isNotEmpty() && c.all { it == null } && r.isException() }, + { c, r -> c.isNotEmpty() && r.getOrThrow() == Optional.of(c.minOrNull()!!) }, + coverage = DoNotCalculate // TODO 2 instructions are uncovered https://github.com/UnitTestBot/UTBotJava/issues/193 + ) + } + + @Test + fun testMaxExample() { + checkWithException( + BaseStreamExample::maxExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r.getOrThrow() == Optional.empty() }, + { c, r -> c.isNotEmpty() && c.all { it == null } && r.isException() }, + { c, r -> c.isNotEmpty() && r.getOrThrow() == Optional.of(c.maxOrNull()!!) }, + coverage = DoNotCalculate // TODO 2 instructions are uncovered https://github.com/UnitTestBot/UTBotJava/issues/193 + ) + } + + @Test + fun testCountExample() { + check( + BaseStreamExample::countExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == 0L }, + { c, r -> c.isNotEmpty() && c.size.toLong() == r }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testAnyMatchExample() { + check( + BaseStreamExample::anyMatchExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == false }, + { c, r -> c.isNotEmpty() && c.all { it == null } && r == true }, + { c, r -> c.isNotEmpty() && c.first() != null && c.last() == null && r == true }, + { c, r -> c.isNotEmpty() && c.first() == null && c.last() != null && r == true }, + { c, r -> c.isNotEmpty() && c.none { it == null } && r == false }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + + @Test + fun testAllMatchExample() { + check( + BaseStreamExample::allMatchExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == true }, + { c, r -> c.isNotEmpty() && c.all { it == null } && r == true }, + { c, r -> c.isNotEmpty() && c.first() != null && c.last() == null && r == false }, + { c, r -> c.isNotEmpty() && c.first() == null && c.last() != null && r == false }, + { c, r -> c.isNotEmpty() && c.none { it == null } && r == false }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + + @Test + fun testNoneMatchExample() { + check( + BaseStreamExample::noneMatchExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == true }, + { c, r -> c.isNotEmpty() && c.all { it == null } && r == false }, + { c, r -> c.isNotEmpty() && c.first() != null && c.last() == null && r == false }, + { c, r -> c.isNotEmpty() && c.first() == null && c.last() != null && r == false }, + { c, r -> c.isNotEmpty() && c.none { it == null } && r == true }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + + @Test + fun testFindFirstExample() { + checkWithException( + BaseStreamExample::findFirstExample, + eq(3), + { c, r -> c.isEmpty() && r.getOrThrow() == Optional.empty() }, + { c: List, r -> c.isNotEmpty() && c.first() == null && r.isException() }, + { c, r -> c.isNotEmpty() && r.getOrThrow() == Optional.of(c.first()) }, + coverage = DoNotCalculate + ) + } + + @Test + fun testIteratorExample() { + checkWithException( + BaseStreamExample::iteratorSumExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r.getOrThrow() == 0 }, + { c, r -> null in c && r.isException() }, + { c, r -> c.isNotEmpty() && null !in c && r.getOrThrow() == c.sum() }, + coverage = AtLeast(75) + ) + } + + @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) + ) + } + } + + @Test + fun testClosedStreamExample() { + checkWithException( + BaseStreamExample::closedStreamExample, + eq(1), + { _, r -> r.isException() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCustomCollectionStreamExample() { + check( + BaseStreamExample::customCollectionStreamExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == 0L }, + { c, r -> c.isNotEmpty() && c.size.toLong() == r }, + coverage = DoNotCalculate // TODO failed coverage calculation + ) + } + + @Test + fun testAnyCollectionStreamExample() { + check( + BaseStreamExample::anyCollectionStreamExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == 0L }, + { c, r -> c.isNotEmpty() && c.size.toLong() == r }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testGenerateExample() { + check( + BaseStreamExample::generateExample, + ignoreExecutionsNumber, + { r -> r!!.contentEquals(Array(10) { 42 }) }, + coverage = Full + ) + } + + @Test + fun testIterateExample() { + check( + BaseStreamExample::iterateExample, + ignoreExecutionsNumber, + { r -> r!!.contentEquals(Array(10) { i -> 42 + i }) }, + coverage = Full + ) + } + + @Test + fun testConcatExample() { + check( + BaseStreamExample::concatExample, + ignoreExecutionsNumber, + { r -> r!!.contentEquals(Array(10) { 42 } + Array(10) { i -> 42 + i }) }, + coverage = Full + ) + } +} + +internal val streamConsumerStaticsMatchers = arrayOf( + { _: Any, c: List, _: StaticsType, _: Int? -> null in c }, + { _: Any, c: List, statics: StaticsType, r: Int? -> + val x = statics.values.single().value as Int + + r!! + c.sumOf { it ?: 0 } == x + } +) + +internal fun > Sequence.isSorted(): Boolean = zipWithNext { a, b -> a <= b }.all { it } diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/stream/DoubleStreamExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/stream/DoubleStreamExampleTest.kt new file mode 100644 index 0000000000..71062b8b82 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/stream/DoubleStreamExampleTest.kt @@ -0,0 +1,534 @@ +package org.utbot.examples.stream + +import org.junit.jupiter.api.Tag +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 java.util.OptionalDouble +import java.util.stream.DoubleStream +import kotlin.streams.toList + +// TODO failed Kotlin compilation (generics) JIRA:1332 +@Tag("slow") // we do not really need to always use this test in CI because it is almost the same as BaseStreamExampleTest +class DoubleStreamExampleTest : UtValueTestCaseChecker( + testClass = DoubleStreamExample::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testReturningStreamAsParameterExample() { + withoutConcrete { + check( + DoubleStreamExample::returningStreamAsParameterExample, + eq(1), + { s, r -> s != null && s.toList() == r!!.toList() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + } + + @Test + fun testUseParameterStream() { + check( + DoubleStreamExample::useParameterStream, + eq(2), + { s, r -> s.toArray().isEmpty() && r == 0 }, + { s, r -> s.toArray().let { + it.isNotEmpty() && r == it.size } + }, + coverage = AtLeast(94) + ) + } + + @Test + fun testFilterExample() { + check( + DoubleStreamExample::filterExample, + ignoreExecutionsNumber, + { c, r -> null !in c && r == false }, + { c, r -> null in c && r == true }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMapExample() { + check( + DoubleStreamExample::mapExample, + ignoreExecutionsNumber, + { c, r -> null in c && r.contentEquals(c.doubles { it?.toDouble()?.times(2) ?: 0.0 }) }, + { c: List, r -> null !in c && r.contentEquals(c.doubles { it?.toDouble()?.times(2) ?: 0.0 }) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMapToObjExample() { + check( + DoubleStreamExample::mapToObjExample, + ignoreExecutionsNumber, + { c, r -> + val intArrays = c.doubles().map { it.let { i -> doubleArrayOf(i, i) } }.toTypedArray() + + null in c && intArrays.zip(r as Array) + .all { it.first.contentEquals(it.second as DoubleArray?) } + }, + { c: List, r -> + val intArrays = c.doubles().map { it.let { i -> doubleArrayOf(i, i) } }.toTypedArray() + + null !in c && intArrays.zip(r as Array) + .all { it.first.contentEquals(it.second as DoubleArray?) } + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMapToIntExample() { + check( + DoubleStreamExample::mapToIntExample, + ignoreExecutionsNumber, + { c, r -> + val ints = c.doubles().map { it.toInt() }.toIntArray() + + null in c && ints.contentEquals(r) + }, + { c: List, r -> + val ints = c.doubles().map { it.toInt() }.toIntArray() + + null !in c && ints.contentEquals(r) + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMapToLongExample() { + check( + DoubleStreamExample::mapToLongExample, + ignoreExecutionsNumber, + { c, r -> + val longs = c.doubles().map { it.toLong() }.toLongArray() + + null in c && longs.contentEquals(r) + }, + { c: List, r -> + val longs = c.doubles().map { it.toLong() }.toLongArray() + + null !in c && longs.contentEquals(r) + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testFlatMapExample() { + check( + DoubleStreamExample::flatMapExample, + ignoreExecutionsNumber, + { c, r -> + val intLists = c.mapNotNull { + it.toDouble().let { i -> listOf(i, i) } + } + + r!!.contentEquals(intLists.flatten().toDoubleArray()) + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testDistinctExample() { + check( + DoubleStreamExample::distinctExample, + ignoreExecutionsNumber, + { c, r -> + val doubles = c.doubles() + + doubles.contentEquals(doubles.distinct().toDoubleArray()) && r == false + }, + { c, r -> + val doubles = c.doubles() + + !doubles.contentEquals(doubles.distinct().toDoubleArray()) && r == true + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + @Tag("slow") + // TODO slow sorting https://github.com/UnitTestBot/UTBotJava/issues/188 + fun testSortedExample() { + check( + DoubleStreamExample::sortedExample, + ignoreExecutionsNumber, + { c, r -> c.last() < c.first() && r!!.asSequence().isSorted() }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + + @Test + fun testPeekExample() { + checkThisAndStaticsAfter( + DoubleStreamExample::peekExample, + ignoreExecutionsNumber, + *streamConsumerStaticsMatchers, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testLimitExample() { + check( + DoubleStreamExample::limitExample, + ignoreExecutionsNumber, + { c, r -> c.size <= 2 && c.doubles().contentEquals(r) }, + { c, r -> c.size > 2 && c.take(2).doubles().contentEquals(r) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testSkipExample() { + check( + DoubleStreamExample::skipExample, + ignoreExecutionsNumber, + { c, r -> c.size > 2 && c.drop(2).doubles().contentEquals(r) }, + { c, r -> c.size <= 2 && r!!.isEmpty() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testForEachExample() { + checkThisAndStaticsAfter( + DoubleStreamExample::forEachExample, + ignoreExecutionsNumber, + *streamConsumerStaticsMatchers, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testToArrayExample() { + check( + DoubleStreamExample::toArrayExample, + ignoreExecutionsNumber, + { c, r -> c.doubles().contentEquals(r) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testReduceExample() { + check( + DoubleStreamExample::reduceExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == 42.0 }, + { c: List, r -> c.isNotEmpty() && r == c.filterNotNull().sum() + 42.0 }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testOptionalReduceExample() { + checkWithException( + DoubleStreamExample::optionalReduceExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r.getOrThrow() == OptionalDouble.empty() }, + { c: List, r -> + c.isNotEmpty() && r.getOrThrow() == OptionalDouble.of( + c.filterNotNull().sum().toDouble() + ) + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testSumExample() { + check( + DoubleStreamExample::sumExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == 0.0 }, + { c, r -> c.isNotEmpty() && c.filterNotNull().sum().toDouble() == r }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMinExample() { + checkWithException( + DoubleStreamExample::minExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r.getOrThrow() == OptionalDouble.empty() }, + { c, r -> + c.isNotEmpty() && r.getOrThrow() == OptionalDouble.of(c.mapNotNull { it.toDouble() }.minOrNull()!!) + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMaxExample() { + checkWithException( + DoubleStreamExample::maxExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r.getOrThrow() == OptionalDouble.empty() }, + { c, r -> + c.isNotEmpty() && r.getOrThrow() == OptionalDouble.of(c.mapNotNull { it.toDouble() }.maxOrNull()!!) + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testCountExample() { + check( + DoubleStreamExample::countExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == 0L }, + { c, r -> c.isNotEmpty() && c.size.toLong() == r }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testAverageExample() { + check( + DoubleStreamExample::averageExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == OptionalDouble.empty() }, + { c, r -> c.isNotEmpty() && c.mapNotNull { it.toDouble() }.average() == r!!.asDouble }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @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 + + 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 + + val doubles = c.doubles() + + val allStatisticsAreCorrect = sum == doubles.sum() && + count == doubles.size.toLong() && + min == doubles.minOrNull() && + max == doubles.maxOrNull() + + c.isNotEmpty() && allStatisticsAreCorrect + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + } + + @Test + fun testAnyMatchExample() { + // TODO exceeds even default step limit 3500 => too slow + withPathSelectorStepsLimit(2000) { + check( + DoubleStreamExample::anyMatchExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == false }, + { c, r -> c.isNotEmpty() && c.doubles().all { it == 0.0 } && r == false }, + { c, r -> + val doubles = c.doubles() + + c.isNotEmpty() && doubles.first() != 0.0 && doubles.last() == 0.0 && r == true + }, + { c, r -> + val doubles = c.doubles() + + c.isNotEmpty() && doubles.first() == 0.0 && doubles.last() != 0.0 && r == true + }, + { c, r -> + val doubles = c.doubles() + + c.isNotEmpty() && doubles.none { it == 0.0 } && r == true + }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + } + + @Test + fun testAllMatchExample() { + // TODO exceeds even default step limit 3500 => too slow + withPathSelectorStepsLimit(2000) { + check( + DoubleStreamExample::allMatchExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == true }, + { c, r -> c.isNotEmpty() && c.doubles().all { it == 0.0 } && r == false }, + { c, r -> + val doubles = c.doubles() + + c.isNotEmpty() && doubles.first() != 0.0 && doubles.last() == 0.0 && r == false + }, + { c, r -> + val doubles = c.doubles() + + c.isNotEmpty() && doubles.first() == 0.0 && doubles.last() != 0.0 && r == false + }, + { c, r -> + val doubles = c.doubles() + + c.isNotEmpty() && doubles.none { it == 0.0 } && r == true + }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + } + + @Test + fun testNoneMatchExample() { + // TODO exceeds even default step limit 3500 => too slow + withPathSelectorStepsLimit(2000) { + check( + DoubleStreamExample::noneMatchExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == true }, + { c, r -> c.isNotEmpty() && c.doubles().all { it == 0.0 } && r == true }, + { c, r -> + val doubles = c.doubles() + + c.isNotEmpty() && doubles.first() != 0.0 && doubles.last() == 0.0 && r == false + }, + { c, r -> + val doubles = c.doubles() + + c.isNotEmpty() && doubles.first() == 0.0 && doubles.last() != 0.0 && r == false + }, + { c, r -> + val doubles = c.doubles() + + c.isNotEmpty() && doubles.none { it == 0.0 } && r == false + }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + } + + @Test + fun testFindFirstExample() { + check( + DoubleStreamExample::findFirstExample, + eq(3), + { c, r -> c.isEmpty() && r == OptionalDouble.empty() }, + { c, r -> c.isNotEmpty() && r == OptionalDouble.of(c.doubles().first()) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testBoxedExample() { + check( + DoubleStreamExample::boxedExample, + ignoreExecutionsNumber, + { c, r -> c.doubles().toList() == r!!.toList() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testIteratorExample() { + // TODO exceeds even default step limit 3500 => too slow + withPathSelectorStepsLimit(1000) { + check( + DoubleStreamExample::iteratorSumExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == 0.0 }, + { c: List, r -> c.isNotEmpty() && c.doubles().sum() == r }, + coverage = AtLeast(76) + ) + } + } + + @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) + ) + } + } + + @Test + fun testClosedStreamExample() { + // TODO exceeds even default step limit 3500 => too slow + withPathSelectorStepsLimit(500) { + checkWithException( + DoubleStreamExample::closedStreamExample, + ignoreExecutionsNumber, + { _, r -> r.isException() }, + coverage = AtLeast(88) + ) + } + } + + @Test + fun testGenerateExample() { + check( + DoubleStreamExample::generateExample, + ignoreExecutionsNumber, + { r -> r!!.contentEquals(DoubleArray(10) { 42.0 }) }, + coverage = Full + ) + } + + @Test + fun testIterateExample() { + check( + DoubleStreamExample::iterateExample, + ignoreExecutionsNumber, + { r -> r!!.contentEquals(DoubleArray(10) { i -> 42.0 + i }) }, + coverage = Full + ) + } + + @Test + fun testConcatExample() { + check( + DoubleStreamExample::concatExample, + ignoreExecutionsNumber, + { r -> r!!.contentEquals(DoubleArray(10) { 42.0 } + DoubleArray(10) { i -> 42.0 + i }) }, + coverage = Full + ) + } +} + +private fun List.doubles(mapping: (Short?) -> Double = { it?.toDouble() ?: 0.0 }): DoubleArray = + map { mapping(it) }.toDoubleArray() diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/stream/IntStreamExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/stream/IntStreamExampleTest.kt new file mode 100644 index 0000000000..89a8b5d69e --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/stream/IntStreamExampleTest.kt @@ -0,0 +1,565 @@ +package org.utbot.examples.stream + +import org.junit.jupiter.api.Tag +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 java.util.OptionalDouble +import java.util.OptionalInt +import java.util.stream.IntStream +import kotlin.streams.toList + +// TODO failed Kotlin compilation (generics) JIRA:1332 +@Tag("slow") // we do not really need to always use this test in CI because it is almost the same as BaseStreamExampleTest +class IntStreamExampleTest : UtValueTestCaseChecker( + testClass = IntStreamExample::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testReturningStreamAsParameterExample() { + withoutConcrete { + check( + IntStreamExample::returningStreamAsParameterExample, + eq(1), + { s, r -> s != null && s.toList() == r!!.toList() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + } + + @Test + fun testUseParameterStream() { + check( + IntStreamExample::useParameterStream, + eq(2), + { s, r -> s.toArray().isEmpty() && r == 0 }, + { s, r -> s.toArray().let { + it.isNotEmpty() && r == it.size } + }, + coverage = AtLeast(94) + ) + } + + @Test + fun testFilterExample() { + check( + IntStreamExample::filterExample, + ignoreExecutionsNumber, + { c, r -> null !in c && r == false }, + { c, r -> null in c && r == true }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMapExample() { + check( + IntStreamExample::mapExample, + ignoreExecutionsNumber, + { c, r -> null in c && r.contentEquals(c.ints { it?.toInt()?.times(2) ?: 0 }) }, + { c: List, r -> null !in c && r.contentEquals(c.ints { it?.toInt()?.times(2) ?: 0 }) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMapToObjExample() { + check( + IntStreamExample::mapToObjExample, + ignoreExecutionsNumber, + { c, r -> + val intArrays = c.ints().map { it.let { i -> intArrayOf(i, i) } }.toTypedArray() + + null in c && intArrays.zip(r as Array).all { it.first.contentEquals(it.second as IntArray?) } + }, + { c: List, r -> + val intArrays = c.ints().map { it.let { i -> intArrayOf(i, i) } }.toTypedArray() + + null !in c && intArrays.zip(r as Array).all { it.first.contentEquals(it.second as IntArray?) } + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMapToLongExample() { + check( + IntStreamExample::mapToLongExample, + ignoreExecutionsNumber, + { c, r -> + val longs = c.ints().map { it.toLong() * 2 }.toLongArray() + + null in c && longs.contentEquals(r) + }, + { c: List, r -> + val longs = c.ints().map { it.toLong() * 2 }.toLongArray() + + null !in c && longs.contentEquals(r) + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMapToDoubleExample() { + check( + IntStreamExample::mapToDoubleExample, + ignoreExecutionsNumber, + { c, r -> + val doubles = c.ints().map { it.toDouble() / 2 }.toDoubleArray() + + null in c && doubles.contentEquals(r) + }, + { c: List, r -> + val doubles = c.filterNotNull().map { it.toDouble() / 2 }.toDoubleArray() + + null !in c && doubles.contentEquals(r) + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testFlatMapExample() { + check( + IntStreamExample::flatMapExample, + ignoreExecutionsNumber, + { c, r -> + val intLists = c.mapNotNull { + it.toInt().let { i -> listOf(i, i) } + } + + r!!.contentEquals(intLists.flatten().toIntArray()) + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testDistinctExample() { + check( + IntStreamExample::distinctExample, + ignoreExecutionsNumber, + { c, r -> + val ints = c.ints() + + ints.contentEquals(ints.distinct().toIntArray()) && r == false + }, + { c, r -> + val ints = c.ints() + + !ints.contentEquals(ints.distinct().toIntArray()) && r == true + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + @Tag("slow") + // TODO slow sorting https://github.com/UnitTestBot/UTBotJava/issues/188 + fun testSortedExample() { + check( + IntStreamExample::sortedExample, + ignoreExecutionsNumber, + { c, r -> c.last() < c.first() && r!!.asSequence().isSorted() }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + + @Test + fun testPeekExample() { + checkThisAndStaticsAfter( + IntStreamExample::peekExample, + ignoreExecutionsNumber, + *streamConsumerStaticsMatchers, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testLimitExample() { + check( + IntStreamExample::limitExample, + ignoreExecutionsNumber, + { c, r -> c.size <= 2 && c.ints().contentEquals(r) }, + { c, r -> c.size > 2 && c.take(2).ints().contentEquals(r) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testSkipExample() { + check( + IntStreamExample::skipExample, + ignoreExecutionsNumber, + { c, r -> c.size > 2 && c.drop(2).ints().contentEquals(r) }, + { c, r -> c.size <= 2 && r!!.isEmpty() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testForEachExample() { + checkThisAndStaticsAfter( + IntStreamExample::forEachExample, + ignoreExecutionsNumber, + *streamConsumerStaticsMatchers, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testToArrayExample() { + check( + IntStreamExample::toArrayExample, + ignoreExecutionsNumber, + { c, r -> c.ints().contentEquals(r) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testReduceExample() { + check( + IntStreamExample::reduceExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == 42 }, + { c: List, r -> c.isNotEmpty() && r == c.filterNotNull().sum() + 42 }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testOptionalReduceExample() { + checkWithException( + IntStreamExample::optionalReduceExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r.getOrThrow() == OptionalInt.empty() }, + { c: List, r -> c.isNotEmpty() && r.getOrThrow() == OptionalInt.of(c.filterNotNull().sum()) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testSumExample() { + check( + IntStreamExample::sumExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == 0 }, + { c, r -> c.isNotEmpty() && c.filterNotNull().sum() == r }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMinExample() { + checkWithException( + IntStreamExample::minExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r.getOrThrow() == OptionalInt.empty() }, + { c, r -> c.isNotEmpty() && r.getOrThrow() == OptionalInt.of(c.mapNotNull { it.toInt() }.minOrNull()!!) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMaxExample() { + checkWithException( + IntStreamExample::maxExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r.getOrThrow() == OptionalInt.empty() }, + { c, r -> c.isNotEmpty() && r.getOrThrow() == OptionalInt.of(c.mapNotNull { it.toInt() }.maxOrNull()!!) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testCountExample() { + check( + IntStreamExample::countExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == 0L }, + { c, r -> c.isNotEmpty() && c.size.toLong() == r }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testAverageExample() { + check( + IntStreamExample::averageExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == OptionalDouble.empty() }, + { c, r -> c.isNotEmpty() && c.mapNotNull { it.toInt() }.average() == r!!.asDouble }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @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 + + 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 + + val ints = c.ints() + + val allStatisticsAreCorrect = sum == ints.sum().toLong() && + count == ints.size.toLong() && + min == ints.minOrNull() && + max == ints.maxOrNull() + + c.isNotEmpty() && allStatisticsAreCorrect + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + } + + @Test + fun testAnyMatchExample() { + // TODO exceeds even default step limit 3500 => too slow + withPathSelectorStepsLimit(2000) { + check( + IntStreamExample::anyMatchExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == false }, + { c, r -> c.isNotEmpty() && c.ints().all { it == 0 } && r == false }, + { c, r -> + val ints = c.ints() + + c.isNotEmpty() && ints.first() != 0 && ints.last() == 0 && r == true + }, + { c, r -> + val ints = c.ints() + + c.isNotEmpty() && ints.first() == 0 && ints.last() != 0 && r == true + }, + { c, r -> + val ints = c.ints() + + c.isNotEmpty() && ints.none { it == 0 } && r == true + }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + } + + @Test + fun testAllMatchExample() { + // TODO exceeds even default step limit 3500 => too slow + withPathSelectorStepsLimit(2000) { + check( + IntStreamExample::allMatchExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == true }, + { c, r -> c.isNotEmpty() && c.ints().all { it == 0 } && r == false }, + { c, r -> + val ints = c.ints() + + c.isNotEmpty() && ints.first() != 0 && ints.last() == 0 && r == false + }, + { c, r -> + val ints = c.ints() + + c.isNotEmpty() && ints.first() == 0 && ints.last() != 0 && r == false + }, + { c, r -> + val ints = c.ints() + + c.isNotEmpty() && ints.none { it == 0 } && r == true + }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + } + + @Test + fun testNoneMatchExample() { + // TODO exceeds even default step limit 3500 => too slow + withPathSelectorStepsLimit(2000) { + check( + IntStreamExample::noneMatchExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == true }, + { c, r -> c.isNotEmpty() && c.ints().all { it == 0 } && r == true }, + { c, r -> + val ints = c.ints() + + c.isNotEmpty() && ints.first() != 0 && ints.last() == 0 && r == false + }, + { c, r -> + val ints = c.ints() + + c.isNotEmpty() && ints.first() == 0 && ints.last() != 0 && r == false + }, + { c, r -> + val ints = c.ints() + + c.isNotEmpty() && ints.none { it == 0 } && r == false + }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + } + + @Test + fun testFindFirstExample() { + check( + IntStreamExample::findFirstExample, + eq(3), + { c, r -> c.isEmpty() && r == OptionalInt.empty() }, + { c, r -> c.isNotEmpty() && r == OptionalInt.of(c.ints().first()) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testAsLongStreamExample() { + check( + IntStreamExample::asLongStreamExample, + ignoreExecutionsNumber, + { c, r -> c.ints().map { it.toLong() }.toList() == r!!.toList() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testAsDoubleStreamExample() { + check( + IntStreamExample::asDoubleStreamExample, + ignoreExecutionsNumber, + { c, r -> c.ints().map { it.toDouble() }.toList() == r!!.toList() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testBoxedExample() { + check( + IntStreamExample::boxedExample, + ignoreExecutionsNumber, + { c, r -> c.ints().toList() == r!!.toList() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testIteratorExample() { + // TODO exceeds even default step limit 3500 => too slow + withPathSelectorStepsLimit(1000) { + check( + IntStreamExample::iteratorSumExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == 0 }, + { c: List, r -> c.isNotEmpty() && c.ints().sum() == r }, + coverage = AtLeast(76) + ) + } + } + + @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) + ) + } + } + + @Test + fun testClosedStreamExample() { + // TODO exceeds even default step limit 3500 => too slow + withPathSelectorStepsLimit(500) { + checkWithException( + IntStreamExample::closedStreamExample, + ignoreExecutionsNumber, + { _, r -> r.isException() }, + coverage = AtLeast(88) + ) + } + } + + @Test + fun testGenerateExample() { + check( + IntStreamExample::generateExample, + ignoreExecutionsNumber, + { r -> r!!.contentEquals(IntArray(10) { 42 }) }, + coverage = Full + ) + } + + @Test + fun testIterateExample() { + check( + IntStreamExample::iterateExample, + ignoreExecutionsNumber, + { r -> r!!.contentEquals(IntArray(10) { i -> 42 + i }) }, + coverage = Full + ) + } + + @Test + fun testConcatExample() { + check( + IntStreamExample::concatExample, + ignoreExecutionsNumber, + { r -> r!!.contentEquals(IntArray(10) { 42 } + IntArray(10) { i -> 42 + i }) }, + coverage = Full + ) + } + + @Test + fun testRangeExample() { + check( + IntStreamExample::rangeExample, + ignoreExecutionsNumber, + { r -> r!!.contentEquals(IntArray(10) { it }) }, + coverage = Full + ) + } + + @Test + fun testRangeClosedExample() { + check( + IntStreamExample::rangeClosedExample, + ignoreExecutionsNumber, + { r -> r!!.contentEquals(IntArray(11) { it }) }, + coverage = Full + ) + } +} + +private fun List.ints(mapping: (Short?) -> Int = { it?.toInt() ?: 0 }): IntArray = + map { mapping(it) }.toIntArray() diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/stream/LongStreamExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/stream/LongStreamExampleTest.kt new file mode 100644 index 0000000000..7cac365890 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/stream/LongStreamExampleTest.kt @@ -0,0 +1,559 @@ +package org.utbot.examples.stream + +import org.junit.jupiter.api.Tag +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 java.util.OptionalDouble +import java.util.OptionalLong +import java.util.stream.LongStream +import kotlin.streams.toList + +// TODO failed Kotlin compilation (generics) JIRA:1332 +@Tag("slow") // we do not really need to always use this test in CI because it is almost the same as BaseStreamExampleTest +class LongStreamExampleTest : UtValueTestCaseChecker( + testClass = LongStreamExample::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testReturningStreamAsParameterExample() { + withoutConcrete { + check( + LongStreamExample::returningStreamAsParameterExample, + eq(1), + { s, r -> s != null && s.toList() == r!!.toList() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + } + + @Test + fun testUseParameterStream() { + check( + LongStreamExample::useParameterStream, + eq(2), + { s, r -> s.toArray().isEmpty() && r == 0 }, + { s, r -> s.toArray().let { + it.isNotEmpty() && r == it.size } + }, + coverage = AtLeast(94) + ) + } + + @Test + fun testFilterExample() { + check( + LongStreamExample::filterExample, + ignoreExecutionsNumber, + { c, r -> null !in c && r == false }, + { c, r -> null in c && r == true }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMapExample() { + check( + LongStreamExample::mapExample, + ignoreExecutionsNumber, + { c, r -> null in c && r.contentEquals(c.longs { it?.toLong()?.times(2) ?: 0L }) }, + { c: List, r -> null !in c && r.contentEquals(c.longs { it?.toLong()?.times(2) ?: 0L }) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMapToObjExample() { + check( + LongStreamExample::mapToObjExample, + ignoreExecutionsNumber, + { c, r -> + val intArrays = c.longs().map { it.let { i -> longArrayOf(i, i) } }.toTypedArray() + + null in c && intArrays.zip(r as Array).all { it.first.contentEquals(it.second as LongArray?) } + }, + { c: List, r -> + val intArrays = c.longs().map { it.let { i -> longArrayOf(i, i) } }.toTypedArray() + + null !in c && intArrays.zip(r as Array).all { it.first.contentEquals(it.second as LongArray?) } + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMapToIntExample() { + check( + LongStreamExample::mapToIntExample, + ignoreExecutionsNumber, + { c, r -> + val ints = c.longs().map { it.toInt() }.toIntArray() + + null in c && ints.contentEquals(r) + }, + { c: List, r -> + val ints = c.longs().map { it.toInt() }.toIntArray() + + null !in c && ints.contentEquals(r) + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMapToDoubleExample() { + check( + LongStreamExample::mapToDoubleExample, + ignoreExecutionsNumber, + { c, r -> + val doubles = c.longs().map { it.toDouble() / 2 }.toDoubleArray() + + null in c && doubles.contentEquals(r) + }, + { c: List, r -> + val doubles = c.filterNotNull().map { it.toDouble() / 2 }.toDoubleArray() + + null !in c && doubles.contentEquals(r) + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testFlatMapExample() { + check( + LongStreamExample::flatMapExample, + ignoreExecutionsNumber, + { c, r -> + val intLists = c.map { + (it?.toLong() ?: 0L).let { i -> listOf(i, i) } + } + + r!!.contentEquals(intLists.flatten().toLongArray()) + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testDistinctExample() { + check( + LongStreamExample::distinctExample, + ignoreExecutionsNumber, + { c, r -> + val longs = c.longs() + + longs.contentEquals(longs.distinct().toLongArray()) && r == false + }, + { c, r -> + val longs = c.longs() + + !longs.contentEquals(longs.distinct().toLongArray()) && r == true + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + @Tag("slow") + // TODO slow sorting https://github.com/UnitTestBot/UTBotJava/issues/188 + fun testSortedExample() { + check( + LongStreamExample::sortedExample, + ignoreExecutionsNumber, + { c, r -> c.last() < c.first() && r!!.asSequence().isSorted() }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + + @Test + fun testPeekExample() { + checkThisAndStaticsAfter( + LongStreamExample::peekExample, + ignoreExecutionsNumber, + *streamConsumerStaticsMatchers, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testLimitExample() { + check( + LongStreamExample::limitExample, + ignoreExecutionsNumber, + { c, r -> c.size <= 2 && c.longs().contentEquals(r) }, + { c, r -> c.size > 2 && c.take(2).longs().contentEquals(r) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testSkipExample() { + check( + LongStreamExample::skipExample, + ignoreExecutionsNumber, + { c, r -> c.size > 2 && c.drop(2).longs().contentEquals(r) }, + { c, r -> c.size <= 2 && r!!.isEmpty() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testForEachExample() { + checkThisAndStaticsAfter( + LongStreamExample::forEachExample, + ignoreExecutionsNumber, + *streamConsumerStaticsMatchers, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testToArrayExample() { + check( + LongStreamExample::toArrayExample, + ignoreExecutionsNumber, + { c, r -> c.longs().contentEquals(r) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testReduceExample() { + check( + LongStreamExample::reduceExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == 42L }, + { c: List, r -> c.isNotEmpty() && r == c.filterNotNull().sum() + 42L }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testOptionalReduceExample() { + checkWithException( + LongStreamExample::optionalReduceExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r.getOrThrow() == OptionalLong.empty() }, + { c: List, r -> + c.isNotEmpty() && r.getOrThrow() == OptionalLong.of( + c.filterNotNull().sum().toLong() + ) + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testSumExample() { + check( + LongStreamExample::sumExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == 0L }, + { c, r -> c.isNotEmpty() && c.filterNotNull().sum().toLong() == r }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMinExample() { + checkWithException( + LongStreamExample::minExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r.getOrThrow() == OptionalLong.empty() }, + { c, r -> c.isNotEmpty() && r.getOrThrow() == OptionalLong.of(c.mapNotNull { it.toLong() }.minOrNull()!!) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testMaxExample() { + checkWithException( + LongStreamExample::maxExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r.getOrThrow() == OptionalLong.empty() }, + { c, r -> c.isNotEmpty() && r.getOrThrow() == OptionalLong.of(c.mapNotNull { it.toLong() }.maxOrNull()!!) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testCountExample() { + check( + LongStreamExample::countExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == 0L }, + { c, r -> c.isNotEmpty() && c.size.toLong() == r }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testAverageExample() { + check( + LongStreamExample::averageExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == OptionalDouble.empty() }, + { c, r -> c.isNotEmpty() && c.mapNotNull { it.toLong() }.average() == r!!.asDouble }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @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 + + 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 + + val longs = c.longs() + + val allStatisticsAreCorrect = sum == longs.sum() && + count == longs.size.toLong() && + min == longs.minOrNull() && + max == longs.maxOrNull() + + c.isNotEmpty() && allStatisticsAreCorrect + }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + } + + @Test + fun testAnyMatchExample() { + // TODO exceeds even default step limit 3500 => too slow + withPathSelectorStepsLimit(2000) { + check( + LongStreamExample::anyMatchExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == false }, + { c, r -> c.isNotEmpty() && c.longs().all { it == 0L } && r == false }, + { c, r -> + val longs = c.longs() + + c.isNotEmpty() && longs.first() != 0L && longs.last() == 0L && r == true + }, + { c, r -> + val longs = c.longs() + + c.isNotEmpty() && longs.first() == 0L && longs.last() != 0L && r == true + }, + { c, r -> + val longs = c.longs() + + c.isNotEmpty() && longs.none { it == 0L } && r == true + }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + } + + @Test + fun testAllMatchExample() { + // TODO exceeds even default step limit 3500 => too slow + withPathSelectorStepsLimit(2000) { + check( + LongStreamExample::allMatchExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == true }, + { c, r -> c.isNotEmpty() && c.longs().all { it == 0L } && r == false }, + { c, r -> + val longs = c.longs() + + c.isNotEmpty() && longs.first() != 0L && longs.last() == 0L && r == false + }, + { c, r -> + val longs = c.longs() + + c.isNotEmpty() && longs.first() == 0L && longs.last() != 0L && r == false + }, + { c, r -> + val longs = c.longs() + + c.isNotEmpty() && longs.none { it == 0L } && r == true + }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + } + + @Test + fun testNoneMatchExample() { + // TODO exceeds even default step limit 3500 => too slow + withPathSelectorStepsLimit(2000) { + check( + LongStreamExample::noneMatchExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == true }, + { c, r -> c.isNotEmpty() && c.longs().all { it == 0L } && r == true }, + { c, r -> + val longs = c.longs() + + c.isNotEmpty() && longs.first() != 0L && longs.last() == 0L && r == false + }, + { c, r -> + val longs = c.longs() + + c.isNotEmpty() && longs.first() == 0L && longs.last() != 0L && r == false + }, + { c, r -> + val longs = c.longs() + + c.isNotEmpty() && longs.none { it == 0L } && r == false + }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + } + + @Test + fun testFindFirstExample() { + check( + LongStreamExample::findFirstExample, + eq(3), + { c, r -> c.isEmpty() && r == OptionalLong.empty() }, + { c, r -> c.isNotEmpty() && r == OptionalLong.of(c.longs().first()) }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testAsDoubleStreamExample() { + check( + LongStreamExample::asDoubleStreamExample, + ignoreExecutionsNumber, + { c, r -> c.longs().map { it.toDouble() }.toList() == r!!.toList() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testBoxedExample() { + check( + LongStreamExample::boxedExample, + ignoreExecutionsNumber, + { c, r -> c.longs().toList() == r!!.toList() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testIteratorExample() { + // TODO exceeds even default step limit 3500 => too slow + withPathSelectorStepsLimit(1000) { + check( + LongStreamExample::iteratorSumExample, + ignoreExecutionsNumber, + { c, r -> c.isEmpty() && r == 0L }, + { c: List, r -> c.isNotEmpty() && c.longs().sum() == r }, + coverage = AtLeast(76) + ) + } + } + + @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) + ) + } + } + + @Test + fun testClosedStreamExample() { + // TODO exceeds even default step limit 3500 => too slow + withPathSelectorStepsLimit(500) { + checkWithException( + LongStreamExample::closedStreamExample, + ignoreExecutionsNumber, + { _, r -> r.isException() }, + coverage = AtLeast(88) + ) + } + } + + @Test + fun testGenerateExample() { + check( + LongStreamExample::generateExample, + ignoreExecutionsNumber, + { r -> r!!.contentEquals(LongArray(10) { 42L }) }, + coverage = Full + ) + } + + @Test + fun testIterateExample() { + check( + LongStreamExample::iterateExample, + ignoreExecutionsNumber, + { r -> r!!.contentEquals(LongArray(10) { i -> 42L + i }) }, + coverage = Full + ) + } + + @Test + fun testConcatExample() { + check( + LongStreamExample::concatExample, + ignoreExecutionsNumber, + { r -> r!!.contentEquals(LongArray(10) { 42L } + LongArray(10) { i -> 42L + i }) }, + coverage = Full + ) + } + + @Test + fun testRangeExample() { + check( + LongStreamExample::rangeExample, + ignoreExecutionsNumber, + { r -> r!!.contentEquals(LongArray(10) { it.toLong() }) }, + coverage = Full + ) + } + + @Test + fun testRangeClosedExample() { + check( + LongStreamExample::rangeClosedExample, + ignoreExecutionsNumber, + { r -> r!!.contentEquals(LongArray(11) { it.toLong() }) }, + coverage = Full + ) + } +} + +private fun List.longs(mapping: (Short?) -> Long = { it?.toLong() ?: 0L }): LongArray = + map { mapping(it) }.toLongArray() diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt new file mode 100644 index 0000000000..30fb1d0553 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt @@ -0,0 +1,69 @@ +package org.utbot.examples.stream + +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.framework.plugin.api.visible.UtStreamConsumingException +import org.utbot.testcheckers.eq + + + + +import kotlin.streams.toList + +// TODO 1 instruction is always uncovered https://github.com/UnitTestBot/UTBotJava/issues/193 +// TODO failed Kotlin compilation (generics) JIRA:1332 +class StreamsAsMethodResultExampleTest : UtValueTestCaseChecker( + testClass = StreamsAsMethodResultExample::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ), +) { + @Test + fun testReturningStreamExample() { + check( + StreamsAsMethodResultExample::returningStreamExample, + eq(2), + { c, r -> c.isEmpty() && c == r!!.toList() }, + { c, r -> c.isNotEmpty() && c == r!!.toList() }, + coverage = FullWithAssumptions(assumeCallsNumber = 1) + ) + } + + @Test + fun testReturningIntStreamExample() { + checkWithException( + StreamsAsMethodResultExample::returningIntStreamExample, + eq(3), + { c, r -> c.isEmpty() && c == r.getOrThrow().toList() }, + { c, r -> c.isNotEmpty() && c.none { it == null } && c.toIntArray().contentEquals(r.getOrThrow().toArray()) }, + { c, r -> c.isNotEmpty() && c.any { it == null } && r.isException() }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + + @Test + fun testReturningLongStreamExample() { + checkWithException( + StreamsAsMethodResultExample::returningLongStreamExample, + eq(3), + { c, r -> c.isEmpty() && c == r.getOrThrow().toList() }, + { c, r -> c.isNotEmpty() && c.none { it == null } && c.map { it.toLong() }.toLongArray().contentEquals(r.getOrThrow().toArray()) }, + { c, r -> c.isNotEmpty() && c.any { it == null } && r.isException() }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } + + @Test + fun testReturningDoubleStreamExample() { + checkWithException( + StreamsAsMethodResultExample::returningDoubleStreamExample, + eq(3), + { c, r -> c.isEmpty() && c == r.getOrThrow().toList() }, + { c, r -> c.isNotEmpty() && c.none { it == null } && c.map { it.toDouble() }.toDoubleArray().contentEquals(r.getOrThrow().toArray()) }, + { c, r -> c.isNotEmpty() && c.any { it == null } && r.isException() }, + coverage = FullWithAssumptions(assumeCallsNumber = 2) + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/strings/GenericExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/strings/GenericExamplesTest.kt new file mode 100644 index 0000000000..8548f82b13 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/strings/GenericExamplesTest.kt @@ -0,0 +1,35 @@ +package org.utbot.examples.strings + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +@Disabled("TODO: Fails and takes too long") +internal class GenericExamplesTest : UtValueTestCaseChecker( + testClass = GenericExamples::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testContainsOkWithIntegerType() { + checkWithException( + GenericExamples::containsOk, + eq(2), + { obj, result -> obj == null && result.isException() }, + { obj, result -> obj != null && result.isSuccess && result.getOrNull() == false } + ) + } + + @Test + fun testContainsOkExampleTest() { + check( + GenericExamples::containsOkExample, + eq(1), + { result -> result == true } + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/strings/StringExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/strings/StringExamplesTest.kt new file mode 100644 index 0000000000..f219660f44 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/strings/StringExamplesTest.kt @@ -0,0 +1,667 @@ +package org.utbot.examples.strings + +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.withSolverTimeoutInMillis +import org.utbot.testcheckers.withoutMinimization + +internal class StringExamplesTest : UtValueTestCaseChecker( + testClass = StringExamples::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testByteToString() { + check( + StringExamples::byteToString, + eq(2), + { a, b, r -> a > b && r == a.toString() }, + { a, b, r -> a <= b && r == b.toString() }, + ) + } + + @Test + fun testByteToStringWithConstants() { + val values: Array = arrayOf( + Byte.MIN_VALUE, + (Byte.MIN_VALUE + 100).toByte(), + 0.toByte(), + (Byte.MAX_VALUE - 100).toByte(), + Byte.MAX_VALUE + ) + + val expected = values.map { it.toString() } + + check( + StringExamples::byteToStringWithConstants, + eq(1), + { r -> r != null && r.indices.all { r[it] == expected[it] } } + ) + } + + @Test + fun testReplace() { + check( + StringExamples::replace, + between(3..4), // replace with eq when JIRA:1475 fixed + { fst, _, _ -> fst == null }, + { fst, snd, _ -> fst != null && snd == null }, + { fst, snd, r -> fst != null && snd != null && r != null && (!r.contains("abc") || snd == "abc") }, + coverage = DoNotCalculate + ) + } + + @Test + fun testShortToString() { + check( + StringExamples::shortToString, + ignoreExecutionsNumber, + { a, b, r -> a > b && r == a.toString() }, + { a, b, r -> a <= b && r == b.toString() }, + ) + } + + @Test + fun testShortToStringWithConstants() { + val values: Array = arrayOf( + Short.MIN_VALUE, + (Short.MIN_VALUE + 100).toShort(), + 0.toShort(), + (Short.MAX_VALUE - 100).toShort(), + Short.MAX_VALUE + ) + + val expected = values.map { it.toString() } + + check( + StringExamples::shortToStringWithConstants, + eq(1), + { r -> r != null && r.indices.all { r[it] == expected[it] } } + ) + } + + @Test + fun testIntToString() { + check( + StringExamples::intToString, + ignoreExecutionsNumber, + { a, b, r -> a > b && r == a.toString() }, + { a, b, r -> a <= b && r == b.toString() }, + ) + } + + @Test + fun testIntToStringWithConstants() { + val values: Array = arrayOf( + Integer.MIN_VALUE, + Integer.MIN_VALUE + 100, + 0, + Integer.MAX_VALUE - 100, + Integer.MAX_VALUE + ) + + val expected = values.map { it.toString() } + + check( + StringExamples::intToStringWithConstants, + eq(1), + { r -> r != null && r.indices.all { r[it] == expected[it] } } + ) + } + + @Test + fun testLongToString() { + check( + StringExamples::longToString, + ignoreExecutionsNumber, + { a, b, r -> a > b && r == a.toString() }, + { a, b, r -> a <= b && r == b.toString() }, + ) + } + + @Test + fun testLongToStringWithConstants() { + val values: Array = arrayOf( + Long.MIN_VALUE, + Long.MIN_VALUE + 100L, + 0L, + Long.MAX_VALUE - 100L, + Long.MAX_VALUE + ) + + val expected = values.map { it.toString() } + + check( + StringExamples::longToStringWithConstants, + eq(1), + { r -> r != null && r.indices.all { r[it] == expected[it] } } + ) + } + + @Test + fun testStartsWithLiteral() { + check( + StringExamples::startsWithLiteral, + ge(4), // replace with eq when JIRA:1475 fixed + { v, _ -> v == null }, + { v, r -> v != null && v.startsWith("1234567890") && r!!.startsWith("12a4567890") }, + { v, r -> v != null && v[0] == 'x' && r!![0] == 'x' }, + { v, r -> v != null && v.toLowerCase() == r } + ) + } + + @Test + fun testBooleanToString() { + check( + StringExamples::booleanToString, + eq(2), + { a, b, r -> a == b && r == "false" }, + { a, b, r -> a != b && r == "true" }, + ) + } + + + @Test + fun testCharToString() { + // TODO related to the https://github.com/UnitTestBot/UTBotJava/issues/131 + withSolverTimeoutInMillis(5000) { + check( + StringExamples::charToString, + eq(2), + { a, b, r -> a > b && r == a.toString() }, + { a, b, r -> a <= b && r == b.toString() }, + ) + } + } + + + @Test + @Disabled("TODO:add Byte.valueOf(String) support") + fun testStringToByte() { + check( + StringExamples::stringToByte, + eq(-1), + coverage = DoNotCalculate + ) + } + + @Test + @Disabled("TODO:add Short.valueOf(String) support") + fun testStringToShort() { + check( + StringExamples::stringToShort, + eq(-1), + coverage = DoNotCalculate + ) + } + + @Test + @Disabled("TODO:add Integer.valueOf(String) support") + fun testStringToInt() { + check( + StringExamples::stringToInt, + eq(-1), + coverage = DoNotCalculate + ) + } + + @Test + @Disabled("TODO:add Long.valueOf support") + fun testStringToLong() { + check( + StringExamples::stringToLong, + eq(-1), + coverage = DoNotCalculate + ) + } + + @Test + fun testStringToBoolean() { + check( + StringExamples::stringToBoolean, + ge(2), + { s, r -> (s == null || r == java.lang.Boolean.valueOf(s)) && r == false}, // minimization + { s, r -> s != null && r == true && r == java.lang.Boolean.valueOf(s) }, + ) + } + + @Test + fun testConcat() { + check( + StringExamples::concat, + between(1..2), + { fst, snd, r -> fst == null || snd == null && r == fst + snd }, + { fst, snd, r -> r == fst + snd }, + ) + } + + @Test + @Disabled("Sometimes it freezes the execution for several hours JIRA:1453") + fun testConcatWithObject() { + check( + StringExamples::concatWithObject, + between(2..3), + { pair, r -> pair == null && r == "fst.toString() = $pair" }, + { pair, r -> pair != null && r == "fst.toString() = $pair" } + ) + } + + @Test + fun testStringConstants() { + check( + StringExamples::stringConstants, + between(1..2), + { s, r -> r == "String('$s')" }, + ) + } + + @Test + fun testContainsOnLiterals() { + check( + StringExamples::containsOnLiterals, + eq(1), + ) + } + + @Test + @Disabled("This is a flaky test") + fun testConcatWithInt() { + check( + StringExamples::concatWithInts, + eq(3), + { a, b, r -> a == b && r == null }, // IllegalArgumentException + { a, b, r -> a > b && r == "a > b, a:$a, b:$b" }, + { a, b, r -> a < b && r == "a < b, a:$a, b:$b" }, + ) + } + + @Test + fun testUseStringBuffer() { + check( + StringExamples::useStringBuffer, + between(1..2), + { fst, snd, r -> r == "$fst, $snd" }, + ) + } + + @Test + fun testNullableStringBuffer() { + checkWithException( + StringExamples::nullableStringBuffer, + eq(4), + { _, i, r -> i >= 0 && r.isException() }, + { _, i, r -> i < 0 && r.isException() }, + { buffer, i, r -> i >= 0 && r.getOrNull() == "${buffer}Positive" }, + { buffer, i, r -> i < 0 && r.getOrNull() == "${buffer}Negative" }, + ) + } + + @Test + fun testIsStringBuilderEmpty() { + check( + StringExamples::isStringBuilderEmpty, + eq(2), + { stringBuilder, result -> result == stringBuilder.isEmpty() } + ) + } + + @Test + @Disabled("Flaky on GitHub: https://github.com/UnitTestBot/UTBotJava/issues/1004") + fun testIsValidUuid() { + val pattern = Regex("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}") + check( + StringExamples::isValidUuid, + ignoreExecutionsNumber, + { uuid, r -> uuid == null || uuid.length == 0 && r == false }, + { uuid, r -> uuid.length > 0 && uuid.isBlank() && r == false }, + { uuid, r -> uuid.length > 0 && uuid.isNotBlank() && r == false }, + { uuid, r -> uuid.length > 1 && uuid.isNotBlank() && !uuid.matches(pattern) && r == false }, + { uuid, r -> uuid.length > 1 && uuid.isNotBlank() && uuid.matches(pattern) && r == true }, + ) + } + + @Test + fun testIsValidUuidShortVersion() { + val pattern = Regex("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}") + check( + StringExamples::isValidUuidShortVersion, + eq(3), + { uuid, r -> uuid == null && r == false }, + { uuid, r -> uuid.matches(pattern) && r == true }, + { uuid, r -> !uuid.matches(pattern) && r == false }, + ) + } + + @Test + fun testIsBlank() { + check( + StringExamples::isBlank, + ge(4), + { cs, r -> cs == null && r == true }, + { cs, r -> cs.length == 0 && r == true }, + { cs, r -> cs.length > 0 && cs.isBlank() && r == true }, + { cs, r -> cs.length > 0 && cs.isNotBlank() && r == false }, + summaryNameChecks = listOf( + keyMatch("testIsBlank_StrLenEqualsZero"), + keyMatch("testIsBlank_NotCharacterIsWhitespace"), + keyMatch("testIsBlank_CharacterIsWhitespace") + ) + ) + } + + @Test + fun testLength() { + check( + StringExamples::length, + eq(2), // TODO: that strange, why we haven't 3rd option? + { cs, r -> cs == null && r == 0 }, + { cs, r -> cs != null && r == cs.length }, + ) + } + + @Test + fun testLonger() { + checkWithException( + StringExamples::longer, + ignoreExecutionsNumber, + { _, i, r -> i <= 0 && r.isException() }, + { cs, i, r -> i > 0 && cs == null && !r.getOrThrow() }, + { cs, i, r -> i > 0 && cs != null && cs.length > i && r.getOrThrow() }, + coverage = DoNotCalculate // TODO: Coverage calculation fails in the child process with Illegal Argument Exception + ) + } + + @Test + fun testEqualChar() { + checkWithException( + StringExamples::equalChar, + eq(4), + { cs, r -> cs == null && r.isException() }, + { cs, r -> cs.isEmpty() && r.isException() }, + { cs, r -> cs.isNotEmpty() && cs[0] == 'a' && r.getOrThrow() }, + { cs, r -> cs.isNotEmpty() && cs[0] != 'a' && !r.getOrThrow() }, + ) + } + + @Test + fun testSubstring() { + checkWithException( + StringExamples::substring, + between(5..8), + { s, _, r -> s == null && r.isException() }, + { s, i, r -> s != null && i < 0 || i > s.length && r.isException() }, + { s, i, r -> s != null && i in 0..s.length && r.getOrThrow() == s.substring(i) && s.substring(i) != "password" }, + { s, i, r -> s != null && i == 0 && r.getOrThrow() == s.substring(i) && s.substring(i) == "password" }, + { s, i, r -> s != null && i != 0 && r.getOrThrow() == s.substring(i) && s.substring(i) == "password" }, + ) + } + + @Test + fun testSubstringWithEndIndex() { + checkWithException( + StringExamples::substringWithEndIndex, + ignoreExecutionsNumber, + { s, _, _, r -> s == null && r.isException() }, + { s, b, e, r -> s != null && b < 0 || e > s.length || b > e && r.isException() }, + { s, b, e, r -> r.getOrThrow() == s.substring(b, e) && s.substring(b, e) != "password" }, + { s, b, e, r -> b == 0 && r.getOrThrow() == s.substring(b, e) && s.substring(b, e) == "password" }, + { s, b, e, r -> + b != 0 && e == s.length && r.getOrThrow() == s.substring(b, e) && s.substring(b, e) == "password" + }, + { s, b, e, r -> + b != 0 && e != s.length && r.getOrThrow() == s.substring(b, e) && s.substring(b, e) == "password" + }, + ) + } + + @Test + fun testSubstringWithEndIndexNotEqual() { + checkWithException( + StringExamples::substringWithEndIndexNotEqual, + ignoreExecutionsNumber, + { s, _, r -> s == null && r.isException() }, + { s, e, r -> s != null && e < 1 || e > s.length && r.isException() }, + { s, e, r -> s != null && r.getOrThrow() == s.substring(1, e) }, + ) + } + + @Test + fun testFullSubstringEquality() { + checkWithException( + StringExamples::fullSubstringEquality, + eq(2), + { s, r -> s == null && r.isException() }, + { s, r -> s != null && r.getOrThrow() }, + ) + } + + @Test + @Disabled("TODO: add intern support") + fun testUseIntern() { + checkWithException( + StringExamples::useIntern, + eq(3), + { s, r -> s == null && r.isException() }, + { s, r -> s != null && s != "abc" && r.getOrThrow() == 1 }, + { s, r -> s != null && s == "abc" && r.getOrThrow() == 3 }, + coverage = atLeast(66) + ) + } + + @Test + fun testPrefixAndSuffix() { + check( + StringExamples::prefixAndSuffix, + eq(6), + { s, r -> s == null && r == null }, // NullPointerException + { s, r -> s.length != 5 && r == 0 }, + { s, r -> s.length == 5 && !s.startsWith("ab") && r == 1 }, + { s, r -> s.length == 5 && s.startsWith("ab") && !s.endsWith("de") && r == 2 }, + { s, r -> s.length == 5 && s.startsWith("ab") && s.endsWith("de") && !s.contains("+") && r == 4 }, + { s, r -> s.length == 5 && s == "ab+de" && r == 3 }, + ) + } + + @Test + fun testPrefixWithTwoArgs() { + checkWithException( + StringExamples::prefixWithTwoArgs, + between(3..4), + { s, r -> s == null && r.isException() }, + { s, r -> s != null && s.startsWith("abc", 1) && r.getOrThrow() == 1 }, + { s, r -> s != null && !s.startsWith("abc", 1) && r.getOrThrow() == 2 }, + ) + } + + @Test + fun testPrefixWithOffset() { + withoutMinimization { + check( + StringExamples::prefixWithOffset, + eq(4), // should be 4, but path selector eliminates several results with false + { o, r -> o < 0 && r == 2 }, + { o, r -> o > "babc".length - "abc".length && r == 2 }, + { o, r -> o in 0..1 && !"babc".startsWith("abc", o) && r == 2 }, + { o, r -> "babc".startsWith("abc", o) && r == 1 }, + ) + } + } + + @Test + fun testStartsWith() { + check( + StringExamples::startsWith, + between(5..6), + { _, prefix, _ -> prefix == null }, + { _, prefix, _ -> prefix != null && prefix.length < 2 }, + { s, prefix, _ -> prefix != null && prefix.length >= 2 && s == null }, + { s, prefix, r -> prefix != null && prefix.length >= 2 && s != null && s.startsWith(prefix) && r == true }, + { s, prefix, r -> prefix != null && prefix.length >= 2 && s != null && !s.startsWith(prefix) && r == false } + + ) + } + + @Test + fun testStartsWithOffset() { + check( + StringExamples::startsWithOffset, + between(6..10), + { _, prefix, _, _ -> prefix == null }, + { _, prefix, _, _ -> prefix != null && prefix.length < 2 }, + { s, prefix, _, _ -> prefix != null && prefix.length >= 2 && s == null }, + { s, prefix, o, r -> + prefix != null && prefix.length >= 2 && s != null && s.startsWith(prefix, o) && o > 0 && r == 0 + }, + { s, prefix, o, r -> + prefix != null && prefix.length >= 2 && s != null && s.startsWith(prefix, o) && o == 0 && r == 1 + }, + { s, prefix, o, r -> + prefix != null && prefix.length >= 2 && s != null && !s.startsWith(prefix, o) && r == 2 + } + ) + } + + @Test + fun testEndsWith() { + check( + StringExamples::endsWith, + between(5..6), + { s, suffix, r -> suffix == null }, + { s, suffix, r -> suffix != null && suffix.length < 2 }, + { s, suffix, r -> suffix != null && suffix.length >= 2 && s == null }, + { s, suffix, r -> suffix != null && suffix.length >= 2 && s != null && s.endsWith(suffix) && r == true }, + { s, suffix, r -> suffix != null && suffix.length >= 2 && s != null && !s.endsWith(suffix) && r == false } + ) + } + + @Test + @Disabled("TODO: support replace") + fun testReplaceAll() { + checkWithException( + StringExamples::replaceAll, + eq(4), + { s, _, _, r -> s == null && r.isException() }, + { s, regex, _, r -> s != null && regex == null && r.isException() }, + { s, regex, replacement, r -> s != null && regex != null && replacement == null && r.isException() }, + { s, regex, replacement, r -> + s != null && regex != null && replacement != null && r.getOrThrow() == s.replace(regex, replacement) + }, // one replace only! + ) + } + + @Test + fun testLastIndexOf() { + check( + StringExamples::lastIndexOf, + between(5..7), + { s, _, _ -> s == null }, + { s, find, _ -> s != null && find == null }, + { s, find, r -> r == s.lastIndexOf(find) && r == s.length - find.length }, + { s, find, r -> r == s.lastIndexOf(find) && r < s.length - find.length }, + { s, find, r -> r == s.lastIndexOf(find) && r == -1 }, + ) + } + + @Test + fun testIndexOfWithOffset() { + check( + StringExamples::indexOfWithOffset, + between(5..9), + { s, _, _, _ -> s == null }, + { s, find, _, _ -> s != null && find == null }, + { s, find, offset, r -> r == s.indexOf(find, offset) && r > offset && offset > 0 }, + { s, find, offset, r -> r == s.indexOf(find, offset) && r == offset }, + { s, find, offset, r -> r == s.indexOf(find, offset) && !(r == offset || (offset in 1 until r)) }, + ) + } + + + @Test + fun testLastIndexOfWithOffset() { + check( + StringExamples::lastIndexOfWithOffset, + between(5..9), + { s, _, _, _ -> s == null }, + { s, find, _, _ -> s != null && find == null }, + { s, find, i, r -> r == s.lastIndexOf(find, i) && r >= 0 && r < i - find.length && i < s.length }, + { s, find, i, r -> r == s.lastIndexOf(find, i) && r >= 0 && !(r < i - find.length && i < s.length) }, + { s, find, i, r -> r == s.lastIndexOf(find, i) && r == -1 }, + ) + } + + @Test + fun testCompareCodePoints() { + checkWithException( + StringExamples::compareCodePoints, + between(8..10), + { s, t, i, r -> s == null && r.isException() }, + { s, t, i, r -> s != null && i < 0 || i >= s.length && r.isException() }, + { s, t, i, r -> s != null && t == null && r.isException() }, + { s, t, i, r -> t != null && i < 0 || i >= t.length && r.isException() }, + { s, t, i, r -> s != null && t != null && s.codePointAt(i) < t.codePointAt(i) && i == 0 && r.getOrThrow() == 0 }, + { s, t, i, r -> s != null && t != null && s.codePointAt(i) < t.codePointAt(i) && i != 0 && r.getOrThrow() == 1 }, + { s, t, i, r -> s != null && t != null && s.codePointAt(i) >= t.codePointAt(i) && i == 0 && r.getOrThrow() == 2 }, + { s, t, i, r -> s != null && t != null && s.codePointAt(i) >= t.codePointAt(i) && i != 0 && r.getOrThrow() == 3 }, + ) + } + + @Test + fun testToCharArray() { + check( + StringExamples::toCharArray, + eq(2), + { s, r -> s == null }, + { s, r -> s.toCharArray().contentEquals(r) } + ) + } + + @Test + fun testGetObj() { + check( + StringExamples::getObj, + eq(1), + { obj, r -> obj == r } + ) + } + + @Test + fun testGetObjWithCondition() { + check( + StringExamples::getObjWithCondition, + between(3..4), + { obj, r -> obj == null && r == "null" }, + { obj, r -> obj != null && obj == "BEDA" && r == "48858" }, + { obj, r -> obj != null && obj != "BEDA" && obj == r } + ) + } + + @Test + fun testEqualsIgnoreCase() { + withPushingStateFromPathSelectorForConcrete { + check( + StringExamples::equalsIgnoreCase, + ignoreExecutionsNumber, + { s, r -> "SUCCESS".equals(s, ignoreCase = true) && r == "success" }, + { s, r -> !"SUCCESS".equals(s, ignoreCase = true) && r == "failure" }, + ) + } + } + + // 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 + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/strings11/StringConcatTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/strings11/StringConcatTest.kt new file mode 100644 index 0000000000..090cbb2c7f --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/strings11/StringConcatTest.kt @@ -0,0 +1,113 @@ +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 + +class StringConcatTest : UtValueTestCaseChecker( + testClass = StringConcat::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun testConcatArguments() { + withoutConcrete { + 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 }, + ) + } + } + + @Test + fun testConcatWithPrimitives() { + withoutConcrete { + 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 + ) + } + } + + @Test + fun testConcatWithField() { + withoutConcrete { + 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 + ) + } + } + + @Test + fun testSameConcat() { + withoutConcrete { + 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" } + ) + } + } + +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/structures/HeapTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/structures/HeapTest.kt new file mode 100644 index 0000000000..92f87808f8 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/structures/HeapTest.kt @@ -0,0 +1,20 @@ +package org.utbot.examples.structures + +import org.junit.jupiter.api.Test + +internal class HeapTest : UtValueTestCaseChecker(testClass = Heap::class) { + @Test + fun testIsHeap() { + val method = Heap::isHeap + checkStaticMethod( + method, + ignoreExecutionsNumber, + { values, _ -> values == null }, + { values, _ -> values.size < 3 }, + { values, r -> values.size >= 3 && r == method(values) }, + { values, r -> values.size >= 3 && values[1] < values[0] && r == method(values) }, + { values, r -> values.size >= 3 && values[1] >= values[0] && values[2] < values[0] && r == method(values) }, + { values, r -> values.size >= 3 && r == method(values) }, + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/structures/MinStackExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/structures/MinStackExampleTest.kt new file mode 100644 index 0000000000..53676ee1d1 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/structures/MinStackExampleTest.kt @@ -0,0 +1,103 @@ +package org.utbot.examples.structures + +import kotlin.math.min +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class MinStackExampleTest : UtValueTestCaseChecker(testClass = MinStackExample::class) { + @Test + fun testCreate() { + check( + MinStackExample::create, + eq(3), + { initialValues, _ -> initialValues == null }, + { initialValues, _ -> initialValues != null && initialValues.size < 3 }, + { initialValues, result -> + require(initialValues != null && result != null) + + val stackExample = MinStackExample().create(initialValues) + val initialSize = initialValues.size + + val sizesConstraint = initialSize >= 3 && result.size == 4 + val stacksSize = stackExample.stack.take(initialSize) == result.stack.take(initialSize) + val minStackSize = stackExample.minStack.take(initialSize) == result.minStack.take(initialSize) + + sizesConstraint && stacksSize && minStackSize + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testAddSingleValue() { + check( + MinStackExample::addSingleValue, + eq(3), + { initialValues, _ -> initialValues == null }, + { initialValues, _ -> initialValues != null && initialValues.isEmpty() }, + { initialValues, result -> + require(initialValues != null && result != null) + + val sizeConstraint = initialValues.isNotEmpty() + val firstElementConstraint = result.stack.first() == initialValues.first() + val secondElementConstraint = result.stack[1] == initialValues.first() - 100 + + sizeConstraint && firstElementConstraint && secondElementConstraint + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetMinValue() { + check( + MinStackExample::getMinValue, + eq(3), + { initialValues, _ -> initialValues == null }, + { initialValues, result -> initialValues != null && initialValues.isEmpty() && result == -1L }, + { initialValues, result -> + initialValues != null && initialValues.isNotEmpty() && result == min(-1L, initialValues.minOrNull()!!) + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testRemoveValue() { + check( + MinStackExample::removeValue, + eq(4), + { initialValues, _ -> initialValues == null }, + { initialValues, _ -> initialValues != null && initialValues.isEmpty() }, + { initialValues, result -> + initialValues != null && initialValues.size == 1 && result != null && result.size == initialValues.size - 1 + }, + { initialValues, result -> + initialValues != null && initialValues.size > 1 && result != null && result.size == initialValues.size - 1 + }, + coverage = DoNotCalculate + ) + } + + @Test + fun testConstruct() { + check( + MinStackExample::construct, + between(3..4), + { values, _ -> values == null }, + { values, result -> values != null && values.isEmpty() && result != null && result.size == 0 }, + { values, result -> + require(values != null && result != null) + + val stackExample = MinStackExample().construct(values) + + val sizeConstraint = values.isNotEmpty() && result.size == values.size + val stackSize = stackExample.stack.take(values.size) == result.stack.take(values.size) + val valueConstraint = stackExample.minStack.take(values.size) == result.minStack.take(values.size) + + sizeConstraint && stackSize && valueConstraint + }, + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt new file mode 100644 index 0000000000..5f2c35d34f --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt @@ -0,0 +1,100 @@ +package org.utbot.examples.structures + +import org.utbot.framework.plugin.api.DocCodeStmt +import org.utbot.framework.plugin.api.DocPreTagStatement +import org.utbot.framework.plugin.api.DocRegularStmt +import org.utbot.framework.plugin.api.DocStatement +import java.util.LinkedList +import java.util.TreeMap +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.eq + +internal class StandardStructuresTest : UtValueTestCaseChecker( + testClass = StandardStructures::class, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + @Disabled("TODO down cast for object wrapper JIRA:1480") + fun testGetList() { + check( + StandardStructures::getList, + eq(4), + { l, r -> l is ArrayList && r is ArrayList }, + { l, r -> l is LinkedList && r is LinkedList }, + { l, r -> l == null && r == null }, + { l, r -> + l !is ArrayList && l !is LinkedList && l != null && r !is ArrayList && r !is LinkedList && r != null + }, + coverage = DoNotCalculate + ) + } + + @Test + @Disabled("TODO down cast for object wrapper JIRA:1480") + fun testGetMap() { + check( + StandardStructures::getMap, + eq(3), + { m, r -> m is TreeMap && r is TreeMap }, + { m, r -> m == null && r == null }, + { m, r -> m !is TreeMap && m != null && r !is TreeMap && r != null }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetDeque() { + val dequeSummary = listOf( + DocPreTagStatement( + listOf( + DocRegularStmt("Test "), + DocRegularStmt("executes conditions:\n"), + DocRegularStmt(" "), + DocCodeStmt("(deque instanceof LinkedList): False"), + DocRegularStmt(",\n"), + DocRegularStmt(" "), + DocCodeStmt("(deque == null): True"), + DocRegularStmt("\n"), + DocRegularStmt("returns from: "), + DocCodeStmt("return null;"), + DocRegularStmt("\n") + ) + ) + ) + + check( + StandardStructures::getDeque, + eq(4), + { d, r -> d is java.util.ArrayDeque && r is java.util.ArrayDeque }, + { d, r -> d is LinkedList && r is LinkedList }, + { d, r -> d == null && r == null }, + { d, r -> + d !is java.util.ArrayDeque<*> && d !is LinkedList && d != null && r !is java.util.ArrayDeque<*> && r !is LinkedList && r != null + }, + coverage = DoNotCalculate, + summaryTextChecks = listOf( + keyContain(DocCodeStmt("(deque instanceof ArrayDeque): True")), + keyContain(DocCodeStmt("(deque instanceof LinkedList): True")), + keyContain(DocCodeStmt("(deque == null): True")), + keyMatch(dequeSummary) + ), + summaryNameChecks = listOf( + keyMatch("testGetDeque_DequeInstanceOfArrayDeque"), + keyMatch("testGetDeque_DequeInstanceOfLinkedList"), + keyMatch("testGetDeque_DequeEqualsNull"), + keyMatch("testGetDeque_DequeNotEqualsNull"), + ), + summaryDisplayNameChecks = listOf( + keyContain("deque", "instance", "ArrayDeque"), + keyContain("deque", "instance", "LinkedList"), + keyContain("deque == null", "True"), + keyContain("deque == null", "False"), + ) + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/thirdparty/numbers/ArithmeticUtilsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/thirdparty/numbers/ArithmeticUtilsTest.kt new file mode 100644 index 0000000000..fc7658c50d --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/thirdparty/numbers/ArithmeticUtilsTest.kt @@ -0,0 +1,46 @@ +package org.utbot.examples.thirdparty.numbers + +import org.junit.jupiter.api.Tag +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker + +// example from Apache common-numbers +internal class ArithmeticUtilsTest : UtValueTestCaseChecker(testClass = ArithmeticUtils::class) { + @Test + @Tag("slow") + fun testPow() { + check( + ArithmeticUtils::pow, + eq(11), + { _, e, _ -> e < 0 }, // IllegalArgumentException + { k, e, r -> k == 0 && e == 0 && r == 1 }, + { k, e, r -> k == 0 && e != 0 && r == 0 }, + { k, _, r -> k == 1 && r == 1 }, + { k, e, r -> k == -1 && e and 1 == 0 && r == 1 }, + { k, e, r -> k == -1 && e and 1 != 0 && r == -1 }, + { _, e, _ -> e >= 31 }, // ArithmeticException + { k, e, r -> k !in -1..1 && e in 0..30 && r == pow(k, e) }, + + // And 2 additional branches here with ArithmeticException reg integer overflow + { k, e, r -> k !in -1..1 && e in 0..30 && r == null }, + ) + } +} + +fun pow(k: Int, e: Int): Int { + var exp = e + var result = 1 + var k2p = k + while (true) { + if (exp and 0x1 != 0) { + result = Math.multiplyExact(result, k2p) + } + exp = exp shr 1 + if (exp == 0) { + break + } + k2p = Math.multiplyExact(k2p, k2p) + } + return result +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/types/CastExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/types/CastExamplesTest.kt new file mode 100644 index 0000000000..1cc939a373 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/types/CastExamplesTest.kt @@ -0,0 +1,77 @@ +package org.utbot.examples.types + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker + +@Suppress("SimplifyNegatedBinaryExpression") +internal class CastExamplesTest : UtValueTestCaseChecker(testClass = CastExamples::class) { + @Test + fun testLongToByte() { + check( + CastExamples::longToByte, + eq(3), + { a, b, r -> (a.toByte() + b.toByte()).toByte() > 10 && r == (a.toByte() + b.toByte()).toByte() }, + { a, b, r -> (a.toByte() + b.toByte()).toByte() <= 10 && a.toByte() > b.toByte() && r == (-1).toByte() }, + { a, b, r -> (a.toByte() + b.toByte()).toByte() <= 10 && a.toByte() <= b.toByte() && r == (0).toByte() }, + ) + } + + @Test + fun testShortToLong() { + check( + CastExamples::shortToLong, + eq(3), + { a, b, r -> a + b > 10 && r == a.toLong() + b.toLong() }, + { a, b, r -> a + b <= 10 && a > b && r == -1L }, + { a, b, r -> a + b <= 10 && a <= b && r == 0L }, + ) + } + + @Test + fun testFloatToDouble() { + check( + CastExamples::floatToDouble, + eq(4), + { a, b, r -> a.toDouble() + b.toDouble() > Float.MAX_VALUE && r == 2.0 }, + { a, b, r -> a.toDouble() + b.toDouble() > 10 && r == 1.0 }, + { a, b, r -> !(a.toDouble() + b.toDouble() > 10) && !(a.toDouble() > b.toDouble()) && r == 0.0 }, + { a, b, r -> !(a.toDouble() + b.toDouble() > 10) && a.toDouble() > b.toDouble() && r == -1.0 }, + ) + } + + @Test + fun testDoubleToFloatArray() { + check( + CastExamples::doubleToFloatArray, + eq(2), + { x, r -> x.toFloat() + 5 > 20 && r == 1.0f }, + { x, r -> !(x.toFloat() + 5 > 20) && r == 0.0f } + ) + } + + @Test + fun testFloatToInt() { + check( + CastExamples::floatToInt, + eq(3), + { x, r -> x < 0 && x.toInt() < 0 && r == 1 }, + { x, r -> x < 0 && x.toInt() >= 0 && r == 2 }, + { x, r -> !(x < 0) && r == 3 }, + ) + } + + @Test + fun testShortToChar() { + check( + CastExamples::shortToChar, + eq(3), + { a, b, r -> (a.charInt() + b.charInt()).charInt() > 10 && r == (a.charInt() + b.charInt()).toChar() }, + { a, b, r -> (a.charInt() + b.charInt()).charInt() <= 10 && a.charInt() <= b.charInt() && r == (0).toChar() }, + { a, b, r -> (a.charInt() + b.charInt()).charInt() <= 10 && a.charInt() > b.charInt() && r == (-1).toChar() }, + ) + } + + // Special cast to emulate Java binary numeric promotion + private fun Number.charInt() = toChar().toInt() +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/types/TypeBordersTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/types/TypeBordersTest.kt new file mode 100644 index 0000000000..e1325710de --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/types/TypeBordersTest.kt @@ -0,0 +1,76 @@ +package org.utbot.examples.types + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class TypeBordersTest : UtValueTestCaseChecker(testClass = TypeBorders::class) { + @Test + fun testByteBorder() { + check( + TypeBorders::byteBorder, + eq(3), + { x, r -> x == Byte.MIN_VALUE && r == 3 }, + { x, r -> x == Byte.MAX_VALUE && r == 2 }, + { x, r -> x > Byte.MIN_VALUE && x < Byte.MAX_VALUE && r == 4 }, + coverage = atLeast(75) + ) + } + + @Test + fun testShortBorder() { + check( + TypeBorders::shortBorder, + eq(3), + { x, r -> x == Short.MIN_VALUE && r == 3 }, + { x, r -> x == Short.MAX_VALUE && r == 2 }, + { x, r -> x > Short.MIN_VALUE && x < Short.MAX_VALUE && r == 4 }, + coverage = atLeast(75) + ) + } + + @Test + fun testCharBorder() { + check( + TypeBorders::charBorder, + eq(3), + { x, r -> x == Char.MIN_VALUE && r == 3 }, + { x, r -> x == Char.MAX_VALUE && r == 2 }, + { x, r -> x > Char.MIN_VALUE && x < Char.MAX_VALUE && r == 4 }, + coverage = atLeast(75) + ) + } + + @Test + fun testIntBorder() { + check( + TypeBorders::intBorder, + eq(3), + { x, r -> x == Int.MIN_VALUE && r == 3 }, + { x, r -> x == Int.MAX_VALUE && r == 2 }, + { x, r -> x > Int.MIN_VALUE && x < Int.MAX_VALUE && r == 4 }, + coverage = atLeast(75) + ) + } + + @Test + fun testLongBorder() { + check( + TypeBorders::longBorder, + eq(3), + { x, r -> x == Long.MIN_VALUE && r == 3 }, + { x, r -> x == Long.MAX_VALUE && r == 2 }, + { x, r -> x > Long.MIN_VALUE && x < Long.MAX_VALUE && r == 4 }, + coverage = atLeast(75) + ) + } + + @Test + fun testUnreachableByteValue() { + check( + TypeBorders::unreachableByteValue, + eq(1), // should generate one branch with legal byte value + { x, r -> r == 0 && x < 200 }, + coverage = atLeast(50) + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/types/TypeMatchesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/types/TypeMatchesTest.kt new file mode 100644 index 0000000000..4a3f8d3c76 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/types/TypeMatchesTest.kt @@ -0,0 +1,60 @@ +package org.utbot.examples.types + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker + +@Suppress("SimplifyNegatedBinaryExpression") +internal class TypeMatchesTest : UtValueTestCaseChecker(testClass = TypeMatches::class) { + @Test + fun testCompareDoubleByte() { + check( + TypeMatches::compareDoubleByte, + eq(2), + { a, b, r -> a < b && r == 0.0 }, + { a, b, r -> !(a < b) && r == 1.0 } + ) + } + + @Test + fun testCompareShortLong() { + check( + TypeMatches::compareShortLong, + eq(2), + { a, b, r -> a < b && r == 0.toShort() }, + { a, b, r -> a >= b && r == 1.toShort() } + ) + } + + @Test + fun testCompareFloatDouble() { + check( + TypeMatches::compareFloatDouble, + eq(2), + { a, b, r -> a < b && r == 0.0f }, + { a, b, r -> !(a < b) && r == 1.0f } + ) + } + + @Test + fun testSumByteAndShort() { + check( + TypeMatches::sumByteAndShort, + eq(3), + { a, b, r -> a + b > Short.MAX_VALUE && r == 1 }, + { a, b, r -> a + b < Short.MIN_VALUE && r == 2 }, + { a, b, r -> a + b in Short.MIN_VALUE..Short.MAX_VALUE && r == 3 }, + ) + } + + @Test + fun testSumShortAndChar() { + check( + TypeMatches::sumShortAndChar, + eq(3), + { a, b, r -> a + b.toInt() > Char.MAX_VALUE.toInt() && r == 1 }, + { a, b, r -> a + b.toInt() < Char.MIN_VALUE.toInt() && r == 2 }, + { a, b, r -> a + b.toInt() in Char.MIN_VALUE.toInt()..Char.MAX_VALUE.toInt() && r == 3 }, + ) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt new file mode 100644 index 0000000000..03d29c8eab --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt @@ -0,0 +1,39 @@ +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.withoutSandbox +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker + +internal class UnsafeOperationsTest : UtValueTestCaseChecker(testClass = UnsafeOperations::class) { + @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 + ) + } + } + + @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 + ) + } + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/unsafe/UnsafeWithFieldTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/unsafe/UnsafeWithFieldTest.kt new file mode 100644 index 0000000000..4b486a3d23 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/unsafe/UnsafeWithFieldTest.kt @@ -0,0 +1,18 @@ +package org.utbot.examples.unsafe + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker + +internal class UnsafeWithFieldTest: UtValueTestCaseChecker(UnsafeWithField::class) { + + @Test + fun checkSetField() { + check( + UnsafeWithField::setField, + eq(1) + // TODO JIRA:1579 + // for now we might have any value as a result, so there is no need in the matcher + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/BooleanWrapperTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/BooleanWrapperTest.kt new file mode 100644 index 0000000000..aa874a5f3e --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/BooleanWrapperTest.kt @@ -0,0 +1,40 @@ +package org.utbot.examples.wrappers + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class BooleanWrapperTest : UtValueTestCaseChecker(testClass = BooleanWrapper::class) { + @Test + fun primitiveToWrapperTest() { + check( + BooleanWrapper::primitiveToWrapper, + eq(2), + { x, r -> x && r == true }, + { x, r -> !x && r == true }, + coverage = DoNotCalculate + ) + } + + @Test + fun wrapperToPrimitiveTest() { + check( + BooleanWrapper::wrapperToPrimitive, + eq(3), + { x, _ -> x == null }, + { x, r -> x && r == true }, + { x, r -> !x && r == true }, + coverage = DoNotCalculate + ) + } + + @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 + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/ByteWrapperTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/ByteWrapperTest.kt new file mode 100644 index 0000000000..51241e7880 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/ByteWrapperTest.kt @@ -0,0 +1,40 @@ +package org.utbot.examples.wrappers + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class ByteWrapperTest : UtValueTestCaseChecker(testClass = ByteWrapper::class) { + @Test + fun primitiveToWrapperTest() { + check( + ByteWrapper::primitiveToWrapper, + eq(2), + { x, r -> x >= 0 && r!! <= 0 }, + { x, r -> x < 0 && r!! < 0 }, + coverage = DoNotCalculate + ) + } + + @Test + fun wrapperToPrimitiveTest() { + check( + ByteWrapper::wrapperToPrimitive, + eq(3), + { x, _ -> x == null }, + { x, r -> x >= 0 && r!! <= 0 }, + { x, r -> x < 0 && r!! < 0 }, + coverage = DoNotCalculate + ) + } + + @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 + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/CharacterWrapperTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/CharacterWrapperTest.kt new file mode 100644 index 0000000000..bce33bb2f5 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/CharacterWrapperTest.kt @@ -0,0 +1,50 @@ +package org.utbot.examples.wrappers + +import org.utbot.framework.plugin.api.CodegenLanguage +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +// TODO failed Kotlin compilation +internal class CharacterWrapperTest : UtValueTestCaseChecker( + testClass = CharacterWrapper::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun primitiveToWrapperTest() { + check( + CharacterWrapper::primitiveToWrapper, + eq(2), + { x, r -> x.toInt() >= 100 && r!!.toInt() >= 100 }, + { x, r -> x.toInt() < 100 && r!!.toInt() == x.toInt() + 100 }, + ) + } + + @Test + fun wrapperToPrimitiveTest() { + check( + CharacterWrapper::wrapperToPrimitive, + eq(3), + { x, _ -> x == null }, + { x, r -> x.toInt() >= 100 && r!!.toInt() >= 100 }, + { x, r -> x.toInt() < 100 && r!!.toInt() == x.toInt() + 100 }, + ) + } + + @Disabled("Caching char values between -128 and 127 isn't supported JIRA:1481") + @Test + fun equalityTest() { + check( + CharacterWrapper::equality, + eq(3), + { a, b, result -> a == b && a.toInt() <= 127 && result == 1 }, + { a, b, result -> a == b && a.toInt() > 127 && result == 2 }, + { a, b, result -> a != b && result == 4 }, + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/DoubleWrapperTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/DoubleWrapperTest.kt new file mode 100644 index 0000000000..049fba0fa5 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/DoubleWrapperTest.kt @@ -0,0 +1,30 @@ +package org.utbot.examples.wrappers + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +@Suppress("SimplifyNegatedBinaryExpression") +internal class DoubleWrapperTest : UtValueTestCaseChecker(testClass = DoubleWrapper::class) { + @Test + fun primitiveToWrapperTest() { + check( + DoubleWrapper::primitiveToWrapper, + eq(2), + { x, r -> x >= 0 && r!!.toDouble() >= 0 }, + { x, r -> (x < 0 || x.isNaN()) && (r!!.toDouble() > 0 || r.isNaN()) }, + coverage = DoNotCalculate + ) + } + + @Test + fun wrapperToPrimitiveTest() { + check( + DoubleWrapper::wrapperToPrimitive, + eq(3), + { x, _ -> x == null }, + { x, r -> x >= 0 && r!! >= 0 }, + { x, r -> (x < 0 || x.isNaN()) && (r!! > 0 || r.isNaN()) }, + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/FloatWrapperTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/FloatWrapperTest.kt new file mode 100644 index 0000000000..2142305a1d --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/FloatWrapperTest.kt @@ -0,0 +1,30 @@ +package org.utbot.examples.wrappers + +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +@Suppress("SimplifyNegatedBinaryExpression") +internal class FloatWrapperTest : UtValueTestCaseChecker(testClass = FloatWrapper::class) { + @Test + fun primitiveToWrapperTest() { + check( + FloatWrapper::primitiveToWrapper, + eq(2), + { x, r -> x >= 0 && r!! >= 0 }, + { x, r -> (x < 0 || x.isNaN()) && (r!! > 0 || r.isNaN()) }, + coverage = DoNotCalculate + ) + } + + @Test + fun wrapperToPrimitiveTest() { + check( + FloatWrapper::wrapperToPrimitive, + eq(3), + { x, _ -> x == null }, + { x, r -> x >= 0 && r!! >= 0 }, + { x, r -> (x < 0 || x.isNaN()) && (r!! > 0 || r.isNaN()) }, + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/IntegerWrapperTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/IntegerWrapperTest.kt new file mode 100644 index 0000000000..27c78191af --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/IntegerWrapperTest.kt @@ -0,0 +1,70 @@ +package org.utbot.examples.wrappers + +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class IntegerWrapperTest : UtValueTestCaseChecker(testClass = IntegerWrapper::class) { + @Test + fun primitiveToWrapperTest() { + check( + IntegerWrapper::primitiveToWrapper, + eq(2), + { x, r -> x >= 0 && r!! <= 0 }, + { x, r -> x < 0 && r!! < 0 }, + coverage = DoNotCalculate + ) + } + + @Test + fun wrapperToPrimitiveTest() { + check( + IntegerWrapper::wrapperToPrimitive, + eq(3), + { x, _ -> x == null }, + { x, r -> x >= 0 && r!! <= 0 }, + { x, r -> x < 0 && r!! < 0 }, + coverage = DoNotCalculate + ) + } + + @Test + fun numberOfZerosTest() { + check( + IntegerWrapper::numberOfZeros, + eq(4), + { x, _ -> x == null }, + { x, r -> Integer.numberOfLeadingZeros(x) >= 5 && r == 0 }, + { x, r -> Integer.numberOfLeadingZeros(x) < 5 && Integer.numberOfTrailingZeros(x) >= 5 && r == 0 }, + { x, r -> Integer.numberOfLeadingZeros(x) < 5 && Integer.numberOfTrailingZeros(x) < 5 && r == 1 }, + coverage = DoNotCalculate + ) + } + + @Test + fun bitCountTest() { + check( + IntegerWrapper::bitCount, + eq(3), + { x, _ -> x == null }, + { x, r -> Integer.bitCount(x) != 5 && r == 0 }, + { x, r -> Integer.bitCount(x) == 5 && r == 1 }, + coverage = DoNotCalculate + ) + } + + + @Disabled("Caching integer values between -128 and 127 isn't supported JIRA:1481") + @Test + fun equalityTest() { + check( + IntegerWrapper::equality, + eq(3), + { a, b, result -> a == b && a >= -128 && a <= 127 && result == 1 }, + { a, b, result -> a == b && (a < -128 || a > 127) && result == 2 }, + { a, b, result -> a != b && result == 4 }, + coverage = DoNotCalculate + ) + } + +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/LongWrapperTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/LongWrapperTest.kt new file mode 100644 index 0000000000..78ead57ad4 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/LongWrapperTest.kt @@ -0,0 +1,69 @@ +package org.utbot.examples.wrappers + +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.withoutMinimization + +internal class LongWrapperTest : UtValueTestCaseChecker( + testClass = LongWrapper::class, + testCodeGeneration = true, + pipelines = listOf( + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) + ) +) { + @Test + fun primitiveToWrapperTest() { + check( + LongWrapper::primitiveToWrapper, + eq(2), + { x, r -> x >= 0 && r!! <= 0 }, + { x, r -> x < 0 && r!! < 0 }, + coverage = DoNotCalculate + ) + } + + @Test + fun wrapperToPrimitiveTest() { + check( + LongWrapper::wrapperToPrimitive, + eq(3), + { x, _ -> x == null }, + { x, r -> x >= 0 && r!! <= 0 }, + { x, r -> x < 0 && r!! < 0 }, + coverage = DoNotCalculate + ) + } + + @Disabled("Caching long values between -128 and 127 doesn't work JIRA:1481") + @Test + fun equalityTest() { + check( + LongWrapper::equality, + eq(3), + { a, b, result -> a == b && a >= -128 && a <= 127 && result == 1 }, + { a, b, result -> a == b && (a < -128 || a > 127) && result == 2 }, + { a, b, result -> a != b && result == 4 }, + coverage = DoNotCalculate + ) + } + + @Test + fun parseLong() { + withoutMinimization { // TODO: JIRA:1506. These branches will be minimized. + check( + LongWrapper::parseLong, + eq(6), + { line, _ -> line == null }, + { line, _ -> line.isEmpty() }, + { line, _ -> line == "-" }, + { line, _ -> line == "+" }, + { line, _ -> line.startsWith("-") }, + { line, _ -> !line.startsWith("-") }, + coverage = DoNotCalculate + ) + } + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/ShortWrapperTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/ShortWrapperTest.kt new file mode 100644 index 0000000000..9e8281ddfe --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/ShortWrapperTest.kt @@ -0,0 +1,43 @@ +package org.utbot.examples.wrappers + +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.testcheckers.eq + +internal class ShortWrapperTest : UtValueTestCaseChecker(testClass = ShortWrapper::class) { + @Test + fun primitiveToWrapperTest() { + check( + ShortWrapper::primitiveToWrapper, + eq(2), + { x, r -> x >= 0 && r!! <= 0 }, + { x, r -> x < 0 && r!! < 0 }, + coverage = DoNotCalculate + ) + } + + @Test + fun wrapperToPrimitiveTest() { + check( + ShortWrapper::wrapperToPrimitive, + eq(3), + { x, _ -> x == null }, + { x, r -> x >= 0 && r!! <= 0 }, + { x, r -> x < 0 && r!! < 0 }, + coverage = DoNotCalculate + ) + } + + @Disabled("Caching short values between -128 and 127 isn't supported JIRA:1481") + @Test + fun equalityTest() { + check( + ShortWrapper::equality, + eq(3), + { a, b, result -> a == b && a >= -128 && a <= 127 && result == 1 }, + { a, b, result -> a == b && (a < -128 || a > 127) && result == 2 }, + { a, b, result -> a != b && result == 4 }, + coverage = DoNotCalculate + ) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/JUnitSetup.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/JUnitSetup.kt new file mode 100644 index 0000000000..19a91f0e50 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/framework/JUnitSetup.kt @@ -0,0 +1,38 @@ +package org.utbot.framework + +import org.apache.logging.log4j.Level +import org.apache.logging.log4j.LogManager +import org.apache.logging.log4j.core.LogEvent +import org.apache.logging.log4j.core.Logger +import org.apache.logging.log4j.core.appender.AbstractAppender +import org.apache.logging.log4j.core.appender.AppenderLoggingException +import org.junit.jupiter.api.extension.AfterAllCallback +import org.junit.jupiter.api.extension.BeforeAllCallback +import org.junit.jupiter.api.extension.ExtensionContext + +class JUnitSetup : BeforeAllCallback, AfterAllCallback { + + private var appender: ThrowingAppender? = null + private val rootLogger = LogManager.getRootLogger() as Logger + + override fun beforeAll(context: ExtensionContext?) { + appender = ThrowingAppender().apply { start() } + rootLogger.addAppender(appender) + } + + override fun afterAll(context: ExtensionContext?) { + appender?.let { + it.stop() + rootLogger.removeAppender(it) + appender = null + } + } + +} + +class ThrowingAppender : AbstractAppender(ThrowingAppender::class.simpleName, null, null, false, null) { + override fun append(event: LogEvent) { + if (event.level.isMoreSpecificThan(Level.ERROR)) + throw event.thrown ?: AppenderLoggingException(event.message.formattedMessage) + } +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt new file mode 100644 index 0000000000..7a252bb33e --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt @@ -0,0 +1,1503 @@ +package org.utbot.framework.assemble + +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.examples.assemble.AssembleTestUtils +import org.utbot.examples.assemble.ComplexField +import org.utbot.examples.assemble.DirectAccess +import org.utbot.examples.assemble.DirectAccessAndSetter +import org.utbot.examples.assemble.DirectAccessFinal +import org.utbot.examples.assemble.InheritedField +import org.utbot.examples.assemble.ListItem +import org.utbot.examples.assemble.NoModifier +import org.utbot.examples.assemble.PackagePrivateFields +import org.utbot.examples.assemble.PrimitiveFields +import org.utbot.examples.assemble.ArrayOfComplexArrays +import org.utbot.examples.assemble.ArrayOfPrimitiveArrays +import org.utbot.examples.assemble.AssignedArray +import org.utbot.examples.assemble.ComplexArray +import org.utbot.examples.assemble.another.MethodUnderTest +import org.utbot.examples.assemble.PrimitiveArray +import org.utbot.examples.assemble.ComplexConstructor +import org.utbot.examples.assemble.ComplexConstructorWithSetter +import org.utbot.examples.assemble.ConstructorModifyingStatic +import org.utbot.examples.assemble.InheritComplexConstructor +import org.utbot.examples.assemble.InheritPrimitiveConstructor +import org.utbot.examples.assemble.PrimitiveConstructor +import org.utbot.examples.assemble.PrimitiveConstructorWithDefaultField +import org.utbot.examples.assemble.PrivateConstructor +import org.utbot.examples.assemble.PseudoComplexConstructor +import org.utbot.examples.assemble.DefaultField +import org.utbot.examples.assemble.DefaultFieldModifiedInConstructor +import org.utbot.examples.assemble.DefaultFieldWithDirectAccessor +import org.utbot.examples.assemble.DefaultFieldWithSetter +import org.utbot.examples.assemble.DefaultPackagePrivateField +import org.utbot.examples.assemble.StaticField +import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.ExecutableId +import org.utbot.framework.plugin.api.FieldId +import org.utbot.framework.plugin.api.MethodId +import org.utbot.framework.plugin.api.UtArrayModel +import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtCompositeModel +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.UtNullModel +import org.utbot.framework.plugin.api.UtPrimitiveModel +import org.utbot.framework.plugin.api.util.UtContext +import org.utbot.framework.plugin.api.util.UtContext.Companion.setUtContext +import org.utbot.framework.plugin.api.util.executableId +import org.utbot.framework.plugin.api.util.id +import org.utbot.framework.plugin.api.util.intArrayClassId +import org.utbot.framework.plugin.api.util.intClassId +import org.utbot.framework.plugin.services.JdkInfoDefaultProvider +import org.utbot.framework.util.SootUtils +import org.utbot.framework.util.instanceCounter +import org.utbot.framework.util.modelIdCounter +import kotlin.reflect.full.functions +import org.utbot.framework.codegen.model.constructor.util.arrayTypeOf + +/** + * Test classes must be located in the same folder as [AssembleTestUtils] class. + */ +class AssembleModelGeneratorTests { + + private lateinit var context: AutoCloseable + private lateinit var statementsChain: MutableList + + @BeforeEach + fun setUp() { + instanceCounter.set(0) + modelIdCounter.set(0) + statementsChain = mutableListOf() + SootUtils.runSoot(AssembleTestUtils::class.java, forceReload = false, jdkInfo = JdkInfoDefaultProvider().info) + context = setUtContext(UtContext(AssembleTestUtils::class.java.classLoader)) + } + + @AfterEach + fun tearDown() { + context.close() + } + + @Test + fun testOnObjectWithPrimitiveFields() { + val testClassId = PrimitiveFields::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "a" to 5, "b" to 3) + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("a", 5)) + statementsChain.add("$v1." + ("b" `=` 3)) + + val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithDefaultFields() { + val testClassId = PrimitiveFields::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "a" to 5, "b" to 0) + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("a", 5)) + + val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithPackagePrivateFields() { + val testClassId = PackagePrivateFields::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "a" to 5, "b" to 3) + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + ("a" `=` 5)) + statementsChain.add("$v1." + ("b" `=` 3)) + + val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithPackagePrivateFieldsFromAnotherPackage() { + val testClassId = PackagePrivateFields::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "a" to 5, "b" to 3) + ) + + val methodFromAnotherPackage = MethodUnderTest::class.functions.first() + + createModelAndAssert(compositeModel, null, methodFromAnotherPackage.executableId) + } + + @Test + fun testOnObjectWithComplexFields() { + val testClassId = ComplexField::class.id + val innerClassId = PrimitiveFields::class.id + + val innerCompositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + innerClassId, + isMock = false, + fields(innerClassId, "a" to 2, "b" to 4) + ) + + val complexObjectFields = fields( + testClassId, + "i" to 5, + "s" to innerCompositeModel, + ) + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), testClassId, isMock = false, complexObjectFields + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("i", 5)) + val v2 = createExpectedVariableName() + statementsChain.add("$v1." + addExpectedSetter("s", v2)) + val firstExpectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain.toList()) + + statementsChain.clear() + statementsChain.add("${innerClassId.canonicalName}()") + statementsChain.add("$v2." + addExpectedSetter("a", 2)) + statementsChain.add("$v2." + ("b" `=` 4)) + val secondExpectedRepresentation = printExpectedModel(innerClassId.simpleName, v2, statementsChain.toList()) + + createModelsAndAssert( + listOf(compositeModel, innerCompositeModel), + listOf(firstExpectedRepresentation, secondExpectedRepresentation), + ) + } + + @Test + fun testOnObjectWithComplexDefaultFields() { + val testClassId = ComplexField::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "i" to 5), + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("i", 5)) + + val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnListObject() { + val listClassId = ListItem::class.id + + val secondModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + listClassId, + isMock = false, + fields(listClassId, "value" to 2, "next" to UtNullModel(listClassId)) + ) + + val firstModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + listClassId, + isMock = false, + fields(listClassId, "value" to 1, "next" to secondModel) + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("value", 1)) + val v2 = createExpectedVariableName() + statementsChain.add("$v1." + addExpectedSetter("next", v2)) + val firstExpectedRepresentation = printExpectedModel(listClassId.simpleName, v1, statementsChain.toList()) + + statementsChain.clear() + statementsChain.add("${listClassId.canonicalName}()") + statementsChain.add("$v2." + addExpectedSetter("value", 2)) + val secondExpectedRepresentation = printExpectedModel(listClassId.simpleName, v2, statementsChain.toList()) + + createModelsAndAssert( + listOf(firstModel, secondModel), + listOf(firstExpectedRepresentation, secondExpectedRepresentation), + ) + } + + @Test + fun testOnObjectsTriangle() { + val listClassId = ListItem::class.id + + val firstModel = UtCompositeModel(modelIdCounter.incrementAndGet(), listClassId, isMock = false) + val secondModel = UtCompositeModel(modelIdCounter.incrementAndGet(), listClassId, isMock = false) + val thirdModel = UtCompositeModel(modelIdCounter.incrementAndGet(), listClassId, isMock = false) + + firstModel.fields += fields(listClassId, "value" to 1, "next" to secondModel) + secondModel.fields += fields(listClassId, "value" to 2, "next" to thirdModel) + thirdModel.fields += fields(listClassId, "value" to 3, "next" to firstModel) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("value", 1)) + val v2 = createExpectedVariableName() + val v3 = createExpectedVariableName() + statementsChain.add("$v1." + addExpectedSetter("next", v2)) + val firstExpectedRepresentation = printExpectedModel(listClassId.simpleName, v1, statementsChain.toList()) + + statementsChain.clear() + statementsChain.add("${listClassId.canonicalName}()") + statementsChain.add("$v2." + addExpectedSetter("value", 2)) + statementsChain.add("$v2." + addExpectedSetter("next", v3)) + val secondExpectedRepresentation = printExpectedModel(listClassId.simpleName, v2, statementsChain.toList()) + + statementsChain.clear() + statementsChain.add("${listClassId.canonicalName}()") + statementsChain.add("$v3." + addExpectedSetter("value", 3)) + statementsChain.add("$v3." + addExpectedSetter("next", v1)) + val thirdExpectedRepresentation = printExpectedModel(listClassId.simpleName, v3, statementsChain.toList()) + + createModelsAndAssert( + listOf(firstModel, secondModel, thirdModel), + listOf(firstExpectedRepresentation, secondExpectedRepresentation, thirdExpectedRepresentation), + ) + } + + @Test + fun testOnObjectWithPublicFields() { + val testClassId = DirectAccess::class.id + val innerClassId = PrimitiveFields::class.id + + val primitiveFields = fields(innerClassId, "a" to 2, "b" to 4) + + val fields = fields( + testClassId, + "a" to 5, + "b" to 3, + "s" to UtCompositeModel( + modelIdCounter.incrementAndGet(), + innerClassId, + isMock = false, + primitiveFields + ), + ) + val compositeModel = UtCompositeModel(modelIdCounter.incrementAndGet(), testClassId, isMock = false, fields) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("a", 5)) + statementsChain.add("$v1." + ("b" `=` 3)) + val v2 = createExpectedVariableName() + statementsChain.add("$v1." + ("s" `=` v2)) + + val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithPublicFieldAndSetter() { + val testClassId = DirectAccessAndSetter::class.id + val innerClassId = PrimitiveFields::class.id + + val primitiveFields = fields(innerClassId, "a" to 2, "b" to 4) + + val fields = fields( + testClassId, + "a" to 3, + "p" to UtCompositeModel( + modelIdCounter.incrementAndGet(), + innerClassId, + isMock = false, + primitiveFields + ), + ) + val compositeModel = UtCompositeModel(modelIdCounter.incrementAndGet(), testClassId, isMock = false, fields) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + ("a" `=` 3)) + val v2 = createExpectedVariableName() + statementsChain.add("$v1." + ("p" `=` v2)) + + val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithFinalFields() { + val testClassId = DirectAccessFinal::class.id + + val arrayObjectFields = fields( + testClassId, + "array" to UtArrayModel( + modelIdCounter.incrementAndGet(), + intArrayClassId, + length = 2, + UtPrimitiveModel(0), + mutableMapOf(0 to UtPrimitiveModel(1), 1 to UtPrimitiveModel(2)), + ), + ) + val compositeModel = + UtCompositeModel(modelIdCounter.incrementAndGet(), testClassId, isMock = false, arrayObjectFields) + + createModelAndAssert(compositeModel, null) + } + + //region inheritance_tests + + @Test + fun testOnInheritedObjectWithoutBaseFields() { + val testClassId = InheritedField::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "i" to 5, "d" to 3.0) + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + ("i" `=` 5)) + statementsChain.add("$v1." + ("d" `=` 3.0)) + + val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnInheritedObjectWithDefaultBaseFields() { + val inheritedFieldClassId = InheritedField::class.id + val baseClassId = PrimitiveFields::class.id + + val thisFields = fields(inheritedFieldClassId, "i" to 5, "d" to 3.0) + val baseFields = fields(baseClassId, "a" to 0, "b" to 0) + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + inheritedFieldClassId, + isMock = false, + (thisFields + baseFields).toMutableMap(), + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + ("i" `=` 5)) + statementsChain.add("$v1." + ("d" `=` 3.0)) + + val expectedRepresentation = printExpectedModel(inheritedFieldClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnInheritedObjectWithBaseFields() { + val inheritedFieldClassId = InheritedField::class.id + val baseClassId = PrimitiveFields::class.id + + val thisFields = fields(inheritedFieldClassId, "i" to 5, "d" to 3.0) + val baseFields = fields(baseClassId, "b" to 4) + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + inheritedFieldClassId, + isMock = false, + (thisFields + baseFields).toMutableMap(), + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + ("i" `=` 5)) + statementsChain.add("$v1." + ("d" `=` 3.0)) + statementsChain.add("$v1." + ("b" `=` 4)) + + val expectedRepresentation = printExpectedModel(inheritedFieldClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + //endregion + + @Test + fun testOnObjectWithoutSetter() { + val modelClassId = NoModifier::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + modelClassId, + isMock = false, + fields(modelClassId, "a" to 5), + ) + + createModelAndAssert(compositeModel, null) + } + + @Test + fun testOnObjectWithPrimitiveConstructor() { + val modelClassId = PrimitiveConstructor::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + modelClassId, + isMock = false, + fields(modelClassId, "a" to 5, "b" to 3), + ) + + val v1 = statementsChain.addExpectedVariableDecl(5, 3) + + val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithSimpleConstructorAndDefaultField() { + val modelClassId = PrimitiveConstructor::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + modelClassId, + isMock = false, + fields(modelClassId, "a" to 5, "b" to 0), + ) + + val v1 = statementsChain.addExpectedVariableDecl(5, 0) + + val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithPrimitiveConstructorAndStaticFieldNotInModel() { + val modelClassId = StaticField::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + modelClassId, + isMock = false, + fields(modelClassId, "a" to 5, "b" to 3), + ) + + val v1 = statementsChain.addExpectedVariableDecl(5,3) + + val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithPrimitiveConstructorAndStaticFieldInModel() { + val modelClassId = StaticField::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + modelClassId, + isMock = false, + fields(modelClassId, "a" to 5, "b" to 3, "staticField" to 4), + ) + + createModelAndAssert(compositeModel, null) + } + + @Test + fun testOnObjectWithInheritedPrimitiveConstructor() { + val inheritedClassId = InheritPrimitiveConstructor::class.id + val baseClassId = PrimitiveConstructor::class.id + + val thisFields = fields(inheritedClassId, "c" to 1, "d" to 2.0) + val baseFields = fields(baseClassId, "a" to 3, "b" to 4) + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + inheritedClassId, + isMock = false, + (thisFields + baseFields).toMutableMap(), + ) + + val v1 = statementsChain.addExpectedVariableDecl(4, 3, 1, 2.0) + + val expectedRepresentation = printExpectedModel(inheritedClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithInheritedComplexConstructor() { + val inheritedClassId = InheritComplexConstructor::class.id + val baseClassId = ComplexConstructor::class.id + + val thisFields = fields(inheritedClassId, "c" to 1, "d" to 2.0) + val baseFields = fields(baseClassId, "a" to 3, "b" to 4) + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + inheritedClassId, + isMock = false, + (thisFields + baseFields).toMutableMap(), + ) + + createModelAndAssert(compositeModel, null) + } + + @Test + fun testOnObjectWithDefaultConstructorModifyingField() { + val modelClassId = DefaultField::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + modelClassId, + isMock = false, + fields(modelClassId, "z" to 5), + ) + + createModelAndAssert(compositeModel, null) + } + + @Test + fun testOnObjectWithDefaultConstructorModifyingPackagePrivateField() { + val modelClassId = DefaultPackagePrivateField::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + modelClassId, + isMock = false, + fields(modelClassId, "z" to 0), + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + ("z" `=` 0)) + + val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithConstructorModifyingAffectedField() { + val modelClassId = DefaultFieldModifiedInConstructor::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + modelClassId, + isMock = false, + fields(modelClassId, "z" to 5), + ) + + val v1 = statementsChain.addExpectedVariableDecl(5) + statementsChain.add("$v1." + ("z" `=` 5)) + + val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithPublicFieldModifiedByDefaultConstructor() { + val modelClassId = DefaultFieldWithDirectAccessor::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + modelClassId, + isMock = false, + fields(modelClassId, "z" to 5), + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + ("z" `=` 5)) + + val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithFieldWithSetterModifiedByDefaultConstructor() { + val modelClassId = DefaultFieldWithSetter::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + modelClassId, + isMock = false, + fields(modelClassId, "z" to 5), + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("z", 5)) + + val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithFieldWithPrivateSetterModifiedByDefaultConstructor() { + val modelClassId = PrivateConstructor::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + modelClassId, + isMock = false, + fields(modelClassId, "z" to 5), + ) + + val expectedRepresentation = null + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithPrimitiveConstructorModifyingStaticField() { + val modelClassId = ConstructorModifyingStatic::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + modelClassId, + isMock = false, + fields(modelClassId, "x" to 5), + ) + + createModelAndAssert(compositeModel, null) + } + + @Test + fun testOnObjectWithComplexConstructor() { + val modelClassId = ComplexConstructor::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + modelClassId, + isMock = false, + fields(modelClassId, "a" to 5, "b" to 3), + ) + + createModelAndAssert(compositeModel, null) + } + + @Test + fun testOnObjectWithComplexConstructorAndSetter() { + val modelClassId = ComplexConstructorWithSetter::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + modelClassId, + isMock = false, + fields(modelClassId, "a" to 5, "b" to 3), + ) + + val v1 = statementsChain.addExpectedVariableDecl(5, 0) + statementsChain.add("$v1." + addExpectedSetter("b", 3)) + + val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithPseudoComplexConstructor() { + val modelClassId = PseudoComplexConstructor::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + modelClassId, + isMock = false, + fields(modelClassId, "a" to 5), + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + ("a" `=` 5)) + + val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithPrimitiveConstructorHavingDefaultField() { + val modelClassId = PrimitiveConstructorWithDefaultField::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + modelClassId, + isMock = false, + fields(modelClassId, "a" to 5, "b" to 3), + ) + + createModelAndAssert(compositeModel, null) + } + + @Test + fun testOnObjectWithPrimitiveConstructorHavingDefaultFieldNotInModel() { + val modelClassId = PrimitiveConstructorWithDefaultField::class.id + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + modelClassId, + isMock = false, + fields(modelClassId, "a" to 5), + ) + + val v1 = statementsChain.addExpectedVariableDecl(5) + val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) + + createModelAndAssert(compositeModel, expectedRepresentation) + } + + //region coupling_models_tests + + @Test + fun testOnTwoDecoupledPrimitiveObjects() { + val testClassId = PrimitiveFields::class.id + + val firstModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "a" to 5, "b" to 3), + ) + val secondModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "a" to 4, "b" to 2), + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("a", 5)) + statementsChain.add("$v1." + ("b" `=` 3)) + val firstExpectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain.toList()) + + statementsChain.clear() + val v2 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v2." + addExpectedSetter("a", 4)) + statementsChain.add("$v2." + ("b" `=` 2)) + val secondExpectedRepresentation = printExpectedModel(testClassId.simpleName, v2, statementsChain.toList()) + + createModelsAndAssert( + listOf(firstModel, secondModel), + listOf(firstExpectedRepresentation, secondExpectedRepresentation) + ) + } + + @Test + fun testOnTwoDecoupledComplexObjects() { + val testClassId = ComplexField::class.id + val innerClassId = PrimitiveFields::class.id + + val firstSimpleObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + innerClassId, + isMock = false, + fields(innerClassId, "a" to 2, "b" to 4), + ) + val secondSimpleObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + innerClassId, + isMock = false, + fields(innerClassId, "a" to 3, "b" to 5), + ) + + val firstComplexObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "i" to 5, "s" to firstSimpleObjectModel), + ) + val secondComplexObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "i" to 6, "s" to secondSimpleObjectModel), + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("i", 5)) + val v2 = createExpectedVariableName() + statementsChain.add( + "$v1." + addExpectedSetter("s", v2) + ) + val firstExpectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain.toList()) + + statementsChain.clear() + val v3 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v3." + addExpectedSetter("i", 6)) + val v4 = createExpectedVariableName() + statementsChain.add("$v3." + addExpectedSetter("s", v4)) + val secondExpectedRepresentation = printExpectedModel(testClassId.simpleName, v3, statementsChain.toList()) + + createModelsAndAssert( + listOf(firstComplexObjectModel, secondComplexObjectModel), + listOf(firstExpectedRepresentation, secondExpectedRepresentation) + ) + } + + @Test + fun testOnTwoCoupledComplexObjects() { + val testClassId = ComplexField::class.id + val innerClassId = PrimitiveFields::class.id + + val primitiveObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + innerClassId, + isMock = false, + fields(innerClassId, "a" to 2, "b" to 4), + ) + + val firstComplexObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "i" to 5, "s" to primitiveObjectModel), + ) + val secondComplexObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "i" to 6, "s" to primitiveObjectModel), + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("i", 5)) + val v2 = createExpectedVariableName() + statementsChain.add( + "$v1." + addExpectedSetter("s", v2) + ) + val firstExpectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain.toList()) + + statementsChain.clear() + val v3 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v3." + addExpectedSetter("i", 6)) + statementsChain.add("$v3." + addExpectedSetter("s", v2)) + val secondExpectedRepresentation = printExpectedModel(testClassId.simpleName, v3, statementsChain.toList()) + + createModelsAndAssert( + listOf(firstComplexObjectModel, secondComplexObjectModel), + listOf(firstExpectedRepresentation, secondExpectedRepresentation) + ) + } + + @Test + fun testOnThreeCoupledComplexObjects() { + val testClassId = ComplexField::class.id + val innerClassId = PrimitiveFields::class.id + + val primitiveObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + innerClassId, + isMock = false, + fields(innerClassId, "a" to 2, "b" to 4), + ) + + val firstComplexObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "i" to 1, "s" to primitiveObjectModel), + ) + val secondComplexObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "i" to 2, "s" to primitiveObjectModel), + ) + val thirdComplexObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "i" to 3, "s" to primitiveObjectModel), + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("i", 1)) + val v2 = createExpectedVariableName() + statementsChain.add("$v1." + addExpectedSetter("s", v2)) + val firstExpectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain.toList()) + + statementsChain.clear() + val v3 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v3." + addExpectedSetter("i", 2)) + statementsChain.add("$v3." + addExpectedSetter("s", v2)) + val secondExpectedRepresentation = printExpectedModel(testClassId.simpleName, v3, statementsChain.toList()) + + statementsChain.clear() + val v4 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v4." + addExpectedSetter("i", 3)) + statementsChain.add("$v4." + addExpectedSetter("s", v2)) + val thirdExpectedRepresentation = printExpectedModel(testClassId.simpleName, v4, statementsChain.toList()) + + createModelsAndAssert( + listOf(firstComplexObjectModel, secondComplexObjectModel, thirdComplexObjectModel), + listOf(firstExpectedRepresentation, secondExpectedRepresentation, thirdExpectedRepresentation) + ) + } + + @Test + fun testOnTwoEqualComplexObjects() { + val testClassId = ComplexField::class.id + val innerClassId = PrimitiveFields::class.id + + val primitiveObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + innerClassId, + isMock = false, + fields(innerClassId, "a" to 2, "b" to 4), + ) + + val complexObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "i" to 5, "s" to primitiveObjectModel), + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("i", 5)) + val v2 = createExpectedVariableName() + statementsChain.add("$v1." + addExpectedSetter("s", v2)) + + val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) + createModelsAndAssert(listOf(complexObjectModel, complexObjectModel), listOf(expectedRepresentation)) + } + + @Test + fun testOnTwoCoupledListObjects() { + val listClassId = ListItem::class.id + + val secondModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + listClassId, + isMock = false, + fields(listClassId, "value" to 2, "next" to UtNullModel(listClassId)), + ) + + val firstModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + listClassId, + isMock = false, + fields(listClassId, "value" to 1, "next" to secondModel), + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("value", 1)) + val v2 = createExpectedVariableName() + statementsChain.add("$v1." + addExpectedSetter("next", v2)) + val firstExpectedRepresentation = printExpectedModel(listClassId.simpleName, v1, statementsChain.toList()) + + statementsChain.clear() + statementsChain.add("${listClassId.canonicalName}()") + statementsChain.add("$v2." + addExpectedSetter("value", 2)) + val secondExpectedRepresentation = printExpectedModel(listClassId.simpleName, v2, statementsChain.toList()) + + createModelsAndAssert( + listOf(firstModel, secondModel), + listOf(firstExpectedRepresentation, secondExpectedRepresentation) + ) + } + + @Test + fun testOnTwoCrossCoupledListObjects() { + val listClassId = ListItem::class.id + + val firstModel = UtCompositeModel(modelIdCounter.incrementAndGet(), listClassId, isMock = false) + val secondModel = UtCompositeModel(modelIdCounter.incrementAndGet(), listClassId, isMock = false) + + firstModel.fields += fields(listClassId, "value" to 1, "next" to secondModel) + secondModel.fields += fields(listClassId, "value" to 2, "next" to firstModel) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("value", 1)) + val v2 = createExpectedVariableName() + statementsChain.add("$v1." + addExpectedSetter("next", v2)) + + val firstExpectedRepresentation = printExpectedModel(listClassId.simpleName, v1, statementsChain.toList()) + + statementsChain.clear() + statementsChain.add("${listClassId.canonicalName}()") + statementsChain.add("$v2." + addExpectedSetter("value", 2)) + statementsChain.add("$v2." + addExpectedSetter("next", v1)) + val secondExpectedRepresentation = printExpectedModel(listClassId.simpleName, v2, statementsChain) + + createModelsAndAssert( + listOf(firstModel, secondModel), + listOf(firstExpectedRepresentation, secondExpectedRepresentation) + ) + } + + @Test + fun testOnPrimitiveObjectAndNonConstructableOne() { + val simpleClassId = PrimitiveFields::class.id + val nonConstructableClassId = ComplexConstructor::class.id + + val simpleModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + simpleClassId, + isMock = false, + fields(simpleClassId, "a" to 5), + ) + + val nonConstructableModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + nonConstructableClassId, + isMock = false, + fields(nonConstructableClassId, "a" to 5, "b" to 3), + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("a", 5)) + + val simpleModelRepresentation = printExpectedModel(simpleClassId.simpleName, v1, statementsChain.toList()) + + createModelsAndAssert( + listOf(simpleModel, nonConstructableModel), + listOf(simpleModelRepresentation, null) + ) + } + + //endregion + + //region array_field_tests + + @Test + fun testOnObjectWithPrimitiveArrayField() { + val testClassId = PrimitiveArray::class.id + + val arrayObjectFields = fields( + testClassId, + "array" to UtArrayModel( + modelIdCounter.incrementAndGet(), + intArrayClassId, + length = 3, + UtPrimitiveModel(0), + mutableMapOf(0 to UtPrimitiveModel(1), 1 to UtPrimitiveModel(2)), + ), + ) + val compositeModel = + UtCompositeModel(modelIdCounter.incrementAndGet(), testClassId, isMock = false, arrayObjectFields) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + ("array" `=` "[1, 2, 0]")) + + val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithAssignedArrayField() { + val testClassId = AssignedArray::class.id + + val arrayObjectFields = fields( + testClassId, + "array" to UtArrayModel( + modelIdCounter.incrementAndGet(), + intArrayClassId, + length = 3, + UtPrimitiveModel(0), + mutableMapOf(0 to UtPrimitiveModel(1), 1 to UtPrimitiveModel(2)), + ), + ) + val compositeModel = + UtCompositeModel(modelIdCounter.incrementAndGet(), testClassId, isMock = false, arrayObjectFields) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + ("array" `=` "[1, 2, 0]")) + + val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithComplexArrayField() { + val testClassId = ComplexArray::class.id + val innerClassId = PrimitiveFields::class.id + + val arrayObjectFields = fields( + testClassId, + "array" to UtArrayModel( + modelIdCounter.incrementAndGet(), + arrayTypeOf(innerClassId), + length = 3, + UtNullModel(innerClassId), + mutableMapOf( + 1 to UtCompositeModel( + modelIdCounter.incrementAndGet(), + innerClassId, + isMock = false, + fields(innerClassId, "a" to 5) + ) + ), + ), + ) + val compositeModel = + UtCompositeModel(modelIdCounter.incrementAndGet(), testClassId, isMock = false, arrayObjectFields) + + val v1 = statementsChain.addExpectedVariableDecl() + val v2 = createExpectedVariableName() + statementsChain.add( + "$v1." + ("array" `=` "[" + + "null, " + + "UtAssembleModel(${innerClassId.simpleName} $v2) ${innerClassId.canonicalName}() $v2.setA(5), " + + "null" + + "]") + ) + + val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Disabled("Ignored due to https:///unittestbot/UnitTestBot/-/merge_requests/1311") + @Test + fun testOnObjectWithArrayOfPrimitiveArrays() { + val testClassId = ArrayOfPrimitiveArrays::class.id + + val innerArrayModel = UtArrayModel( + modelIdCounter.incrementAndGet(), + intArrayClassId, + length = 2, + UtPrimitiveModel(0), + mutableMapOf(0 to UtPrimitiveModel(1)), + ) + + val arrayModel = UtArrayModel( + modelIdCounter.incrementAndGet(), + intArrayClassId, + length = 2, + innerArrayModel, + mutableMapOf(0 to innerArrayModel, 1 to innerArrayModel), + ) + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "array" to arrayModel) + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + ("array" `=` "[[1, 0], [1, 0]]")) + + val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + @Test + fun testOnObjectWithArrayOfComplexArrays() { + val testClassId = ArrayOfComplexArrays::class.id + val innerClassId = PrimitiveFields::class.id + + val innerArrayClassId = arrayTypeOf(innerClassId) + + val arrayOfArraysModel = UtArrayModel( + modelIdCounter.incrementAndGet(), + arrayTypeOf(testClassId), + length = 2, + UtNullModel(innerArrayClassId), + mutableMapOf( + 0 to UtArrayModel( + modelIdCounter.incrementAndGet(), + innerArrayClassId, + length = 2, + UtNullModel(testClassId), + mutableMapOf( + 0 to UtCompositeModel( + modelIdCounter.incrementAndGet(), + innerClassId, + isMock = false, + fields(innerClassId, "a" to 5) + ) + ) + ), + 1 to UtArrayModel( + modelIdCounter.incrementAndGet(), + innerArrayClassId, + length = 2, + UtNullModel(testClassId), + mutableMapOf( + 0 to UtCompositeModel( + modelIdCounter.incrementAndGet(), + innerClassId, + isMock = false, + fields(innerClassId, "b" to 4) + ) + ), + ) + ), + ) + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = false, + fields(testClassId, "array" to arrayOfArraysModel) + ) + + val v1 = statementsChain.addExpectedVariableDecl() + val v2 = createExpectedVariableName() + val v3 = createExpectedVariableName() + statementsChain.add( + "$v1." + ("array" `=` "[" + + "[UtAssembleModel(${innerClassId.simpleName} $v2) ${innerClassId.canonicalName}() $v2.setA(5), ${null}], " + + "[UtAssembleModel(${innerClassId.simpleName} $v3) ${innerClassId.canonicalName}() $v3.b = 4, ${null}]" + + "]") + ) + + + val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) + createModelAndAssert(compositeModel, expectedRepresentation) + } + + + //endregion + + //region mocks_tests + + @Test + fun testOnObjectWithPrimitiveModelInMock() { + val testClassId = ComplexField::class.id + + val executableId = MethodId(testClassId, "fake_method_name", intClassId, listOf()) + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = true, + mocks = mutableMapOf( + executableId to listOf(UtPrimitiveModel(5), UtPrimitiveModel(3)) + ) + ) + + createModelWithMockAndAssert(compositeModel, listOf(null, null)) + } + + @Test + fun testOnObjectWithCompositeModelInMock() { + val testClassId = ComplexField::class.id + val innerClassId = PrimitiveFields::class.id + + val executableId = MethodId(testClassId, "fake_method_name", innerClassId, listOf()) + + val mockObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + innerClassId, + isMock = false, + fields(innerClassId, "a" to 2, "b" to 3), + ) + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = true, + mocks = mutableMapOf(executableId to listOf(mockObjectModel)) + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("a", 2)) + statementsChain.add("$v1." + ("b" `=` 3)) + + val expectedModelRepresentation = printExpectedModel(innerClassId.simpleName, v1, statementsChain.toList()) + createModelWithMockAndAssert(compositeModel, listOf(expectedModelRepresentation)) + } + + @Test + fun testOnObjectWithCompositeModelInFieldsInMocks() { + val testClassId = ComplexField::class.id + val innerClassId = PrimitiveFields::class.id + + val executableId = MethodId(testClassId, "fake_method_name", innerClassId, listOf()) + + val mockObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + innerClassId, + isMock = false, + fields(innerClassId, "a" to 2), + ) + + val fieldObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + innerClassId, + isMock = false, + fields(innerClassId, "b" to 3), + ) + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = true, + fields = fields(testClassId, "field" to fieldObjectModel), + mocks = mutableMapOf(executableId to listOf(mockObjectModel)), + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + ("b" `=` 3)) + val firstModelRepresentation = printExpectedModel(innerClassId.simpleName, v1, statementsChain.toList()) + + statementsChain.clear() + val v2 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v2." + addExpectedSetter("a", 2)) + val secondModelRepresentation = printExpectedModel(innerClassId.simpleName, v2, statementsChain.toList()) + + createModelWithMockAndAssert( + compositeModel, + listOf(firstModelRepresentation, secondModelRepresentation) + ) + } + + @Test + fun testOnObjectWithCoupledCompositeModelsInMock() { + val testClassId = ComplexField::class.id + val mockObjectClassId = ComplexField::class.id + val innerClassId = PrimitiveFields::class.id + + val executableId = MethodId(testClassId, "fake_method_name", innerClassId, listOf()) + + val innerObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + innerClassId, + isMock = false, + fields(innerClassId, "a" to 2, "b" to 4), + ) + + val firstMockObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + mockObjectClassId, + isMock = false, + fields(mockObjectClassId, "i" to 1, "s" to innerObjectModel), + ) + + val secondMockObjectModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + mockObjectClassId, + isMock = false, + fields(mockObjectClassId, "i" to 2, "s" to innerObjectModel), + ) + + val compositeModel = UtCompositeModel( + modelIdCounter.incrementAndGet(), + testClassId, + isMock = true, + mocks = mutableMapOf(executableId to listOf(firstMockObjectModel, secondMockObjectModel)) + ) + + val v1 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v1." + addExpectedSetter("i", 1)) + val v2 = createExpectedVariableName() + statementsChain.add("$v1." + addExpectedSetter("s", v2)) + val firstExpectedRepresentation = printExpectedModel(mockObjectClassId.simpleName, v1, statementsChain.toList()) + + statementsChain.clear() + val v3 = statementsChain.addExpectedVariableDecl() + statementsChain.add("$v3." + addExpectedSetter("i", 2)) + statementsChain.add("$v3." + addExpectedSetter("s", v2)) + val secondExpectedRepresentation = + printExpectedModel(mockObjectClassId.simpleName, v3, statementsChain.toList()) + + createModelWithMockAndAssert( + compositeModel, + listOf(firstExpectedRepresentation, secondExpectedRepresentation) + ) + } + + //endregion + + /** + * Represents fields of class [classId] as [UtCompositeModel] parameter. + */ + private fun fields( + classId: ClassId, + vararg fields: Pair + ): MutableMap { + return fields + .associate { + val fieldId = FieldId(classId, it.first) + val fieldValue = when (val value = it.second) { + is UtModel -> value + else -> UtPrimitiveModel(value) + } + fieldId to fieldValue + } + .toMutableMap() + } + + /** + * Calls [createModelsAndAssert] for one model. + */ + private fun createModelAndAssert( + model: UtModel, + expectedModelRepresentation: String?, + methodUnderTest: ExecutableId = AssembleTestUtils::class.id.allMethods.first(), + ) = createModelsAndAssert(listOf(model), listOf(expectedModelRepresentation), methodUnderTest) + + /** + * Assembles a model with mock and asserts that it is same as expected. + */ + private fun createModelWithMockAndAssert( + mockModel: UtCompositeModel, + expectedModelRepresentations: List, + ) { + val innerModels = mockModel.fields.values + mockModel.mocks.values.flatten() + createModelsAndAssert(innerModels, expectedModelRepresentations) + } + + /** + * Creates assemble models and asserts that it is same as expected. + */ + private fun createModelsAndAssert( + models: List, + expectedModelRepresentations: List, + assembleTestDummyMethod: ExecutableId = AssembleTestUtils::class.id.allMethods.first(), + ) { + val modelsMap = AssembleModelGenerator(assembleTestDummyMethod.classId.packageName).createAssembleModels(models) + //we sort values to fix order of models somehow (IdentityHashMap does not guarantee the order) + val assembleModels = modelsMap.values + .filterIsInstance() + .sortedBy { it.modelName } + + val assembledModelsCount = assembleModels.count() + val expectedAssembledModelsCount = expectedModelRepresentations.filterNotNull().count() + assertTrue( + assembledModelsCount == expectedAssembledModelsCount, + "Expected $expectedAssembledModelsCount assembled models, but found $assembledModelsCount" + ) + + expectedModelRepresentations.forEachIndexed { i, expectedModelRepresentation -> + if (expectedModelRepresentation != null) { + assertEquals(expectedModelRepresentation, "${assembleModels[i]}") + } + } + } + + private var expectedVariableCounter = 0 + + /** + * Adds declaration of instantiated variable into expected statements chain. + */ + private inline fun MutableList.addExpectedVariableDecl(vararg params: Any): String { + val fqn = T::class.qualifiedName + val varName = createExpectedVariableName() + + val paramString = if (params.any()) params.joinToString(", ") else "" + this.add("$fqn($paramString)") + + return varName + } + + /** + * Creates the name of the variable in expected statements chain. + */ + private inline fun createExpectedVariableName(): String { + return T::class.simpleName!!.decapitalize() + (++expectedVariableCounter) + } + + /** + * Adds setter of variable named [fName] with value [fValue] into expected statements chain. + */ + private fun addExpectedSetter(fName: String, fValue: Any): String = "set${fName.capitalize()}($fValue)" + private infix fun String.`=`(fValue: Any): String = "$this = $fValue" + + /** + * Prints expected assemble model representation. + */ + private fun printExpectedModel(className: String, instanceName: String, statementsChain: List): String = + "UtAssembleModel(${className} $instanceName) ${statementsChain.joinToString(" ")}" +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/BaseConstructorTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/BaseConstructorTest.kt new file mode 100644 index 0000000000..71c63531fa --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/BaseConstructorTest.kt @@ -0,0 +1,34 @@ +package org.utbot.framework.concrete.constructors + +import org.utbot.engine.ValueConstructor +import org.utbot.framework.concrete.UtModelConstructor +import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.util.UtContext +import org.utbot.framework.plugin.api.util.id +import java.util.IdentityHashMap +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.BeforeEach + +abstract class BaseConstructorTest { + private lateinit var cookie: AutoCloseable + + @BeforeEach + fun setup() { + cookie = UtContext.setUtContext(UtContext(ClassLoader.getSystemClassLoader())) + } + + @AfterEach + fun tearDown() { + cookie.close() + } + + protected fun computeReconstructed(value: T): T { + val model = UtModelConstructor(IdentityHashMap()).construct(value, value::class.java.id) + + Assertions.assertTrue(model is UtAssembleModel) + + @Suppress("UNCHECKED_CAST") + return ValueConstructor().construct(listOf(model)).single().value as T + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/ListConstructorTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/ListConstructorTest.kt new file mode 100644 index 0000000000..e3ef59049e --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/ListConstructorTest.kt @@ -0,0 +1,38 @@ +package org.utbot.framework.concrete.constructors + +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class ListConstructorTest : BaseConstructorTest() { + @Test + fun testEmptyList() { + val arrayList = java.util.LinkedList() + + val reconstructed = computeReconstructed(arrayList) + assertEquals(arrayList, reconstructed) + } + + @Test + fun testList() { + val arrayList = java.util.ArrayList() + arrayList.addAll(listOf(1, 2, 3, 4)) + + val reconstructed = computeReconstructed(arrayList) + assertEquals(arrayList, reconstructed) + } + + @Test + fun testListOfLists() { + val arrayList = java.util.ArrayList?>() + val arrayList1 = java.util.ArrayList() + val arrayList2 = java.util.ArrayList() + val arrayList3 = null + arrayList1.addAll(listOf(1, 2, 3)) + arrayList2.addAll(listOf(10, 20, 30)) + arrayList.addAll(listOf(arrayList1, arrayList2, arrayList3)) + + val reconstructed = computeReconstructed(arrayList) + assertEquals(arrayList, reconstructed) + } + +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/MapConstructorTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/MapConstructorTest.kt new file mode 100644 index 0000000000..e756e02942 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/MapConstructorTest.kt @@ -0,0 +1,36 @@ +package org.utbot.framework.concrete.constructors + +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class MapConstructorTest : BaseConstructorTest() { + @Test + fun testEmptyLinkedHashMap() { + val map = java.util.LinkedHashMap() + + val reconstructed = computeReconstructed(map) + + assertEquals(map, reconstructed) + } + + @Test + fun testMapOfIntegersToStrings() { + val map = java.util.LinkedHashMap() + map.putAll(listOf(1 to "1", 2 to "2", 3 to "3", 1 to "4", 1 to "5", 2 to "6")) + + val reconstructed = computeReconstructed(map) + + assertEquals(map, reconstructed) + } + + + @Test + fun testMapOfStringsToStrings() { + val map = java.util.TreeMap() + map.putAll(listOf("1" to "!", "2" to "?", "3" to "#", "3" to "@", "1" to "*")) + + val reconstructed = computeReconstructed(map) + + assertEquals(map, reconstructed) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/OptionalConstructorTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/OptionalConstructorTest.kt new file mode 100644 index 0000000000..7c515f9d55 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/OptionalConstructorTest.kt @@ -0,0 +1,65 @@ +package org.utbot.framework.concrete.constructors + +import java.util.Optional +import java.util.OptionalDouble +import java.util.OptionalInt +import java.util.OptionalLong +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class OptionalConstructorTest : BaseConstructorTest() { + @Test + fun testOptionalInt() { + val optionalInt = OptionalInt.of(42) + + val reconstructed = computeReconstructed(optionalInt) + + assertEquals(optionalInt, reconstructed) + } + + @Test + fun testOptionalDouble() { + val optionalDouble = OptionalDouble.of(42.0) + + val reconstructed = computeReconstructed(optionalDouble) + + assertEquals(optionalDouble, reconstructed) + } + + @Test + fun testOptionalLong() { + val optionalLong = OptionalLong.of(42L) + + val reconstructed = computeReconstructed(optionalLong) + + assertEquals(optionalLong, reconstructed) + } + + @Test + fun testOptional() { + val optional = Optional.of("42") + + val reconstructed = computeReconstructed(optional) + + assertEquals(optional, reconstructed) + } + + @Test + fun testRecursiveOptional() { + val optional = Optional.of("42") + val recursiveOptional = optional.map { optional } + + val reconstructed = computeReconstructed(recursiveOptional) + + assertEquals(reconstructed.get().get(), "42") + } + + @Test + fun testEmptyOptional() { + val emptyOptional = Optional.empty() + + val reconstructed = computeReconstructed(emptyOptional) + + assertEquals(emptyOptional, reconstructed) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/SetConstructorTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/SetConstructorTest.kt new file mode 100644 index 0000000000..56cfe25ff9 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/SetConstructorTest.kt @@ -0,0 +1,36 @@ +package org.utbot.framework.concrete.constructors + +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class SetConstructorTest : BaseConstructorTest() { + @Test + fun testEmptyLinkedHashSet() { + val set = java.util.LinkedHashSet() + + val reconstructed = computeReconstructed(set) + + assertEquals(set, reconstructed) + } + + @Test + fun testSetOfIntegers() { + val set = java.util.LinkedHashSet() + set.addAll(listOf(1, 2, 3, 1, 1, 2)) + + val reconstructed = computeReconstructed(set) + + assertEquals(set, reconstructed) + } + + + @Test + fun testSetOfStrings() { + val set = java.util.LinkedHashSet() + set.addAll(listOf("1", "2", "3", "3", "1")) + + val reconstructed = computeReconstructed(set) + + assertEquals(set, reconstructed) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/minimization/MinimizationGreedyEssentialTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/minimization/MinimizationGreedyEssentialTest.kt new file mode 100644 index 0000000000..993f23059a --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/framework/minimization/MinimizationGreedyEssentialTest.kt @@ -0,0 +1,71 @@ +package org.utbot.framework.minimization + +import kotlin.math.min +import kotlin.ranges.IntProgression.Companion.fromClosedRange +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test + +class MinimizationGreedyEssentialTest { + @Test + fun testEmpty() { + val executions = emptyMap>() + val minimizedExecutions = GreedyEssential.minimize(executions) + assertTrue(minimizedExecutions.isEmpty()) + } + + @Test + fun testCustom1() { + val executions = mapOf( + 1 to listOf(1, 2, 3, 4, 5), + 2 to listOf(2, 3, 4, 5, 6, 7), + 3 to listOf(1, 7), + 4 to listOf(8), + 5 to listOf(1, 8) + ) + val minimizedExecutions = GreedyEssential.minimize(executions) + assertEquals(listOf(2, 5), minimizedExecutions) + } + + @Test + fun testCustom2() { + val executions = mapOf( + 10 to listOf(1, 2, 3, 4, 5), + 20 to listOf(2, 3, 4, 5, 6, 7), + 21 to listOf(1, 7, 2, 3, 5), + 24 to listOf(8, 5, 6, 7), + 50 to listOf(1, 8) + ) + val minimizedExecutions = GreedyEssential.minimize(executions) + assertEquals(listOf(20, 50), minimizedExecutions) + } + + @Test + fun testBigExecutionAndSmallExecutions() { + val size = 10000 + val executions = (1..size) + .associateWith { listOf(it, it + size, it + 2 * size) } + .toMutableMap().apply { + put(0, (1..3 * size).toList()) + } + val minimizedExecutions = GreedyEssential.minimize(executions) + assertEquals(listOf(0), minimizedExecutions.sorted()) + } + + @Test + fun testSameSizeExecutions() { + val size = 2000 + val executionSize = 100 + val executions = (0 until size).associateWith { (it until min(size, it + executionSize)).toList() } + val minimizedExecutions = GreedyEssential.minimize(executions) + assertEquals(fromClosedRange(0, size - 1, executionSize).toList(), minimizedExecutions.sorted()) + } + + @Test + fun testManyExcluding() { + val size = 10000 + val executions = (1..size).associateWith { listOf(it, it + size, it + 2 * size) } + val minimizedExecutions = GreedyEssential.minimize(executions) + assertEquals((1..size).toList(), minimizedExecutions.sorted()) + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt new file mode 100644 index 0000000000..7fd12c48b1 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt @@ -0,0 +1,324 @@ +package org.utbot.framework.modificators + +import org.utbot.examples.modificators.ConstructorsAndSetters +import org.utbot.examples.modificators.DefaultField +import org.utbot.examples.modificators.InvokeInAssignment +import org.utbot.examples.modificators.NoFields +import org.utbot.examples.modificators.NoMethods +import org.utbot.examples.modificators.PrimitiveModifications +import org.utbot.examples.modificators.RecursiveAndCrossCalls +import org.utbot.examples.modificators.StronglyConnectedComponent +import org.utbot.examples.modificators.StronglyConnectedComponents +import org.utbot.examples.modificators.coupling.ClassA +import org.utbot.examples.modificators.coupling.ClassB +import org.utbot.examples.modificators.hierarchy.InheritedModifications +import org.utbot.framework.modifications.AnalysisMode +import org.utbot.framework.modifications.AnalysisMode.AllModificators +import org.utbot.framework.modifications.AnalysisMode.SettersAndDirectAccessors +import org.utbot.framework.modifications.UtBotFieldsModificatorsSearcher +import org.utbot.framework.plugin.api.util.UtContext +import org.utbot.framework.plugin.api.util.id +import kotlin.reflect.KClass +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.utbot.common.nameOfPackage +import org.utbot.framework.plugin.services.JdkInfoDefaultProvider +import org.utbot.framework.util.SootUtils + +internal class UtBotFieldModificatorsTest { + private lateinit var fieldsModificatorsSearcher: UtBotFieldsModificatorsSearcher + private lateinit var context: AutoCloseable + + @BeforeEach + fun setUp() { + context = UtContext.setUtContext(UtContext(PrimitiveModifications::class.java.classLoader)) + } + + @AfterEach + fun tearDown() { + context.close() + } + + //region EdgeCases + + @Test + fun testOnClassesWithoutFields() { + val actualResponse = runFullAnalysis(setOf(NoFields::class)) + + assertTrue(actualResponse.isEmpty()) + } + + @Test + fun testOnClassesWithoutMethods() { + val actualResponse = runFullAnalysis(setOf(NoMethods::class)) + + assertTrue(actualResponse.isEmpty()) + } + + //endregion + + @Test + fun testOnClassHierarchy() { + val actualResponse = runFullAnalysis(setOf(ClassA::class, ClassB::class)) + + assertEquals(expectedForHierarchy, actualResponse) + } + + @Test + fun testClassUpdates() { + val actualResponse = runFullAnalysis( + setOf(ClassA::class), + setOf(ClassA::class, ClassB::class) + ) + + assertEquals(expectedForHierarchy, actualResponse) + } + + @Test + fun testClassDeletion() { + setOf(ClassA::class, ClassB::class).also { + initAnalysis() + runUpdate(it) + } + + runDelete(setOf(ClassB::class)) + runUpdate(setOf(ClassB::class)) + + val actualResponse = runFieldModificatorsSearch(analysisMode = AllModificators) + + assertEquals(expectedForHierarchy, actualResponse) + } + + @Test + fun testOnSimpleClass() { + val actualResponse = runFullAnalysis(setOf(PrimitiveModifications::class)) + + assertEquals(expectedForSimpleClass, actualResponse) + } + + @Test + fun testInSettersMode() { + val actualResponse = runFullAnalysis( + setOf(ConstructorsAndSetters::class), + analysisMode = SettersAndDirectAccessors, + ) + + assertEquals(expectedForClassWithSetters, actualResponse) + } + + @Test + fun testOnRecursiveClass() { + val actualResponse = runFullAnalysis(setOf(RecursiveAndCrossCalls::class)) + + assertEquals(expectedForRecursiveClass, actualResponse) + } + + @Test + fun testOnInheritedClass() { + val actualResponse = runFullAnalysis(setOf(InheritedModifications::class)) + + assertEquals(expectedForInheritedClass, actualResponse) + } + + @Test + fun testOnClassWithOneComponent() { + val actualResponse = runFullAnalysis(setOf(StronglyConnectedComponent::class)) + + assertEquals(expectedForClassWithOneComponent, actualResponse) + } + + @Test + fun testOnClassWithComponents() { + val actualResponse = runFullAnalysis(setOf(StronglyConnectedComponents::class)) + + assertEquals(expectedForClassWithComponents, actualResponse) + } + + @Test + fun testOnClassWithInvokeInAssignment() { + val actualResponse = runFullAnalysis(setOf(InvokeInAssignment::class)) + + assertEquals(expectedForClassWithInvokeInAssignment, actualResponse) + } + + @Test + fun testOnClassWithDefaultField() { + val actualResponse = runFullAnalysis(setOf(DefaultField::class)) + + assertEquals(expectedForClassWithDefaultField, actualResponse) + } + + @Test + fun testRunRequestTwice() { + runFullAnalysis(setOf(PrimitiveModifications::class)) + + val actualResponse = runFieldModificatorsSearch(analysisMode = AllModificators) + + assertEquals(expectedForSimpleClass, actualResponse) + } + + private fun runFullAnalysis( + vararg classSets: Set>, + analysisMode: AnalysisMode = AllModificators, + ): Map> { + initAnalysis() + classSets.forEach { runUpdate(it) } + + return runFieldModificatorsSearch(analysisMode) + } + + private fun initAnalysis() { + SootUtils.runSoot( + PrimitiveModifications::class.java, + forceReload = false, + jdkInfo = JdkInfoDefaultProvider().info + ) + fieldsModificatorsSearcher = UtBotFieldsModificatorsSearcher() + } + + private fun runUpdate(classes: Set>) { + val classIds = classes.map { it.id }.toSet() + + fieldsModificatorsSearcher.update(classIds) + } + + private fun runDelete(classes: Set>) { + val classIds = classes.map { it.id }.toSet() + + fieldsModificatorsSearcher.delete(classIds) + } + + //We use sorting here to make comparing with sorted in advance expected collections easier + private fun runFieldModificatorsSearch(analysisMode: AnalysisMode) = + fieldsModificatorsSearcher.findModificators(analysisMode) + .map { (key, value) -> + val modificatorNames = value.filterNot { it.name.startsWith("direct_set_") }.map { it.name } + key.name to modificatorNames.toSortedSet() + } + .toMap() + .filterNot { it.value.isEmpty() } + .toSortedMap() + + private val expectedForHierarchy = sortedMapOf( + "v1" to setOf("a1Pub"), + "v2" to setOf("a2Pub"), + "v3" to setOf("a1Pub"), + "v4" to setOf("a1Pub"), + "v5" to setOf("a2Pub"), + "v6" to setOf("a1Pub", "a2Pub", "b1Pub"), + "w1" to setOf("a1Pub", "b1Pub"), + "w2" to setOf("b2Pub"), + "w3" to setOf("a1Pub", "b1Pub"), + "w4" to setOf("a1Pub", "b1Pub"), + ) + + private val expectedForSimpleClass = sortedMapOf( + "x" to setOf( + "", + "setCallResult", + "setSeveral", + "setStaticCallResult", + "setWithPrivateCall", + "setWithPrivateCallsHierarchy", + "setWithStdCall", + ), + "y" to setOf( + "", + "setStaticCallResult", + ), + "z" to setOf( + "", + "setAndThrow", + "setOne", + "setSeveral", + "setWithPrivateCallsHierarchy", + ), + "t" to setOf( + "setWithPrivateCall", + "setWithPrivateCallsHierarchy", + ), + ) + + private val expectedForClassWithSetters = sortedMapOf( + "d1" to setOf("setWithInternalCall"), + "i" to setOf("setI"), + ) + + private val expectedForRecursiveClass = sortedMapOf( + "x" to setOf( + "setRecursively", + "setWithReverseCalls", + ), + "z" to setOf( + "setRecursively", + "setWithReverseCalls", + ), + "t" to setOf( + "setWithReverseCalls", + ), + "y" to setOf( + "setRecursively", + "setWithReverseCalls", + ) + ) + + private val expectedForInheritedClass = sortedMapOf( + "x" to setOf( + "setInInterfaceMethod", + "setInStaticInterfaceMethodCall", + "setWithModifyingBaseCall", + "setWithOverrideCall", + "writeAndModify" + ), + "y" to setOf( + "", + "setBaseField", + "setBaseFieldInChild", + "setFieldHereAndInChild", + "setInClassAndBaseClassMethods", + "setInInterfaceMethod", + "setInStaticInterfaceMethodCall", + "setWithModifyingBaseCall", + "setWithOverrideCall", + ), + "baseField" to setOf( + "", + "setBaseField", + "setBaseFieldInChild", + "setInChildAbstract", + "setInClassAndBaseClassMethods", + "setWithModifyingBaseCall", + "setWithOverrideCall", + "write", + "writeAndModify", + ), + ) + + private val expectedForClassWithOneComponent = sortedMapOf( + "x0" to setOf("f0"), + "x1" to setOf("f0", "f1"), + "x2" to setOf("f0", "f1"), + "x3" to setOf("f0", "f1"), + "x4" to setOf("f0", "f1", "f4"), + ) + + private val expectedForClassWithComponents = sortedMapOf( + "x0" to setOf("f0", "f1"), + "x1" to setOf("f0", "f1"), + "x2" to setOf("f0", "f1"), + "x3" to setOf("f0", "f1", "f3", "f4"), + "x4" to setOf("f0", "f1", "f3", "f4"), + ) + + private val expectedForClassWithInvokeInAssignment = sortedMapOf( + "x" to setOf("fun"), + "y" to setOf("fun"), + ) + + private val expectedForClassWithDefaultField = sortedMapOf( + "z" to setOf("", "foo"), + ) +} diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/plugin/api/MockStrategyApiTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/plugin/api/MockStrategyApiTest.kt new file mode 100644 index 0000000000..4ce43e1a95 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/framework/plugin/api/MockStrategyApiTest.kt @@ -0,0 +1,48 @@ +package org.utbot.framework.plugin.api + +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Test +import org.utbot.engine.MockStrategy +import org.utbot.framework.util.toModel + +internal class MockStrategyApiTest { + + @Test + fun testApiToModel() { + assertEquals( + MockStrategyApi.values().size, MockStrategy.values().size, + "The number of strategies in the contract and engine model should match" + ) + + assertEquals(3, MockStrategyApi.values().size, "Three options only (so far)") + assertEquals(MockStrategy.NO_MOCKS, MockStrategyApi.NO_MOCKS.toModel()) + assertEquals(MockStrategy.OTHER_PACKAGES, MockStrategyApi.OTHER_PACKAGES.toModel()) + assertEquals(MockStrategy.OTHER_CLASSES, MockStrategyApi.OTHER_CLASSES.toModel()) + } + + @Test + fun ensureDefaultStrategyIsOtherPackages() { + assertEquals( + MockStrategyApi.OTHER_PACKAGES, + MockStrategyApi.defaultItem, + "Expecting that ${MockStrategyApi.OTHER_PACKAGES} is the default policy for Mocks " + + "but ${MockStrategyApi.defaultItem} found" + ) + } + + @Test + fun testLabelToEnum() { + assertEquals( + MockStrategyApi.values().size, + MockStrategyApi.labels().toSet().size, + "Expecting all labels are unique" + ) + + assertFalse( + MockStrategyApi.labels().any { it.isBlank() }, + "Expecting all labels are not empty" + ) + } + +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/z3/extension/Z3ExtensionForTests.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/z3/extension/Z3ExtensionForTests.kt new file mode 100644 index 0000000000..fdc65fd713 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/framework/z3/extension/Z3ExtensionForTests.kt @@ -0,0 +1,60 @@ +@file:Suppress("PackageDirectoryMismatch", "unused", "NonAsciiCharacters") + +package com.microsoft.z3 + +import kotlin.reflect.KProperty + + +operator fun ArithExpr.plus(other: ArithExpr): ArithExpr = context.mkAdd(this, other) +operator fun ArithExpr.plus(other: Int): ArithExpr = this + context.mkInt(other) + +operator fun ArithExpr.minus(other: ArithExpr): ArithExpr = context.mkSub(this, other) +operator fun ArithExpr.minus(other: Int): ArithExpr = this - context.mkInt(other) + +operator fun ArithExpr.times(other: ArithExpr): ArithExpr = context.mkMul(this, other) +operator fun ArithExpr.times(other: Int): ArithExpr = this * context.mkInt(other) + +infix fun Expr.`=`(other: Int): BoolExpr = this eq context.mkInt(other) +infix fun Expr.`=`(other: Expr): BoolExpr = this eq other +infix fun Expr.eq(other: Expr): BoolExpr = context.mkEq(this, other) +infix fun Expr.`!=`(other: Expr): BoolExpr = context.mkNot(this `=` other) +operator fun BoolExpr.not(): BoolExpr = context.mkNot(this) + +infix fun BoolExpr.`⇒`(other: BoolExpr): BoolExpr = this implies other +infix fun BoolExpr.`⇒`(other: Boolean): BoolExpr = this implies other +infix fun BoolExpr.implies(other: Boolean): BoolExpr = this implies context.mkBool(other) +infix fun BoolExpr.implies(other: BoolExpr): BoolExpr = context.mkImplies(this, other) +infix fun BoolExpr.and(other: BoolExpr): BoolExpr = context.mkAnd(this, other) +infix fun BoolExpr.or(other: BoolExpr): BoolExpr = context.mkOr(this, other) + +infix fun ArithExpr.gt(other: ArithExpr): BoolExpr = context.mkGt(this, other) +infix fun ArithExpr.gt(other: Int): BoolExpr = context.mkGt(this, context.mkInt(other)) + +infix fun ArithExpr.`=`(other: Int): BoolExpr = context.mkEq(this, context.mkInt(other)) + +operator fun ArrayExpr.get(index: IntExpr): Expr = context.mkSelect(this, index) +operator fun ArrayExpr.get(index: Int): Expr = this[context.mkInt(index)] +fun ArrayExpr.set(index: IntExpr, value: Expr): ArrayExpr = context.mkStore(this, index, value) +fun ArrayExpr.set(index: Int, value: Expr): ArrayExpr = set(context.mkInt(index), value) + +operator fun SeqExpr.plus(other: SeqExpr): SeqExpr = context.mkConcat(this, other) +operator fun SeqExpr.plus(other: String): SeqExpr = context.mkConcat(context.mkString(other)) + +infix fun SeqExpr.`=`(other: String): BoolExpr = context.mkEq(this, context.mkString(other)) + +class Const(private val ctx: Context, val produce: (Context, name: String) -> T) { + operator fun getValue(thisRef: Nothing?, property: KProperty<*>): T = produce(ctx, property.name) +} + +fun Context.declareInt() = Const(this) { ctx, name -> ctx.mkIntConst(name) } +fun Context.declareBool() = Const(this) { ctx, name -> ctx.mkBoolConst(name) } +fun Context.declareReal() = Const(this) { ctx, name -> ctx.mkRealConst(name) } +fun Context.declareString() = Const(this) { ctx, name -> ctx.mkConst(name, stringSort) as SeqExpr } +fun Context.declareList(sort: ListSort) = Const(this) { ctx, name -> ctx.mkConst(name, sort) } +fun Context.declareIntArray() = Const(this) { ctx, name -> ctx.mkArrayConst(name, intSort, intSort) } + + +operator fun FuncDecl.invoke(vararg expr: Expr): Expr = context.mkApp(this, *expr) + +fun Model.eval(expr: Expr): Expr = this.eval(expr, true) +fun Model.eval(vararg exprs: Expr): List = exprs.map { this.eval(it, true) } \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/z3/extension/Z3ExtensionTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/z3/extension/Z3ExtensionTest.kt new file mode 100644 index 0000000000..c31298bac8 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/framework/z3/extension/Z3ExtensionTest.kt @@ -0,0 +1,155 @@ +package org.utbot.framework.z3.extension + +import org.utbot.engine.z3.Z3Initializer +import com.microsoft.z3.ArrayExpr +import com.microsoft.z3.Context +import com.microsoft.z3.IntNum +import com.microsoft.z3.RatNum +import com.microsoft.z3.SeqExpr +import com.microsoft.z3.Status +import com.microsoft.z3.`=` +import com.microsoft.z3.and +import com.microsoft.z3.declareInt +import com.microsoft.z3.declareIntArray +import com.microsoft.z3.declareList +import com.microsoft.z3.declareReal +import com.microsoft.z3.declareString +import com.microsoft.z3.eval +import com.microsoft.z3.get +import com.microsoft.z3.invoke +import com.microsoft.z3.minus +import com.microsoft.z3.not +import com.microsoft.z3.plus +import com.microsoft.z3.set +import com.microsoft.z3.times +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test + +class Z3ExtensionTest : Z3Initializer() { + + @Test + fun testArrayDefault() { + Context().use { ctx -> + val arraySort = ctx.mkArraySort(arrayOf(ctx.mkIntSort(), ctx.mkIntSort()), ctx.mkIntSort()) + val ourArray = ctx.mkConst("a", arraySort) as ArrayExpr + + val solver = ctx.mkSolver() + + solver.add(ctx.mkEq(ctx.mkInt(42), ctx.mkTermArray(ourArray))) //mkTermArray function! + solver.check() + val evalArray = solver.model.eval(ourArray) + assertEquals("((as const (Array Int Int Int)) 42)", evalArray.toString()) + } + } + + @Test + fun testInt() { + Context().use { ctx -> + val a by ctx.declareInt() + val b by ctx.declareInt() + + val solver = ctx.mkSolver().apply { add(a * a + b * b `=` 8) } + + assertEquals(Status.SATISFIABLE, solver.check()) + + val (aVal, bVal) = solver.model + .eval(a, b) + .filterIsInstance() + .map(IntNum::getInt) + .also { list -> assertEquals(2, list.size) } + + assertEquals(8, aVal * aVal + bVal * bVal) + } + } + + @Test + fun testReal() { + Context().use { ctx -> + val x by ctx.declareReal() + + val solver = ctx.mkSolver().apply { + add((x * x - x * 4 + 3 `=` 0) and !(x `=` 3)) + } + + assertEquals(Status.SATISFIABLE, solver.check()) + + val xVal = (solver.model.eval(x) as RatNum).let { + it.bigIntNumerator.divide(it.bigIntDenominator).toDouble() + } + + assertEquals(1.0, xVal, 1E-8) + } + } + + @Test + fun testStrings() { + Context().use { ctx -> + val a by ctx.declareString() + val b by ctx.declareString() + val c by ctx.declareString() + + val solver = ctx.mkSolver().apply { + add(a + b `=` "abcd") + add(b + c `=` "cdef") + add(!(b `=` "")) + } + + assertEquals(Status.SATISFIABLE, solver.check()) + + val (aVal, bVal, cVal) = solver.model + .eval(a, b, c) + .filterIsInstance() + .map(SeqExpr::getString) + .also { list -> assertEquals(3, list.size) } + + assertEquals("abcd", "$aVal$bVal") + assertEquals("cdef", "$bVal$cVal") + assertTrue(bVal.isNotBlank()) + } + } + + @Test + fun testArrays() { + Context().use { ctx -> + val x by ctx.declareInt() + val y by ctx.declareInt() + val a1 by ctx.declareIntArray() + + val solver = ctx.mkSolver().apply { + add(a1[x] `=` x) + add(a1.set(x, y) `=` a1) + } + + assertEquals(Status.SATISFIABLE, solver.check()) + + val (xVal, yVal) = solver.model + .eval(x, y) + .filterIsInstance() + .map(IntNum::getInt) + .also { list -> assertEquals(2, list.size) } + + assertTrue(xVal == yVal) + } + } + + @Test + fun testList() { + Context().use { ctx -> + val type = ctx.mkListSort("intList", ctx.intSort) + val l by ctx.declareList(type) + + val solver = ctx.mkSolver().apply { + add(!(l `=` type.nil)) + add(type.headDecl(l) `=` 1) + add(type.tailDecl(l) `=` type.consDecl(type.headDecl(l), type.nil)) + } + + assertEquals(Status.SATISFIABLE, solver.check()) + + val lVal = solver.model.eval(l) + + assertEquals("(cons 1 (cons 1 nil))", "$lVal") + } + } +} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/sarif/SarifReportTest.kt b/utbot-testing/src/test/kotlin/org/utbot/sarif/SarifReportTest.kt new file mode 100644 index 0000000000..44aa51e5f3 --- /dev/null +++ b/utbot-testing/src/test/kotlin/org/utbot/sarif/SarifReportTest.kt @@ -0,0 +1,351 @@ +package org.utbot.sarif + +import org.junit.Test +import org.mockito.Mockito +import org.utbot.framework.plugin.api.ExecutableId +import org.utbot.framework.plugin.api.UtExecution +import org.utbot.framework.plugin.api.UtImplicitlyThrownException +import org.utbot.framework.plugin.api.UtPrimitiveModel +import org.utbot.framework.plugin.api.UtMethodTestSet +import org.utbot.framework.plugin.api.UtSymbolicExecution + +class SarifReportTest { + + @Test + fun testNonEmptyReport() { + val actualReport = SarifReport( + testSets = listOf(), + generatedTestsCode = "", + sourceFindingEmpty + ).createReport().toJson() + + assert(actualReport.isNotEmpty()) + } + + @Test + fun testNoUncheckedExceptions() { + val sarif = SarifReport( + testSets = listOf(testSet), + generatedTestsCode = "", + sourceFindingEmpty + ).createReport() + + assert(sarif.runs.first().results.isEmpty()) + } + + @Test + fun testDetectAllUncheckedExceptions() { + mockUtMethodNames() + + val mockUtExecutionNPE = Mockito.mock(UtExecution::class.java, Mockito.RETURNS_DEEP_STUBS) + Mockito.`when`(mockUtExecutionNPE.result).thenReturn( + UtImplicitlyThrownException(NullPointerException(), false), + ) + Mockito.`when`(mockUtExecutionNPE.stateBefore.parameters).thenReturn(listOf()) + + val mockUtExecutionAIOBE = Mockito.mock(UtExecution::class.java, Mockito.RETURNS_DEEP_STUBS) + Mockito.`when`(mockUtExecutionAIOBE.result).thenReturn( + UtImplicitlyThrownException(ArrayIndexOutOfBoundsException(), false), + ) + Mockito.`when`(mockUtExecutionAIOBE.stateBefore.parameters).thenReturn(listOf()) + + val testSets = listOf( + UtMethodTestSet(mockExecutableId, listOf(mockUtExecutionNPE)), + UtMethodTestSet(mockExecutableId, listOf(mockUtExecutionAIOBE)) + ) + + val report = SarifReport( + testSets = testSets, + generatedTestsCode = "", + sourceFindingEmpty + ).createReport() + + assert(report.runs.first().results[0].message.text.contains("NullPointerException")) + assert(report.runs.first().results[1].message.text.contains("ArrayIndexOutOfBoundsException")) + } + + @Test + fun testCorrectResultLocations() { + mockUtMethodNames() + + Mockito.`when`(mockUtExecution.result).thenReturn( + UtImplicitlyThrownException(NullPointerException(), false) + ) + Mockito.`when`(mockUtExecution.stateBefore.parameters).thenReturn(listOf()) + Mockito.`when`(mockUtExecution.path.lastOrNull()?.stmt?.javaSourceStartLineNumber).thenReturn(1337) + Mockito.`when`(mockUtExecution.testMethodName).thenReturn("testMain_ThrowArithmeticException") + + val report = sarifReportMain.createReport() + + val result = report.runs.first().results.first() + val location = result.locations.first().physicalLocation + val relatedLocation = result.relatedLocations.first().physicalLocation + + assert(location.artifactLocation.uri.contains("Main.java")) + assert(location.region.startLine == 1337) + assert(relatedLocation.artifactLocation.uri.contains("MainTest.java")) + assert(relatedLocation.region.startLine == 1) + assert(relatedLocation.region.startColumn == 1) + } + + @Test + fun testCorrectMethodParameters() { + mockUtMethodNames() + + Mockito.`when`(mockUtExecution.result).thenReturn( + UtImplicitlyThrownException(NullPointerException(), false) + ) + Mockito.`when`(mockUtExecution.stateBefore.parameters).thenReturn( + listOf( + UtPrimitiveModel(227), + UtPrimitiveModel(3.14), + UtPrimitiveModel(false) + ) + ) + + val report = sarifReportMain.createReport() + + val result = report.runs.first().results.first() + assert(result.message.text.contains("227")) + assert(result.message.text.contains("3.14")) + assert(result.message.text.contains("false")) + } + + @Test + fun testCorrectCodeFlows() { + mockUtMethodNames() + + val uncheckedException = Mockito.mock(NullPointerException::class.java) + val stackTraceElement = StackTraceElement("Main", "main", "Main.java", 17) + Mockito.`when`(uncheckedException.stackTrace).thenReturn( + Array(2) { stackTraceElement } + ) + + Mockito.`when`(mockUtExecution.result).thenReturn( + UtImplicitlyThrownException(uncheckedException, false) + ) + Mockito.`when`(mockUtExecution.stateBefore.parameters).thenReturn(listOf()) + + val report = sarifReportMain.createReport() + + val result = report.runs.first().results.first().codeFlows.first().threadFlows.first().locations.map { + it.location.physicalLocation + } + for (index in 0..1) { + assert(result[index].artifactLocation.uri.contains("Main.java")) + assert(result[index].region.startLine == 17) + } + } + + @Test + fun testCodeFlowsStartsWithMethodCall() { + mockUtMethodNames() + + val uncheckedException = Mockito.mock(NullPointerException::class.java) + val stackTraceElement = StackTraceElement("Main", "main", "Main.java", 3) + Mockito.`when`(uncheckedException.stackTrace).thenReturn(arrayOf(stackTraceElement)) + + Mockito.`when`(mockUtExecution.result).thenReturn( + UtImplicitlyThrownException(uncheckedException, false) + ) + Mockito.`when`(mockUtExecution.stateBefore.parameters).thenReturn(listOf()) + Mockito.`when`(mockUtExecution.testMethodName).thenReturn("testMain_ThrowArithmeticException") + + val report = sarifReportMain.createReport() + + val codeFlowPhysicalLocations = report.runs[0].results[0].codeFlows[0].threadFlows[0].locations.map { + it.location.physicalLocation + } + assert(codeFlowPhysicalLocations[0].artifactLocation.uri.contains("MainTest.java")) + assert(codeFlowPhysicalLocations[0].region.startLine == 5) + assert(codeFlowPhysicalLocations[0].region.startColumn == 7) + } + + @Test + fun testCodeFlowsStartsWithPrivateMethodCall() { + mockUtMethodNames() + + val uncheckedException = Mockito.mock(NullPointerException::class.java) + val stackTraceElement = StackTraceElement("Main", "main", "Main.java", 3) + Mockito.`when`(uncheckedException.stackTrace).thenReturn(arrayOf(stackTraceElement)) + + Mockito.`when`(mockUtExecution.result).thenReturn( + UtImplicitlyThrownException(uncheckedException, false) + ) + Mockito.`when`(mockUtExecution.stateBefore.parameters).thenReturn(listOf()) + Mockito.`when`(mockUtExecution.testMethodName).thenReturn("testMain_ThrowArithmeticException") + + val report = sarifReportPrivateMain.createReport() + + val codeFlowPhysicalLocations = report.runs[0].results[0].codeFlows[0].threadFlows[0].locations.map { + it.location.physicalLocation + } + assert(codeFlowPhysicalLocations[0].artifactLocation.uri.contains("MainTest.java")) + assert(codeFlowPhysicalLocations[0].region.startLine == 6) + assert(codeFlowPhysicalLocations[0].region.startColumn == 5) + } + + @Test + fun testMinimizationRemovesDuplicates() { + mockUtMethodNames() + + val mockUtExecution = Mockito.mock(UtExecution::class.java, Mockito.RETURNS_DEEP_STUBS) + Mockito.`when`(mockUtExecution.result).thenReturn(UtImplicitlyThrownException(NullPointerException(), false)) + + val testSets = listOf( + UtMethodTestSet(mockExecutableId, listOf(mockUtExecution)), + UtMethodTestSet(mockExecutableId, listOf(mockUtExecution)) // duplicate + ) + + val report = SarifReport( + testSets = testSets, + generatedTestsCode = "", + sourceFindingMain + ).createReport() + + assert(report.runs.first().results.size == 1) // no duplicates + } + + @Test + fun testMinimizationDoesNotRemoveResultsWithDifferentRuleId() { + mockUtMethodNames() + + val mockUtExecution1 = Mockito.mock(UtExecution::class.java, Mockito.RETURNS_DEEP_STUBS) + val mockUtExecution2 = Mockito.mock(UtExecution::class.java, Mockito.RETURNS_DEEP_STUBS) + + // different ruleId's + Mockito.`when`(mockUtExecution1.result).thenReturn(UtImplicitlyThrownException(NullPointerException(), false)) + Mockito.`when`(mockUtExecution2.result).thenReturn(UtImplicitlyThrownException(ArithmeticException(), false)) + + val testSets = listOf( + UtMethodTestSet(mockExecutableId, listOf(mockUtExecution1)), + UtMethodTestSet(mockExecutableId, listOf(mockUtExecution2)) // not a duplicate + ) + + val report = SarifReport( + testSets = testSets, + generatedTestsCode = "", + sourceFindingMain + ).createReport() + + assert(report.runs.first().results.size == 2) // no results have been removed + } + + @Test + fun testMinimizationDoesNotRemoveResultsWithDifferentLocations() { + mockUtMethodNames() + + val mockUtExecution1 = Mockito.mock(UtSymbolicExecution::class.java, Mockito.RETURNS_DEEP_STUBS) + val mockUtExecution2 = Mockito.mock(UtSymbolicExecution::class.java, Mockito.RETURNS_DEEP_STUBS) + + // the same ruleId's + Mockito.`when`(mockUtExecution1.result).thenReturn(UtImplicitlyThrownException(NullPointerException(), false)) + Mockito.`when`(mockUtExecution2.result).thenReturn(UtImplicitlyThrownException(NullPointerException(), false)) + + // different locations + Mockito.`when`(mockUtExecution1.path.lastOrNull()?.stmt?.javaSourceStartLineNumber).thenReturn(11) + Mockito.`when`(mockUtExecution2.path.lastOrNull()?.stmt?.javaSourceStartLineNumber).thenReturn(22) + + val testSets = listOf( + UtMethodTestSet(mockExecutableId, listOf(mockUtExecution1)), + UtMethodTestSet(mockExecutableId, listOf(mockUtExecution2)) // not a duplicate + ) + + val report = SarifReport( + testSets = testSets, + generatedTestsCode = "", + sourceFindingMain + ).createReport() + + assert(report.runs.first().results.size == 2) // no results have been removed + } + + @Test + fun testMinimizationChoosesShortestCodeFlow() { + mockUtMethodNames() + + val mockNPE1 = Mockito.mock(NullPointerException::class.java) + val mockNPE2 = Mockito.mock(NullPointerException::class.java) + + val mockUtExecution1 = Mockito.mock(UtExecution::class.java, Mockito.RETURNS_DEEP_STUBS) + val mockUtExecution2 = Mockito.mock(UtExecution::class.java, Mockito.RETURNS_DEEP_STUBS) + + // the same ruleId's + Mockito.`when`(mockUtExecution1.result).thenReturn(UtImplicitlyThrownException(mockNPE1, false)) + Mockito.`when`(mockUtExecution2.result).thenReturn(UtImplicitlyThrownException(mockNPE2, false)) + + // but different stack traces + val stackTraceElement1 = StackTraceElement("Main", "main", "Main.java", 3) + val stackTraceElement2 = StackTraceElement("Main", "main", "Main.java", 7) + Mockito.`when`(mockNPE1.stackTrace).thenReturn(arrayOf(stackTraceElement1)) + Mockito.`when`(mockNPE2.stackTrace).thenReturn(arrayOf(stackTraceElement1, stackTraceElement2)) + + val testSets = listOf( + UtMethodTestSet(mockExecutableId, listOf(mockUtExecution1)), + UtMethodTestSet(mockExecutableId, listOf(mockUtExecution2)) // duplicate with a longer stack trace + ) + + val report = SarifReport( + testSets = testSets, + generatedTestsCode = "", + sourceFindingMain + ).createReport() + + assert(report.runs.first().results.size == 1) // no duplicates + assert(report.runs.first().results.first().totalCodeFlowLocations() == 1) // with a shorter stack trace + } + + // internal + + private val mockExecutableId = Mockito.mock(ExecutableId::class.java, Mockito.RETURNS_DEEP_STUBS) + + private val mockUtExecution = Mockito.mock(UtSymbolicExecution::class.java, Mockito.RETURNS_DEEP_STUBS) + + private val testSet = UtMethodTestSet(mockExecutableId, listOf(mockUtExecution)) + + private fun mockUtMethodNames() { + Mockito.`when`(mockExecutableId.name).thenReturn("main") + Mockito.`when`(mockExecutableId.classId.name).thenReturn("Main") + } + + // constants + + private val sourceFindingEmpty = SourceFindingStrategyDefault( + sourceClassFqn = "", + sourceFilePath = "", + testsFilePath = "", + projectRootPath = "" + ) + + private val sourceFindingMain = SourceFindingStrategyDefault( + sourceClassFqn = "Main", + sourceFilePath = "src/Main.java", + testsFilePath = "test/MainTest.java", + projectRootPath = "." + ) + + private val generatedTestsCodeMain = """ + public void testMain_ThrowArithmeticException() { + /* This test fails because method [Main.main] produces [java.lang.ArithmeticException: / by zero] + Main.main(Main.java:15) */ + Main main = new Main(); + main.main(0); // shift for `startColumn` == 7 + } + """.trimIndent() + + private val generatedTestsCodePrivateMain = """ + public void testMain_ThrowArithmeticException() { + /* This test fails because method [Main.main] produces [java.lang.ArithmeticException: / by zero] + Main.main(Main.java:15) */ + Main main = new Main(); + // ... + mainMethod.invoke(main, mainMethodArguments); + } + """.trimIndent() + + private val sarifReportMain = + SarifReport(listOf(testSet), generatedTestsCodeMain, sourceFindingMain) + + private val sarifReportPrivateMain = + SarifReport(listOf(testSet), generatedTestsCodePrivateMain, sourceFindingMain) +} \ No newline at end of file diff --git a/utbot-testing/src/test/resources/junit-platform.properties b/utbot-testing/src/test/resources/junit-platform.properties new file mode 100644 index 0000000000..b059a65dc4 --- /dev/null +++ b/utbot-testing/src/test/resources/junit-platform.properties @@ -0,0 +1 @@ +junit.jupiter.extensions.autodetection.enabled=true \ No newline at end of file diff --git a/utbot-testing/src/test/resources/log4j2.xml b/utbot-testing/src/test/resources/log4j2.xml new file mode 100644 index 0000000000..11a2d0701c --- /dev/null +++ b/utbot-testing/src/test/resources/log4j2.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/utbot-testing/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/utbot-testing/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 0000000000..ca6ee9cea8 --- /dev/null +++ b/utbot-testing/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline \ No newline at end of file diff --git a/utbot-testing/src/test/resources/services/org.junit.jupiter.api.extension.Extension b/utbot-testing/src/test/resources/services/org.junit.jupiter.api.extension.Extension new file mode 100644 index 0000000000..3885d45734 --- /dev/null +++ b/utbot-testing/src/test/resources/services/org.junit.jupiter.api.extension.Extension @@ -0,0 +1 @@ +org.utbot.framework.JUnitSetup \ No newline at end of file From 0a0582e9cd05cb9793394b0bfdec40cb47768692 Mon Sep 17 00:00:00 2001 From: Denis Fokin Date: Thu, 10 Nov 2022 15:29:04 +0300 Subject: [PATCH 07/12] More imports --- .../algorithms/CorrectBracketSequencesTest.kt | 3 + .../utbot/examples/algorithms/GraphTest.kt | 3 + .../org/utbot/examples/algorithms/SortTest.kt | 1 + .../examples/arrays/ArrayOfObjectsTest.kt | 1 + .../arrays/ArrayStoreExceptionExamplesTest.kt | 4 + .../examples/arrays/IntArrayBasicsTest.kt | 4 + .../examples/casts/ArrayCastExampleTest.kt | 3 + .../utbot/examples/casts/CastExampleTest.kt | 4 + .../examples/casts/GenericCastExampleTest.kt | 4 + .../examples/casts/InstanceOfExampleTest.kt | 4 + .../ClassWithStaticAndInnerClassesTest.kt | 4 + .../examples/codegen/CodegenExampleTest.kt | 1 + .../deepequals/ClassWithNullableFieldTest.kt | 3 + .../codegen/deepequals/DeepEqualsTest.kt | 3 + .../collections/CustomerExamplesTest.kt | 1 + .../collections/GenericListsExampleTest.kt | 3 + .../examples/collections/LinkedListsTest.kt | 4 + .../examples/collections/ListIteratorsTest.kt | 4 + .../collections/ListWrapperReturnsVoidTest.kt | 4 + .../examples/collections/ListsPart2Test.kt | 3 + .../examples/collections/ListsPart3Test.kt | 1 + .../examples/collections/MapEntrySetTest.kt | 1 + .../examples/collections/MapKeySetTest.kt | 1 + .../examples/collections/MapValuesTest.kt | 1 + .../examples/collections/MapsPart1Test.kt | 1 + .../examples/collections/MapsPart2Test.kt | 4 + .../examples/collections/OptionalsTest.kt | 1 + .../examples/collections/SetIteratorsTest.kt | 1 + .../utbot/examples/collections/SetsTest.kt | 1 + .../examples/controlflow/ConditionsTest.kt | 4 + .../controlflow/CycleDependedConditionTest.kt | 3 + .../utbot/examples/controlflow/CyclesTest.kt | 1 + .../utbot/examples/controlflow/SwitchTest.kt | 3 + .../utbot/examples/enums/ClassWithEnumTest.kt | 3 + .../examples/enums/ComplexEnumExamplesTest.kt | 3 + .../exceptions/ExceptionExamplesTest.kt | 1 + .../examples/invokes/InvokeExampleTest.kt | 4 + .../examples/invokes/NativeExampleTest.kt | 3 + .../invokes/VirtualInvokeExampleTest.kt | 3 + .../lambda/CustomPredicateExampleTest.kt | 4 + .../lambda/SimpleLambdaExamplesTest.kt | 4 + .../ClassWithComplicatedMethodsTest.kt | 3 + .../utbot/examples/math/BitOperatorsTest.kt | 4 +- .../examples/math/OverflowAsErrorTest.kt | 1 + .../mixed/PrivateConstructorExampleTest.kt | 3 + .../mixed/StaticMethodExamplesTest.kt | 1 + .../utbot/examples/mock/ArgumentsMockTest.kt | 1 + .../examples/mock/CommonMocksExampleTest.kt | 2 + .../org/utbot/examples/mock/FieldMockTest.kt | 1 + .../org/utbot/examples/mock/MockRandomTest.kt | 1 + .../mock/MockStaticMethodExampleTest.kt | 1 + .../mock/MockWithSideEffectExampleTest.kt | 3 + .../examples/mock/StaticFieldMockTest.kt | 4 + .../org/utbot/examples/mock/UseNetworkTest.kt | 4 +- .../aliasing/AliasingInParamsExampleTest.kt | 2 + .../examples/mock/model/FieldMockChecker.kt | 2 + .../models/ModelsIdEqualityChecker.kt | 2 + .../examples/natives/NativeExamplesTest.kt | 3 + .../objects/AnonymousClassesExampleTest.kt | 1 + .../utbot/examples/objects/ClassRefTest.kt | 3 + .../examples/objects/ClassWithClassRefTest.kt | 1 + .../objects/HiddenFieldExampleTest.kt | 2 + .../objects/ModelMinimizationExamplesTest.kt | 2 + .../objects/ObjectWithFinalStaticTest.kt | 4 + .../objects/ObjectWithPrimitivesClassTest.kt | 2 + .../ObjectWithPrimitivesExampleTest.kt | 1 + .../objects/ObjectWithRefFieldsExampleTest.kt | 1 + .../ObjectWithStaticFieldsExampleTest.kt | 1 + .../objects/SimpleClassExampleTest.kt | 1 + .../examples/primitives/IntExamplesTest.kt | 1 + .../utbot/examples/recursion/RecursionTest.kt | 1 + .../substitution/StaticsSubstitutionTest.kt | 2 + .../utbot/examples/stdlib/DateExampleTest.kt | 2 + .../examples/stream/BaseStreamExampleTest.kt | 1 + .../stream/DoubleStreamExampleTest.kt | 1 + .../examples/stream/IntStreamExampleTest.kt | 1 + .../examples/stream/LongStreamExampleTest.kt | 1 + .../StreamsAsMethodResultExampleTest.kt | 6 +- .../examples/strings/GenericExamplesTest.kt | 3 + .../examples/strings/StringExamplesTest.kt | 1 + .../examples/strings11/StringConcatTest.kt | 1 + .../org/utbot/examples/structures/HeapTest.kt | 2 + .../structures/MinStackExampleTest.kt | 3 + .../structures/StandardStructuresTest.kt | 1 + .../utbot/examples/types/TypeBordersTest.kt | 2 + .../examples/wrappers/BooleanWrapperTest.kt | 2 + .../examples/wrappers/ByteWrapperTest.kt | 2 + .../examples/wrappers/CharacterWrapperTest.kt | 3 + .../examples/wrappers/DoubleWrapperTest.kt | 2 + .../examples/wrappers/FloatWrapperTest.kt | 2 + .../examples/wrappers/IntegerWrapperTest.kt | 2 + .../examples/wrappers/LongWrapperTest.kt | 3 + .../examples/wrappers/ShortWrapperTest.kt | 2 + .../examples/SummaryTestCaseGeneratorTest.kt | 5 +- .../algorithms/SummaryReturnExampleTest.kt | 1 + .../SummaryListWrapperReturnsVoidTest.kt | 1 + .../examples/controlflow/SummaryCycleTest.kt | 1 + .../examples/inner/SummaryInnerCallsTest.kt | 1 + .../examples/inner/SummaryNestedCallsTest.kt | 1 + .../structures/SummaryMinStackTest.kt | 1 + .../examples/ternary/SummaryTernaryTest.kt | 1 + .../test/kotlin/math/SummaryIntMathTest.kt | 1 + .../examples/manual/UtBotJavaApiTest.java | 1359 --------------- .../org/utbot/bytecode/versions/SootTest.kt | 69 - .../utbot/engine/pc/QueryOptimizationsTest.kt | 642 ------- .../org/utbot/engine/z3/ExtensionsKtTest.kt | 396 ----- .../org/utbot/engine/z3/OperatorsKtTest.kt | 76 - .../examples/algorithms/BinarySearchTest.kt | 97 -- .../algorithms/CorrectBracketSequencesTest.kt | 145 -- .../utbot/examples/algorithms/GraphTest.kt | 50 - .../org/utbot/examples/algorithms/SortTest.kt | 183 -- .../annotations/NotNullAnnotationTest.kt | 101 -- .../lombok/EnumWithAnnotationsTest.kt | 25 - .../lombok/EnumWithoutAnnotationsTest.kt | 16 - .../lombok/NotNullAnnotationsTest.kt | 25 - .../examples/arrays/ArrayOfArraysTest.kt | 283 ---- .../examples/arrays/ArrayOfObjectsTest.kt | 111 -- .../arrays/ArrayStoreExceptionExamplesTest.kt | 210 --- .../arrays/ArraysOverwriteValueTest.kt | 153 -- .../arrays/FinalStaticFieldArrayTest.kt | 21 - .../examples/arrays/IntArrayBasicsTest.kt | 228 --- .../examples/arrays/PrimitiveArraysTest.kt | 186 -- .../examples/casts/ArrayCastExampleTest.kt | 172 -- .../org/utbot/examples/casts/CastClassTest.kt | 26 - .../utbot/examples/casts/CastExampleTest.kt | 89 - .../examples/casts/GenericCastExampleTest.kt | 77 - .../examples/casts/InstanceOfExampleTest.kt | 406 ----- .../ClassWithStaticAndInnerClassesTest.kt | 129 -- .../examples/codegen/CodegenExampleTest.kt | 56 - .../codegen/FileWithTopLevelFunctionsTest.kt | 43 - .../utbot/examples/codegen/JavaAssertTest.kt | 21 - .../examples/codegen/VoidStaticMethodsTest.kt | 36 - ...ClassWithCrossReferenceRelationshipTest.kt | 26 - .../deepequals/ClassWithNullableFieldTest.kt | 32 - .../codegen/deepequals/DeepEqualsTest.kt | 164 -- ...ithPrivateMutableFieldOfPrivateTypeTest.kt | 41 - .../collections/CustomerExamplesTest.kt | 76 - .../collections/GenericListsExampleTest.kt | 160 -- .../examples/collections/LinkedListsTest.kt | 261 --- .../collections/ListAlgorithmsTest.kt | 32 - .../examples/collections/ListIteratorsTest.kt | 108 -- .../collections/ListWrapperReturnsVoidTest.kt | 43 - .../examples/collections/ListsPart1Test.kt | 30 - .../examples/collections/ListsPart2Test.kt | 27 - .../examples/collections/ListsPart3Test.kt | 246 --- .../examples/collections/MapEntrySetTest.kt | 172 -- .../examples/collections/MapKeySetTest.kt | 161 -- .../examples/collections/MapValuesTest.kt | 179 -- .../examples/collections/MapsPart1Test.kt | 382 ----- .../examples/collections/MapsPart2Test.kt | 87 - .../examples/collections/OptionalsTest.kt | 489 ------ .../examples/collections/QueueUsagesTest.kt | 127 -- .../examples/collections/SetIteratorsTest.kt | 98 -- .../utbot/examples/collections/SetsTest.kt | 239 --- .../examples/controlflow/ConditionsTest.kt | 55 - .../controlflow/CycleDependedConditionTest.kt | 117 -- .../utbot/examples/controlflow/CyclesTest.kt | 216 --- .../utbot/examples/controlflow/SwitchTest.kt | 88 - .../utbot/examples/enums/ClassWithEnumTest.kt | 194 --- .../examples/enums/ComplexEnumExamplesTest.kt | 106 -- .../exceptions/ExceptionClusteringChecker.kt | 57 - .../exceptions/ExceptionExamplesTest.kt | 135 -- .../exceptions/JvmCrashExamplesTest.kt | 41 - .../examples/invokes/InvokeExampleTest.kt | 212 --- .../examples/invokes/NativeExampleTest.kt | 52 - .../invokes/SimpleInterfaceExampleTest.kt | 40 - .../invokes/StaticInvokeExampleTest.kt | 22 - .../invokes/VirtualInvokeExampleTest.kt | 145 -- .../lambda/CustomPredicateExampleTest.kt | 77 - .../lambda/PredicateNotExampleTest.kt | 19 - .../lambda/SimpleLambdaExamplesTest.kt | 35 - .../ClassWithComplicatedMethodsTest.kt | 95 -- .../utbot/examples/math/BitOperatorsTest.kt | 175 -- .../utbot/examples/math/DivRemExamplesTest.kt | 78 - .../examples/math/DoubleFunctionsTest.kt | 61 - .../examples/math/OverflowAsErrorTest.kt | 282 ---- .../utbot/examples/mixed/LoggerExampleTest.kt | 58 - .../utbot/examples/mixed/MonitorUsageTest.kt | 19 - .../org/utbot/examples/mixed/OverloadTest.kt | 29 - .../mixed/PrivateConstructorExampleTest.kt | 39 - .../examples/mixed/SimpleNoConditionTest.kt | 32 - .../utbot/examples/mixed/SimplifierTest.kt | 20 - .../mixed/StaticInitializerExampleTest.kt | 31 - .../mixed/StaticMethodExamplesTest.kt | 42 - .../utbot/examples/mock/ArgumentsMockTest.kt | 363 ---- .../examples/mock/CommonMocksExampleTest.kt | 59 - .../org/utbot/examples/mock/FieldMockTest.kt | 290 ---- .../mock/InnerMockWithFieldChecker.kt | 52 - .../utbot/examples/mock/MockFinalClassTest.kt | 34 - .../org/utbot/examples/mock/MockRandomTest.kt | 146 -- .../mock/MockReturnObjectExampleTest.kt | 69 - .../mock/MockStaticFieldExampleTest.kt | 71 - .../mock/MockStaticMethodExampleTest.kt | 46 - .../examples/mock/MockWithFieldChecker.kt | 47 - .../mock/MockWithSideEffectExampleTest.kt | 66 - .../examples/mock/StaticFieldMockTest.kt | 277 --- .../org/utbot/examples/mock/UseNetworkTest.kt | 57 - .../aliasing/AliasingInParamsExampleTest.kt | 31 - .../examples/mock/model/FieldMockChecker.kt | 38 - .../mock/model/UseNetworkModelBasedTest.kt | 28 - .../CompositeModelMinimizationChecker.kt | 78 - .../models/ModelsIdEqualityChecker.kt | 143 -- .../examples/natives/NativeExamplesTest.kt | 39 - .../objects/AnonymousClassesExampleTest.kt | 57 - .../utbot/examples/objects/ClassRefTest.kt | 137 -- .../examples/objects/ClassWithClassRefTest.kt | 32 - .../objects/HiddenFieldAccessModifiersTest.kt | 20 - .../objects/HiddenFieldExampleTest.kt | 34 - .../objects/ModelMinimizationExamplesTest.kt | 131 -- .../objects/ObjectWithFinalStaticTest.kt | 26 - .../objects/ObjectWithPrimitivesClassTest.kt | 34 - .../ObjectWithPrimitivesExampleTest.kt | 266 --- .../objects/ObjectWithRefFieldsExampleTest.kt | 154 -- .../ObjectWithStaticFieldsExampleTest.kt | 186 -- .../ObjectWithThrowableConstructorTest.kt | 22 - .../examples/objects/PrivateFieldsTest.kt | 21 - .../examples/objects/RecursiveTypeTest.kt | 36 - .../objects/SimpleClassExampleTest.kt | 100 -- .../SimpleClassMultiInstanceExampleTest.kt | 22 - .../examples/primitives/ByteExamplesTest.kt | 39 - .../examples/primitives/CharExamplesTest.kt | 52 - .../examples/primitives/DoubleExamplesTest.kt | 161 -- .../examples/primitives/FloatExamplesTest.kt | 18 - .../examples/primitives/IntExamplesTest.kt | 119 -- .../utbot/examples/recursion/RecursionTest.kt | 138 -- .../substitution/StaticsSubstitutionTest.kt | 30 - .../utbot/examples/stdlib/DateExampleTest.kt | 67 - .../examples/stream/BaseStreamExampleTest.kt | 462 ----- .../stream/DoubleStreamExampleTest.kt | 534 ------ .../examples/stream/IntStreamExampleTest.kt | 565 ------- .../examples/stream/LongStreamExampleTest.kt | 559 ------ .../StreamsAsMethodResultExampleTest.kt | 69 - .../examples/strings/GenericExamplesTest.kt | 35 - .../examples/strings/StringExamplesTest.kt | 667 -------- .../examples/strings11/StringConcatTest.kt | 113 -- .../org/utbot/examples/structures/HeapTest.kt | 20 - .../structures/MinStackExampleTest.kt | 103 -- .../structures/StandardStructuresTest.kt | 100 -- .../thirdparty/numbers/ArithmeticUtilsTest.kt | 46 - .../utbot/examples/types/CastExamplesTest.kt | 77 - .../utbot/examples/types/TypeBordersTest.kt | 76 - .../utbot/examples/types/TypeMatchesTest.kt | 60 - .../examples/unsafe/UnsafeOperationsTest.kt | 39 - .../examples/unsafe/UnsafeWithFieldTest.kt | 18 - .../examples/wrappers/BooleanWrapperTest.kt | 40 - .../examples/wrappers/ByteWrapperTest.kt | 40 - .../examples/wrappers/CharacterWrapperTest.kt | 50 - .../examples/wrappers/DoubleWrapperTest.kt | 30 - .../examples/wrappers/FloatWrapperTest.kt | 30 - .../examples/wrappers/IntegerWrapperTest.kt | 70 - .../examples/wrappers/LongWrapperTest.kt | 69 - .../examples/wrappers/ShortWrapperTest.kt | 43 - .../kotlin/org/utbot/framework/JUnitSetup.kt | 38 - .../assemble/AssembleModelGeneratorTests.kt | 1503 ----------------- .../constructors/BaseConstructorTest.kt | 34 - .../constructors/ListConstructorTest.kt | 38 - .../constructors/MapConstructorTest.kt | 36 - .../constructors/OptionalConstructorTest.kt | 65 - .../constructors/SetConstructorTest.kt | 36 - .../MinimizationGreedyEssentialTest.kt | 71 - .../UtBotFieldModificatorsTest.kt | 324 ---- .../plugin/api/MockStrategyApiTest.kt | 48 - .../z3/extension/Z3ExtensionForTests.kt | 60 - .../framework/z3/extension/Z3ExtensionTest.kt | 155 -- .../kotlin/org/utbot/sarif/SarifReportTest.kt | 351 ---- .../test/resources/junit-platform.properties | 1 - utbot-testing/src/test/resources/log4j2.xml | 36 - .../org.mockito.plugins.MockMaker | 1 - .../org.junit.jupiter.api.extension.Extension | 1 - 269 files changed, 220 insertions(+), 21738 deletions(-) delete mode 100644 utbot-testing/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/bytecode/versions/SootTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/engine/pc/QueryOptimizationsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/engine/z3/ExtensionsKtTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/engine/z3/OperatorsKtTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/BinarySearchTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/GraphTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/annotations/NotNullAnnotationTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithAnnotationsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithoutAnnotationsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/NotNullAnnotationsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayOfArraysTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayStoreExceptionExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArraysOverwriteValueTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/arrays/FinalStaticFieldArrayTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/arrays/IntArrayBasicsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/arrays/PrimitiveArraysTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/casts/ArrayCastExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/casts/CastClassTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/casts/CastExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/casts/GenericCastExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/casts/InstanceOfExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/ClassWithStaticAndInnerClassesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/CodegenExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/FileWithTopLevelFunctionsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/VoidStaticMethodsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithCrossReferenceRelationshipTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithNullableFieldTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/DeepEqualsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/GenericListsExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/LinkedListsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListAlgorithmsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListIteratorsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListWrapperReturnsVoidTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart1Test.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart2Test.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart3Test.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapEntrySetTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapKeySetTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapValuesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapsPart1Test.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapsPart2Test.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/QueueUsagesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/SetIteratorsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/collections/SetsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/ConditionsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/CycleDependedConditionTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/SwitchTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/enums/ClassWithEnumTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/enums/ComplexEnumExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/ExceptionClusteringChecker.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/ExceptionExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/JvmCrashExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/invokes/InvokeExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/invokes/NativeExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/invokes/SimpleInterfaceExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/invokes/StaticInvokeExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/invokes/VirtualInvokeExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/lambda/CustomPredicateExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/lambda/PredicateNotExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/make/symbolic/ClassWithComplicatedMethodsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/math/BitOperatorsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/math/DivRemExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/math/DoubleFunctionsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mixed/LoggerExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mixed/MonitorUsageTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mixed/OverloadTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mixed/SimpleNoConditionTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mixed/SimplifierTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mixed/StaticInitializerExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/InnerMockWithFieldChecker.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockFinalClassTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockReturnObjectExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockStaticFieldExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockWithFieldChecker.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockWithSideEffectExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/UseNetworkTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/aliasing/AliasingInParamsExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/mock/model/UseNetworkModelBasedTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/models/CompositeModelMinimizationChecker.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/models/ModelsIdEqualityChecker.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/natives/NativeExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ClassRefTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ClassWithClassRefTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/HiddenFieldAccessModifiersTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ModelMinimizationExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithFinalStaticTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesClassTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithThrowableConstructorTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/RecursiveTypeTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/objects/SimpleClassMultiInstanceExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/primitives/ByteExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/primitives/CharExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/primitives/DoubleExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/primitives/FloatExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/statics/substitution/StaticsSubstitutionTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/stream/DoubleStreamExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/stream/IntStreamExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/stream/LongStreamExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/strings/GenericExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/strings/StringExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/strings11/StringConcatTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/structures/HeapTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/structures/MinStackExampleTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/thirdparty/numbers/ArithmeticUtilsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/types/CastExamplesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/types/TypeBordersTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/types/TypeMatchesTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/unsafe/UnsafeWithFieldTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/BooleanWrapperTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/ByteWrapperTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/CharacterWrapperTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/DoubleWrapperTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/FloatWrapperTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/IntegerWrapperTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/LongWrapperTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/ShortWrapperTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/JUnitSetup.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/BaseConstructorTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/ListConstructorTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/MapConstructorTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/OptionalConstructorTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/SetConstructorTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/minimization/MinimizationGreedyEssentialTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/plugin/api/MockStrategyApiTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/z3/extension/Z3ExtensionForTests.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/framework/z3/extension/Z3ExtensionTest.kt delete mode 100644 utbot-testing/src/test/kotlin/org/utbot/sarif/SarifReportTest.kt delete mode 100644 utbot-testing/src/test/resources/junit-platform.properties delete mode 100644 utbot-testing/src/test/resources/log4j2.xml delete mode 100644 utbot-testing/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker delete mode 100644 utbot-testing/src/test/resources/services/org.junit.jupiter.api.extension.Extension diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt index 415d7e0b12..1326ce4d05 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt @@ -5,7 +5,10 @@ import org.utbot.framework.plugin.api.DocCodeStmt import org.utbot.framework.plugin.api.DocPreTagStatement import org.utbot.framework.plugin.api.DocRegularStmt import org.junit.jupiter.api.Test +import org.utbot.examples.algorithms.CorrectBracketSequences.isBracket +import org.utbot.examples.algorithms.CorrectBracketSequences.isOpen import org.utbot.testcheckers.eq +import org.utbot.testing.* internal class CorrectBracketSequencesTest : UtValueTestCaseChecker( testClass = CorrectBracketSequences::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/GraphTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/GraphTest.kt index 2ac25b02f9..bf669b9c1e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/GraphTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/GraphTest.kt @@ -3,6 +3,9 @@ package org.utbot.examples.algorithms import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException internal class GraphTest : UtValueTestCaseChecker(testClass = GraphExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt index 354558b3fb..b999cddae3 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt @@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq import org.utbot.testcheckers.ge +import org.utbot.testing.* // TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 internal class SortTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt index f26c944212..d82da01587 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt @@ -4,6 +4,7 @@ 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.testing.* // TODO failed Kotlin compilation SAT-1332 internal class ArrayOfObjectsTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayStoreExceptionExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayStoreExceptionExamplesTest.kt index dfd48eafad..0eabf7adad 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayStoreExceptionExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayStoreExceptionExamplesTest.kt @@ -4,6 +4,10 @@ import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq +import org.utbot.testing.AtLeast +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException class ArrayStoreExceptionExamplesTest : UtValueTestCaseChecker( testClass = ArrayStoreExceptionExamples::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/IntArrayBasicsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/IntArrayBasicsTest.kt index aedb08e43a..a68df2f63c 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/IntArrayBasicsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/IntArrayBasicsTest.kt @@ -5,6 +5,10 @@ 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.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException // TODO failed Kotlin compilation SAT-1332 internal class IntArrayBasicsTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/ArrayCastExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/ArrayCastExampleTest.kt index 51c4c3123f..0dda6a1d11 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/ArrayCastExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/ArrayCastExampleTest.kt @@ -4,6 +4,9 @@ import org.junit.jupiter.api.Disabled import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker // TODO failed Kotlin compilation (generics) SAT-1332 //TODO: SAT-1487 calculate coverage for all methods of this test class diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/CastExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/CastExampleTest.kt index 77747a3035..57725ecd06 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/CastExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/CastExampleTest.kt @@ -3,6 +3,10 @@ package org.utbot.examples.casts import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException // TODO failed Kotlin compilation SAT-1332 internal class CastExampleTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/GenericCastExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/GenericCastExampleTest.kt index e62fe49cbe..58b719cd1f 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/GenericCastExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/casts/GenericCastExampleTest.kt @@ -3,6 +3,10 @@ package org.utbot.examples.casts import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.between // TODO failed Kotlin compilation SAT-1332 internal class GenericCastExampleTest : UtValueTestCaseChecker( 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 fe9fa10068..ba85c0051d 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 @@ -5,6 +5,10 @@ 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.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber // TODO failed Kotlin compilation SAT-1332 internal class InstanceOfExampleTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/ClassWithStaticAndInnerClassesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/ClassWithStaticAndInnerClassesTest.kt index a2576397ee..71a4942631 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/ClassWithStaticAndInnerClassesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/ClassWithStaticAndInnerClassesTest.kt @@ -3,6 +3,10 @@ package org.utbot.examples.codegen import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq +import org.utbot.testing.Compilation +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.TestExecution +import org.utbot.testing.UtValueTestCaseChecker @Suppress("INACCESSIBLE_TYPE") internal class ClassWithStaticAndInnerClassesTest : UtValueTestCaseChecker( 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 ce9b6b757f..bd07565c1e 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,6 +5,7 @@ import kotlin.reflect.full.functions import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.testcheckers.withoutConcrete +import org.utbot.testing.UtValueTestCaseChecker internal class CodegenExampleTest : UtValueTestCaseChecker(testClass = CodegenExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithNullableFieldTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithNullableFieldTest.kt index 4dbf645bd8..fd8b77b2e4 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithNullableFieldTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithNullableFieldTest.kt @@ -3,6 +3,9 @@ package org.utbot.examples.codegen.deepequals import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker class ClassWithNullableFieldTest : UtValueTestCaseChecker( testClass = ClassWithNullableField::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/DeepEqualsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/DeepEqualsTest.kt index 9d206c61d4..045178471d 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/DeepEqualsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/codegen/deepequals/DeepEqualsTest.kt @@ -4,6 +4,9 @@ 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.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker // TODO failed Kotlin compilation (generics) SAT-1332 class DeepEqualsTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt index 94e1a81f36..ffbed5d177 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt @@ -5,6 +5,7 @@ import org.utbot.framework.plugin.api.FieldId import org.utbot.framework.plugin.api.UtConcreteValue import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.* internal class CustomerExamplesTest: UtValueTestCaseChecker( testClass = CustomerExamples::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/GenericListsExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/GenericListsExampleTest.kt index fbabf6523c..cadc6bd4bb 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/GenericListsExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/GenericListsExampleTest.kt @@ -4,6 +4,9 @@ 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.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker // TODO disabled tests should be fixes with SAT-1441 internal class GenericListsExampleTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/LinkedListsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/LinkedListsTest.kt index ca667af7e9..d0190dc5ba 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/LinkedListsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/LinkedListsTest.kt @@ -3,6 +3,10 @@ package org.utbot.examples.collections import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException // TODO failed Kotlin compilation (generics) SAT-1332 internal class LinkedListsTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListIteratorsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListIteratorsTest.kt index a8274f04df..377e2d1f83 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListIteratorsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListIteratorsTest.kt @@ -5,6 +5,10 @@ import org.utbot.framework.plugin.api.CodegenLanguage import kotlin.math.min import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber // TODO failed Kotlin compilation (generics) SAT-1332 internal class ListIteratorsTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListWrapperReturnsVoidTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListWrapperReturnsVoidTest.kt index d4c5cae8dc..956f243b90 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListWrapperReturnsVoidTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListWrapperReturnsVoidTest.kt @@ -4,6 +4,10 @@ import org.junit.jupiter.api.Disabled import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException // TODO failed Kotlin compilation ($ in function names, generics) SAT-1220 SAT-1332 @Disabled("Java 11 transition") diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart2Test.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart2Test.kt index 616ec2e4a7..621f95aedb 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart2Test.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/ListsPart2Test.kt @@ -3,6 +3,9 @@ package org.utbot.examples.collections import org.junit.jupiter.api.Disabled import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber // TODO failed Kotlin compilation SAT-1332 @Disabled 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 d7ac68b90a..54d6fa13b8 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,6 +5,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.testing.* // TODO failed Kotlin compilation SAT-1332 internal class ListsPart3Test : UtValueTestCaseChecker( 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 4c9bd82989..7cf2352a81 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 @@ -5,6 +5,7 @@ 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.testing.* // TODO failed Kotlin compilation SAT-1332 class MapEntrySetTest : UtValueTestCaseChecker( 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 92aa202c2e..64ea3ec835 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 @@ -6,6 +6,7 @@ import org.utbot.testcheckers.eq import org.utbot.testcheckers.ge import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete import org.utbot.testcheckers.withoutMinimization +import org.utbot.testing.* // TODO failed Kotlin compilation SAT-1332 class MapKeySetTest : UtValueTestCaseChecker( 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 cd92dfb0b8..935b2e0fe1 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 @@ -4,6 +4,7 @@ import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.ge import org.utbot.testcheckers.withoutMinimization +import org.utbot.testing.* // TODO failed Kotlin compilation SAT-1332 class MapValuesTest : UtValueTestCaseChecker( 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 4f73aec84b..a228364a3d 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 @@ -9,6 +9,7 @@ import org.utbot.testcheckers.ge import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete import org.utbot.testcheckers.withoutConcrete import org.utbot.testcheckers.withoutMinimization +import org.utbot.testing.* // TODO failed Kotlin compilation ($ in names, generics) SAT-1220 SAT-1332 internal class MapsPart1Test : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapsPart2Test.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapsPart2Test.kt index 12a0c585e4..30920238ec 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapsPart2Test.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/MapsPart2Test.kt @@ -5,6 +5,10 @@ import org.junit.jupiter.api.Test import org.utbot.testcheckers.ge import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete import org.utbot.testcheckers.withoutMinimization +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException // TODO failed Kotlin compilation ($ in names, generics) SAT-1220 SAT-1332 internal class MapsPart2Test : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt index fab2ca1d57..47834d270c 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt @@ -3,6 +3,7 @@ package org.utbot.examples.collections import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.* import java.util.* class OptionalsTest : UtValueTestCaseChecker( 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 21c9945b94..2d741c6158 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 @@ -3,6 +3,7 @@ package org.utbot.examples.collections import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.ge +import org.utbot.testing.* // TODO failed Kotlin compilation SAT-1332 class SetIteratorsTest : UtValueTestCaseChecker( 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 4e368f8085..831d0fe064 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 @@ -7,6 +7,7 @@ import org.utbot.testcheckers.eq import org.utbot.testcheckers.ge import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete import org.utbot.testcheckers.withoutMinimization +import org.utbot.testing.* // TODO failed Kotlin compilation SAT-1332 internal class SetsTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/ConditionsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/ConditionsTest.kt index 4cd9376ef9..4466f6f369 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/ConditionsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/ConditionsTest.kt @@ -6,6 +6,10 @@ import org.utbot.framework.plugin.api.DocRegularStmt import org.utbot.framework.plugin.api.DocStatement import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.keyContain +import org.utbot.testing.keyMatch internal class ConditionsTest : UtValueTestCaseChecker(testClass = Conditions::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CycleDependedConditionTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CycleDependedConditionTest.kt index c0dc060e96..b36cc8901e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CycleDependedConditionTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CycleDependedConditionTest.kt @@ -6,6 +6,9 @@ import org.utbot.framework.plugin.api.DocRegularStmt import org.utbot.framework.plugin.api.DocStatement import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.keyContain +import org.utbot.testing.keyMatch internal class CycleDependedConditionTest : UtValueTestCaseChecker(testClass = CycleDependedCondition::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt index 878ecb6ca5..6ba747d945 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt @@ -6,6 +6,7 @@ import org.utbot.framework.plugin.api.DocRegularStmt import org.utbot.framework.plugin.api.DocStatement import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.* internal class CyclesTest : UtValueTestCaseChecker(testClass = Cycles::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/SwitchTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/SwitchTest.kt index 381c097be9..1149872edf 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/SwitchTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/SwitchTest.kt @@ -13,6 +13,9 @@ import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq import org.utbot.testcheckers.ge import org.utbot.testcheckers.withoutMinimization +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.keyContain +import org.utbot.testing.keyMatch internal class SwitchTest : UtValueTestCaseChecker(testClass = Switch::class) { @Test 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 a6d62721ca..21bd1f33bb 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 @@ -10,6 +10,9 @@ 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.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException class ClassWithEnumTest : UtValueTestCaseChecker(testClass = ClassWithEnum::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/enums/ComplexEnumExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/enums/ComplexEnumExamplesTest.kt index e0d35726a4..b4d969962e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/enums/ComplexEnumExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/enums/ComplexEnumExamplesTest.kt @@ -8,6 +8,9 @@ import org.utbot.examples.enums.ComplexEnumExamples.Color.GREEN import org.utbot.examples.enums.ComplexEnumExamples.Color.RED import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber class ComplexEnumExamplesTest : UtValueTestCaseChecker( testClass = ComplexEnumExamples::class, 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 29b62857fa..44bc2c47e6 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 @@ -4,6 +4,7 @@ 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.testing.* internal class ExceptionExamplesTest : UtValueTestCaseChecker( testClass = ExceptionExamples::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/InvokeExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/InvokeExampleTest.kt index 44ec7ceb69..5abc14bd7d 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/InvokeExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/InvokeExampleTest.kt @@ -2,6 +2,10 @@ package org.utbot.examples.invokes import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException internal class InvokeExampleTest : UtValueTestCaseChecker(testClass = InvokeExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/NativeExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/NativeExampleTest.kt index 9949638cb1..f437801c68 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/NativeExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/invokes/NativeExampleTest.kt @@ -6,6 +6,9 @@ import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq import org.utbot.testcheckers.ge +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast +import org.utbot.testing.ignoreExecutionsNumber internal class NativeExampleTest : UtValueTestCaseChecker(testClass = NativeExample::class) { @Test 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 05f4395083..57536896dc 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 @@ -5,6 +5,9 @@ package org.utbot.examples.invokes import java.lang.Boolean import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException internal class VirtualInvokeExampleTest : UtValueTestCaseChecker(testClass = VirtualInvokeExample::class) { @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 868273353e..5653e43ca2 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,10 @@ 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.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException class CustomPredicateExampleTest : UtValueTestCaseChecker( testClass = CustomPredicateExample::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt index 2c893b55b6..f3b2705124 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt @@ -3,6 +3,10 @@ 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.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException // TODO failed Kotlin compilation (generics) SAT-1332 class SimpleLambdaExamplesTest : UtValueTestCaseChecker( 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 083220f4c5..2dde06a193 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 @@ -8,6 +8,9 @@ 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.testing.Compilation +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker // This class is substituted with ComplicatedMethodsSubstitutionsStorage // but we cannot do in code generation. diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/BitOperatorsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/BitOperatorsTest.kt index a54b0146dc..a40a390fef 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/BitOperatorsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/BitOperatorsTest.kt @@ -2,6 +2,8 @@ package org.utbot.examples.math import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast internal class BitOperatorsTest : UtValueTestCaseChecker(testClass = BitOperators::class) { @Test @@ -35,7 +37,7 @@ internal class BitOperatorsTest : UtValueTestCaseChecker(testClass = BitOperator } @Test - @kotlin.ExperimentalStdlibApi + @ExperimentalStdlibApi fun testAnd() { check( BitOperators::and, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt index 4adc79d13b..09b547714c 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt @@ -7,6 +7,7 @@ import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq import org.utbot.testcheckers.withSolverTimeoutInMillis import org.utbot.testcheckers.withTreatingOverflowAsError +import org.utbot.testing.* import kotlin.math.floor import kotlin.math.sqrt diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt index 45126e0bad..26e091ff64 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt @@ -3,6 +3,9 @@ package org.utbot.examples.mixed import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq +import org.utbot.testing.Compilation +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class PrivateConstructorExampleTest : UtValueTestCaseChecker( testClass = PrivateConstructorExample::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt index 40cfd0945d..baab044c23 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt @@ -3,6 +3,7 @@ package org.utbot.examples.mixed import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker internal class StaticMethodExamplesTest : UtValueTestCaseChecker(testClass = StaticMethodExamples::class) { // TODO: inline local variables when types inference bug in Kotlin fixed diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt index 5fa176228b..74663fca45 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt @@ -12,6 +12,7 @@ import org.utbot.examples.mock.service.impl.ServiceWithArguments import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.* internal class ArgumentsMockTest : UtValueTestCaseChecker(testClass = ServiceWithArguments::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt index 5c4a3a24d0..4d2f841b25 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt @@ -5,6 +5,8 @@ package org.utbot.examples.mock import org.utbot.framework.plugin.api.MockStrategyApi import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class CommonMocksExampleTest: UtValueTestCaseChecker(testClass = CommonMocksExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt index 3edd155c0b..4ce60d4a49 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt @@ -7,6 +7,7 @@ import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq +import org.utbot.testing.* internal class FieldMockTest : UtValueTestCaseChecker( testClass = ServiceWithField::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt index d46281fd6c..5e80898dac 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt @@ -6,6 +6,7 @@ import java.util.Random import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq +import org.utbot.testing.* // TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 internal class MockRandomTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt index 821435ca21..59a4e58e79 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt @@ -8,6 +8,7 @@ import org.utbot.framework.util.singleValue import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq +import org.utbot.testing.* // TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 internal class MockStaticMethodExampleTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockWithSideEffectExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockWithSideEffectExampleTest.kt index 1fba9e414b..bb31390546 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockWithSideEffectExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockWithSideEffectExampleTest.kt @@ -3,6 +3,9 @@ package org.utbot.examples.mock import org.utbot.framework.plugin.api.MockStrategyApi import org.junit.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException internal class MockWithSideEffectExampleTest : UtValueTestCaseChecker(testClass = MockWithSideEffectExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt index 9246daad57..db1b4e8ee9 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt @@ -8,6 +8,10 @@ import org.utbot.examples.mock.service.impl.ServiceWithStaticField import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.mocksMethod +import org.utbot.testing.value internal class StaticFieldMockTest : UtValueTestCaseChecker(testClass = ServiceWithStaticField::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/UseNetworkTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/UseNetworkTest.kt index f481cb78be..772990f206 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/UseNetworkTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/UseNetworkTest.kt @@ -3,8 +3,10 @@ package org.utbot.examples.mock import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtConcreteValue import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException internal class UseNetworkTest : UtValueTestCaseChecker(testClass = UseNetwork::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/aliasing/AliasingInParamsExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/aliasing/AliasingInParamsExampleTest.kt index c0ce27528f..6efcdf3089 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/aliasing/AliasingInParamsExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/aliasing/AliasingInParamsExampleTest.kt @@ -3,6 +3,8 @@ package org.utbot.examples.mock.aliasing import org.utbot.framework.plugin.api.MockStrategyApi import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class AliasingInParamsExampleTest : UtValueTestCaseChecker(testClass = AliasingInParamsExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt index 2499893bf3..39dbef6ef2 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt @@ -10,6 +10,8 @@ import org.utbot.framework.plugin.api.isNull import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtModelTestCaseChecker +import org.utbot.testing.primitiveValue internal class FieldMockChecker : UtModelTestCaseChecker(testClass = ServiceWithField::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/models/ModelsIdEqualityChecker.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/models/ModelsIdEqualityChecker.kt index 8e50a4b48b..b61abdc554 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/models/ModelsIdEqualityChecker.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/models/ModelsIdEqualityChecker.kt @@ -8,6 +8,8 @@ import org.utbot.framework.plugin.api.UtExecutionSuccess import org.utbot.framework.plugin.api.UtReferenceModel import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtModelTestCaseChecker // TODO failed Kotlin compilation SAT-1332 internal class ModelsIdEqualityChecker : UtModelTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/natives/NativeExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/natives/NativeExamplesTest.kt index 4b7bd42a9e..a84604cb6e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/natives/NativeExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/natives/NativeExamplesTest.kt @@ -5,6 +5,9 @@ import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq import org.utbot.testcheckers.ge import org.utbot.testcheckers.withSolverTimeoutInMillis +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker // TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 internal class NativeExamplesTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt index efab9304b1..4aa14e715c 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt @@ -3,6 +3,7 @@ package org.utbot.examples.objects import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq +import org.utbot.testing.* class AnonymousClassesExampleTest : UtValueTestCaseChecker( testClass = AnonymousClassesExample::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ClassRefTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ClassRefTest.kt index 6382bc09c5..7e7aa33bb8 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ClassRefTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ClassRefTest.kt @@ -9,6 +9,9 @@ import kotlin.Suppress import kotlin.arrayOf import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast internal class ClassRefTest : UtValueTestCaseChecker( testClass = ClassRef::class, 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 d081c8c0a3..87fd61f6cc 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 @@ -4,6 +4,7 @@ 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.testing.* // TODO Kotlin compilation SAT-1332 // Code generation executions fail due we cannot analyze strings properly for now diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt index 41d2edfbfb..5aa703df56 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt @@ -2,6 +2,8 @@ package org.utbot.examples.objects import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class HiddenFieldExampleTest : UtValueTestCaseChecker(testClass = HiddenFieldExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ModelMinimizationExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ModelMinimizationExamplesTest.kt index 80ab112c2b..658f834229 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ModelMinimizationExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ModelMinimizationExamplesTest.kt @@ -2,6 +2,8 @@ package org.utbot.examples.objects import org.junit.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class ModelMinimizationExamplesTest : UtValueTestCaseChecker(testClass = ModelMinimizationExamples::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithFinalStaticTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithFinalStaticTest.kt index 4f2e04c94c..82c272f572 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithFinalStaticTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithFinalStaticTest.kt @@ -3,6 +3,10 @@ package org.utbot.examples.objects import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.singleValue class ObjectWithFinalStaticTest : UtValueTestCaseChecker( testClass = ObjectWithFinalStatic::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesClassTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesClassTest.kt index aa568046f5..6cc5aa08e3 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesClassTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesClassTest.kt @@ -4,6 +4,8 @@ import kotlin.reflect.KFunction0 import kotlin.reflect.KFunction3 import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class ObjectWithPrimitivesClassTest : UtValueTestCaseChecker(testClass = ObjectWithPrimitivesClass::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt index bff483ad3f..f8f3d3ff3a 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt @@ -3,6 +3,7 @@ package org.utbot.examples.objects import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.* internal class ObjectWithPrimitivesExampleTest : UtValueTestCaseChecker(testClass = ObjectWithPrimitivesExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt index 1d331f9d0d..2f745fbe64 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt @@ -2,6 +2,7 @@ package org.utbot.examples.objects import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.* internal class ObjectWithRefFieldsExampleTest : UtValueTestCaseChecker(testClass = ObjectWithRefFieldExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt index 6af50704af..79d00425b1 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt @@ -2,6 +2,7 @@ package org.utbot.examples.objects import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.* internal class ObjectWithStaticFieldsExampleTest : UtValueTestCaseChecker(testClass = ObjectWithStaticFieldsExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt index 67bad2c9f3..7008599b8b 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt @@ -6,6 +6,7 @@ import org.utbot.framework.plugin.api.DocRegularStmt import org.utbot.framework.plugin.api.DocStatement import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.* internal class SimpleClassExampleTest : UtValueTestCaseChecker(testClass = SimpleClassExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt index ba51507276..bded155112 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker @Suppress("ConvertTwoComparisonsToRangeCheck") internal class IntExamplesTest : UtValueTestCaseChecker(testClass = IntExamples::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt index a5ee5eda7e..cb5c500528 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt @@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq import org.utbot.testcheckers.ge +import org.utbot.testing.* // TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 internal class RecursionTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/statics/substitution/StaticsSubstitutionTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/statics/substitution/StaticsSubstitutionTest.kt index 0b97f4e0c7..ff5c014a68 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/statics/substitution/StaticsSubstitutionTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/statics/substitution/StaticsSubstitutionTest.kt @@ -3,6 +3,8 @@ package org.utbot.examples.statics.substitution import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq import org.utbot.testcheckers.withoutSubstituteStaticsWithSymbolicVariable +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker class StaticsSubstitutionTest : UtValueTestCaseChecker(testClass = StaticSubstitutionExamples::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt index ddbe69d720..9b62b55953 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt @@ -7,6 +7,8 @@ import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq import org.utbot.testcheckers.withUsingReflectionForMaximizingCoverage +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException import java.util.Date @Disabled("Java 11 transition -- these tests seems to take too much time and memory") 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 b3bed63f70..a34e0d7f5a 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 @@ -13,6 +13,7 @@ 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.testing.* import java.util.Optional 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 71062b8b82..65a158ff43 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 @@ -6,6 +6,7 @@ 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.testing.* import java.util.OptionalDouble import java.util.stream.DoubleStream 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 89a8b5d69e..5549d81214 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 @@ -6,6 +6,7 @@ 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.testing.* import java.util.OptionalDouble import java.util.OptionalInt 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 7cac365890..522c0bca7f 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 @@ -6,6 +6,7 @@ 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.testing.* import java.util.OptionalDouble import java.util.OptionalLong diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt index 30fb1d0553..5273c8321f 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt @@ -4,8 +4,10 @@ import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.framework.plugin.api.visible.UtStreamConsumingException import org.utbot.testcheckers.eq - - +import org.utbot.testing.CodeGeneration +import org.utbot.testing.FullWithAssumptions +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException import kotlin.streams.toList diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/strings/GenericExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/strings/GenericExamplesTest.kt index 8548f82b13..c7cc3d8401 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/strings/GenericExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/strings/GenericExamplesTest.kt @@ -4,6 +4,9 @@ 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.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException @Disabled("TODO: Fails and takes too long") internal class GenericExamplesTest : UtValueTestCaseChecker( 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 f219660f44..35d029142c 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 @@ -8,6 +8,7 @@ import org.utbot.testcheckers.ge import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete import org.utbot.testcheckers.withSolverTimeoutInMillis import org.utbot.testcheckers.withoutMinimization +import org.utbot.testing.* internal class StringExamplesTest : UtValueTestCaseChecker( testClass = StringExamples::class, 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 090cbb2c7f..e1bf478b25 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 @@ -4,6 +4,7 @@ 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.testing.* class StringConcatTest : UtValueTestCaseChecker( testClass = StringConcat::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/HeapTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/HeapTest.kt index 92f87808f8..dd405f15b0 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/HeapTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/HeapTest.kt @@ -1,6 +1,8 @@ package org.utbot.examples.structures import org.junit.jupiter.api.Test +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber internal class HeapTest : UtValueTestCaseChecker(testClass = Heap::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/MinStackExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/MinStackExampleTest.kt index 53676ee1d1..f391339671 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/MinStackExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/MinStackExampleTest.kt @@ -3,6 +3,9 @@ package org.utbot.examples.structures import kotlin.math.min import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.between internal class MinStackExampleTest : UtValueTestCaseChecker(testClass = MinStackExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt index 5f2c35d34f..14be6af6d6 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt @@ -10,6 +10,7 @@ import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq +import org.utbot.testing.* internal class StandardStructuresTest : UtValueTestCaseChecker( testClass = StandardStructures::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/types/TypeBordersTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/types/TypeBordersTest.kt index e1325710de..a2251d00c4 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/types/TypeBordersTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/types/TypeBordersTest.kt @@ -2,6 +2,8 @@ package org.utbot.examples.types import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast internal class TypeBordersTest : UtValueTestCaseChecker(testClass = TypeBorders::class) { @Test 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 aa874a5f3e..6f97af67d6 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 @@ -2,6 +2,8 @@ package org.utbot.examples.wrappers import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class BooleanWrapperTest : UtValueTestCaseChecker(testClass = BooleanWrapper::class) { @Test 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 51241e7880..489e04fcf7 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 @@ -2,6 +2,8 @@ package org.utbot.examples.wrappers import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class ByteWrapperTest : UtValueTestCaseChecker(testClass = ByteWrapper::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/CharacterWrapperTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/CharacterWrapperTest.kt index bce33bb2f5..7236297e16 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/CharacterWrapperTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/CharacterWrapperTest.kt @@ -4,6 +4,9 @@ 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.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker // TODO failed Kotlin compilation internal class CharacterWrapperTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/DoubleWrapperTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/DoubleWrapperTest.kt index 049fba0fa5..d355ca86ac 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/DoubleWrapperTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/DoubleWrapperTest.kt @@ -2,6 +2,8 @@ package org.utbot.examples.wrappers import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker @Suppress("SimplifyNegatedBinaryExpression") internal class DoubleWrapperTest : UtValueTestCaseChecker(testClass = DoubleWrapper::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/FloatWrapperTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/FloatWrapperTest.kt index 2142305a1d..fcb3eeae52 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/FloatWrapperTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/FloatWrapperTest.kt @@ -2,6 +2,8 @@ package org.utbot.examples.wrappers import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker @Suppress("SimplifyNegatedBinaryExpression") internal class FloatWrapperTest : UtValueTestCaseChecker(testClass = FloatWrapper::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/IntegerWrapperTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/IntegerWrapperTest.kt index 27c78191af..f9e360c352 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/IntegerWrapperTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/IntegerWrapperTest.kt @@ -3,6 +3,8 @@ package org.utbot.examples.wrappers import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class IntegerWrapperTest : UtValueTestCaseChecker(testClass = IntegerWrapper::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/LongWrapperTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/LongWrapperTest.kt index 78ead57ad4..8cac4bc66e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/LongWrapperTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/LongWrapperTest.kt @@ -5,6 +5,9 @@ import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq import org.utbot.testcheckers.withoutMinimization +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class LongWrapperTest : UtValueTestCaseChecker( testClass = LongWrapper::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/ShortWrapperTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/ShortWrapperTest.kt index 9e8281ddfe..ec4e0498e2 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/ShortWrapperTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/wrappers/ShortWrapperTest.kt @@ -3,6 +3,8 @@ package org.utbot.examples.wrappers import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker internal class ShortWrapperTest : UtValueTestCaseChecker(testClass = ShortWrapper::class) { @Test diff --git a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt index f6799edf6a..b1d6bfb564 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt @@ -11,10 +11,11 @@ import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.executableId import org.utbot.summary.comment.nextSynonyms import org.utbot.summary.summarize +import org.utbot.testing.CoverageMatcher +import org.utbot.testing.TestExecution +import org.utbot.testing.UtValueTestCaseChecker import kotlin.reflect.KClass import kotlin.reflect.KFunction -import org.utbot.testing.DoNotCalculate -import org.utbot.testing.TestLastStage private const val NEW_LINE = "\n" private const val POINT_IN_THE_LIST = " * " diff --git a/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt index 33e22341ae..fe7db953eb 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt @@ -5,6 +5,7 @@ import org.utbot.examples.algorithms.ReturnExample import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.MockStrategyApi +import org.utbot.testing.DoNotCalculate class SummaryReturnExampleTest : SummaryTestCaseGeneratorTest( ReturnExample::class, diff --git a/utbot-summary-tests/src/test/kotlin/examples/collections/SummaryListWrapperReturnsVoidTest.kt b/utbot-summary-tests/src/test/kotlin/examples/collections/SummaryListWrapperReturnsVoidTest.kt index b7cb654af2..c487269439 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/collections/SummaryListWrapperReturnsVoidTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/collections/SummaryListWrapperReturnsVoidTest.kt @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test import org.utbot.examples.collections.ListWrapperReturnsVoidExample import org.utbot.framework.plugin.api.MockStrategyApi +import org.utbot.testing.DoNotCalculate /** * Tests verify that the previously discovered bug is not reproducible anymore. diff --git a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt index a62c2a02c1..a736946fbd 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test import org.utbot.examples.controlflow.Cycles import org.utbot.framework.plugin.api.MockStrategyApi +import org.utbot.testing.DoNotCalculate class SummaryCycleTest : SummaryTestCaseGeneratorTest( Cycles::class, diff --git a/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt index 540c58dab8..a40490a429 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test import org.utbot.examples.inner.InnerCalls import org.utbot.framework.plugin.api.MockStrategyApi +import org.utbot.testing.DoNotCalculate class SummaryInnerCallsTest : SummaryTestCaseGeneratorTest( InnerCalls::class, diff --git a/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt index e4a1a2f4d0..ed7edf7ca2 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test import org.utbot.examples.inner.NestedCalls import org.utbot.framework.plugin.api.MockStrategyApi +import org.utbot.testing.DoNotCalculate class SummaryNestedCallsTest : SummaryTestCaseGeneratorTest( NestedCalls::class, diff --git a/utbot-summary-tests/src/test/kotlin/examples/structures/SummaryMinStackTest.kt b/utbot-summary-tests/src/test/kotlin/examples/structures/SummaryMinStackTest.kt index ddec782eab..12031c45cb 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/structures/SummaryMinStackTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/structures/SummaryMinStackTest.kt @@ -7,6 +7,7 @@ import org.junit.jupiter.api.extension.ExtendWith import org.utbot.examples.structures.MinStack import org.utbot.framework.plugin.api.MockStrategyApi +import org.utbot.testing.DoNotCalculate @ExtendWith(CustomJavaDocTagsEnabler::class) class SummaryMinStackTest : SummaryTestCaseGeneratorTest( diff --git a/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernaryTest.kt b/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernaryTest.kt index 2616cf889c..817f14a782 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernaryTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernaryTest.kt @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test import org.utbot.examples.ternary.Ternary import org.utbot.framework.plugin.api.MockStrategyApi +import org.utbot.testing.DoNotCalculate class SummaryTernaryTest : SummaryTestCaseGeneratorTest( Ternary::class, diff --git a/utbot-summary-tests/src/test/kotlin/math/SummaryIntMathTest.kt b/utbot-summary-tests/src/test/kotlin/math/SummaryIntMathTest.kt index f167939a2d..14dd5cac5f 100644 --- a/utbot-summary-tests/src/test/kotlin/math/SummaryIntMathTest.kt +++ b/utbot-summary-tests/src/test/kotlin/math/SummaryIntMathTest.kt @@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtClusterInfo +import org.utbot.testing.DoNotCalculate class SummaryIntMathTest : SummaryTestCaseGeneratorTest( IntMath::class, diff --git a/utbot-testing/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java b/utbot-testing/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java deleted file mode 100644 index b04512aafc..0000000000 --- a/utbot-testing/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java +++ /dev/null @@ -1,1359 +0,0 @@ -package org.utbot.examples.manual; - -import kotlin.Pair; -import org.jetbrains.annotations.NotNull; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.utbot.common.PathUtil; -import org.utbot.examples.assemble.DirectAccess; -import org.utbot.examples.assemble.PrimitiveFields; -import org.utbot.examples.assemble.ArrayOfComplexArrays; -import org.utbot.examples.assemble.ArrayOfPrimitiveArrays; -import org.utbot.examples.assemble.AssignedArray; -import org.utbot.examples.assemble.ComplexArray; -import org.utbot.examples.manual.examples.*; -import org.utbot.examples.manual.examples.customer.B; -import org.utbot.examples.manual.examples.customer.C; -import org.utbot.examples.manual.examples.customer.Demo9; -import org.utbot.external.api.TestMethodInfo; -import org.utbot.external.api.UtBotJavaApi; -import org.utbot.external.api.UtModelFactory; -import org.utbot.framework.codegen.ForceStaticMocking; -import org.utbot.framework.codegen.Junit4; -import org.utbot.framework.codegen.MockitoStaticMocking; -import org.utbot.framework.plugin.api.*; -import org.utbot.framework.plugin.api.util.UtContext; -import org.utbot.framework.plugin.services.JdkInfoDefaultProvider; -import org.utbot.framework.util.Snippet; -import org.utbot.framework.util.SootUtils; - -import java.io.File; -import java.lang.reflect.Method; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.IdentityHashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.framework.plugin.api.MockFramework.MOCKITO; -import static org.utbot.framework.plugin.api.util.IdUtilKt.getIntArrayClassId; -import static org.utbot.framework.util.TestUtilsKt.compileClassAndGetClassPath; -import static org.utbot.framework.util.TestUtilsKt.compileClassFile; - -class PredefinedGeneratorParameters { - - static String destinationClassName = "GeneratedTest"; - - static Method getMethodByName(Class clazz, String name, Class... parameters) { - try { - return clazz.getDeclaredMethod(name, parameters); - } catch (NoSuchMethodException ignored) { - Assertions.fail(); - } - throw new RuntimeException(); - } -} - -public class UtBotJavaApiTest { - private AutoCloseable context; - private UtModelFactory modelFactory; - - @BeforeEach - public void setUp() { - context = UtContext.Companion.setUtContext(new UtContext(PrimitiveFields.class.getClassLoader())); - modelFactory = new UtModelFactory(); - } - - @AfterEach - public void tearDown() { - try { - context.close(); - modelFactory = null; - } catch (Exception e) { - Assertions.fail(); - } - } - - @Test - public void testMultiMethodClass() { - - UtBotJavaApi.setStopConcreteExecutorOnExit(false); - - String classpath = getClassPath(MultiMethodExample.class); - String dependencyClassPath = getDependencyClassPath(); - - UtCompositeModel classUnderTestModel = modelFactory.produceCompositeModel( - classIdForType(MultiMethodExample.class) - ); - - EnvironmentModels initialState = new EnvironmentModels( - classUnderTestModel, - Collections.emptyList(), - Collections.emptyMap() - ); - - EnvironmentModels thirdMethodState = new EnvironmentModels( - classUnderTestModel, - Collections.singletonList(new UtPrimitiveModel("some")), - Collections.emptyMap() - ); - - - Method firstMethodUnderTest = PredefinedGeneratorParameters.getMethodByName( - MultiMethodExample.class, - "firstMethod" - ); - - Method secondMethodUnderTest = PredefinedGeneratorParameters.getMethodByName( - MultiMethodExample.class, - "secondMethod" - ); - - Method thirdMethodUnderTest = PredefinedGeneratorParameters.getMethodByName( - MultiMethodExample.class, - "thirdMethod", - String.class - ); - - TestMethodInfo firstTestMethodInfo = new TestMethodInfo( - firstMethodUnderTest, - initialState); - TestMethodInfo secondTestMethodInfo = new TestMethodInfo( - secondMethodUnderTest, - initialState); - TestMethodInfo thirdTestMethodInfo = new TestMethodInfo( - thirdMethodUnderTest, - thirdMethodState); - - List testSets = UtBotJavaApi.generateTestSets( - Arrays.asList(firstTestMethodInfo, secondTestMethodInfo, thirdTestMethodInfo), - MultiMethodExample.class, - classpath, - dependencyClassPath, - MockStrategyApi.OTHER_PACKAGES, - 3000L - ); - - String generationResult = UtBotJavaApi.generate( - Collections.emptyList(), - testSets, - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - MultiMethodExample.class, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE, - MultiMethodExample.class.getPackage().getName() - ); - - Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); - String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( - Arrays.asList(firstTestMethodInfo, secondTestMethodInfo, thirdTestMethodInfo), - Collections.emptyList(), - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - MultiMethodExample.class - ); - - Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); - } - - @Test - public void testCustomPackage() { - - UtBotJavaApi.setStopConcreteExecutorOnExit(false); - - String classpath = getClassPath(DirectAccess.class); - String dependencyClassPath = getDependencyClassPath(); - - HashMap fields = new HashMap<>(); - fields.put("stringClass", modelFactory.produceClassRefModel(String.class)); - - UtCompositeModel classUnderTestModel = modelFactory.produceCompositeModel( - classIdForType(ClassRefExample.class), - fields - ); - - UtClassRefModel classRefModel = modelFactory.produceClassRefModel(Class.class); - - EnvironmentModels initialState = new EnvironmentModels( - classUnderTestModel, - Collections.singletonList(classRefModel), - Collections.emptyMap() - ); - - Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( - ClassRefExample.class, - "assertInstance", - Class.class - ); - - List testSets = UtBotJavaApi.generateTestSets( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - initialState) - ), - ClassRefExample.class, - classpath, - dependencyClassPath, - MockStrategyApi.OTHER_PACKAGES, - 3000L - ); - - String generationResult = UtBotJavaApi.generate( - Collections.emptyList(), - testSets, - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - ClassRefExample.class, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE, - "some.custom.name" - ); - - Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); - - String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - initialState) - ), - Collections.emptyList(), - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - ClassRefExample.class, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE, - "some.custom.name" - ); - - Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); - } - - @Test - public void testOnObjectWithAssignedArrayField() { - - UtBotJavaApi.setStopConcreteExecutorOnExit(false); - - String classpath = getClassPath(DirectAccess.class); - String dependencyClassPath = getDependencyClassPath(); - - ClassId classIdAssignedArray = classIdForType(AssignedArray.class); - - HashMap values = new HashMap<>(); - values.put(0, new UtPrimitiveModel(1)); - values.put(1, new UtPrimitiveModel(2)); - - UtArrayModel utArrayModel = modelFactory.produceArrayModel( - getIntArrayClassId(), - 10, - new UtPrimitiveModel(0), - values - ); - - UtCompositeModel compositeModel = modelFactory.produceCompositeModel( - classIdAssignedArray, - Collections.singletonMap("array", utArrayModel) - ); - - UtCompositeModel classUnderTestModel = modelFactory.produceCompositeModel( - classIdForType(AssignedArrayExample.class) - ); - - EnvironmentModels initialState = new EnvironmentModels( - classUnderTestModel, - Collections.singletonList(compositeModel), - Collections.emptyMap() - ); - - - Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( - AssignedArrayExample.class, - "foo", - AssignedArray.class - ); - - List testSets = UtBotJavaApi.generateTestSets( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - initialState) - ), - AssignedArrayExample.class, - classpath, - dependencyClassPath, - MockStrategyApi.OTHER_PACKAGES, - 3000L - ); - - String generationResult = UtBotJavaApi.generate( - Collections.emptyList(), - testSets, - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - AssignedArrayExample.class, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE - ); - - Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); - - String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - initialState) - ), - Collections.emptyList(), - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - AssignedArrayExample.class, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE - ); - - Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); - } - - @Test - public void testClassRef() { - - UtBotJavaApi.setStopConcreteExecutorOnExit(false); - - String classpath = getClassPath(DirectAccess.class); - String dependencyClassPath = getDependencyClassPath(); - - HashMap fields = new HashMap<>(); - fields.put("stringClass", modelFactory.produceClassRefModel(String.class)); - - UtCompositeModel classUnderTestModel = modelFactory.produceCompositeModel( - classIdForType(ClassRefExample.class), - fields - ); - - UtClassRefModel classRefModel = modelFactory.produceClassRefModel(Class.class); - - EnvironmentModels initialState = new EnvironmentModels( - classUnderTestModel, - Collections.singletonList(classRefModel), - Collections.emptyMap() - ); - - Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( - ClassRefExample.class, - "assertInstance", - Class.class - ); - - List testSets = UtBotJavaApi.generateTestSets( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - initialState) - ), - ClassRefExample.class, - classpath, - dependencyClassPath, - MockStrategyApi.OTHER_PACKAGES, - 3000L - ); - - String generationResult = UtBotJavaApi.generate( - Collections.emptyList(), - testSets, - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - ClassRefExample.class, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE - ); - - - Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); - - String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - initialState) - ), - Collections.emptyList(), - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - ClassRefExample.class, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE - ); - - Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); - } - - @Test - public void testObjectWithPublicFields() { - - UtBotJavaApi.setStopConcreteExecutorOnExit(false); - - String classpath = getClassPath(DirectAccess.class); - String dependencyClassPath = getDependencyClassPath(); - - ClassId testClassId = classIdForType(DirectAccess.class); - ClassId innerClassId = classIdForType(PrimitiveFields.class); - - HashMap primitiveFields = new HashMap<>(); - primitiveFields.put("a", new UtPrimitiveModel(2)); - primitiveFields.put("b", new UtPrimitiveModel(4)); - - HashMap fields = new HashMap<>(); - fields.put("a", new UtPrimitiveModel(2)); - fields.put("b", new UtPrimitiveModel(4)); - fields.put("s", - modelFactory.produceCompositeModel( - innerClassId, - primitiveFields, - Collections.emptyMap() - ) - ); - - UtCompositeModel compositeModel = modelFactory.produceCompositeModel( - testClassId, - fields, - Collections.emptyMap() - ); - - // This class does not contain any fields. Using overloads - UtCompositeModel classUnderTestModel = modelFactory.produceCompositeModel( - classIdForType(DirectAccessExample.class) - ); - - EnvironmentModels initialState = new EnvironmentModels( - classUnderTestModel, - Collections.singletonList(compositeModel), - Collections.emptyMap() - ); - - - Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( - DirectAccessExample.class, - "foo", - DirectAccess.class - ); - - List testSets = UtBotJavaApi.generateTestSets( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - initialState) - ), - DirectAccessExample.class, - classpath, - dependencyClassPath, - MockStrategyApi.OTHER_PACKAGES, - 3000L - ); - - String generationResult = UtBotJavaApi.generate( - Collections.emptyList(), - testSets, - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - DirectAccessExample.class, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE - ); - - Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); - - String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - initialState) - ), - Collections.emptyList(), - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - DirectAccessExample.class, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE - ); - - Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); - } - - @Test - public void testObjectWithPublicFieldsWithAssembleModel() { - - UtBotJavaApi.setStopConcreteExecutorOnExit(false); - - String classpath = getClassPath(DirectAccess.class); - String dependencyClassPath = getDependencyClassPath(); - - ClassId testClassId = classIdForType(DirectAccess.class); - ClassId innerClassId = classIdForType(PrimitiveFields.class); - - HashMap primitiveFields = new HashMap<>(); - primitiveFields.put("a", new UtPrimitiveModel(2)); - primitiveFields.put("b", new UtPrimitiveModel(4)); - - HashMap fields = new HashMap<>(); - fields.put("a", new UtPrimitiveModel(2)); - fields.put("b", new UtPrimitiveModel(4)); - fields.put("s", - modelFactory.produceCompositeModel( - innerClassId, - primitiveFields, - Collections.emptyMap() - ) - ); - - UtCompositeModel compositeModel = modelFactory.produceCompositeModel( - testClassId, - fields, - Collections.emptyMap() - ); - - // This class does not contain any fields. Using overloads - UtCompositeModel classUnderTestModel = modelFactory.produceCompositeModel( - classIdForType(DirectAccessExample.class) - ); - - EnvironmentModels initialState = new EnvironmentModels( - classUnderTestModel, - Collections.singletonList(compositeModel), - Collections.emptyMap() - ); - - Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( - DirectAccessExample.class, - "foo", - DirectAccess.class - ); - - List testSets = UtBotJavaApi.generateTestSets( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - initialState) - ), - DirectAccessExample.class, - classpath, - dependencyClassPath, - MockStrategyApi.OTHER_PACKAGES, - 3000L - ); - - String generationResult = UtBotJavaApi.generate( - Collections.emptyList(), - testSets, - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - DirectAccessExample.class, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE - ); - - Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); - } - - - @Test - public void testOnObjectWithArrayOfPrimitiveArrays() { - - UtBotJavaApi.setStopConcreteExecutorOnExit(false); - - String classpath = getClassPath(ArrayOfPrimitiveArraysExample.class); - String dependencyClassPath = getDependencyClassPath(); - - ClassId cidPrimitiveArrays = getIntArrayClassId(); - ClassId cidPrimitiveArraysOuter = new ClassId("[[I", cidPrimitiveArrays); - ClassId classIdArrayOfPrimitiveArraysClass = classIdForType(ArrayOfPrimitiveArrays.class); - ClassId cidArrayOfPrimitiveArraysTest = classIdForType(ArrayOfPrimitiveArraysExample.class); - - HashMap arrayParameters = new HashMap<>(); - arrayParameters.put(0, new UtPrimitiveModel(88)); - arrayParameters.put(1, new UtPrimitiveModel(42)); - - UtArrayModel innerArrayOfPrimitiveArrayModel = modelFactory.produceArrayModel( - cidPrimitiveArrays, - 2, - new UtPrimitiveModel(0), - arrayParameters - ); - - HashMap enclosingArrayParameters = new HashMap<>(); - enclosingArrayParameters.put(0, innerArrayOfPrimitiveArrayModel); - enclosingArrayParameters.put(1, innerArrayOfPrimitiveArrayModel); - - UtArrayModel enclosingArrayOfPrimitiveArrayModel = modelFactory.produceArrayModel( - cidPrimitiveArraysOuter, - 1, - new UtNullModel(getIntArrayClassId()), - enclosingArrayParameters - ); - - UtCompositeModel cmArrayOfPrimitiveArrays = modelFactory.produceCompositeModel( - classIdArrayOfPrimitiveArraysClass, - Collections.singletonMap("array", enclosingArrayOfPrimitiveArrayModel) - ); - - UtCompositeModel testClassCompositeModel = modelFactory.produceCompositeModel( - cidArrayOfPrimitiveArraysTest - ); - - EnvironmentModels initialState = new EnvironmentModels( - testClassCompositeModel, - Collections.singletonList(cmArrayOfPrimitiveArrays), - Collections.emptyMap() - ); - - Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( - ArrayOfPrimitiveArraysExample.class, - "assign10", - ArrayOfPrimitiveArrays.class - ); - - List testSets = UtBotJavaApi.generateTestSets( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - initialState) - ), - ArrayOfPrimitiveArraysExample.class, - classpath, - dependencyClassPath, - MockStrategyApi.OTHER_PACKAGES, - 3000L - ); - - String generationResult = UtBotJavaApi.generate( - Collections.emptyList(), - testSets, - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - ArrayOfPrimitiveArraysExample.class, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE - ); - - Snippet snippet = new Snippet(CodegenLanguage.JAVA, generationResult); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet); - - String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - initialState) - ), - Collections.emptyList(), - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - ArrayOfPrimitiveArraysExample.class, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE - ); - - Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); - } - - /** - * The test is inspired by the API customers - */ - @Test - public void testProvided3() { - - UtBotJavaApi.setStopConcreteExecutorOnExit(false); - - String classpath = getClassPath(ArrayOfComplexArraysExample.class); - String dependencyClassPath = getDependencyClassPath(); - - UtCompositeModel cClassModel = modelFactory. - produceCompositeModel( - classIdForType(C.class), - Collections.singletonMap("integer", new UtPrimitiveModel(1)) - ); - - UtCompositeModel bClassModel = modelFactory - .produceCompositeModel( - classIdForType(B.class), - Collections.singletonMap("c", cClassModel) - ); - - UtCompositeModel demo9Model = modelFactory. - produceCompositeModel( - classIdForType(Demo9.class), - Collections.singletonMap("b0", bClassModel) - ); - - EnvironmentModels environmentModels = new EnvironmentModels( - demo9Model, - Collections.singletonList(bClassModel), - Collections.emptyMap() - ); - - Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( - Demo9.class, - "test", - B.class - ); - - List testSets = UtBotJavaApi.generateTestSets( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - environmentModels - ) - ), - Demo9.class, - classpath, - dependencyClassPath, - MockStrategyApi.OTHER_PACKAGES, - 3000L - ); - - String generationResult = UtBotJavaApi.generate( - Collections.emptyList(), - testSets, - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - Demo9.class, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE - ); - - Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); - - String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - environmentModels - ) - ), - Collections.emptyList(), - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - Demo9.class - ); - - Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); - } - - @Test - public void testCustomAssertion() { - String classpath = getClassPath(Trivial.class); - String dependencyClassPath = getDependencyClassPath(); - - UtCompositeModel model = modelFactory. - produceCompositeModel( - classIdForType(Trivial.class) - ); - - EnvironmentModels environmentModels = new EnvironmentModels( - model, - Collections.singletonList(new UtPrimitiveModel(2)), - Collections.emptyMap() - ); - - Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( - Trivial.class, - "aMethod", - int.class - ); - - List testSets = UtBotJavaApi.generateTestSets( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - environmentModels - ) - ), - Trivial.class, - classpath, - dependencyClassPath, - MockStrategyApi.OTHER_PACKAGES, - 3000L - ); - - String generationResult = UtBotJavaApi.generate( - Collections.emptyList(), - testSets, - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - Trivial.class, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE - ); - - Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); - - String generationResult2 = UtBotJavaApi.generate( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - environmentModels - ) - ), - Collections.emptyList(), - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - Trivial.class, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE - ); - - Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResult2); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); - } - - /** - * The test is inspired by the API customers - */ - @Test - public void testProvided3Reused() { - - UtBotJavaApi.setStopConcreteExecutorOnExit(true); - - String dependencyClassPath = getDependencyClassPath(); - - // The method in the class contains only one parameter - String classSourceAsString = - "public class Demo9Recompiled {" + - " public int test(int b1) {" + - " return 0;" + - " }" + - "}"; - - String demo9RecompiledClassName = "Demo9Recompiled"; - Pair classpathToClassLoader = - compileClassAndGetClassPath(new Pair<>(demo9RecompiledClassName, classSourceAsString)); - - - String classpath = classpathToClassLoader.getFirst(); - ClassLoader classLoader = classpathToClassLoader.getSecond(); - - Class compiledClass = null; - - try { - compiledClass = classLoader.loadClass(demo9RecompiledClassName); - } catch (ClassNotFoundException e) { - Assertions.fail("Failed to load a class; Classpath: " + classpathToClassLoader.getFirst()); - } - - if (compiledClass == null) { - Assertions.fail("Failed to load the class"); - } - - UtCompositeModel demo9Model = modelFactory. - produceCompositeModel( - classIdForType(compiledClass), - Collections.emptyMap() - ); - - EnvironmentModels environmentModels = new EnvironmentModels( - demo9Model, - Collections.singletonList(new UtPrimitiveModel(3)), - Collections.emptyMap() - ); - - Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( - compiledClass, - "test", - int.class - ); - - List testSets = UtBotJavaApi.generateTestSets( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - environmentModels - ) - ), - compiledClass, - classpath, - dependencyClassPath, - MockStrategyApi.OTHER_PACKAGES, - 3000L - ); - - String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( - Collections.emptyList(), - testSets, - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - compiledClass, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE - ); - - Snippet snippet = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet); - - // The test compiles and everything goes well. - // Let's recompile the initial clas file - - // The method below has an extra parameter - classSourceAsString = - "public class Demo9Recompiled {" + - " public int test(int b1, String s) {" + - " return 0;" + - " }" + - "}"; - - Pair stringClassLoaderPair = - compileClassAndGetClassPath(new Pair<>(demo9RecompiledClassName, classSourceAsString), classpath); - - ClassLoader reloadedClassLoader = stringClassLoaderPair.getSecond(); - - Class recompiledClass = null; - - try { - recompiledClass = reloadedClassLoader.loadClass(demo9RecompiledClassName); - } catch (ClassNotFoundException e) { - Assertions.fail("Failed to load the class after recompilation; classpath: " + stringClassLoaderPair.getFirst()); - } - - if (recompiledClass == null) { - Assertions.fail("Failed to load the class after recompilation"); - } - - EnvironmentModels environmentModels2 = new EnvironmentModels( - demo9Model, - Arrays.asList(new UtPrimitiveModel(4), new UtPrimitiveModel("Some String")), - Collections.emptyMap() - ); - - Method methodUnderTest2 = PredefinedGeneratorParameters.getMethodByName( - recompiledClass, - "test", - int.class, - String.class - ); - - List testSets1 = UtBotJavaApi.generateTestSets( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest2, - environmentModels - ) - ), - recompiledClass, - classpath, - dependencyClassPath, - MockStrategyApi.OTHER_PACKAGES, - 3000L - ); - - String generationResultWithConcreteExecutionOnly2 = UtBotJavaApi.generate( - Collections.emptyList(), - testSets1, - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - recompiledClass, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE - ); - - Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly2); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); - } - - @Test - public void testProvided1() { - - UtBotJavaApi.setStopConcreteExecutorOnExit(false); - - String classpath = getClassPath(ArrayOfComplexArraysExample.class); - String dependencyClassPath = getDependencyClassPath(); - - UtCompositeModel providedTestModel = modelFactory.produceCompositeModel( - classIdForType(ProvidedExample.class), - Collections.emptyMap(), - Collections.emptyMap() - ); - - List parameters = Arrays.asList( - new UtPrimitiveModel(5), - new UtPrimitiveModel(9), - new UtPrimitiveModel("Some Text") - ); - - EnvironmentModels initialState = new EnvironmentModels( - providedTestModel, - parameters, - Collections.emptyMap() - ); - - Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( - ProvidedExample.class, - "test0", - int.class, int.class, String.class - ); - - List testSets = UtBotJavaApi.generateTestSets( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - initialState - ) - ), - ProvidedExample.class, - classpath, - dependencyClassPath, - MockStrategyApi.OTHER_PACKAGES, - 3000L - ); - - String generationResult = UtBotJavaApi.generate( - Collections.emptyList(), - testSets, - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - ProvidedExample.class, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE - ); - - Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); - - String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - initialState - ) - ), - Collections.emptyList(), - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - ProvidedExample.class - ); - - Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); - } - - @Test - public void testOnObjectWithArrayOfComplexArrays() { - - UtBotJavaApi.setStopConcreteExecutorOnExit(false); - - String classpath = getClassPath(ArrayOfComplexArraysExample.class); - String dependencyClassPath = getDependencyClassPath(); - - UtCompositeModel cmArrayOfComplexArrays = createArrayOfComplexArraysModel(); - - UtCompositeModel testClassCompositeModel = modelFactory.produceCompositeModel( - classIdForType(ArrayOfComplexArraysExample.class) - ); - - EnvironmentModels initialState = new EnvironmentModels( - testClassCompositeModel, - Collections.singletonList(cmArrayOfComplexArrays), - Collections.emptyMap() - ); - - Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName( - ArrayOfComplexArraysExample.class, - "getValue", - ArrayOfComplexArrays.class - ); - - List testSets = UtBotJavaApi.generateTestSets( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - initialState - ) - ), - ArrayOfComplexArraysExample.class, - classpath, - dependencyClassPath, - MockStrategyApi.OTHER_PACKAGES, - 3000L - ); - - String generationResult = UtBotJavaApi.generate( - Collections.emptyList(), - testSets, - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - ArrayOfComplexArraysExample.class, - Junit4.INSTANCE, - MOCKITO, - CodegenLanguage.JAVA, - MockitoStaticMocking.INSTANCE, - false, - ForceStaticMocking.DO_NOT_FORCE - ); - - Snippet snippet1 = new Snippet(CodegenLanguage.JAVA, generationResult); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet1); - - String generationResultWithConcreteExecutionOnly = UtBotJavaApi.generate( - Collections.singletonList( - new TestMethodInfo( - methodUnderTest, - initialState - ) - ), - Collections.emptyList(), - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - ArrayOfComplexArraysExample.class - ); - - Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generationResultWithConcreteExecutionOnly); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); - } - - @Test - public void testFuzzingSimple() { - SootUtils.INSTANCE.runSoot(StringSwitchExample.class, false, new JdkInfoDefaultProvider().getInfo()); - UtBotJavaApi.setStopConcreteExecutorOnExit(false); - - String classpath = getClassPath(StringSwitchExample.class); - String dependencyClassPath = getDependencyClassPath(); - - UtCompositeModel classUnderTestModel = modelFactory.produceCompositeModel( - classIdForType(StringSwitchExample.class) - ); - - Method methodUnderTest = PredefinedGeneratorParameters.getMethodByName(StringSwitchExample.class, "validate", String.class, int.class, int.class); - - IdentityHashMap models = modelFactory.produceAssembleModel( - methodUnderTest, - StringSwitchExample.class, - Collections.singletonList(classUnderTestModel) - ); - - EnvironmentModels methodState = new EnvironmentModels( - models.get(classUnderTestModel), - Arrays.asList(new UtPrimitiveModel("initial model"), new UtPrimitiveModel(-10), new UtPrimitiveModel(0)), - Collections.emptyMap() - ); - - TestMethodInfo methodInfo = new TestMethodInfo( - methodUnderTest, - methodState); - List testSets1 = UtBotJavaApi.fuzzingTestSets( - Collections.singletonList( - methodInfo - ), - StringSwitchExample.class, - classpath, - dependencyClassPath, - MockStrategyApi.OTHER_PACKAGES, - 3000L, - (type) -> { - if (int.class.equals(type) || Integer.class.equals(type)) { - return Arrays.asList(0, Integer.MIN_VALUE, Integer.MAX_VALUE); - } - return null; - } - ); - - String generate = UtBotJavaApi.generate( - Collections.singletonList(methodInfo), - testSets1, - PredefinedGeneratorParameters.destinationClassName, - classpath, - dependencyClassPath, - StringSwitchExample.class - ); - - Snippet snippet2 = new Snippet(CodegenLanguage.JAVA, generate); - compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2); - } - - @NotNull - private String getClassPath(Class clazz) { - return clazz.getProtectionDomain().getCodeSource().getLocation().getPath(); - } - - @NotNull - private String getDependencyClassPath() { - - ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - URL[] urls = PathUtil.getUrlsFromClassLoader(contextClassLoader); - - - return Arrays.stream(urls).map(url -> - { - try { - return new File(url.toURI()).toString(); - } catch (URISyntaxException e) { - Assertions.fail(e); - } - throw new RuntimeException(); - }).collect(Collectors.joining(File.pathSeparator)); - } - public UtCompositeModel createArrayOfComplexArraysModel() { - ClassId classIdOfArrayOfComplexArraysClass = classIdForType(ArrayOfComplexArrays.class); - ClassId classIdOfComplexArray = classIdForType(ComplexArray.class); - ClassId classIdOfPrimitiveFieldsClass = classIdForType(PrimitiveFields.class); - - ClassId classIdOfArrayOfPrimitiveFieldsClass = new ClassId("[L" + classIdOfPrimitiveFieldsClass.getCanonicalName() + ";", classIdOfPrimitiveFieldsClass); - - Map elementsOfComplexArrayArray = new HashMap<>(); - - Map elementsWithPrimitiveFieldsClasses = new HashMap<>(); - - elementsWithPrimitiveFieldsClasses.put(0, modelFactory.produceCompositeModel( - classIdOfPrimitiveFieldsClass, - Collections.singletonMap("a", new UtPrimitiveModel(5)), - Collections.emptyMap() - )); - - elementsWithPrimitiveFieldsClasses.put(1, modelFactory.produceCompositeModel( - classIdOfPrimitiveFieldsClass, - Collections.singletonMap("b", new UtPrimitiveModel(4)), - Collections.emptyMap() - )); - - UtArrayModel arrayOfPrimitiveFieldsModel = modelFactory.produceArrayModel( - classIdOfArrayOfPrimitiveFieldsClass, - 2, - new UtNullModel(classIdOfPrimitiveFieldsClass), - elementsWithPrimitiveFieldsClasses - ); - - UtCompositeModel complexArrayClassModel = modelFactory.produceCompositeModel( - classIdOfComplexArray, - Collections.singletonMap("array", arrayOfPrimitiveFieldsModel) - ); - - elementsOfComplexArrayArray.put(1, complexArrayClassModel); - - ClassId classIdOfArraysOfComplexArrayClass = new ClassId("[L" + classIdOfComplexArray.getCanonicalName() + ";", classIdOfComplexArray); - - UtArrayModel arrayOfComplexArrayClasses = modelFactory.produceArrayModel( - classIdOfArraysOfComplexArrayClass, - 2, - new UtNullModel(classIdOfComplexArray), - elementsOfComplexArrayArray - ); - - return modelFactory.produceCompositeModel( - classIdOfArrayOfComplexArraysClass, - Collections.singletonMap("array", arrayOfComplexArrayClasses)); - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/bytecode/versions/SootTest.kt b/utbot-testing/src/test/kotlin/org/utbot/bytecode/versions/SootTest.kt deleted file mode 100644 index e988274ce0..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/bytecode/versions/SootTest.kt +++ /dev/null @@ -1,69 +0,0 @@ -package org.utbot.bytecode.versions - -import org.junit.jupiter.api.Assertions.assertFalse -import org.junit.jupiter.api.Assertions.assertNotNull -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.examples.objects.SimpleDataClass -import org.utbot.framework.util.SootUtils.runSoot -import soot.Scene - -@Suppress("UNREACHABLE_CODE") -@Disabled("TODO: https://github.com/UnitTestBot/UTBotJava/issues/891") -class SootTest { - @Test - fun `no method isBlank in JDK 8`() { - runSoot( - SimpleDataClass::class.java, - forceReload = true, - TODO("Get JDK 8") - ) - - val stringClass = Scene.v().getSootClass("java.lang.String") - assertFalse(stringClass.isPhantomClass) - - val isBlankMethod = stringClass.getMethodByNameUnsafe("isBlank") // no such method in JDK 8 - assertNull(isBlankMethod) - } - - @Test - fun `method isBlank exists in JDK 11`() { - runSoot( - SimpleDataClass::class.java, - forceReload = true, - TODO("Get JDK 11") - ) - - val stringClass = Scene.v().getSootClass("java.lang.String") - assertFalse(stringClass.isPhantomClass) - - val isBlankMethod = stringClass.getMethodByNameUnsafe("isBlank") // there is such method in JDK 11 - assertNotNull(isBlankMethod) - } - - @Test - fun `no records in JDK 11`() { - runSoot( - SimpleDataClass::class.java, - forceReload = true, - TODO("Get JDK 11") - ) - - val stringClass = Scene.v().getSootClass("java.lang.Record") // must not exist in JDK 11 - assertTrue(stringClass.isPhantomClass) - } - - @Test - fun `records exists in JDK 17`() { - runSoot( - SimpleDataClass::class.java, - forceReload = true, - TODO("Get JDK 17") - ) - - val stringClass = Scene.v().getSootClass("java.lang.Record") // must exist in JDK 17 - assertFalse(stringClass.isPhantomClass) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/engine/pc/QueryOptimizationsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/engine/pc/QueryOptimizationsTest.kt deleted file mode 100644 index 498c3ee2e5..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/engine/pc/QueryOptimizationsTest.kt +++ /dev/null @@ -1,642 +0,0 @@ -package org.utbot.engine.pc - -import org.utbot.engine.Add -import org.utbot.engine.And -import org.utbot.engine.Cmp -import org.utbot.engine.Cmpg -import org.utbot.engine.Cmpl -import org.utbot.engine.Div -import org.utbot.engine.Eq -import org.utbot.engine.Ge -import org.utbot.engine.Gt -import org.utbot.engine.Le -import org.utbot.engine.Lt -import org.utbot.engine.Mul -import org.utbot.engine.Ne -import org.utbot.engine.Or -import org.utbot.engine.Rem -import org.utbot.engine.Shl -import org.utbot.engine.Shr -import org.utbot.engine.Sub -import org.utbot.engine.Ushr -import org.utbot.engine.Xor -import org.utbot.engine.primitiveToSymbolic -import org.utbot.engine.toBoolValue -import org.utbot.engine.toByteValue -import org.utbot.engine.toDoubleValue -import org.utbot.engine.toFloatValue -import org.utbot.engine.toIntValue -import org.utbot.engine.toLongValue -import org.utbot.engine.toPrimitiveValue -import org.utbot.engine.toShortValue -import org.utbot.framework.UtSettings -import kotlinx.collections.immutable.persistentListOf -import org.junit.jupiter.api.AfterAll -import org.junit.jupiter.api.BeforeAll -import org.junit.jupiter.api.Test - -private var expressionSimplificationValue: Boolean = UtSettings.useExpressionSimplification - -@BeforeAll -fun beforeAll() { - UtSettings.useExpressionSimplification = true -} - -@AfterAll -fun afterAll() { - UtSettings.useExpressionSimplification = expressionSimplificationValue -} - - -class QueryOptimizationsTest { - - private fun BaseQuery.check(vararg exprs: UtBoolExpression, checker: (BaseQuery) -> Unit = {}): BaseQuery = - this.with(hard = exprs.toList(), soft = emptyList(), assumptions = emptyList()).also { - checker(it) - } - - private fun BaseQuery.checkUnsat(vararg exprs: UtBoolExpression): BaseQuery = - this.check(*exprs) { unsat(it) } - - private val empty: (BaseQuery) -> Unit = { query -> - assert(query.hard.isEmpty()) { "$query isn't empty" } - } - - private val notEmpty: (BaseQuery) -> Unit = { query -> - assert(query.hard.isNotEmpty()) { "$query is empty" } - } - - private fun size(value: Int): (BaseQuery) -> Unit = { query -> - assert(query.hard.size == value) { "$query size doesn't match with $value" } - } - - private fun contains(constraint: UtBoolExpression): (BaseQuery) -> Unit = { query -> - assert(query.hard.contains(constraint)) { "$query doesn't contain $constraint" } - } - - private val unsat: (BaseQuery) -> Unit = { query -> - assert(query.status is UtSolverStatusUNSAT) { "$query isn't unsat" } - } - - private val unknown: (BaseQuery) -> Unit = { query -> - assert(query.status is UtSolverStatusUNDEFINED) { "$query status is known" } - } - - private fun `is`(vararg checkers: (BaseQuery) -> Unit): (BaseQuery) -> Unit = { query -> - checkers.forEach { it(query) } - } - - @Test - fun testConcreteEq() { - var query: BaseQuery = Query() - query = query.check(Eq(0.toPrimitiveValue(), 0)) { - `is`(empty, unknown)(it) - } - query.check(Eq(1.toPrimitiveValue(), 0)) { - `is`(contains(UtFalse), unsat)(it) - } - } - - @Test - fun testSymbolicEq() { - var query: BaseQuery = Query() - val p = mkBVConst("p", UtIntSort).toIntValue() - // p == p === true - query.check(Eq(p, p)) { - `is`(empty, unknown)(it) - } - // query = Query(p == 0) - query = query.check(Eq(p, 0)) { - `is`(notEmpty, unknown)(it) - } - // p == 0, p == 1 is unsat - query.checkUnsat(Eq(p, 1)) - // p == 0, p != 0 is unsat - query.checkUnsat(Ne(p, 0)) - // p == 0, not (p == 0) is unsat - query.checkUnsat(NotBoolExpression(Eq(p, 0))) - // p == 0, p == p === p == 0 - query.check(Eq(p, p)) { - `is`(size(1), contains(Eq(p, 0)), unknown)(it) - } - } - - @Test - fun testArbitraryExpressionEq() { - var query: BaseQuery = Query() - val a = mkBVConst("a", UtIntSort).toIntValue() - val b = mkBVConst("b", UtIntSort).toIntValue() - // query = Query(a + b == 0) - query = query.check(Eq(Add(a, b).toIntValue(), 0)) { - `is`(size(1), unknown)(it) - } - // a + b == 0, a + b == 1 is unsat - query.checkUnsat(Eq(Add(a, b).toIntValue(), 1)) - val array = mkArrayConst("a", UtIntSort, UtIntSort) - val first = array.select(mkInt(0)).toIntValue() - // query = Query(a + b == 0, select(array, 0) == 0) - query = query.check(Eq(first, 0)) { - `is`(size(2), unknown)(it) - } - // select(array, 0) == 0, select(array, 0) == 1 is unsat - query.checkUnsat(Eq(first, 1)) - } - - @Test - fun testEvalIndexOfSelect() { - var query: BaseQuery = Query() - val array = mkArrayConst("a", UtIntSort, UtIntSort) - // query = Query(select(array, 3) == 0) - query = query.check(Eq(array.select(mkInt(3)).toIntValue(), 0)) { - `is`(size(1), unknown)(it) - } - // select(array, 3) == 0, select(array, 1 + 2) == 2 is unsat - query.checkUnsat( - Eq(array.select(Add(1.toPrimitiveValue(), 2.toPrimitiveValue())).toIntValue(), 2) - ) - } - - @Test - fun testFpEq() { - var query: BaseQuery = Query() - val fp = mkFpConst("a", Double.SIZE_BITS).toDoubleValue() - // query = Query(a == 0.0) - query = query.check(Eq(fp, 0.0.toPrimitiveValue())) { - `is`(size(1), unknown)(it) - } - // a == 0.0, a == 1.0 is unsat - query.checkUnsat(Eq(fp, 1.0.toPrimitiveValue())) - // a == 0.0, a == 0.0 === a == 0.0 - query.check(Eq(0.0.toPrimitiveValue(), fp)) { - `is`(size(1), unknown)(it) - } - } - - @Test - fun testOperations() { - val query: BaseQuery = Query() - val a = 10.toPrimitiveValue() - val b = 5.toPrimitiveValue() - query.check( - // 10 + 5 == 15 - Eq(Add(a, b).toIntValue(), 15), - // 10 - 5 == 5 - Eq(Sub(a, b).toIntValue(), 5), - // 10 * 5 == 50 - Eq(Mul(a, b).toIntValue(), 50), - // 10 / 5 == 2 - Eq(Div(a, b).toIntValue(), 2), - // 5 % 10 == 5 - Eq(Rem(b, a).toIntValue(), 5), - // 10 cmp 5 == 1 - Eq(Cmp(a, b).toIntValue(), 1), - Eq(Cmpg(a, b).toIntValue(), 1), - Eq(Cmpl(a, b).toIntValue(), 1), - // 10 and 5 - Eq(And(a, b).toIntValue(), 10 and 5), - // 10 or 5 - Eq(Or(a, b).toIntValue(), 10 or 5), - // 10 xor 5 - Eq(Xor(a, b).toIntValue(), 10 xor 5), - // 10 << 5 - Eq(Shl(a, b).toIntValue(), 10 shl 5), - // -1 >> 5 == -1 - Eq(Shr((-1).toPrimitiveValue(), b).toIntValue(), -1 shr 5), - // -1 >>> 5 - Eq(Ushr((-1).toPrimitiveValue(), b).toIntValue(), -1 ushr 5), - // 10 << 37 == 10 << 5 - Eq(Shl(a, 37.toPrimitiveValue()).toIntValue(), 10 shl 37), - // -5 >> 37 == -5 >> 5 - Eq(Shr(mkByte(-5).toIntValue(), 37.toPrimitiveValue()).toIntValue(), -5 shr 37), - Eq(Ushr((-5).toPrimitiveValue(), 37.toPrimitiveValue()).toIntValue(), -5 ushr 37), - ) { - `is`(empty, unknown)(it) - } - } - - @Test - fun testUtEqExpression() { - var query: BaseQuery = Query() - // 0 == 0 === true - query.check(UtEqExpression(mkInt(0), mkInt(0))) { - `is`(empty, unknown)(it) - } - // 1 == 0 === false - query.checkUnsat(UtEqExpression(mkInt(1), mkInt(0))) - val array = mkArrayConst("a", UtIntSort, UtIntSort) - val first = array.select(mkInt(0)) - // query = Query(select(array, 0) == 0) - query = query.check(UtEqExpression(first, mkInt(0))) { - `is`(size(1), unknown)(it) - } - // select(array, 0) == 0, select(array, 0) == 1 is unsat - query.checkUnsat(UtEqExpression(first, mkInt(1))) - } - - @Test - fun testSplitAndExpression() { - val query: BaseQuery = Query() - val a = mkBoolConst("a") - val b = mkBoolConst("b") - val c = mkBoolConst("c") - // a and b and c and true === a, b, c - query.check(mkAnd(a, b, c, UtTrue)) { - `is`(size(3), contains(a), contains(b), contains(c), unknown)(it) - } - } - - @Test - fun testAndExpression() { - val query: BaseQuery = Query() - val a = mkBoolConst("a") - val b = mkBoolConst("b") - val c = mkBoolConst("c") - // a and b and false === false - query.check(mkAnd(a, b, UtFalse)) { - `is`(unsat, contains(UtFalse))(it) - } - // a and b and true and c === a and b and c - query.check(mkAnd(a, b, UtTrue, c)) { - `is`(size(3), contains(a), contains(b), contains(c), unknown)(it) - } - // true and true and true === true - query.check(mkAnd(UtTrue, UtTrue, UtTrue)) { - `is`(empty, unknown)(it) - } - // a and true === a - query.check(mkAnd(a, UtTrue)) { - `is`(size(1), contains(a), unknown)(it) - } - // a and b and (true and true) === a and b - query.check(mkAnd(a, b, (mkAnd(UtTrue, UtTrue)))) { - `is`(size(2), contains(a), contains(b), unknown)(it) - } - } - - @Test - fun testOrExpression() { - val query: BaseQuery = Query() - val a = mkBoolConst("a") - val b = mkBoolConst("b") - val c = mkBoolConst("c") - // a or b or true === a or b - query.check(mkOr(a, b, UtTrue)) { - `is`(empty, unknown)(it) - } - // a or b or false or c === a or b or c - query.check(mkOr(a, b, UtFalse, c)) { - `is`(size(1), contains(mkOr(a, b, c)), unknown)(it) - } - // false or false or false === false - query.checkUnsat(mkOr(UtFalse, UtFalse, UtFalse)) - // a or false === a - query.check(mkOr(a, UtFalse)) { - `is`(size(1), contains(a), unknown)(it) - } - // a or b or (false or false) === a or b - query.check(mkOr(a, b, mkOr(UtFalse, UtFalse))) { - `is`(size(1), contains(mkOr(a, b)))(it) - } - } - - @Test - fun testNotExpression() { - val query: BaseQuery = Query() - val a = mkBoolConst("a") - val b = mkBoolConst("b") - // not true === false - query.checkUnsat(NotBoolExpression(UtTrue)) - // not false === true - query.check(NotBoolExpression(UtFalse)) { - `is`(empty, unknown)(it) - } - // not (a and b) === (not a) or (not b) - query.check(NotBoolExpression(mkAnd(a, b))) { - `is`(size(1), contains(mkOr(NotBoolExpression(a), NotBoolExpression(b))), unknown)(it) - } - // not (a and true) === (not a) - query.check(NotBoolExpression(mkAnd(a, UtTrue))) { - `is`(size(1), contains(NotBoolExpression(a)), unknown)(it) - } - // not (a or b) === (not a) and (not b) - query.check(NotBoolExpression(mkOr(a, b))) { - `is`(size(2), contains(NotBoolExpression(a)), contains(NotBoolExpression(b)), unknown)(it) - } - // not (a or false) === not a - query.check(NotBoolExpression(mkOr(a, UtFalse))) { - `is`(size(1), contains(NotBoolExpression(a)), unknown)(it) - } - // not (a != b) === a == b - query.check(NotBoolExpression(Ne(a.toBoolValue(), b.toBoolValue()))) { - `is`(size(1), contains(Eq(a.toBoolValue(), b.toBoolValue())), unknown)(it) - } - } - - @Test - fun testUtNegExpression() { - val query: BaseQuery = Query() - val a = 50 - query.check( - // neg Byte(50) == Byte(-50) - Eq(UtNegExpression(a.toByte().toPrimitiveValue()).toByteValue(), (-a).toPrimitiveValue()), - // neg Short(50) == Short(-50) - Eq(UtNegExpression(a.toShort().toPrimitiveValue()).toShortValue(), (-a).toPrimitiveValue()), - // neg 50 == -50 - Eq(UtNegExpression(a.toPrimitiveValue()).toIntValue(), (-a).toPrimitiveValue()), - // neg Long(50) == Long(-50) - Eq(UtNegExpression(a.toLong().toPrimitiveValue()).toLongValue(), (-a).toLong().toPrimitiveValue()), - // neg Float(50) == Float(-50) - Eq( - UtNegExpression(a.toFloat().toPrimitiveValue()).toFloatValue(), - (-a).toFloat().toPrimitiveValue() - ), - // neg Double(50) == Double(-50) - Eq( - UtNegExpression(a.toDouble().toPrimitiveValue()).toDoubleValue(), - (-a).toDouble().toPrimitiveValue() - ) - ) { - `is`(empty, unknown)(it) - } - } - - @Test - fun testSelectStoreExpression() { - val query: BaseQuery = Query() - val constArray = mkArrayWithConst(UtArraySort(UtIntSort, UtIntSort), mkInt(10)) - // select(constArray(1), 10) == 10 - query.check(Eq(constArray.select(mkInt(1)).toIntValue(), 10)) { - `is`(empty, unknown)(it) - } - // select(constArray(1), 10) != 20 - query.checkUnsat(Eq(constArray.select(mkInt(1)).toIntValue(), 20)) - val a = mkBVConst("a", UtIntSort) - val array = mkArrayConst("array", UtIntSort, UtIntSort) - val multistore1 = UtArrayMultiStoreExpression( - array, - persistentListOf( - UtStore(mkInt(2), mkInt(10)), - UtStore(a, mkInt(30)), - UtStore(mkInt(0), mkInt(10)), - UtStore(mkInt(0), mkInt(20)), - UtStore(mkInt(1), mkInt(10)) - ) - ) - val multistore2 = UtArrayMultiStoreExpression( - array, - persistentListOf( - UtStore(mkInt(2), mkInt(10)), - UtStore(mkInt(0), mkInt(10)), - UtStore(mkInt(0), mkInt(20)), - UtStore(mkInt(1), mkInt(10)), - UtStore(a, mkInt(30)) - ) - ) - query.check( - // select(store(...., 1, 10), 1) == 10 - Eq(multistore1.select(mkInt(1)).toIntValue(), 10), - // select(store(store(store(..., 0, 10), 0, 20), 1, 10), 1) == 20 - Eq(multistore1.select(mkInt(0)).toIntValue(), 20), - // select(store(...., a, 30), a) == 30 - Eq(multistore2.select(a).toIntValue(), 30) - ) { - `is`(empty, unknown)(it) - } - query.check( - // select(store(...(store(store(..., 2, 10), a, 30)...), 2) == 10 can't be simplified - Eq(multistore1.select(mkInt(2)).toIntValue(), 10) - ) { - `is`(size(1), unknown)(it) - } - query.check( - // select(store(...(store(..., a, 30))...), a) == 30 can't be simplified - Eq(multistore1.select(a).toIntValue(), 30) - ) { - `is`(size(1), unknown)(it) - } - } - - @Test - fun testPartialArithmeticExpression() { - val query: BaseQuery = Query() - - val a = mkBVConst("a", UtIntSort).toIntValue() - val zero = 0.toPrimitiveValue() - val one = 1.toPrimitiveValue() - val minusOne = (-1).toPrimitiveValue() - query.check( - // a + 0 == a - Eq(Add(a, zero).toIntValue(), a), - // a - 0 == a - Eq(Sub(a, zero).toIntValue(), a), - // 0 + a == a - Eq(Add(zero, a).toIntValue(), a), - // 0 - a == neg a - Eq(Sub(zero, a).toIntValue(), UtNegExpression(a).toIntValue()), - // 0 * a == 0 - Eq(Mul(zero, a).toIntValue(), zero), - Eq(Mul(a, zero).toIntValue(), zero), - // a * 1 == a - Eq(Mul(a, one).toIntValue(), a), - Eq(Mul(one, a).toIntValue(), a), - // a * (-1) == neg a - Eq(Mul(a, minusOne).toIntValue(), UtNegExpression(a).toIntValue()), - Eq(Mul(minusOne, a).toIntValue(), UtNegExpression(a).toIntValue()), - ) { - `is`(empty, unknown)(it) - } - } - - @Test - fun testOpenLiteralFromInnerExpr() { - val query: BaseQuery = Query() - - val a = mkBVConst("a", UtIntSort).toIntValue() - val five = 5.toPrimitiveValue() - val ten = 10.toPrimitiveValue() - val fifteen = 15.toPrimitiveValue() - val fifty = 50.toPrimitiveValue() - query.check( - // ((a + 5) + 10) == a + 15 - Eq(Add(Add(a, five).toIntValue(), ten).toIntValue(), Add(a, fifteen).toIntValue()), - Eq(Add(Add(five, a).toIntValue(), ten).toIntValue(), Add(a, fifteen).toIntValue()), - Eq(Add(ten, Add(a, five).toIntValue()).toIntValue(), Add(a, fifteen).toIntValue()), - Eq(Add(ten, Add(five, a).toIntValue()).toIntValue(), Add(a, fifteen).toIntValue()), - // ((a * 5) * 10) == a * 50 - Eq(Mul(Mul(a, five).toIntValue(), ten).toIntValue(), Mul(a, fifty).toIntValue()), - Eq(Mul(Mul(five, a).toIntValue(), ten).toIntValue(), Mul(a, fifty).toIntValue()), - Eq(Mul(ten, Mul(a, five).toIntValue()).toIntValue(), Mul(a, fifty).toIntValue()), - Eq(Mul(ten, Mul(five, a).toIntValue()).toIntValue(), Mul(a, fifty).toIntValue()), - // ((a - 5) + 10) == a + 5 - Eq(Add(Sub(a, five).toIntValue(), ten).toIntValue(), Add(a, five).toIntValue()), - Eq(Add(ten, Sub(a, five).toIntValue()).toIntValue(), Add(a, five).toIntValue()), - // ((a + 5) * 10) == a * 10 + 50 - Eq(Mul(Add(a, five).toIntValue(), ten).toIntValue(), Add(Mul(a, ten).toIntValue(), fifty).toIntValue()), - Eq(Mul(Add(five, a).toIntValue(), ten).toIntValue(), Add(Mul(a, ten).toIntValue(), fifty).toIntValue()), - Eq(Mul(ten, Add(a, five).toIntValue()).toIntValue(), Add(Mul(a, ten).toIntValue(), fifty).toIntValue()), - Eq(Mul(ten, Add(five, a).toIntValue()).toIntValue(), Add(Mul(a, ten).toIntValue(), fifty).toIntValue()), - ) { - `is`(empty, unknown)(it) - } - } - - @Test - fun testEqSimplificationWithInnerExpr() { - val query: BaseQuery = Query() - - val a = mkBVConst("a", UtIntSort).toIntValue() - val five = 5.toPrimitiveValue() - val ten = 10.toPrimitiveValue() - val fifteen = 15.toPrimitiveValue() - // (a + 5) == 10 === a == 5 - query.check(Eq(Add(a, five).toIntValue(), ten)) { - `is`(contains(Eq(a, five)), unknown)(it) - } - // (a - 5) == 10 === a == 15 - query.check(Eq(Sub(a, five).toIntValue(), ten)) { - `is`(contains(Eq(a, fifteen)), unknown)(it) - } - // (a xor 5) == 10 === a == 5 xor 10 - query.check(Eq(Xor(a, five).toIntValue(), ten)) { - `is`(contains(Eq(a, (10 xor 5).toPrimitiveValue())), unknown)(it) - } - } - - @Test - fun testLtSimplifications() { - val query: BaseQuery = Query() - - val a = mkBVConst("a", UtIntSort).toIntValue() - val five = 5.toPrimitiveValue() - val ten = 10.toPrimitiveValue() - val fifteen = 15.toPrimitiveValue() - val nine = 9.toPrimitiveValue() - val four = 4.toPrimitiveValue() - // ltQuery = Query(a < 10) - val ltQuery = query.check(Lt(a, ten)) { - `is`(size(1), unknown)(it) - } - // a < 10, a < 15, a <= 10, a > 5 === a < 10, a > 5 - ltQuery.check(Lt(a, fifteen), Le(a, ten), Gt(a, five)) { - `is`(contains(Lt(a, ten)), contains(Gt(a, five)), unknown)(it) - } - // a < 10, a >= 9 === a == 9 - ltQuery.check(Ge(a, nine)) { `is`(contains(Eq(a, nine)), unknown)(it) } - // a < 10, a >= 10 is unsat - ltQuery.checkUnsat(Ge(a, ten)) - // a < 10, a > 10 is unsat - ltQuery.checkUnsat(Gt(a, ten)) - // a < 10, a == 10 is unsat - ltQuery.checkUnsat(Eq(a, ten)) - val lessLtQuery = ltQuery.check(Lt(a, five)) { `is`(size(1), unknown)(it) } - // a < 5, a >= 5 is unsat - lessLtQuery.checkUnsat(Ge(a, five)) - // a < 5, a >= 4 === a == 4 - lessLtQuery.check(Ge(a, four)) { `is`(contains(Eq(a, four)), unknown)(it) } - // a < Long.MIN_VALUE is unsat - query.checkUnsat(Lt(a, Long.MIN_VALUE.primitiveToSymbolic())) - } - - @Test - fun testLeSimplifications() { - val query: BaseQuery = Query() - - val a = mkBVConst("a", UtIntSort).toIntValue() - val five = 5.toPrimitiveValue() - val ten = 10.toPrimitiveValue() - val fifteen = 15.toPrimitiveValue() - val nine = 9.toPrimitiveValue() - // geQuery = Query(a <= 10) - val leQuery = query.check(Le(a, ten)) { - `is`(size(1), unknown)(it) - } - // a <= 10, a < 15, a < 10, a > 5 === a < 10, a > 5 - leQuery.check(Lt(a, fifteen), Lt(a, ten), Gt(a, five)) { - `is`(contains(Lt(a, ten)), contains(Gt(a, five)), unknown)(it) - } - // a <= 10, a > 9 === a == 10 - leQuery.check(Gt(a, nine)) { `is`(contains(Eq(a, ten)), unknown)(it) } - // a <= 10, a >= 10 === a == 10 - leQuery.check(Ge(a, ten)) { `is`(contains(Eq(a, ten)), unknown)(it) } - // a <= 10, a > 10 is unsat - leQuery.checkUnsat(Gt(a, ten)) - // a <= 10, a == 15 is unsat - leQuery.checkUnsat(Eq(a, fifteen)) - val lessLeQuery = leQuery.check(Le(a, five)) { `is`(size(1), unknown)(it) } - // a <= 5, a > 5 is unsat - lessLeQuery.checkUnsat(Gt(a, five)) - // a <= 5, a >= 5 === a == 5 - lessLeQuery.check(Ge(a, five)) { `is`(contains(Eq(a, five)), unknown)(it) } - // a <= Long.MIN_VALUE is unsat - query.check(Le(a, Long.MIN_VALUE.primitiveToSymbolic())) { `is`(size(1), unknown)(it) } - } - - @Test - fun testGtSimplifications() { - val query: BaseQuery = Query() - - val a = mkBVConst("a", UtIntSort).toIntValue() - val five = 5.toPrimitiveValue() - val ten = 10.toPrimitiveValue() - val fifteen = 15.toPrimitiveValue() - val eleven = 11.toPrimitiveValue() - val sixteen = 16.toPrimitiveValue() - // geQuery = Query(a > 10) - val gtQuery = query.check(Gt(a, ten)) { - `is`(size(1), unknown)(it) - } - // a > 10, a > 5, a >= 10, a < 15 === a > 10, a < 15 - gtQuery.check(Gt(a, five), Ge(a, ten), Lt(a, fifteen)) { - `is`(contains(Gt(a, ten)), contains(Lt(a, fifteen)), unknown)(it) - } - // a > 10, a <= 11 === a == 11 - gtQuery.check(Le(a, eleven)) { `is`(contains(Eq(a, eleven)), unknown)(it) } - // a > 10, a <= 10 is unsat - gtQuery.checkUnsat(Le(a, ten)) - // a > 10, a < 10 is unsat - gtQuery.checkUnsat(Lt(a, ten)) - // a > 10, a == 10 is unsat - gtQuery.checkUnsat(Eq(a, ten)) - val greaterGtQuery = gtQuery.check(Gt(a, fifteen)) { `is`(size(1), unknown)(it) } - // a > 15, a <= 15 is unsat - greaterGtQuery.checkUnsat(Le(a, fifteen)) - // a > 15, a <= 16 === a == 16 - greaterGtQuery.check(Le(a, sixteen)) { `is`(contains(Eq(a, sixteen)), unknown)(it) } - // a > Long.MAX_VALUE is unsat - query.checkUnsat(Gt(a, Long.MAX_VALUE.primitiveToSymbolic())) - } - - @Test - fun testGeSimplifications() { - val query: BaseQuery = Query() - - val a = mkBVConst("a", UtIntSort).toIntValue() - val five = 5.toPrimitiveValue() - val ten = 10.toPrimitiveValue() - val fifteen = 15.toPrimitiveValue() - val eleven = 11.toPrimitiveValue() - // geQuery = Query(a >= 10) - val geQuery = query.check(Ge(a, ten)) { - `is`(size(1), unknown)(it) - } - // a >= 10, a > 5, a > 10, a < 15 === a > 10, a < 15 - geQuery.check(Gt(a, five), Gt(a, ten), Lt(a, fifteen)) { - `is`(contains(Gt(a, ten)), contains(Lt(a, fifteen)), unknown)(it) - } - // a >= 10, a < 11 === a == 10 - geQuery.check(Lt(a, eleven)) { `is`(contains(Eq(a, ten)), unknown)(it) } - // a >= 10, a <= 10 === a == 10 - geQuery.check(Le(a, ten)) { `is`(contains(Eq(a, ten)), unknown)(it) } - // a >= 10, a < 10 is unsat - geQuery.checkUnsat(Lt(a, ten)) - // a >= 10, a == 5 is unsat - geQuery.checkUnsat(Eq(a, five)) - val greaterGeQuery = geQuery.check(Ge(a, fifteen)) { `is`(size(1), unknown)(it) } - // a >= 15, a < 15 is unsat - greaterGeQuery.checkUnsat(Lt(a, fifteen)) - // a >= 15, a <= 15 === a == 15 - greaterGeQuery.check(Le(a, fifteen)) { `is`(contains(Eq(a, fifteen)), unknown)(it) } - // a >= Long.MaxVAlue is sat - query.check(Ge(a, Long.MAX_VALUE.primitiveToSymbolic())) { `is`(size(1), unknown)(it) } - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/engine/z3/ExtensionsKtTest.kt b/utbot-testing/src/test/kotlin/org/utbot/engine/z3/ExtensionsKtTest.kt deleted file mode 100644 index 6beffa785e..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/engine/z3/ExtensionsKtTest.kt +++ /dev/null @@ -1,396 +0,0 @@ -@file:Suppress("unused") - -package org.utbot.engine.z3 - -import org.utbot.engine.pc.Z3Variable -import com.microsoft.z3.BoolExpr -import com.microsoft.z3.FPExpr -import com.microsoft.z3.Sort -import kotlin.random.Random -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.assertThrows -import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.Arguments.arguments -import org.junit.jupiter.params.provider.MethodSource -import org.utbot.engine.z3.ExtensionsKtTest.Companion.toSort -import soot.BooleanType -import soot.ByteType -import soot.CharType -import soot.DoubleType -import soot.FloatType -import soot.IntType -import soot.LongType -import soot.ShortType -import soot.Type - -internal class ExtensionsKtTest { - @ParameterizedTest - @MethodSource("convertVarArgs") - fun testConvertVar(variable: Z3Variable, type: Type) { - val expr = variable.expr - when { - // this fine, we don't have such conversion, so let's check fail here - expr is FPExpr && type is BooleanType -> assertThrows { - context.convertVar( - variable, - type - ) - } - expr is BoolExpr && type !is BooleanType -> assertThrows { - context.convertVar( - variable, - type - ) - } - else -> { - val alignVar = context.convertVar(variable, type) - assertEquals(type, alignVar.type) - assertEquals(context.toSort(type), alignVar.expr.sort) - } - } - } - - @ParameterizedTest - @MethodSource("conversions") - fun testConversions(conversion: Conversion) { - with(conversion) { - for ((i, number) in numbers.withIndex()) { - testConversions(number, numbers.subList(i + 1, numbers.size)) - } - } - } - - @ParameterizedTest - @MethodSource("fromCharArgs") - fun testFromChar(from: Char, result: Number) { - testCharJavaConversion(from, result) - val variable = variable(from) - val value = context.convertVar(variable, result.toType()).expr.simplify().value() - when (result) { - is Byte -> assertEquals(result, value as Byte) { "$from to $result" } - is Short -> assertEquals(result, value as Short) { "$from to $result" } - is Int -> assertEquals(result, value as Int) { "$from to $result" } - is Long -> assertEquals(result, value as Long) { "$from to $result" } - is Float -> assertEquals(result, value as Float) { "$from to $result" } - is Double -> assertEquals(result, value as Double) { "$from to $result" } - } - } - - @ParameterizedTest - @MethodSource("toCharArgs") - fun testToChar(from: Number, result: Char) { - assertEquals(result, from.toChar()) { - "Java: $from (${ - from.toChar().prettify() - }) to $result (${result.prettify()})" - } - val variable = variable(from) - val value = context.convertVar(variable, CharType.v()).expr.simplify().value(true) as Char - assertEquals(result, value) { "$from to $result" } - } - - @ParameterizedTest - @MethodSource("fromSolverStringArgs") - fun testConvertFromSolver(from: String, to: String) { - val converted = convertSolverString(from) - assertEquals(to, converted) { "${to.codes()} != ${converted.codes()}" } - } - - private fun String.codes() = map { it.toInt() }.joinToString() - - private fun testConversions(from: Number, to: List) { - to.forEach { result -> - testJavaConversion(from, result) - val variable = variable(from) - val value = context.convertVar(variable, result.toType()).expr.simplify().value() - when (result) { - is Byte -> assertEquals(result, value as Byte) { "$from to $result" } - is Short -> assertEquals(result, value as Short) { "$from to $result" } - is Int -> assertEquals(result, value as Int) { "$from to $result" } - is Long -> assertEquals(result, value as Long) { "$from to $result" } - is Float -> assertEquals(result, value as Float) { "$from to $result" } - is Double -> assertEquals(result, value as Double) { "$from to $result" } - } - } - } - - private fun testJavaConversion(from: Number, result: Number) { - when (result) { - is Byte -> assertEquals(result, from.toByte()) { "Java: $from to $result" } - is Short -> assertEquals(result, from.toShort()) { "Java: $from to $result" } - is Int -> assertEquals(result, from.toInt()) { "Java: $from to $result" } - is Long -> assertEquals(result, from.toLong()) { "Java: $from to $result" } - is Float -> assertEquals(result, from.toFloat()) { "Java: $from to $result" } - is Double -> assertEquals(result, from.toDouble()) { "Java: $from to $result" } - } - } - - private fun testCharJavaConversion(from: Char, result: Number) { - when (result) { - is Byte -> assertEquals(result, from.toByte()) { "Java: $from to $result" } - is Short -> assertEquals(result, from.toShort()) { "Java: $from to $result" } - is Int -> assertEquals(result, from.toInt()) { "Java: $from to $result" } - is Long -> assertEquals(result, from.toLong()) { "Java: $from to $result" } - is Float -> assertEquals(result, from.toFloat()) { "Java: $from to $result" } - is Double -> assertEquals(result, from.toDouble()) { "Java: $from to $result" } - } - } - - companion object : Z3Initializer() { - @JvmStatic - fun convertVarArgs() = - series.flatMap { left -> series.map { right -> arguments(left, right.type) } } - - private val series = listOf( - Z3Variable(ByteType.v(), context.mkBV(Random.nextInt(0, 100), Byte.SIZE_BITS)), - Z3Variable(ShortType.v(), context.mkBV(Random.nextInt(0, 100), Short.SIZE_BITS)), - Z3Variable(CharType.v(), context.mkBV(Random.nextInt(50000, 60000), Char.SIZE_BITS)), - Z3Variable(IntType.v(), context.mkBV(Random.nextInt(0, 100), Int.SIZE_BITS)), - Z3Variable(LongType.v(), context.mkBV(Random.nextInt(0, 100), Long.SIZE_BITS)), - Z3Variable(FloatType.v(), context.mkFP(Random.nextFloat(), context.mkFPSort32())), - Z3Variable(DoubleType.v(), context.mkFP(Random.nextDouble(), context.mkFPSort64())), - Z3Variable(BooleanType.v(), context.mkBool(Random.nextBoolean())) - ) - - /** - * Arguments for conversion checks. - * - * How to read conversion line: from left to right each number can be converted to all following, - * so Conversion(100.toByte(), 100.toShort(), 100, 100L) means it checks: - * - byte to short, int, long - * - short to int, long - * - int to long - * - * Notes: - * - char primitive class is missing with its conversions - * - * @see - * Java Language Specification - */ - @JvmStatic - fun conversions() = listOf( - // A widening, from an integral type to another integral type, sign-extends - Conversion((-100).toByte(), (-100).toShort(), -100, -100L), - Conversion(100.toByte(), 100.toShort(), 100, 100L), - - /** - * A narrowing conversion may lose information about the overall magnitude of a numeric value - * and may also lose precision and range. - * Integral: simply discards all but the n lowest order bits - */ - Conversion(-100L, -100, (-100).toShort(), (-100).toByte()), - Conversion(0x1111222233334444L, 0x33334444, (0x4444).toShort(), (0x44).toByte()), - Conversion(4000000012L, -294967284, 10252.toShort(), 12.toByte()), - Conversion(-1L, -1, (-1).toShort(), (-1).toByte()), - - // Int to float, long to double, may lose some of the least significant bits of the value - Conversion(1234567890, 1.23456794E9f), - Conversion(-1234567890, -1.23456794E9f), - Conversion(6000372036854775807L, 6.0003720368547758E18), - Conversion(-6000372036854775807L, -6.0003720368547758E18), - - /** - * Double to float, narrowing. - * A finite value too small to be represented as a float is converted to a zero of the same sign; - * a finite value too large to be represented as a float is converted to an infinity of the same sign. - * A double NaN is converted to a float NaN. - */ - Conversion(100.0, 100.0f), - Conversion(-100.0, -100.0f), - Conversion(Double.NaN, Float.NaN), - Conversion(Double.POSITIVE_INFINITY, Float.POSITIVE_INFINITY), - Conversion(Double.MAX_VALUE, Float.POSITIVE_INFINITY), - Conversion(1E40, Float.POSITIVE_INFINITY), - Conversion(Double.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY), - Conversion(-Double.MAX_VALUE, Float.NEGATIVE_INFINITY), - Conversion(-1E40, Float.NEGATIVE_INFINITY), - Conversion(0.0, 0.0f), - Conversion(-0.0, -0.0f), - Conversion(Double.MIN_VALUE, 0.0f), - Conversion(-Double.MIN_VALUE, -0.0f), - - /** - * Float to double, widening. - * A float infinity is converted to a double infinity of the same sign. - * A float NaN is converted to a double NaN. - */ - Conversion(100.0f, 100.0), - Conversion(-100.0f, -100.0), - Conversion(Float.NaN, Double.NaN), - Conversion(Float.POSITIVE_INFINITY, Double.POSITIVE_INFINITY), - Conversion(Float.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), - Conversion(0.0f, 0.0), - Conversion(-0.0f, -0.0), - - // float/double to long - Conversion(100.999, 100L), - Conversion(-100.999, -100L), - Conversion(0.0, 0L), - Conversion(-0.0, 0L), - Conversion(Double.MIN_VALUE, 0L), - Conversion(-Double.MIN_VALUE, 0L), - Conversion(100.999f, 100L), - Conversion(-100.999f, -100L), - Conversion(0.0f, 0L), - Conversion(-0.0f, -0L), - - // Special cases - Conversion(Float.NaN, 0L), - Conversion(Float.POSITIVE_INFINITY, Long.MAX_VALUE), - Conversion(Float.NEGATIVE_INFINITY, Long.MIN_VALUE), - Conversion(Double.NaN, 0L), - Conversion(Double.POSITIVE_INFINITY, Long.MAX_VALUE), - Conversion(Double.MAX_VALUE, Long.MAX_VALUE), - Conversion(1E40, Long.MAX_VALUE), - Conversion(Double.NEGATIVE_INFINITY, Long.MIN_VALUE), - Conversion(-Double.MAX_VALUE, Long.MIN_VALUE), - Conversion(-1E40, Long.MIN_VALUE), - - // float/double to int - Conversion(100.999, 100), - Conversion(-100.999, -100), - Conversion(0.0, 0), - Conversion(-0.0, 0), - Conversion(Double.MIN_VALUE, 0), - Conversion(-Double.MIN_VALUE, 0), - Conversion(100.999f, 100), - Conversion(-100.999f, -100), - Conversion(0.0f, 0), - Conversion(-0.0f, -0), - - // Special cases - Conversion(Float.NaN, 0), - Conversion(Float.POSITIVE_INFINITY, Int.MAX_VALUE), - Conversion(Float.NEGATIVE_INFINITY, Int.MIN_VALUE), - Conversion(Double.NaN, 0), - Conversion(Double.POSITIVE_INFINITY, Int.MAX_VALUE), - Conversion(Double.MAX_VALUE, Int.MAX_VALUE), - Conversion(1E40, Int.MAX_VALUE), - Conversion(Double.NEGATIVE_INFINITY, Int.MIN_VALUE), - Conversion(-Double.MAX_VALUE, Int.MIN_VALUE), - Conversion(-1E40, Int.MIN_VALUE), - - // float/double to byte (through int) - Conversion(100.999, 100.toByte()), - Conversion(-100.999, (-100).toByte()), - Conversion(0.0, 0.toByte()), - Conversion(-0.0, 0.toByte()), - Conversion(Double.MIN_VALUE, 0.toByte()), - Conversion(-Double.MIN_VALUE, 0.toByte()), - Conversion(100.999f, 100.toByte()), - Conversion(-100.999f, (-100).toByte()), - Conversion(0.0f, 0.toByte()), - Conversion(-0.0f, (-0).toByte()), - - // Special cases - Conversion(Float.NaN, 0.toByte()), - Conversion(Float.POSITIVE_INFINITY, (-1).toByte()), // narrowing from int to byte - Conversion(Float.NEGATIVE_INFINITY, 0.toByte()), // narrowing from int to byte - Conversion(Double.NaN, 0.toByte()), - Conversion(Double.POSITIVE_INFINITY, (-1).toByte()), // narrowing from int to byte - Conversion(Double.MAX_VALUE, (-1).toByte()), // narrowing from int to byte - Conversion(1E40, (-1).toByte()), // narrowing from int to byte - Conversion(Double.NEGATIVE_INFINITY, 0.toByte()), // narrowing from int to byte - Conversion(-Double.MAX_VALUE, 0.toByte()), // narrowing from int to byte - Conversion(-1E40, 0.toByte()), // narrowing from int to byte - ) - - @JvmStatic - fun fromCharArgs() = listOf( - arguments('\u9999', (-103).toByte()), - arguments('\u9999', (-26215).toShort()), - arguments('\u9999', 39321), - arguments('\u9999', 39321L), - arguments('\u9999', 39321.0f), - arguments('\u9999', 39321.0), - ) - - @JvmStatic - fun toCharArgs() = listOf( - arguments((-103).toByte(), '\uFF99'), - arguments(103.toByte(), '\u0067'), - arguments((-26215).toShort(), '\u9999'), - arguments(26215.toShort(), '\u6667'), - arguments(1234567890, '\u02D2'), - arguments(-1234567890, '\uFD2E'), - arguments(6000372036854775807L, '\u7FFF'), - arguments(-6000372036854775807L, '\u8001'), - - // float/double to char (through int) - arguments(-39321.0, '\u6667'), - arguments(100.999, '\u0064'), - arguments(-100.999, '\uFF9C'), - arguments(0.0, '\u0000'), - arguments(-0.0, '\u0000'), - arguments(Double.MIN_VALUE, '\u0000'), - arguments(-Double.MIN_VALUE, '\u0000'), - arguments(-39321.0f, '\u6667'), - arguments(100.999f, '\u0064'), - arguments(-100.999f, '\uFF9C'), - arguments(0.0f, '\u0000'), - arguments(-0.0f, '\u0000'), - - // Special cases - arguments(Float.NaN, '\u0000'), - arguments(Float.POSITIVE_INFINITY, '\uFFFF'), // narrowing from int to char - arguments(Float.NEGATIVE_INFINITY, '\u0000'), // narrowing from int to char - arguments(Double.NaN, '\u0000'), - arguments(Double.POSITIVE_INFINITY, '\uFFFF'), // narrowing from int to char - arguments(Double.MAX_VALUE, '\uFFFF'), // narrowing from int to char - arguments(1E40, '\uFFFF'), // narrowing from int to char - arguments(Double.NEGATIVE_INFINITY, '\u0000'), // narrowing from int to char - arguments(-Double.MAX_VALUE, '\u0000'), // narrowing from int to char - arguments(-1E40, '\u0000'), // narrowing from int to char - ) - - @JvmStatic - fun fromSolverStringArgs() = listOf( - arguments("", ""), - arguments("\\a", "\u0007"), - arguments("\\b", "\b"), - arguments("\\f", "\u000C"), - arguments("\\n", "\n"), - arguments("\\r", "\r"), - arguments("\\t", "\t"), - arguments("\\v", "\u000B"), - - arguments("\\x00", "\u0000"), - arguments("\\xAB", "\u00AB"), - arguments("AaBbCc (){}[]<>,.!@#$%^&*-=_+/?`~\\\\", "AaBbCc (){}[]<>,.!@#$%^&*-=_+/?`~\\"), - ) - - private fun variable(from: Any): Z3Variable = when (from) { - is Number -> Z3Variable(from.toType(), context.makeConst(from, from.toSort())) - is Char -> Z3Variable(CharType.v(), context.mkBV(from.toInt(), Char.SIZE_BITS)) - else -> error("Unknown constant: ${from::class}") - } - - private fun Any.toSort(): Sort = when (this) { - is Byte -> context.mkBitVecSort(Byte.SIZE_BITS) - is Short -> context.mkBitVecSort(Short.SIZE_BITS) - is Char -> context.mkBitVecSort(Char.SIZE_BITS) - is Int -> context.mkBitVecSort(Int.SIZE_BITS) - is Long -> context.mkBitVecSort(Long.SIZE_BITS) - is Float -> context.mkFPSort32() - is Double -> context.mkFPSort64() - else -> error("Unknown type $this") - } - - private fun Any.toType(): Type = when (this) { - is Byte -> ByteType.v() - is Short -> ShortType.v() - is Char -> CharType.v() - is Int -> IntType.v() - is Long -> LongType.v() - is Float -> FloatType.v() - is Double -> DoubleType.v() - else -> error("Unknown type $this") - } - } -} - -private fun Char.prettify(): String = "%04X".format(this.toInt()).let { "'\\u$it'" } - -data class Conversion(val numbers: List) { - constructor(vararg numbers: Number) : this(numbers.toList()) -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/engine/z3/OperatorsKtTest.kt b/utbot-testing/src/test/kotlin/org/utbot/engine/z3/OperatorsKtTest.kt deleted file mode 100644 index 0325e4c873..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/engine/z3/OperatorsKtTest.kt +++ /dev/null @@ -1,76 +0,0 @@ -@file:Suppress("unused") - -package org.utbot.engine.z3 - -import org.utbot.engine.pc.Z3Variable -import com.microsoft.z3.BitVecSort -import com.microsoft.z3.BoolExpr -import com.microsoft.z3.FPExpr -import kotlin.random.Random -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.assertThrows -import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.Arguments.arguments -import org.junit.jupiter.params.provider.MethodSource -import soot.BooleanType -import soot.ByteType -import soot.CharType -import soot.DoubleType -import soot.FloatType -import soot.IntType -import soot.LongType -import soot.ShortType - -internal class OperatorsKtTest { - @ParameterizedTest - @MethodSource("alignVarsArgs") - fun testAlignVars(left: Z3Variable, right: Z3Variable) { - if (left.expr is BoolExpr && right.expr is FPExpr || left.expr is FPExpr && right.expr is BoolExpr) { - // this fine, we don't have such conversion, so let's check fail here - assertThrows { context.alignVars(left, right) } - } else { - val (aleft, aright) = context.alignVars(left, right) - // Binary numeric promotion - byte, short and char converted to int before operation - if (left.expr.sort is BitVecSort && aleft.sort is BitVecSort) { - assertTrue((aleft.sort as BitVecSort).size >= Int.SIZE_BITS) - } - if (right.expr.sort is BitVecSort && aright.sort is BitVecSort) { - assertTrue((aright.sort as BitVecSort).size >= Int.SIZE_BITS) - } - assertEquals(aleft.sort, aright.sort) - } - } - - @ParameterizedTest - @MethodSource("alignVarArgs") - fun testAlignVar(variable: Z3Variable) { - val aligned = context.alignVar(variable) - // Unary numeric promotion - byte, short and char converted to int before operation - if (variable.expr.sort is BitVecSort && (variable.expr.sort as BitVecSort).size < Int.SIZE_BITS) { - assertTrue((aligned.expr.sort as BitVecSort).size == Int.SIZE_BITS) - } else { - assertEquals(variable, aligned) - } - } - - companion object : Z3Initializer() { - @JvmStatic - fun alignVarsArgs() = - series.flatMap { left -> series.map { right -> arguments(left, right) } } - - @JvmStatic - fun alignVarArgs() = series - - private val series = listOf( - Z3Variable(ByteType.v(), context.mkBV(Random.nextInt(0, 100), Byte.SIZE_BITS)), - Z3Variable(ShortType.v(), context.mkBV(Random.nextInt(0, 100), Short.SIZE_BITS)), - Z3Variable(CharType.v(), context.mkBV(Random.nextInt(50000, 60000), Char.SIZE_BITS)), - Z3Variable(IntType.v(), context.mkBV(Random.nextInt(0, 100), Int.SIZE_BITS)), - Z3Variable(LongType.v(), context.mkBV(Random.nextInt(0, 100), Long.SIZE_BITS)), - Z3Variable(FloatType.v(), context.mkFP(Random.nextFloat(), context.mkFPSort32())), - Z3Variable(DoubleType.v(), context.mkFP(Random.nextDouble(), context.mkFPSort64())), - Z3Variable(BooleanType.v(), context.mkBool(Random.nextBoolean())) - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/BinarySearchTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/BinarySearchTest.kt deleted file mode 100644 index f826a1d413..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/BinarySearchTest.kt +++ /dev/null @@ -1,97 +0,0 @@ -package org.utbot.examples.algorithms - -import org.utbot.framework.plugin.api.DocCodeStmt -import org.utbot.framework.plugin.api.DocPreTagStatement -import org.utbot.framework.plugin.api.DocRegularStmt -import org.utbot.framework.plugin.api.DocStatement -import org.junit.jupiter.api.Test -import org.utbot.testing.UtValueTestCaseChecker -import org.utbot.testing.ignoreExecutionsNumber -import org.utbot.testing.isException - -class BinarySearchTest : UtValueTestCaseChecker(testClass = BinarySearch::class,) { - @Test - fun testLeftBinarySearch() { - val fullSummary = listOf( - DocPreTagStatement( - listOf( - DocRegularStmt("Test "), - DocRegularStmt("does not iterate "), - DocCodeStmt("while(left < right - 1)"), - DocRegularStmt(", "), - DocRegularStmt("executes conditions:\n"), - DocRegularStmt(" "), - DocCodeStmt("(found): False"), - DocRegularStmt("\n"), - DocRegularStmt("returns from: "), - DocCodeStmt("return -1;"), - DocRegularStmt("\n") - - ) - ) - ) - checkWithException( - BinarySearch::leftBinSearch, - ignoreExecutionsNumber, - { a, _, r -> a == null && r.isException() }, - { a, _, r -> a.size >= 2 && a[0] > a[1] && r.isException() }, - { a, _, r -> a.isEmpty() && r.getOrNull() == -1 }, - { a, key, r -> a.isNotEmpty() && key >= a[(a.size - 1) / 2] && key !in a && r.getOrNull() == -1 }, - { a, key, r -> a.isNotEmpty() && key in a && r.getOrNull() == a.indexOfFirst { it == key } + 1 }, - // TODO enable it JIRA:1442 - /* - summaryTextChecks = listOf( - keyContain(DocCodeStmt("(found): False")), - keyContain(DocCodeStmt("(found): True")), - keyContain(DocRegularStmt(" BinarySearch::isUnsorted once")), - keyContain(DocRegularStmt("throws NullPointerException in: isUnsorted(array)")), - keyContain(DocRegularStmt("throws IllegalArgumentException after condition: isUnsorted(array)")), - keyContain(DocCodeStmt("(array[middle] < key): True")), - keyContain(DocCodeStmt("(array[middle] == key): True")), - keyContain(DocCodeStmt("(array[middle] < key): True")), - keyMatch(fullSummary) - ), - summaryNameChecks = listOf( - keyContain("testLeftBinSearch_BinarySearchIsUnsorted"), - keyContain("testLeftBinSearch_ThrowIllegalArgumentException"), - keyContain("testLeftBinSearch_NotFound"), - keyContain("testLeftBinSearch_MiddleOfArrayLessThanKey"), - keyContain("testLeftBinSearch_Found") - ), - summaryDisplayNameChecks = listOf( - keyMatch("isUnsorted(array) -> ThrowIllegalArgumentException"), - keyMatch("isUnsorted(array) -> ThrowIllegalArgumentException"), - keyMatch("found : False -> return -1"), - keyMatch("array[middle] == key : True -> return right + 1"), - keyMatch("array[middle] < key : True -> return -1") - ) - */ - ) - } - - @Test - fun testRightBinarySearch() { - checkWithException( - BinarySearch::rightBinSearch, - ignoreExecutionsNumber, - { a, _, r -> a == null && r.isException() }, - { a, _, r -> a.isEmpty() && r.getOrNull() == -1 }, - { a, _, r -> a.size >= 2 && a[0] > a[1] && r.isException() }, - { a, key, r -> a.isNotEmpty() && key !in a && r.getOrNull() == -1 }, - { a, key, r -> a.isNotEmpty() && key in a && r.getOrNull() == a.indexOfLast { it == key } + 1 } - ) - } - - @Test - fun testDefaultBinarySearch() { - checkWithException( - BinarySearch::defaultBinarySearch, - ignoreExecutionsNumber, - { a, _, r -> a == null && r.isException() }, - { a, _, r -> a.isEmpty() && r.getOrNull() == -1 }, - { a, _, r -> a.size >= 2 && a[0] > a[1] && r.isException() }, - { a, key, r -> a.isNotEmpty() && key < a.first() && r.getOrNull() == a.binarySearch(key) }, - { a, key, r -> a.isNotEmpty() && key == a.first() && r.getOrNull() == a.binarySearch(key) }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt deleted file mode 100644 index 415d7e0b12..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt +++ /dev/null @@ -1,145 +0,0 @@ -package org.utbot.examples.algorithms - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.framework.plugin.api.DocCodeStmt -import org.utbot.framework.plugin.api.DocPreTagStatement -import org.utbot.framework.plugin.api.DocRegularStmt -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class CorrectBracketSequencesTest : UtValueTestCaseChecker( - testClass = CorrectBracketSequences::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) // TODO generics in lists - ) -) { - @Test - fun testIsOpen() { - val isOpenSummary = listOf( - DocPreTagStatement( - listOf( - DocRegularStmt("Test "), - DocRegularStmt("returns from: "), - DocCodeStmt("return a == '(' || a == '{' || a == '[';"), - DocRegularStmt("\n") - ) - ) - ) - - checkStaticMethod( - CorrectBracketSequences::isOpen, - eq(4), - { c, r -> c == '(' && r == true }, - { c, r -> c == '{' && r == true }, - { c, r -> c == '[' && r == true }, - { c, r -> c !in "({[".toList() && r == false }, - summaryNameChecks = listOf( - keyMatch("testIsOpen_AEqualsCharOrAEqualsCharOrAEqualsChar"), - keyMatch("testIsOpen_ANotEqualsCharOrANotEqualsCharOrANotEqualsChar") - ), - summaryDisplayNameChecks = listOf( - keyMatch("return a == '(' || a == '{' || a == '[' : False -> return a == '(' || a == '{' || a == '['"), - keyMatch("return a == '(' || a == '{' || a == '[' : True -> return a == '(' || a == '{' || a == '['") - ), - summaryTextChecks = listOf( - keyMatch(isOpenSummary) - ) - ) - } - - @Test - fun testIsBracket() { - val isBracketSummary = listOf( - DocPreTagStatement( - listOf( - DocRegularStmt("Test "), - DocRegularStmt("returns from: "), - DocCodeStmt("return isOpen(a) || a == ')' || a == '}' || a == ']';"), - DocRegularStmt("\n") - ) - ) - ) - checkStaticMethod( - CorrectBracketSequences::isBracket, - eq(7), - { c, r -> c == '(' && r == true }, - { c, r -> c == '{' && r == true }, - { c, r -> c == '[' && r == true }, - { c, r -> c == ')' && r == true }, - { c, r -> c == '}' && r == true }, - { c, r -> c == ']' && r == true }, - { c, r -> c !in "(){}[]".toList() && r == false }, - summaryNameChecks = listOf( - keyMatch("testIsBracket_IsOpenOrANotEqualsCharOrANotEqualsCharOrANotEqualsChar"), - keyMatch("testIsBracket_IsOpenOrAEqualsCharOrAEqualsCharOrAEqualsChar") - ), - summaryDisplayNameChecks = listOf( - keyMatch("return isOpen(a) || a == ')' || a == '}' || a == ']' : False -> return isOpen(a) || a == ')' || a == '}' || a == ']'"), - keyMatch("return isOpen(a) || a == ')' || a == '}' || a == ']' : True -> return isOpen(a) || a == ')' || a == '}' || a == ']'") - ), - summaryTextChecks = listOf( - keyMatch(isBracketSummary) - ) - ) - } - - @Test - fun testIsTheSameType() { - val isTheSameTypeSummary = listOf( - DocPreTagStatement( - listOf( - DocRegularStmt("Test "), - DocRegularStmt("returns from: "), - DocCodeStmt("return a == '(' && b == ')' || a == '{' && b == '}' || a == '[' && b == ']';"), - DocRegularStmt("\n") - ) - ) - ) - checkStaticMethod( - CorrectBracketSequences::isTheSameType, - ignoreExecutionsNumber, - { a, b, r -> a == '(' && b == ')' && r == true }, - { a, b, r -> a == '{' && b == '}' && r == true }, - { a, b, r -> a == '[' && b == ']' && r == true }, - { a, b, r -> a == '(' && b != ')' && r == false }, - { a, b, r -> a == '{' && b != '}' && r == false }, - { a, b, r -> a == '[' && b != ']' && r == false }, - { a, b, r -> (a != '(' || b != ')') && (a != '{' || b != '}') && (a != '[' || b != ']') && r == false }, - summaryNameChecks = listOf( - keyMatch("testIsTheSameType_ANotEqualsCharAndBNotEqualsCharOrANotEqualsCharAndBNotEqualsCharOrANotEqualsCharAndBNotEqualsChar"), - keyMatch("testIsTheSameType_AEqualsCharAndBEqualsCharOrAEqualsCharAndBEqualsCharOrAEqualsCharAndBEqualsChar"), - ), - summaryDisplayNameChecks = listOf( - keyMatch("return a == '(' && b == ')' || a == '{' && b == '}' || a == '[' && b == ']' : False -> return a == '(' && b == ')' || a == '{' && b == '}' || a == '[' && b == ']'"), - keyMatch("return a == '(' && b == ')' || a == '{' && b == '}' || a == '[' && b == ']' : True -> return a == '(' && b == ')' || a == '{' && b == '}' || a == '[' && b == ']'") - ), - summaryTextChecks = listOf( - keyMatch(isTheSameTypeSummary) - ) - ) - } - - @Test - fun testIsCbs() { - val method = CorrectBracketSequences::isCbs - checkStaticMethodWithException( - method, - ignoreExecutionsNumber, - { chars, r -> chars == null && r.isException() }, - { chars, r -> chars != null && chars.isEmpty() && r.getOrNull() == true }, - { chars, r -> chars.any { it == null } && r.isException() }, - { chars, r -> !isBracket(chars.first()) && r.getOrNull() == false }, - { chars, r -> !isOpen(chars.first()) && r.getOrNull() == false }, - { chars, _ -> isOpen(chars.first()) }, - { chars, r -> chars.all { isOpen(it) } && r.getOrNull() == false }, - { chars, _ -> - val charsWithoutFirstOpenBrackets = chars.dropWhile { isOpen(it) } - val firstNotOpenBracketChar = charsWithoutFirstOpenBrackets.first() - - isBracket(firstNotOpenBracketChar) && !isOpen(firstNotOpenBracketChar) - }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/GraphTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/GraphTest.kt deleted file mode 100644 index 2ac25b02f9..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/GraphTest.kt +++ /dev/null @@ -1,50 +0,0 @@ -package org.utbot.examples.algorithms - -import org.junit.jupiter.api.Tag -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class GraphTest : UtValueTestCaseChecker(testClass = GraphExample::class) { - @Test - @Tag("slow") - fun testRunFindCycle() { - checkWithException( - GraphExample::runFindCycle, - ignoreExecutionsNumber, - { e, r -> e == null && r.isException() }, - { e, r -> e != null && e.contains(null) && r.isException() }, - { e, r -> e != null && e.any { it.first < 0 || it.first >= 10 } && r.isException() }, - { e, r -> e != null && e.any { it.second < 0 || it.second >= 10 } && r.isException() }, - { e, r -> e != null && e.all { it != null } && r.isSuccess } - ) - } - - @Test - fun testDijkstra() { - // The graph is fixed, there should be exactly one execution path, so no matchers are necessary - check( - GraphExample::runDijkstra, - eq(1) - ) - } - - /** - * TODO: fix Dijkstra algorithm. - */ - @Test - fun testRunDijkstraWithParameter() { - checkWithException( - GraphExample::runDijkstraWithParameter, - ignoreExecutionsNumber, - { g, r -> g == null && r.isException() }, - { g, r -> g.isEmpty() && r.isException() }, - { g, r -> g.size == 1 && r.getOrNull()?.size == 1 && r.getOrNull()?.first() == 0 }, - { g, r -> g.size > 1 && g[1] == null && r.isException() }, - { g, r -> g.isNotEmpty() && g.size != g.first().size && r.isException() }, - { g, r -> - val concreteResult = GraphExample().runDijkstraWithParameter(g) - g.isNotEmpty() && r.getOrNull().contentEquals(concreteResult) - } - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt deleted file mode 100644 index 354558b3fb..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt +++ /dev/null @@ -1,183 +0,0 @@ -package org.utbot.examples.algorithms - -import org.utbot.framework.plugin.api.DocCodeStmt -import org.utbot.framework.plugin.api.DocPreTagStatement -import org.utbot.framework.plugin.api.DocRegularStmt -import org.utbot.framework.plugin.api.MockStrategyApi -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq -import org.utbot.testcheckers.ge - -// TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 -internal class SortTest : UtValueTestCaseChecker( - testClass = Sort::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testQuickSort() { - check( - Sort::quickSort, - ignoreExecutionsNumber, - mockStrategy = MockStrategyApi.OTHER_PACKAGES - ) - } - - @Test - fun testSwap() { - checkWithException( - Sort::swap, - ge(4), - { a, _, _, r -> a == null && r.isException() }, - { a, i, _, r -> a != null && (i < 0 || i >= a.size) && r.isException() }, - { a, i, j, r -> a != null && i in a.indices && (j < 0 || j >= a.size) && r.isException() }, - { a, i, j, _ -> a != null && i in a.indices && j in a.indices } - ) - } - - @Test - fun testArrayCopy() { - check( - Sort::arrayCopy, - eq(1), - { r -> r contentEquals intArrayOf(1, 2, 3) } - ) - } - - @Test - fun testMergeSort() { - check( - Sort::mergeSort, - eq(4), - { a, r -> a == null && r == null }, - { a, r -> a != null && r != null && a.size < 2 }, - { a, r -> - require(a is IntArray && r is IntArray) - - val sortedConstraint = a.size >= 2 && a.sorted() == r.toList() - - val maxInLeftHalf = a.slice(0 until a.size / 2).maxOrNull()!! - val maxInRightHalf = a.slice(a.size / 2 until a.size).maxOrNull()!! - - sortedConstraint && maxInLeftHalf >= maxInRightHalf - }, - { a, r -> - require(a is IntArray && r is IntArray) - - val sortedConstraint = a.size >= 2 && a.sorted() == r.toList() - - val maxInLeftHalf = a.slice(0 until a.size / 2).maxOrNull()!! - val maxInRightHalf = a.slice(a.size / 2 until a.size).maxOrNull()!! - - sortedConstraint && maxInLeftHalf < maxInRightHalf - }, - ) - } - - @Test - fun testMerge() { - checkWithException( - Sort::merge, - eq(6), - { lhs, _, r -> lhs == null && r.isException() }, - { lhs, rhs, r -> lhs != null && lhs.isEmpty() && r.getOrNull() contentEquals rhs }, - { lhs, rhs, _ -> lhs != null && lhs.isNotEmpty() && rhs == null }, - { lhs, rhs, r -> - val lhsCondition = lhs != null && lhs.isNotEmpty() - val rhsCondition = rhs != null && rhs.isEmpty() - val connection = r.getOrNull() contentEquals lhs - - lhsCondition && rhsCondition && connection - }, - { lhs, rhs, r -> - val lhsCondition = lhs != null && lhs.isNotEmpty() - val rhsCondition = rhs != null && rhs.isNotEmpty() - val connection = lhs.last() < rhs.last() && r.getOrNull()?.toList() == (lhs + rhs).sorted() - - lhsCondition && rhsCondition && connection - }, - { lhs, rhs, r -> - val lhsCondition = lhs != null && lhs.isNotEmpty() - val rhsCondition = rhs != null && rhs.isNotEmpty() - val connection = lhs.last() >= rhs.last() && r.getOrNull()?.toList() == (lhs + rhs).sorted() - - lhsCondition && rhsCondition && connection - }, - ) - } - - @Test - fun testDefaultSort() { - val defaultSortSummary1 = listOf( - DocPreTagStatement( - listOf( - DocRegularStmt("Test "), - DocRegularStmt("\n"), - DocRegularStmt("throws NullPointerException in: array.length < 4"), - DocRegularStmt("\n") - ) - ) - ) - - val defaultSortSummary2 = listOf( - DocPreTagStatement( - listOf( - DocRegularStmt("Test "), - DocRegularStmt("executes conditions:\n"), - DocRegularStmt(" "), - DocCodeStmt("(array.length < 4): True"), - DocRegularStmt("\n"), - DocRegularStmt("\n"), - DocRegularStmt("throws IllegalArgumentException after condition: array.length < 4"), - DocRegularStmt("\n") - ) - ) - ) - val defaultSortSummary3 = listOf( - DocPreTagStatement( - listOf( - DocRegularStmt("Test "), - DocRegularStmt("executes conditions:\n"), - DocRegularStmt(" "), - DocCodeStmt("(array.length < 4): False"), - DocRegularStmt("\n"), - DocRegularStmt("invokes:\n"), - DocRegularStmt(" {@link java.util.Arrays#sort(int[])} once"), - DocRegularStmt("\n"), - DocRegularStmt("returns from: "), - DocCodeStmt("return array;"), - DocRegularStmt("\n") - ) - ) - ) - checkWithException( - Sort::defaultSort, - eq(3), - { a, r -> a == null && r.isException() }, - { a, r -> a != null && a.size < 4 && r.isException() }, - { a, r -> - val resultArray = intArrayOf(-100, 0, 100, 200) - a != null && r.getOrNull()!!.size >= 4 && r.getOrNull() contentEquals resultArray - }, - summaryTextChecks = listOf( - keyMatch(defaultSortSummary1), - keyMatch(defaultSortSummary2), - keyMatch(defaultSortSummary3), - ), - summaryNameChecks = listOf( - keyMatch("testDefaultSort_ThrowNullPointerException"), - keyMatch("testDefaultSort_ArrayLengthLessThan4"), - keyMatch("testDefaultSort_ArrayLengthGreaterOrEqual4"), - ), - summaryDisplayNameChecks = listOf( - keyMatch("array.length < 4 -> ThrowNullPointerException"), - keyMatch("array.length < 4 -> ThrowIllegalArgumentException"), - keyMatch("array.length < 4 : False -> return array"), - ) - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/NotNullAnnotationTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/NotNullAnnotationTest.kt deleted file mode 100644 index 6ba1d8bf06..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/NotNullAnnotationTest.kt +++ /dev/null @@ -1,101 +0,0 @@ -package org.utbot.examples.annotations - -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker - -internal class NotNullAnnotationTest : UtValueTestCaseChecker(testClass = NotNullAnnotation::class) { - @Test - fun testDoesNotThrowNPE() { - check( - NotNullAnnotation::doesNotThrowNPE, - eq(1), - { value, r -> value == r } - ) - } - - @Test - fun testThrowsNPE() { - check( - NotNullAnnotation::throwsNPE, - eq(2), - { value, _ -> value == null }, - { value, r -> value == r } - ) - } - - @Test - fun testSeveralParameters() { - check( - NotNullAnnotation::severalParameters, - eq(2), - { _, second, _, _ -> second == null }, - { first, second, third, result -> first + second + third == result } - ) - } - - @Test - fun testUseNotNullableValue() { - check( - NotNullAnnotation::useNotNullableValue, - eq(1), - { value, r -> value == r } - ) - } - - @Test - @Disabled("Annotations for local variables are not supported yet") - fun testNotNullableVariable() { - check( - NotNullAnnotation::notNullableVariable, - eq(1), - { first, second, third, r -> first + second + third == r } - ) - } - - @Test - fun testNotNullField() { - check( - NotNullAnnotation::notNullField, - eq(1), - { value, result -> value.boxedInt == result } - ) - } - - @Test - fun testNotNullStaticField() { - checkStatics( - NotNullAnnotation::notNullStaticField, - eq(1), - { statics, result -> result == statics.values.single().value } - ) - } - - @Test - fun testJavaxValidationNotNull() { - check( - NotNullAnnotation::javaxValidationNotNull, - eq(1), - { value, r -> value == r } - ) - } - - @Test - fun testFindBugsNotNull() { - check( - NotNullAnnotation::findBugsNotNull, - eq(1), - { value, r -> value == r } - ) - } - - @Test - fun testJavaxNotNull() { - check( - NotNullAnnotation::javaxNotNull, - eq(1), - { value, r -> value == r } - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithAnnotationsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithAnnotationsTest.kt deleted file mode 100644 index b4c8097e10..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithAnnotationsTest.kt +++ /dev/null @@ -1,25 +0,0 @@ -package org.utbot.examples.annotations.lombok - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.DoNotCalculate -import org.utbot.testing.UtValueTestCaseChecker - -/** - * Tests for Lombok annotations - * - * We do not calculate coverage here as Lombok always make it pure - * (see, i.e. https://stackoverflow.com/questions/44584487/improve-lombok-data-code-coverage) - * and Lombok code is considered to be already tested itself. - */ -internal class EnumWithAnnotationsTest : UtValueTestCaseChecker(testClass = EnumWithAnnotations::class) { - @Test - fun testGetterWithAnnotations() { - check( - EnumWithAnnotations::getConstant, - eq(1), - { r -> r == "Constant_1" }, - coverage = DoNotCalculate, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithoutAnnotationsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithoutAnnotationsTest.kt deleted file mode 100644 index c9977326d6..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/EnumWithoutAnnotationsTest.kt +++ /dev/null @@ -1,16 +0,0 @@ -package org.utbot.examples.annotations.lombok - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker - -internal class EnumWithoutAnnotationsTest : UtValueTestCaseChecker(testClass = EnumWithoutAnnotations::class) { - @Test - fun testGetterWithoutAnnotations() { - check( - EnumWithoutAnnotations::getConstant, - eq(1), - { r -> r == "Constant_1" }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/NotNullAnnotationsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/NotNullAnnotationsTest.kt deleted file mode 100644 index 1d3e95b33c..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/annotations/lombok/NotNullAnnotationsTest.kt +++ /dev/null @@ -1,25 +0,0 @@ -package org.utbot.examples.annotations.lombok - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.DoNotCalculate -import org.utbot.testing.UtValueTestCaseChecker - -/** - * Tests for Lombok NonNull annotation - * - * We do not calculate coverage here as Lombok always make it pure - * (see, i.e. https://stackoverflow.com/questions/44584487/improve-lombok-data-code-coverage) - * and Lombok code is considered to be already tested itself. - */ -internal class NotNullAnnotationsTest : UtValueTestCaseChecker(testClass = NotNullAnnotations::class) { - @Test - fun testNonNullAnnotations() { - check( - NotNullAnnotations::lombokNonNull, - eq(1), - { value, r -> value == r }, - coverage = DoNotCalculate, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayOfArraysTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayOfArraysTest.kt deleted file mode 100644 index 4aa433b0b7..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayOfArraysTest.kt +++ /dev/null @@ -1,283 +0,0 @@ -package org.utbot.examples.arrays - -import org.junit.jupiter.api.Disabled -import org.utbot.examples.casts.ColoredPoint -import org.utbot.examples.casts.Point -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testcheckers.withoutMinimization -import org.utbot.testing.DoNotCalculate -import org.utbot.testing.UtValueTestCaseChecker -import org.utbot.testing.atLeast -import org.utbot.testing.ignoreExecutionsNumber - -@Suppress("NestedLambdaShadowedImplicitParameter") -internal class ArrayOfArraysTest : UtValueTestCaseChecker(testClass = ArrayOfArrays::class) { - @Test - fun testDefaultValues() { - check( - ArrayOfArrays::defaultValues, - eq(1), - { r -> r != null && r.single() == null }, - coverage = atLeast(50) - ) - } - - @Test - fun testExample() { - check( - ArrayOfArrays::sizesWithoutTouchingTheElements, - eq(1), - { r -> r != null && r.size == 10 && r.all { it.size == 3 && it.all { it == 0 } } }, - ) - } - - @Test - fun testDefaultValuesWithoutLastDimension() { - check( - ArrayOfArrays::defaultValuesWithoutLastDimension, - eq(1), - { r -> r != null && r.all { it.size == 4 && it.all { it.size == 4 && it.all { it == null } } } }, - coverage = atLeast(50) - ) - } - - @Test - fun testCreateNewMultiDimensionalArray() { - withoutMinimization { // TODO: JIRA:1506 - check( - ArrayOfArrays::createNewMultiDimensionalArray, - eq(4), - { i, j, _ -> i < 0 || j < 0 }, - { i, j, r -> i == 0 && j >= 0 && r != null && r.size == 2 && r.all { it.isEmpty() } }, - { i, j, r -> - val indicesConstraint = i > 0 && j == 0 - val arrayPropertiesConstraint = r != null && r.size == 2 - val arrayContentConstraint = r?.all { it.size == i && it.all { it.isEmpty() } } ?: false - - indicesConstraint && arrayPropertiesConstraint && arrayContentConstraint - }, - { i, j, r -> - val indicesConstraint = i > 0 && j > 0 - val arrayPropertiesConstraint = r != null && r.size == 2 - val arrayContentConstraint = - r?.all { - it.size == i && it.all { - it.size == j && it.all { - it.size == 3 && it.all { it == 0 } - } - } - } - - indicesConstraint && arrayPropertiesConstraint && (arrayContentConstraint ?: false) - } - ) - } - } - - @Test - fun testDefaultValuesWithoutTwoDimensions() { - check( - ArrayOfArrays::defaultValuesWithoutTwoDimensions, - eq(2), - { i, r -> i < 2 && r == null }, - { i, r -> i >= 2 && r != null && r.all { it.size == i && it.all { it == null } } }, - coverage = atLeast(75) - ) - } - - @Test - fun testDefaultValuesNewMultiArray() { - check( - ArrayOfArrays::defaultValuesNewMultiArray, - eq(1), - { r -> r != null && r.single().single().single() == 0 }, - coverage = atLeast(50) - ) - } - - @Test - fun testSimpleExample() { - check( - ArrayOfArrays::simpleExample, - eq(7), - { m, r -> m.size >= 3 && m[1] === m[2] && r == null }, - { m, r -> m.size >= 3 && m[1] !== m[2] && m[0] === m[2] && r == null }, - { m, _ -> m.size >= 3 && m[1].size < 2 }, - { m, _ -> m.size >= 3 && m[1][1] == 1 && m[2].size < 3 }, - { m, r -> m.size >= 3 && m[1][1] == 1 && m[2].size >= 3 && r != null && r[2][2] == 2 }, - { m, _ -> m.size >= 3 && m[1][1] != 1 && m[2].size < 3 }, - { m, r -> m.size >= 3 && m[1][1] != 1 && m[2].size >= 3 && r != null && r[2][2] == -2 }, - coverage = DoNotCalculate // because of assumes - ) - } - - @Test - fun testSimpleExampleMutation() { - checkParamsMutations( - ArrayOfArrays::simpleExample, - eq(7), - { matrixBefore, matrixAfter -> matrixBefore[1][1] == 1 && matrixAfter[2][2] == 2 }, - { matrixBefore, matrixAfter -> matrixBefore[1][1] != 1 && matrixAfter[2][2] == -2 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testIsIdentityMatrix() { - withoutMinimization { - check( - ArrayOfArrays::isIdentityMatrix, - eq(9), - { m, _ -> m == null }, - { m, _ -> m.size < 3 }, - { m, _ -> m.size >= 3 && m.any { it == null } }, - { m, r -> m.size >= 3 && m.any { it.size != m.size } && r == false }, - { m, r -> m.size >= 3 && m.size == m[0].size && m[0][0] != 1 && r == false }, - { m, r -> m.size >= 3 && m.size == m[0].size && m[0][0] == 1 && m[0][1] != 0 && r == false }, - { m, r -> m.size >= 3 && m.size == m[0].size && m[0][0] == 1 && m[0][1] == 0 && m[0][2] != 0 && r == false }, - { m, r -> - val sizeConstraints = m.size >= 3 && m.size == m[0].size - val valueConstraint = m[0][0] == 1 && m[0].drop(1).all { it == 0 } - val resultCondition = (m[1] == null && r == null) || (m[1]?.size != m.size && r == false) - - sizeConstraints && valueConstraint && resultCondition - }, - { m, r -> - val sizeConstraint = m.size >= 3 && m.size == m.first().size - val contentConstraint = - m.indices.all { i -> - m.indices.all { j -> - (i == j && m[i][j] == 1) || (i != j && m[i][j] == 0) - } - } - - sizeConstraint && contentConstraint && r == true - }, - ) - } - } - - @Test - fun testCreateNewThreeDimensionalArray() { - check( - ArrayOfArrays::createNewThreeDimensionalArray, - eq(2), - { length, _, r -> length != 2 && r != null && r.isEmpty() }, - { length, constValue, r -> - val sizeConstraint = length == 2 && r != null && r.size == length - val contentConstraint = - r!!.all { - it.size == length && it.all { - it.size == length && it.all { it == constValue + 1 } - } - } - - sizeConstraint && contentConstraint - } - ) - } - - @Test - fun testReallyMultiDimensionalArray() { - check( - ArrayOfArrays::reallyMultiDimensionalArray, - eq(8), - { a, _ -> a == null }, - { a, _ -> a.size < 2 }, - { a, _ -> a.size >= 2 && a[1] == null }, - { a, _ -> a.size >= 2 && a[1].size < 3 }, - { a, _ -> a.size >= 2 && a[1].size >= 3 && a[1][2] == null }, - { a, _ -> a.size >= 2 && a[1].size >= 3 && a[1][2].size < 4 }, - { a, r -> - val sizeConstraint = a.size >= 2 && a[1].size >= 3 && a[1][2].size >= 4 - val valueConstraint = a[1][2][3] == 12345 && r != null && r[1][2][3] == -12345 - - sizeConstraint && valueConstraint - }, - { a, r -> - val sizeConstraint = a.size >= 2 && a[1].size >= 3 && a[1][2].size >= 4 - val valueConstraint = a[1][2][3] != 12345 && r != null && r[1][2][3] == 12345 - - sizeConstraint && valueConstraint - }, - ) - } - - @Test - fun testReallyMultiDimensionalArrayMutation() { - checkParamsMutations( - ArrayOfArrays::reallyMultiDimensionalArray, - ignoreExecutionsNumber, - { arrayBefore, arrayAfter -> arrayBefore[1][2][3] != 12345 && arrayAfter[1][2][3] == 12345 }, - { arrayBefore, arrayAfter -> arrayBefore[1][2][3] == 12345 && arrayAfter[1][2][3] == -12345 }, - ) - } - - @Test - fun testMultiDimensionalObjectsArray() { - check( - ArrayOfArrays::multiDimensionalObjectsArray, - eq(4), - { a, _ -> a == null }, - { a, _ -> a.isEmpty() }, - { a, _ -> a.size == 1 }, - { a, r -> - require(r != null && r[0] != null && r[1] != null) - - val propertiesConstraint = a.size > 1 - val zeroElementConstraints = r[0] is Array<*> && r[0].isArrayOf() && r[0].size == 2 - val firstElementConstraints = r[1] is Array<*> && r[1].isArrayOf() && r[1].size == 1 - - propertiesConstraint && zeroElementConstraints && firstElementConstraints - }, - ) - } - - @Test - fun testMultiDimensionalObjectsArrayMutation() { - checkParamsMutations( - ArrayOfArrays::multiDimensionalObjectsArray, - ignoreExecutionsNumber, - { _, arrayAfter -> - arrayAfter[0] is Array<*> && arrayAfter[0].isArrayOf() && arrayAfter[0].size == 2 - }, - { _, arrayAfter -> - arrayAfter[1] is Array<*> && arrayAfter[1].isArrayOf() && arrayAfter[1].size == 1 - }, - ) - } - - @Test - fun testFillMultiArrayWithArray() { - check( - ArrayOfArrays::fillMultiArrayWithArray, - eq(3), - { v, _ -> v == null }, - { v, r -> v.size < 2 && r != null && r.isEmpty() }, - { v, r -> v.size >= 2 && r != null && r.all { a -> a.toList() == v.mapIndexed { i, elem -> elem + i } } } - ) - } - - @Test - fun testFillMultiArrayWithArrayMutation() { - checkParamsMutations( - ArrayOfArrays::fillMultiArrayWithArray, - ignoreExecutionsNumber, - { valueBefore, valueAfter -> valueAfter.withIndex().all { it.value == valueBefore[it.index] + it.index } } - ) - } - - @Test - @Disabled("https://github.com/UnitTestBot/UTBotJava/issues/1267") - fun testArrayWithItselfAnAsElement() { - check( - ArrayOfArrays::arrayWithItselfAnAsElement, - eq(2), - { a, r -> a !== a[0] && r == null }, - { a, r -> a === a[0] && a.contentDeepEquals(r) }, - coverage = atLeast(percents = 94) - // because of the assumption - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt deleted file mode 100644 index f26c944212..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt +++ /dev/null @@ -1,111 +0,0 @@ -package org.utbot.examples.arrays - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testcheckers.ge - -// TODO failed Kotlin compilation SAT-1332 -internal class ArrayOfObjectsTest : UtValueTestCaseChecker( - testClass = ArrayOfObjects::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testDefaultValues() { - check( - ArrayOfObjects::defaultValues, - eq(1), - { r -> r != null && r.single() == null }, - coverage = atLeast(50) - ) - } - - @Test - fun testCreateArray() { - check( - ArrayOfObjects::createArray, - eq(2), - { _, _, length, _ -> length < 3 }, - { x, y, length, r -> - require(r != null) - - val sizeConstraint = length >= 3 && r.size == length - val contentConstraint = r.mapIndexed { i, elem -> elem.x == x + i && elem.y == y + i }.all { it } - - sizeConstraint && contentConstraint - } - ) - } - - @Test - fun testCopyArray() { - checkWithException( - ArrayOfObjects::copyArray, - ge(4), - { a, r -> a == null && r.isException() }, - { a, r -> a.size < 3 && r.isException() }, - { a, r -> a.size >= 3 && null in a && r.isException() }, - { a, r -> a.size >= 3 && r.getOrThrow().all { it.x == -1 && it.y == 1 } }, - ) - } - - @Test - fun testCopyArrayMutation() { - checkParamsMutations( - ArrayOfObjects::copyArray, - ignoreExecutionsNumber, - { _, arrayAfter -> arrayAfter.all { it.x == -1 && it.y == 1 } } - ) - } - - @Test - fun testArrayWithSucc() { - check( - ArrayOfObjects::arrayWithSucc, - eq(3), - { length, _ -> length < 0 }, - { length, r -> length < 2 && r != null && r.size == length && r.all { it == null } }, - { length, r -> - require(r != null) - - val sizeConstraint = length >= 2 && r.size == length - val zeroElementConstraint = r[0] is ObjectWithPrimitivesClass && r[0].x == 2 && r[0].y == 4 - val firstElementConstraint = r[1] is ObjectWithPrimitivesClassSucc && r[1].x == 3 - - sizeConstraint && zeroElementConstraint && firstElementConstraint - }, - ) - } - - @Test - fun testObjectArray() { - check( - ArrayOfObjects::objectArray, - eq(5), - { a, _, _ -> a == null }, - { a, _, r -> a != null && a.size != 2 && r == -1 }, - { a, o, _ -> a != null && a.size == 2 && o == null }, - { a, p, r -> a != null && a.size == 2 && p != null && p.x + 5 > 20 && r == 1 }, - { a, o, r -> a != null && a.size == 2 && o != null && o.x + 5 <= 20 && r == 0 }, - ) - } - - @Test - fun testArrayOfArrays() { - withEnabledTestingCodeGeneration(testCodeGeneration = false) { - check( - ArrayOfObjects::arrayOfArrays, - between(4..5), // might be two ClassCastExceptions - { a, _ -> a.any { it == null } }, - { a, _ -> a.any { it != null && it !is IntArray } }, - { a, r -> (a.all { it != null && it is IntArray && it.isEmpty() } || a.isEmpty()) && r == 0 }, - { a, r -> a.all { it is IntArray } && r == a.sumBy { (it as IntArray).sum() } }, - coverage = DoNotCalculate - ) - } - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayStoreExceptionExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayStoreExceptionExamplesTest.kt deleted file mode 100644 index dfd48eafad..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArrayStoreExceptionExamplesTest.kt +++ /dev/null @@ -1,210 +0,0 @@ -package org.utbot.examples.arrays - -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq - -class ArrayStoreExceptionExamplesTest : UtValueTestCaseChecker( - testClass = ArrayStoreExceptionExamples::class, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - // Type inference errors in generated Kotlin code - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testCorrectAssignmentSamePrimitiveType() { - checkWithException( - ArrayStoreExceptionExamples::correctAssignmentSamePrimitiveType, - eq(3), - { data, result -> result.isSuccess && result.getOrNull() == data?.isNotEmpty() } - ) - } - - @Test - fun testCorrectAssignmentIntToIntegerArray() { - checkWithException( - ArrayStoreExceptionExamples::correctAssignmentIntToIntegerArray, - eq(3), - { data, result -> result.isSuccess && result.getOrNull() == data?.isNotEmpty() } - ) - } - - @Test - fun testCorrectAssignmentSubtype() { - checkWithException( - ArrayStoreExceptionExamples::correctAssignmentSubtype, - eq(3), - { data, result -> result.isSuccess && result.getOrNull() == data?.isNotEmpty() } - ) - } - - @Test - fun testCorrectAssignmentToObjectArray() { - checkWithException( - ArrayStoreExceptionExamples::correctAssignmentToObjectArray, - eq(3), - { data, result -> result.isSuccess && result.getOrNull() == data?.isNotEmpty() } - ) - } - - @Test - fun testWrongAssignmentUnrelatedType() { - checkWithException( - ArrayStoreExceptionExamples::wrongAssignmentUnrelatedType, - eq(3), - { data, result -> data == null && result.isSuccess }, - { data, result -> data.isEmpty() && result.isSuccess }, - { data, result -> data.isNotEmpty() && result.isException() }, - coverage = AtLeast(91) // TODO: investigate - ) - } - - @Test - fun testCheckGenericAssignmentWithCorrectCast() { - checkWithException( - ArrayStoreExceptionExamples::checkGenericAssignmentWithCorrectCast, - eq(1), - { result -> result.isSuccess } - ) - } - - @Test - fun testCheckGenericAssignmentWithWrongCast() { - checkWithException( - ArrayStoreExceptionExamples::checkGenericAssignmentWithWrongCast, - eq(1), - { result -> result.isException() }, - coverage = AtLeast(87) // TODO: investigate - ) - } - - @Test - fun testCheckGenericAssignmentWithExtendsSubtype() { - checkWithException( - ArrayStoreExceptionExamples::checkGenericAssignmentWithExtendsSubtype, - eq(1), - { result -> result.isSuccess } - ) - } - - @Test - fun testCheckGenericAssignmentWithExtendsUnrelated() { - checkWithException( - ArrayStoreExceptionExamples::checkGenericAssignmentWithExtendsUnrelated, - eq(1), - { result -> result.isException() }, - coverage = AtLeast(87) // TODO: investigate - ) - } - - @Test - fun testCheckObjectAssignment() { - checkWithException( - ArrayStoreExceptionExamples::checkObjectAssignment, - eq(1), - { result -> result.isSuccess } - ) - } - - // Should this be allowed at all? - @Test - fun testCheckWrongAssignmentOfItself() { - checkWithException( - ArrayStoreExceptionExamples::checkWrongAssignmentOfItself, - eq(1), - { result -> result.isException() }, - coverage = AtLeast(87) - ) - } - - @Test - fun testCheckGoodAssignmentOfItself() { - checkWithException( - ArrayStoreExceptionExamples::checkGoodAssignmentOfItself, - eq(1), - { result -> result.isSuccess } - ) - } - - @Test - fun testCheckAssignmentToObjectArray() { - checkWithException( - ArrayStoreExceptionExamples::checkAssignmentToObjectArray, - eq(1), - { result -> result.isSuccess } - ) - } - - @Test - fun testArrayCopyForIncompatiblePrimitiveTypes() { - checkWithException( - ArrayStoreExceptionExamples::arrayCopyForIncompatiblePrimitiveTypes, - eq(3), - { data, result -> data == null && result.isSuccess && result.getOrNull() == null }, - { data, result -> data != null && data.isEmpty() && result.isSuccess && result.getOrNull()?.size == 0 }, - { data, result -> data != null && data.isNotEmpty() && result.isException() } - ) - } - - @Test - fun testFill2DPrimitiveArray() { - checkWithException( - ArrayStoreExceptionExamples::fill2DPrimitiveArray, - eq(1), - { result -> result.isSuccess } - ) - } - - @Test - fun testFillObjectArrayWithList() { - check( - ArrayStoreExceptionExamples::fillObjectArrayWithList, - eq(2), - { list, result -> list != null && result != null && result[0] != null }, - { list, result -> list == null && result == null } - ) - } - - @Test - fun testFillWithTreeSet() { - check( - ArrayStoreExceptionExamples::fillWithTreeSet, - eq(2), - { treeSet, result -> treeSet != null && result != null && result[0] != null }, - { treeSet, result -> treeSet == null && result == null } - ) - } - - @Test - fun testFillSomeInterfaceArrayWithSomeInterface() { - check( - ArrayStoreExceptionExamples::fillSomeInterfaceArrayWithSomeInterface, - eq(2), - { impl, result -> impl == null && result == null }, - { impl, result -> impl != null && result != null && result[0] != null } - ) - } - - @Test - @Disabled("TODO: Not null path is not found, need to investigate") - fun testFillObjectArrayWithSomeInterface() { - check( - ArrayStoreExceptionExamples::fillObjectArrayWithSomeInterface, - eq(2), - { impl, result -> impl == null && result == null }, - { impl, result -> impl != null && result != null && result[0] != null } - ) - } - - @Test - fun testFillWithSomeImplementation() { - check( - ArrayStoreExceptionExamples::fillWithSomeImplementation, - eq(2), - { impl, result -> impl == null && result == null }, - { impl, result -> impl != null && result != null && result[0] != null } - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArraysOverwriteValueTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArraysOverwriteValueTest.kt deleted file mode 100644 index 6f6f5f3b23..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/ArraysOverwriteValueTest.kt +++ /dev/null @@ -1,153 +0,0 @@ -package org.utbot.examples.arrays - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.CodeGeneration -import org.utbot.testing.UtValueTestCaseChecker - -// TODO failed Kotlin compilation SAT-1332 -class ArraysOverwriteValueTest : UtValueTestCaseChecker( - testClass = ArraysOverwriteValue::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testByteArray() { - checkParamsMutationsAndResult( - ArraysOverwriteValue::byteArray, - eq(4), - { before, _, _ -> before == null }, - { before, _, r -> before != null && before.isEmpty() && r == 1.toByte() }, - { before, _, r -> before != null && before.isNotEmpty() && before[0] != 0.toByte() && r == 2.toByte() }, - { before, after, r -> - val precondition = before != null && before.isNotEmpty() && before[0] == 0.toByte() - val postcondition = after[0] == 1.toByte() && r == 3.toByte() - - precondition && postcondition - }, - ) - } - - @Test - fun testShortArray() { - checkParamsMutationsAndResult( - ArraysOverwriteValue::shortArray, - eq(4), - { before, _, _ -> before == null }, - { before, _, r -> before != null && before.isEmpty() && r == 1.toByte() }, - { before, _, r -> before != null && before.isNotEmpty() && before[0] != 0.toShort() && r == 2.toByte() }, - { before, after, r -> - val precondition = before != null && before.isNotEmpty() && before[0] == 0.toShort() - val postcondition = after[0] == 1.toShort() && r == 3.toByte() - - precondition && postcondition - }, - ) - } - - @Test - fun testCharArray() { - checkParamsMutationsAndResult( - ArraysOverwriteValue::charArray, - eq(4), - { before, _, _ -> before == null }, - { before, _, r -> before != null && before.isEmpty() && r == 1.toChar() }, - { before, _, r -> before != null && before.isNotEmpty() && before[0] != 0.toChar() && r == 2.toChar() }, - { before, after, r -> - val precondition = before != null && before.isNotEmpty() && before[0] == 0.toChar() - val postcondition = after[0] == 1.toChar() && r == 3.toChar() - - precondition && postcondition - }, - ) - } - - @Test - fun testIntArray() { - checkParamsMutationsAndResult( - ArraysOverwriteValue::intArray, - eq(4), - { before, _, _ -> before == null }, - { before, _, r -> before != null && before.isEmpty() && r == 1.toByte() }, - { before, _, r -> before != null && before.isNotEmpty() && before[0] != 0 && r == 2.toByte() }, - { before, after, r -> - before != null && before.isNotEmpty() && before[0] == 0 && after[0] == 1 && r == 3.toByte() - }, - ) - } - - @Test - fun testLongArray() { - checkParamsMutationsAndResult( - ArraysOverwriteValue::longArray, - eq(4), - { before, _, _ -> before == null }, - { before, _, r -> before != null && before.isEmpty() && r == 1.toLong() }, - { before, _, r -> before != null && before.isNotEmpty() && before[0] != 0.toLong() && r == 2.toLong() }, - { before, after, r -> - val precondition = before != null && before.isNotEmpty() && before[0] == 0.toLong() - val postcondition = after[0] == 1.toLong() && r == 3.toLong() - - precondition && postcondition - }, - ) - } - - @Test - fun testFloatArray() { - checkParamsMutationsAndResult( - ArraysOverwriteValue::floatArray, - eq(4), - { before, _, _ -> before == null }, - { before, _, r -> before != null && before.isEmpty() && r == 1.0f }, - { before, _, r -> before != null && before.isNotEmpty() && !before[0].isNaN() && r == 2.0f }, - { before, after, r -> - before != null && before.isNotEmpty() && before[0].isNaN() && after[0] == 1.0f && r == 3.0f - }, - ) - } - - @Test - fun testDoubleArray() { - checkParamsMutationsAndResult( - ArraysOverwriteValue::doubleArray, - eq(4), - { before, _, _ -> before == null }, - { before, _, r -> before != null && before.isEmpty() && r == 1.00 }, - { before, _, r -> before != null && before.isNotEmpty() && !before[0].isNaN() && r == 2.0 }, - { before, after, r -> - before != null && before.isNotEmpty() && before[0].isNaN() && after[0] == 1.toDouble() && r == 3.0 - }, - ) - } - - @Test - fun testBooleanArray() { - checkParamsMutationsAndResult( - ArraysOverwriteValue::booleanArray, - eq(4), - { before, _, _ -> before == null }, - { before, _, r -> before != null && before.isEmpty() && r == 1 }, - { before, _, r -> before != null && before.isNotEmpty() && before[0] && r == 2 }, - { before, after, r -> before != null && before.isNotEmpty() && !before[0] && after[0] && r == 3 }, - ) - } - - @Test - fun testObjectArray() { - checkParamsMutationsAndResult( - ArraysOverwriteValue::objectArray, - eq(4), - { before, _, _ -> before == null }, - { before, _, r -> before != null && before.isEmpty() && r == 1 }, - { before, _, r -> before != null && before.isNotEmpty() && before[0] == null && r == 2 }, - { before, after, r -> - before != null && before.isNotEmpty() && before[0] != null && after[0] == null && r == 3 - }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/FinalStaticFieldArrayTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/FinalStaticFieldArrayTest.kt deleted file mode 100644 index 55b0d37eed..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/FinalStaticFieldArrayTest.kt +++ /dev/null @@ -1,21 +0,0 @@ -package org.utbot.examples.arrays - -import org.junit.jupiter.api.Test -import org.utbot.testing.UtValueTestCaseChecker -import org.utbot.testing.ignoreExecutionsNumber - -internal class FinalStaticFieldArrayTest : UtValueTestCaseChecker(testClass = FinalStaticFieldArray::class) { - - @Test - fun testFactorial() { - checkStaticMethod( - FinalStaticFieldArray::factorial, - ignoreExecutionsNumber, - { n, r -> - (n as Int) >= 0 && n < FinalStaticFieldArray.MAX_FACTORIAL && r == FinalStaticFieldArray.factorial(n) - }, - { n, _ -> (n as Int) < 0 }, - { n, r -> (n as Int) > FinalStaticFieldArray.MAX_FACTORIAL && r == FinalStaticFieldArray.factorial(n) }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/IntArrayBasicsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/IntArrayBasicsTest.kt deleted file mode 100644 index aedb08e43a..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/IntArrayBasicsTest.kt +++ /dev/null @@ -1,228 +0,0 @@ -package org.utbot.examples.arrays - -import org.junit.jupiter.api.Disabled -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testcheckers.ge - -// TODO failed Kotlin compilation SAT-1332 -internal class IntArrayBasicsTest : UtValueTestCaseChecker( - testClass = IntArrayBasics::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testIntArrayWithAssumeOrExecuteConcretely() { - check( - IntArrayBasics::intArrayWithAssumeOrExecuteConcretely, - eq(4), - { x, n, r -> x > 0 && n < 20 && r?.size == 2 }, - { x, n, r -> x > 0 && n >= 20 && r?.size == 4 }, - { x, n, r -> x <= 0 && n < 20 && r?.size == 10 }, - { x, n, r -> x <= 0 && n >= 20 && r?.size == 20 }, - ) - } - - @Test - fun testInitArray() { - checkWithException( - IntArrayBasics::initAnArray, - eq(4), - { n, r -> n < 0 && r.isException() }, - { n, r -> n == 0 && r.isException() }, - { n, r -> n == 1 && r.isException() }, - { n, r -> - val resultArray = IntArray(n) { if (it == n - 1 || it == n - 2) it else 0 } - n > 1 && r.getOrNull() contentEquals resultArray - } - ) - } - - @Test - fun testIsValid() { - checkWithException( - IntArrayBasics::isValid, - ignoreExecutionsNumber, - { a, _, r -> a == null && r.isException() }, - { a, n, r -> a != null && (n < 0 || n >= a.size) && r.isException() }, - { a, n, r -> a != null && n in a.indices && a[n] == 9 && n == 5 && r.getOrNull() == true }, - { a, n, r -> a != null && n in a.indices && !(a[n] == 9 && n == 5) && r.getOrNull() == false }, - { a, n, r -> a != null && n in a.indices && a[n] > 9 && n == 5 && r.getOrNull() == true }, - { a, n, r -> a != null && n in a.indices && !(a[n] > 9 && n == 5) && r.getOrNull() == false }, - ) - } - - @Test - fun testGetValue() { - checkWithException( - IntArrayBasics::getValue, - ge(4), - { a, _, r -> a == null && r.isException() }, - { a, n, r -> a != null && a.size > 6 && (n < 0 || n >= a.size) && r.isException() }, - { a, n, r -> a != null && a.size > 6 && n < a.size && r.getOrNull() == a[n] }, - { a, _, r -> a != null && a.size <= 6 && r.getOrNull() == -1 } - ) - } - - @Test - fun testSetValue() { - checkWithException( - IntArrayBasics::setValue, - eq(5), - { _, x, r -> x <= 0 && r.getOrNull() == 0 }, - { a, x, r -> x > 0 && a == null && r.isException() }, - { a, x, r -> x > 0 && a != null && a.isEmpty() && r.getOrNull() == 0 }, - { a, x, r -> x in 1..2 && a != null && a.isNotEmpty() && r.getOrNull() == 1 }, - { a, x, r -> x > 2 && a != null && a.isNotEmpty() && r.getOrNull() == 2 } - ) - } - - @Test - fun testCheckFour() { - checkWithException( - IntArrayBasics::checkFour, - eq(7), - { a, r -> a == null && r.isException() }, - { a, r -> a != null && a.size < 4 && r.getOrNull() == -1 }, - { a, r -> a != null && a.size >= 4 && a[0] != 1 && r.getOrNull() == 0 }, - { a, r -> a != null && a.size >= 4 && a[0] == 1 && a[1] != 2 && r.getOrNull() == 0 }, - { a, r -> a != null && a.size >= 4 && a[0] == 1 && a[1] == 2 && a[2] != 3 && r.getOrNull() == 0 }, - { a, r -> a != null && a.size >= 4 && a[0] == 1 && a[1] == 2 && a[2] == 3 && a[3] != 4 && r.getOrNull() == 0 }, - { a, r -> - require(a != null) - - val precondition = a.size >= 4 && a[0] == 1 && a[1] == 2 && a[2] == 3 && a[3] == 4 - val postcondition = r.getOrNull() == IntArrayBasics().checkFour(a) - - precondition && postcondition - } - ) - } - - @Test - fun testNullability() { - check( - IntArrayBasics::nullability, - eq(3), - { a, r -> a == null && r == 1 }, - { a, r -> a != null && a.size > 1 && r == 2 }, - { a, r -> a != null && a.size in 0..1 && r == 3 }, - ) - } - - @Test - fun testEquality() { - check( - IntArrayBasics::equality, - eq(4), - { a, _, r -> a == null && r == 1 }, - { a, b, r -> a != null && b == null && r == 1 }, - { a, b, r -> a != null && b != null && a.size == b.size && r == 2 }, - { a, b, r -> a != null && b != null && a.size != b.size && r == 3 }, - ) - } - - @Test - fun testOverwrite() { - checkWithException( - IntArrayBasics::overwrite, - eq(5), - { a, _, r -> a == null && r.isException() }, - { a, _, r -> a != null && a.size != 1 && r.getOrNull() == 0 }, - { a, b, r -> a != null && a.size == 1 && a[0] > 0 && b < 0 && r.getOrNull() == 1 }, - { a, b, r -> a != null && a.size == 1 && a[0] > 0 && b >= 0 && r.getOrNull() == 2 }, - { a, _, r -> a != null && a.size == 1 && a[0] <= 0 && r.getOrNull() == 3 }, - ) - } - - @Test - fun testMergeArrays() { - check( - IntArrayBasics::mergeArrays, - ignoreExecutionsNumber, - { fst, _, _ -> fst == null }, - { fst, snd, _ -> fst != null && snd == null }, - { fst, snd, r -> fst != null && snd != null && fst.size < 2 && r == null }, - { fst, snd, r -> fst != null && snd != null && fst.size >= 2 && snd.size < 2 && r == null }, - { fst, snd, r -> - require(fst != null && snd != null && r != null) - - val sizeConstraint = fst.size >= 2 && snd.size >= 2 && r.size == fst.size + snd.size - val maxConstraint = fst.maxOrNull()!! < snd.maxOrNull()!! - val contentConstraint = r contentEquals (IntArrayBasics().mergeArrays(fst, snd)) - - sizeConstraint && maxConstraint && contentConstraint - }, - { fst, snd, r -> - require(fst != null && snd != null && r != null) - - val sizeConstraint = fst.size >= 2 && snd.size >= 2 && r.size == fst.size + snd.size - val maxConstraint = fst.maxOrNull()!! >= snd.maxOrNull()!! - val contentConstraint = r contentEquals (IntArrayBasics().mergeArrays(fst, snd)) - - sizeConstraint && maxConstraint && contentConstraint - } - ) - } - - @Test - fun testNewArrayInTheMiddle() { - check( - IntArrayBasics::newArrayInTheMiddle, - eq(5), - { a, _ -> a == null }, - { a, _ -> a != null && a.isEmpty() }, - { a, _ -> a != null && a.size < 2 }, - { a, _ -> a != null && a.size < 3 }, - { a, r -> a != null && a.size >= 3 && r != null && r[0] == 1 && r[1] == 2 && r[2] == 3 } - ) - } - - @Test - fun testNewArrayInTheMiddleMutation() { - checkParamsMutations( - IntArrayBasics::newArrayInTheMiddle, - ignoreExecutionsNumber, - { _, arrayAfter -> arrayAfter[0] == 1 && arrayAfter[1] == 2 && arrayAfter[2] == 3 } - ) - } - - @Test - fun testReversed() { - check( - IntArrayBasics::reversed, - eq(5), - { a, _ -> a == null }, - { a, _ -> a != null && a.size != 3 }, - { a, r -> a != null && a.size == 3 && a[0] <= a[1] && r == null }, - { a, r -> a != null && a.size == 3 && a[0] > a[1] && a[1] <= a[2] && r == null }, - { a, r -> a != null && a.size == 3 && a[0] > a[1] && a[1] > a[2] && r contentEquals a.reversedArray() }, - ) - } - - @Test - fun testUpdateCloned() { - check( - IntArrayBasics::updateCloned, - eq(3), - { a, _ -> a == null }, - { a, _ -> a.size != 3 }, - { a, r -> a.size == 3 && r != null && r.toList() == a.map { it * 2 } }, - ) - } - - @Test - @Disabled("Java 11 transition -- Sergei is looking into it") - fun testArraysEqualsExample() { - check( - IntArrayBasics::arrayEqualsExample, - eq(2), - { a, r -> a.size == 3 && a contentEquals intArrayOf(1, 2, 3) && r == 1 }, - { a, r -> !(a contentEquals intArrayOf(1, 2, 3)) && r == 2 } - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/PrimitiveArraysTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/PrimitiveArraysTest.kt deleted file mode 100644 index b1fc9d41db..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/arrays/PrimitiveArraysTest.kt +++ /dev/null @@ -1,186 +0,0 @@ -package org.utbot.examples.arrays - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.CodeGeneration -import org.utbot.testing.UtValueTestCaseChecker -import org.utbot.testing.atLeast -import org.utbot.testing.isException - -// TODO failed Kotlin compilation SAT-1332 -internal class PrimitiveArraysTest : UtValueTestCaseChecker( - testClass = PrimitiveArrays::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testDefaultIntValues() { - check( - PrimitiveArrays::defaultIntValues, - eq(1), - { r -> r != null && r.all { it == 0 } }, - coverage = atLeast(50) - ) - } - - @Test - fun testDefaultDoubleValues() { - check( - PrimitiveArrays::defaultDoubleValues, - eq(1), - { r -> r != null && r.all { it == 0.0 } }, - coverage = atLeast(50) - ) - } - - @Test - fun testDefaultBooleanValues() { - check( - PrimitiveArrays::defaultBooleanValues, - eq(1), - { r -> r != null && r.none { it } }, - coverage = atLeast(50) - ) - } - - @Test - fun testByteArray() { - checkWithException( - PrimitiveArrays::byteArray, - eq(4), - { a, _, r -> a == null && r.isException() }, - { a, _, r -> a != null && a.size != 2 && r.getOrNull() == (-1).toByte() }, - { a, x, r -> a != null && a.size == 2 && x + 5 <= 20 && r.getOrNull() == 0.toByte() }, - { a, x, r -> a != null && a.size == 2 && x + 5 > 20 && r.getOrNull() == 1.toByte() } - ) - } - - @Test - fun testShortArray() { - checkWithException( - PrimitiveArrays::shortArray, - eq(4), - { a, _, r -> a == null && r.isException() }, - { a, _, r -> a != null && a.size != 2 && r.getOrNull() == (-1).toByte() }, - { a, x, r -> a != null && a.size == 2 && x + 5 <= 20 && r.getOrNull() == 0.toByte() }, - { a, x, r -> a != null && a.size == 2 && x + 5 > 20 && r.getOrNull() == 1.toByte() } - ) - } - - @Test - fun testCharArray() { - checkWithException( - PrimitiveArrays::charArray, - eq(4), - { a, _, r -> a == null && r.isException() }, - { a, _, r -> a != null && a.size != 2 && r.getOrNull() == (-1).toByte() }, - { a, x, r -> a != null && a.size == 2 && x + 5 <= 20.toChar() && r.getOrNull() == 0.toByte() }, - { a, x, r -> a != null && a.size == 2 && x + 5 > 20.toChar() && r.getOrNull() == 1.toByte() } - ) - } - - @Test - fun testIntArray() { - checkWithException( - PrimitiveArrays::intArray, - eq(4), - { a, _, r -> a == null && r.isException() }, - { a, _, r -> a != null && a.size != 2 && r.getOrNull() == (-1).toByte() }, - { a, x, r -> a != null && a.size == 2 && x + 5 <= 20 && r.getOrNull() == 0.toByte() }, - { a, x, r -> a != null && a.size == 2 && x + 5 > 20 && r.getOrNull() == 1.toByte() } - ) - } - - @Test - fun testLongArray() { - checkWithException( - PrimitiveArrays::longArray, - eq(4), - { a, _, r -> a == null && r.isException() }, - { a, _, r -> a != null && a.size != 2 && r.getOrNull() == (-1).toLong() }, - { a, x, r -> a != null && a.size == 2 && x + 5 <= 20 && r.getOrNull() == 0.toLong() }, - { a, x, r -> a != null && a.size == 2 && x + 5 > 20 && r.getOrNull() == 1.toLong() } - ) - } - - @Suppress("SimplifyNegatedBinaryExpression") - @Test - fun testFloatArray() { - checkWithException( - PrimitiveArrays::floatArray, - eq(4), - { a, _, r -> a == null && r.isException() }, - { a, _, r -> a != null && a.size != 2 && r.getOrNull() == (-1).toFloat() }, - { a, x, r -> a != null && a.size == 2 && !(x + 5 > 20) && r.getOrNull() == 0.toFloat() }, - { a, x, r -> a != null && a.size == 2 && x + 5 > 20 && r.getOrNull() == 1.toFloat() } - ) - } - - @Suppress("SimplifyNegatedBinaryExpression") - @Test - fun testDoubleArray() { - checkWithException( - PrimitiveArrays::doubleArray, - eq(4), - { a, _, r -> a == null && r.isException() }, - { a, _, r -> a != null && a.size != 2 && r.getOrNull() == (-1).toDouble() }, - { a, x, r -> a != null && a.size == 2 && !(x + 5 > 20) && r.getOrNull() == 0.toDouble() }, - { a, x, r -> a != null && a.size == 2 && x + 5 > 20 && r.getOrNull() == 1.toDouble() } - ) - } - - @Test - fun testBooleanArray() { - checkWithException( - PrimitiveArrays::booleanArray, - eq(4), - { a, _, _, r -> a == null && r.isException() }, - { a, _, _, r -> a != null && a.size != 2 && r.getOrNull() == -1 }, - { a, x, y, r -> a != null && a.size == 2 && !(x xor y) && r.getOrNull() == 0 }, - { a, x, y, r -> a != null && a.size == 2 && (x xor y) && r.getOrNull() == 1 } - ) - } - - @Test - fun testByteSizeAndIndex() { - check( - PrimitiveArrays::byteSizeAndIndex, - eq(5), - { a, _, r -> a == null && r == (-1).toByte() }, - { a, x, r -> a != null && a.size <= x.toInt() && r == (-1).toByte() }, - { a, x, r -> a != null && a.size > x.toInt() && x.toInt() < 1 && r == (-1).toByte() }, - { a, x, r -> a != null && a.size > x.toInt() && x.toInt() > 0 && x + 5 <= 7 && r == 0.toByte() }, - { a, x, r -> a != null && a.size > x.toInt() && x.toInt() > 0 && x + 5 > 7 && r == 1.toByte() } - ) - } - - @Test - fun testShortSizeAndIndex() { - check( - PrimitiveArrays::shortSizeAndIndex, - eq(5), - { a, _, r -> a == null && r == (-1).toByte() }, - { a, x, r -> a != null && a.size <= x.toInt() && r == (-1).toByte() }, - { a, x, r -> a != null && a.size > x.toInt() && x.toInt() < 1 && r == (-1).toByte() }, - { a, x, r -> a != null && a.size > x.toInt() && x.toInt() > 0 && x + 5 <= 7 && r == 0.toByte() }, - { a, x, r -> a != null && a.size > x.toInt() && x.toInt() > 0 && x + 5 > 7 && r == 1.toByte() } - ) - } - - @Test - fun testCharSizeAndIndex() { - check( - PrimitiveArrays::charSizeAndIndex, - eq(5), - { a, _, r -> a == null && r == (-1).toByte() }, - { a, x, r -> a != null && a.size <= x.toInt() && r == (-1).toByte() }, - { a, x, r -> a != null && a.size > x.toInt() && x.toInt() < 1 && r == (-1).toByte() }, - { a, x, r -> a != null && a.size > x.toInt() && x.toInt() > 0 && x + 5 <= 7.toChar() && r == 0.toByte() }, - { a, x, r -> a != null && a.size > x.toInt() && x.toInt() > 0 && x + 5 > 7.toChar() && r == 1.toByte() } - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/casts/ArrayCastExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/casts/ArrayCastExampleTest.kt deleted file mode 100644 index 51c4c3123f..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/casts/ArrayCastExampleTest.kt +++ /dev/null @@ -1,172 +0,0 @@ -package org.utbot.examples.casts - -import org.junit.jupiter.api.Disabled -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -// TODO failed Kotlin compilation (generics) SAT-1332 -//TODO: SAT-1487 calculate coverage for all methods of this test class -internal class ArrayCastExampleTest : UtValueTestCaseChecker( - testClass = ArrayCastExample::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testCastToAncestor() { - check( - ArrayCastExample::castToAncestor, - eq(2), - { a, r -> a == null && r != null && r is Array }, - { a, r -> a != null && r != null && r.isArrayOf() } - ) - } - - @Test - fun testClassCastException() { - check( - ArrayCastExample::classCastException, - eq(3), - { a, r -> a == null && r != null && r.isEmpty() }, - { a, _ -> !a.isArrayOf() }, - { a, r -> a.isArrayOf() && r != null && r.isArrayOf() }, - ) - } - - @Test - fun testNullCast() { - check( - ArrayCastExample::nullCast, - eq(2), - { a, r -> a != null && r == null }, - { a, r -> a == null && r == null } - ) - } - - @Test - fun testNullArray() { - check( - ArrayCastExample::nullArray, - eq(1), - { r -> r == null } - ) - } - - @Test - fun testSuccessfulExampleFromJLS() { - check( - ArrayCastExample::successfulExampleFromJLS, - eq(1), - { r -> - require(r != null) - - val sizeConstraint = r.size == 4 - val typeConstraint = r[0] is ColoredPoint && r[1] is ColoredPoint - val zeroElementConstraint = r[0].x == 2 && r[0].y == 2 && r[0].color == 12 - val firstElementConstraint = r[1].x == 4 && r[1].y == 5 && r[1].color == 24 - - sizeConstraint && typeConstraint && zeroElementConstraint && firstElementConstraint - } - ) - } - - @Test - fun testCastAfterStore() { - check( - ArrayCastExample::castAfterStore, - eq(5), - { a, _ -> a == null }, - { a, _ -> a.isEmpty() }, - { a, _ -> a.isNotEmpty() && !a.isArrayOf() }, - { a, _ -> a.isArrayOf() && a.size == 1 }, - { a, r -> - require(r != null) - - val sizeConstraint = a.size >= 2 - val typeConstraint = a.isArrayOf() && r.isArrayOf() - val zeroElementConstraint = r[0].color == 12 && r[0].x == 1 && r[0].y == 2 - val firstElementConstraint = r[1].color == 14 && r[1].x == 2 && r[1].y == 3 - - sizeConstraint && typeConstraint && zeroElementConstraint && firstElementConstraint - } - ) - } - - @Test - fun testCastFromObject() { - check( - ArrayCastExample::castFromObject, - eq(3), - { a, _ -> a !is Array<*> || !a.isArrayOf() }, - { a, r -> a == null && r != null && r.isArrayOf() && r.isEmpty() }, - { a, r -> a is Array<*> && a.isArrayOf() && r != null && r.isArrayOf() }, - ) - } - - @Test - fun testCastFromObjectToPrimitivesArray() { - check( - ArrayCastExample::castFromObjectToPrimitivesArray, - eq(2), - { array, r -> array is IntArray && array.size > 0 && r is IntArray && array contentEquals r }, - { array, r -> array != null && array !is IntArray && r !is IntArray }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCastsChainFromObject() { - check( - ArrayCastExample::castsChainFromObject, - eq(8), - { a, r -> a == null && r == null }, - { a, _ -> a !is Array<*> || !a.isArrayOf() }, - { a, r -> a is Array<*> && a.isArrayOf() && a.isEmpty() && r == null }, - { a, _ -> a is Array<*> && a.isArrayOf() && a.isNotEmpty() && a[0] == null }, - { a, _ -> a is Array<*> && a.isArrayOf() && !a.isArrayOf() && (a[0] as Point).x == 1 }, - { a, _ -> a is Array<*> && a.isArrayOf() && !a.isArrayOf() && (a[0] as Point).x != 1 }, - { a, r -> a is Array<*> && a.isArrayOf() && (a[0] as Point).x == 1 && r != null && r[0].x == 10 }, - { a, r -> a is Array<*> && a.isArrayOf() && (a[0] as Point).x != 1 && r != null && r[0].x == 5 }, - ) - } - - @Test - fun testCastFromCollections() { - check( - ArrayCastExample::castFromCollections, - eq(3), - { c, r -> c == null && r == null }, - { c, r -> c != null && c is List<*> && r is List<*> }, - { c, _ -> c is Collection<*> && c !is List<*> }, - coverage = DoNotCalculate, - ) - } - - @Test - fun testCastFromIterable() { - check( - ArrayCastExample::castFromIterable, - eq(3), - { i, r -> i == null && r == null }, - { i, r -> i is List<*> && r is List<*> }, - { i, _ -> i is Iterable<*> && i !is List<*> }, - coverage = DoNotCalculate, - ) - } - - @Test - @Disabled("Fix Traverser.findInvocationTargets to exclude non-exported classes / provide good classes") - fun testCastFromIterableToCollection() { - check( - ArrayCastExample::castFromIterableToCollection, - eq(3), - { i, r -> i == null && r == null }, - { i, r -> i is Collection<*> && r is Collection<*> }, - { i, _ -> i is Iterable<*> && i !is Collection<*> }, - coverage = DoNotCalculate, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/casts/CastClassTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/casts/CastClassTest.kt deleted file mode 100644 index 220e11cc33..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/casts/CastClassTest.kt +++ /dev/null @@ -1,26 +0,0 @@ -package org.utbot.examples.casts - -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq -import org.utbot.testing.CodeGeneration -import org.utbot.testing.DoNotCalculate -import org.utbot.testing.UtValueTestCaseChecker - -internal class CastClassTest : UtValueTestCaseChecker( - testClass = CastClass::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testThisTypeChoice() { - check( - CastClass::castToInheritor, - eq(0), - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/casts/CastExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/casts/CastExampleTest.kt deleted file mode 100644 index 77747a3035..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/casts/CastExampleTest.kt +++ /dev/null @@ -1,89 +0,0 @@ -package org.utbot.examples.casts - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -// TODO failed Kotlin compilation SAT-1332 -internal class CastExampleTest : UtValueTestCaseChecker( - testClass = CastExample::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testSimpleCast() { - check( - CastExample::simpleCast, - eq(3), - { o, _ -> o != null && o !is CastClassFirstSucc }, - { o, r -> o != null && r is CastClassFirstSucc }, - { o, r -> o == null && r == null }, - ) - } - - @Test - fun testClassCastException() { - checkWithException( - CastExample::castClassException, - eq(3), - { o, r -> o == null && r.isException() }, - { o, r -> o != null && o !is CastClassFirstSucc && r.isException() }, - { o, r -> o != null && o is CastClassFirstSucc && r.isException() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCastUp() { - check( - CastExample::castUp, - eq(1) - ) - } - - @Test - fun testCastNullToDifferentTypes() { - check( - CastExample::castNullToDifferentTypes, - eq(1) - ) - } - - @Test - fun testFromObjectToPrimitive() { - check( - CastExample::fromObjectToPrimitive, - eq(3), - { obj, _ -> obj == null }, - { obj, _ -> obj != null && obj !is Int }, - { obj, r -> obj != null && obj is Int && r == obj } - ) - } - - @Test - fun testCastFromObjectToInterface() { - check( - CastExample::castFromObjectToInterface, - eq(2), - { obj, _ -> obj != null && obj !is Colorable }, - { obj, r -> obj != null && obj is Colorable && r == obj }, - coverage = DoNotCalculate - ) - } - - @Test - fun testComplicatedCast() { - withEnabledTestingCodeGeneration(testCodeGeneration = false) { // error: package sun.text is not visible - check( - CastExample::complicatedCast, - eq(2), - { i, a, _ -> i == 0 && a != null && a[i] != null && a[i] !is CastClassFirstSucc }, - { i, a, r -> i == 0 && a != null && a[i] != null && a[i] is CastClassFirstSucc && r is CastClassFirstSucc }, - coverage = DoNotCalculate - ) - } - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/casts/GenericCastExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/casts/GenericCastExampleTest.kt deleted file mode 100644 index e62fe49cbe..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/casts/GenericCastExampleTest.kt +++ /dev/null @@ -1,77 +0,0 @@ -package org.utbot.examples.casts - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -// TODO failed Kotlin compilation SAT-1332 -internal class GenericCastExampleTest : UtValueTestCaseChecker( - testClass = GenericCastExample::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testCompareTwoNumbers() { - check( - GenericCastExample::compareTwoNumbers, - eq(5), - { a, _, _ -> a == null }, - { _, b, _ -> b == null }, - { _, b, _ -> b.comparableGenericField == null }, - { a, b, r -> a >= b.comparableGenericField && r == 1 }, - { a, b, r -> a < b.comparableGenericField && r == -1 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetGenericFieldValue() { - check( - GenericCastExample::getGenericFieldValue, - eq(3), - { g, _ -> g == null }, - { g, _ -> g.genericField == null }, - { g, r -> g?.genericField != null && r == g.genericField }, - ) - } - - @Test - fun testCompareGenericField() { - check( - GenericCastExample::compareGenericField, - between(4..5), - { g, _, _ -> g == null }, - { g, v, _ -> g != null && v == null }, - { g, v, r -> v != null && v != g.comparableGenericField && r == -1 }, - { g, v, r -> g.comparableGenericField is Int && v != null && v == g.comparableGenericField && r == 1 }, - coverage = DoNotCalculate // TODO because of kryo exception: Buffer underflow. - ) - } - - @Test - fun testCreateNewGenericObject() { - check( - GenericCastExample::createNewGenericObject, - eq(1), - { r -> r is Int && r == 10 }, - ) - } - - @Test - fun testSumFromArrayOfGenerics() { - check( - GenericCastExample::sumFromArrayOfGenerics, - eq(7), - { g, _ -> g == null }, - { g, _ -> g.genericArray == null }, - { g, _ -> g.genericArray.isEmpty() }, - { g, _ -> g.genericArray.size == 1 }, - { g, _ -> g.genericArray[0] == null }, - { g, _ -> g.genericArray[0] != null && g.genericArray[1] == null }, - { g, r -> g.genericArray[0] != null && g.genericArray[1] != null && r == g.genericArray[0] + g.genericArray[1] }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/casts/InstanceOfExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/casts/InstanceOfExampleTest.kt deleted file mode 100644 index fe9fa10068..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/casts/InstanceOfExampleTest.kt +++ /dev/null @@ -1,406 +0,0 @@ -package org.utbot.examples.casts - -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 - -// TODO failed Kotlin compilation SAT-1332 -internal class InstanceOfExampleTest : UtValueTestCaseChecker( - testClass = InstanceOfExample::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testSimpleInstanceOf() { - check( - InstanceOfExample::simpleInstanceOf, - eq(2), - { o, r -> o is CastClassFirstSucc && r is CastClassFirstSucc }, - { o, r -> o !is CastClassFirstSucc && r == null }, - ) - } - - @Test - fun testNullPointerCheck() { - check( - InstanceOfExample::nullPointerCheck, - eq(3), - { o, _ -> o == null }, - { o, r -> o is CastClassFirstSucc && r == o.z }, - { o, r -> o !is CastClassFirstSucc && o != null && r == o.x }, - ) - } - - @Test - fun testVirtualCall() { - check( - InstanceOfExample::virtualCall, - eq(2), - { o, r -> o is CastClassFirstSucc && r == o.foo() }, - { o, r -> o !is CastClassFirstSucc && r == -1 }, - ) - } - - @Test - fun testVirtualFunctionCallWithCast() { - check( - InstanceOfExample::virtualFunctionCallWithCast, - eq(3), - { o, r -> o !is CastClassFirstSucc && r == -1 }, - { o, _ -> o is CastClass && o !is CastClassFirstSucc }, - { o, r -> o is CastClassFirstSucc && r == o.z }, - ) - } - - @Test - fun testVirtualCallWithoutOneInheritor() { - check( - InstanceOfExample::virtualCallWithoutOneInheritor, - eq(4), - { o, r -> o !is CastClassFirstSucc && o is CastClass && r == o.foo() }, - { o, r -> o is CastClassSecondSucc && r == o.foo() }, - { o, _ -> o == null }, - { o, r -> o is CastClassFirstSucc && r == o.foo() }, - ) - } - - @Test - fun testVirtualCallWithoutOneInheritorInverse() { - check( - InstanceOfExample::virtualCallWithoutOneInheritorInverse, - eq(4), - { o, r -> o !is CastClassFirstSucc && o is CastClass && r == o.foo() }, - { o, r -> o is CastClassSecondSucc && r == o.foo() }, - { o, _ -> o == null }, - { o, r -> o is CastClassFirstSucc && r == o.foo() }, - ) - } - - @Test - fun testWithoutOneInheritorOnArray() { - check( - InstanceOfExample::withoutOneInheritorOnArray, - eq(2), - { o, r -> o.isInstanceOfArray() && r == 0 }, - { o, r -> !o.isInstanceOfArray() && r == 1 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testWithoutOneInheritorOnArrayInverse() { - check( - InstanceOfExample::withoutOneInheritorOnArrayInverse, - eq(2), - { o, r -> !o.isInstanceOfArray() && r == 0 }, - { o, r -> o.isInstanceOfArray() && r == 1 }, - coverage = DoNotCalculate - ) - } - - - @Test - fun testInstanceOfAsPartOfInternalExpressions() { - check( - InstanceOfExample::instanceOfAsPartOfInternalExpressions, - branches = ignoreExecutionsNumber, - { o, r -> - val o0isFirst = o[0].isInstanceOfArray() - val o1isSecond = o[1].isInstanceOfArray() - val and = o0isFirst && o1isSecond - and && r == 1 - }, - { o, r -> - val o0isSecond = o[0].isInstanceOfArray() - val o1isFirst = o[1].isInstanceOfArray() - val or = o0isSecond || o1isFirst - or && r == 2 - }, - { o, r -> - val o0isFirst = o[0].isInstanceOfArray() - val o1isSecond = o[1].isInstanceOfArray() - - val o0isSecond = o[0].isInstanceOfArray() - val o1isFirst = o[1].isInstanceOfArray() - - val and = o0isFirst && o1isSecond - val or = o0isSecond || o1isFirst - - !and && !or && r == 3 - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testInstanceOfAsPartOfInternalExpressionsCastClass() { - check( - InstanceOfExample::instanceOfAsPartOfInternalExpressionsCastClass, - branches = ignoreExecutionsNumber, - { o, r -> - val o0isFirst = o[0].isInstanceOfArray() - val o1isSecond = o[1].isInstanceOfArray() - val and = o0isFirst && o1isSecond - !and && r == 1 - }, - { o, r -> - val o0isSecond = o[0].isInstanceOfArray() - val o1isFirst = o[1].isInstanceOfArray() - val or = o0isSecond || o1isFirst - !or && r == 2 - }, - { o, r -> - val o0isFirst = o[0].isInstanceOfArray() - val o1isSecond = o[1].isInstanceOfArray() - - val o0isSecond = o[0].isInstanceOfArray() - val o1isFirst = o[1].isInstanceOfArray() - - val and = o0isFirst && o1isSecond - val or = o0isSecond || o1isFirst - - and && or && r == 3 - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testInstanceOfAsPartOfInternalExpressionsXor() { - check( - InstanceOfExample::instanceOfAsPartOfInternalExpressionsXor, - eq(4), - { o, r -> - val o0isSecond = o[0].isInstanceOfArray() - val o1isFirst = o[1].isInstanceOfArray() - r == 1 && !o0isSecond && o1isFirst - }, - { o, r -> - val o0isSecond = o[0].isInstanceOfArray() - val o1isFirst = o[1].isInstanceOfArray() - r == 2 && o0isSecond && !o1isFirst - }, - { o, r -> - val o0isSecond = o[0].isInstanceOfArray() - val o1isFirst = o[1].isInstanceOfArray() - r == 3 && o0isSecond && o1isFirst - }, - { o, r -> - val o0isSecond = o[0].isInstanceOfArray() - val o1isFirst = o[1].isInstanceOfArray() - r == 4 && !o0isSecond && !o1isFirst - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testInstanceOfAsPartOfInternalExpressionsXorInverse() { - check( - InstanceOfExample::instanceOfAsPartOfInternalExpressionsXorInverse, - eq(4), - { o, r -> - val o0isSecond = o[0].isInstanceOfArray() - val o1isFirst = o[1].isInstanceOfArray() - r == 1 && o0isSecond && o1isFirst - }, - { o, r -> - val o0isSecond = o[0].isInstanceOfArray() - val o1isFirst = o[1].isInstanceOfArray() - r == 2 && !o0isSecond && !o1isFirst - }, - { o, r -> - val o0isSecond = o[0].isInstanceOfArray() - val o1isFirst = o[1].isInstanceOfArray() - r == 3 && o0isSecond && !o1isFirst - }, - { o, r -> - val o0isSecond = o[0].isInstanceOfArray() - val o1isFirst = o[1].isInstanceOfArray() - r == 4 && !o0isSecond && o1isFirst - }, - coverage = DoNotCalculate - ) - } - - @Test - @Disabled("TODO: Can't deal with complicated expressions") - fun testInstanceOfAsPartOfInternalExpressionsIntValue() { - check( - InstanceOfExample::instanceOfAsPartOfInternalExpressionsIntValue, - branches = ignoreExecutionsNumber, - { o, r -> - val t1 = o.isInstanceOfArray() - val t2 = !o.isInstanceOfArray() - val t3 = r == 1 - t1 && t2 && t3 - }, - { o, r -> o.isInstanceOfArray() && r == 2 }, - { o, r -> !o.isInstanceOfArray() && r == 3 }, - coverage = DoNotCalculate - ) - } - - @Test - @Disabled("TODO: Zero branches") - fun testInstanceOfAsInternalExpressionsMap() { - check( - InstanceOfExample::instanceOfAsInternalExpressionsMap, - ge(3), - coverage = DoNotCalculate - ) - } - - - @Test - fun testSymbolicInstanceOf() { - check( - InstanceOfExample::symbolicInstanceOf, - eq(6), - { _, i, r -> i < 1 && r == null }, - { _, i, r -> i > 3 && r == null }, - { o, _, _ -> o == null }, - { o, i, _ -> o != null && i > o.lastIndex }, - { o, i, r -> o != null && o[i] is CastClassFirstSucc && r is CastClassFirstSucc }, - { o, i, r -> o != null && o[i] !is CastClassFirstSucc && r is CastClassSecondSucc }, - ) - } - - @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 - ) - } - - @Test - fun testInstanceOfFromArray() { - check( - InstanceOfExample::instanceOfFromArray, - eq(5), - { a, _ -> a == null }, - { a, r -> a.size != 3 && r == null }, - { a, r -> a.size == 3 && a[0] is CastClassFirstSucc && r != null && r[0] is CastClassFirstSucc }, - { a, r -> a.size == 3 && a[0] is CastClassSecondSucc && r != null && r[0] == null }, - { a, r -> a.size == 3 && a[0] !is CastClassFirstSucc && a[0] !is CastClassSecondSucc && r != null }, - ) - } - - @Test - fun testInstanceOfFromArrayWithReadingAnotherElement() { - check( - InstanceOfExample::instanceOfFromArrayWithReadingAnotherElement, - eq(4), - { a, _ -> a == null }, - { a, r -> a != null && a.size < 2 && r == null }, - { a, r -> a != null && a.size >= 2 && a[0] is CastClassFirstSucc && r is CastClassFirstSucc }, - { a, r -> a != null && a.size >= 2 && a[0] !is CastClassFirstSucc && r == null }, - ) - } - - @Test - fun testInstanceOfFromArrayWithReadingSameElement() { - check( - InstanceOfExample::instanceOfFromArrayWithReadingSameElement, - eq(4), - { a, _ -> a == null }, - { a, r -> a != null && a.size < 2 && r == null }, - { a, r -> a != null && a.size >= 2 && a[0] is CastClassFirstSucc && r is CastClassFirstSucc }, - { a, r -> a != null && a.size >= 2 && a[0] !is CastClassFirstSucc && r == null }, - ) - } - - @Test - fun testIsNull() { - check( - InstanceOfExample::isNull, - eq(2), - { a, r -> a is Array<*> && a.isArrayOf() && r == 1 }, - { a, r -> a == null && r == 2 }, - ) - } - - @Test - fun testArrayInstanceOfArray() { - check( - InstanceOfExample::arrayInstanceOfArray, - eq(4), - { a, r -> a == null && r == null }, - { a, r -> a is Array<*> && a.isArrayOf() && r is Array<*> && r.isArrayOf() }, - { a, r -> a is Array<*> && a.isArrayOf() && r is Array<*> && r.isArrayOf() }, - { a, r -> - a is Array<*> && a.isArrayOf() && !a.isArrayOf() && - !a.isArrayOf() && r is Array<*> && a contentDeepEquals r - }, - ) - } - - @Test - fun testObjectInstanceOfArray() { - check( - InstanceOfExample::objectInstanceOfArray, - eq(3), - { a, r -> a is IntArray && r is IntArray && a contentEquals r }, - { a, r -> a is BooleanArray && r is BooleanArray && a contentEquals r }, - { a, r -> (a == null && r == null) || (!(a is IntArray || a is BooleanArray) && a.equals(r)) }, - ) - } - - @Test - fun testInstanceOfObjectArray() { - check( - InstanceOfExample::instanceOfObjectArray, - eq(3), - { a, r -> a == null && r == null }, - { a, r -> a is Array<*> && a.isArrayOf>() && r is Array<*> && r contentDeepEquals a }, - { a, r -> a is Array<*> && !a.isArrayOf>() && r!!::class == a::class }, - ) - } - - - private inline fun Any?.isInstanceOfArray() = - (this as? Array<*>)?.run { T::class.java.isAssignableFrom(this::class.java.componentType) } == true -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/ClassWithStaticAndInnerClassesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/ClassWithStaticAndInnerClassesTest.kt deleted file mode 100644 index a2576397ee..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/ClassWithStaticAndInnerClassesTest.kt +++ /dev/null @@ -1,129 +0,0 @@ -package org.utbot.examples.codegen - -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq - -@Suppress("INACCESSIBLE_TYPE") -internal class ClassWithStaticAndInnerClassesTest : UtValueTestCaseChecker( - testClass = ClassWithStaticAndInnerClasses::class, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA, lastStage = TestExecution, parameterizedModeLastStage = Compilation), - TestLastStage(CodegenLanguage.KOTLIN, lastStage = TestExecution) - ) -) { - @Test - fun testUsePrivateStaticClassWithPrivateField() { - check( - ClassWithStaticAndInnerClasses::usePrivateStaticClassWithPrivateField, - eq(2), - coverage = DoNotCalculate - ) - } - - @Test - fun testUsePrivateStaticClassWithPublicField() { - check( - ClassWithStaticAndInnerClasses::usePrivateStaticClassWithPublicField, - eq(2), - coverage = DoNotCalculate - ) - } - - @Test - fun testUsePublicStaticClassWithPrivateField() { - check( - ClassWithStaticAndInnerClasses::usePublicStaticClassWithPrivateField, - eq(2), - coverage = DoNotCalculate - ) - } - - @Test - fun testUsePublicStaticClassWithPublicField() { - check( - ClassWithStaticAndInnerClasses::usePublicStaticClassWithPublicField, - eq(2), - coverage = DoNotCalculate - ) - } - - @Test - fun testUsePrivateInnerClassWithPrivateField() { - check( - ClassWithStaticAndInnerClasses::usePrivateInnerClassWithPrivateField, - eq(2), - coverage = DoNotCalculate - ) - } - - @Test - fun testUsePrivateInnerClassWithPublicField() { - check( - ClassWithStaticAndInnerClasses::usePrivateInnerClassWithPublicField, - eq(2), - coverage = DoNotCalculate - ) - } - - @Test - fun testUsePublicInnerClassWithPrivateField() { - check( - ClassWithStaticAndInnerClasses::usePublicInnerClassWithPrivateField, - eq(2), - coverage = DoNotCalculate - ) - } - - @Test - fun testUsePublicInnerClassWithPublicField() { - check( - ClassWithStaticAndInnerClasses::usePublicInnerClassWithPublicField, - eq(2), - coverage = DoNotCalculate - ) - } - - @Test - fun testUsePackagePrivateFinalStaticClassWithPackagePrivateField() { - check( - ClassWithStaticAndInnerClasses::usePackagePrivateFinalStaticClassWithPackagePrivateField, - eq(2), - coverage = DoNotCalculate - ) - } - - @Test - fun testUsePackagePrivateFinalInnerClassWithPackagePrivateField() { - check( - ClassWithStaticAndInnerClasses::usePackagePrivateFinalInnerClassWithPackagePrivateField, - eq(2), - coverage = DoNotCalculate - ) - } - - @Test - fun testGetValueFromPublicFieldWithPrivateType() { - check( - ClassWithStaticAndInnerClasses::getValueFromPublicFieldWithPrivateType, - eq(2), - coverage = DoNotCalculate - ) - } - - @Test - fun testPublicStaticClassWithPrivateField_DeepNestedStatic_g() { - checkAllCombinations( - ClassWithStaticAndInnerClasses.PublicStaticClassWithPrivateField.DeepNestedStatic::g, - generateWithNested = true - ) - } - - @Test - fun testPublicStaticClassWithPrivateField_DeepNested_h() { - checkAllCombinations( - ClassWithStaticAndInnerClasses.PublicStaticClassWithPrivateField.DeepNested::h, - generateWithNested = true - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/CodegenExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/CodegenExampleTest.kt deleted file mode 100644 index ce9b6b757f..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/CodegenExampleTest.kt +++ /dev/null @@ -1,56 +0,0 @@ -package org.utbot.examples.codegen - -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, - ) - } - } - - @Test - fun innerClassTest() { - val innerClass = CodegenExample::class.nestedClasses.single { it.simpleName == "InnerClass" } - val fooMethod = innerClass.functions.single { it.name == "foo" } - - checkAllCombinations(fooMethod) - } - - @Test - @Disabled("TODO static initializers JIRA:1483") - fun staticClassTest() { - val staticClass = CodegenExample::class.nestedClasses.single { it.simpleName == "StaticClass" } - val barMethod = staticClass.functions.single { it.name == "bar" } - - checkAllCombinations(barMethod) - } - - @Test - fun randomAsLocalVariableTest() { - checkAllCombinations( - MockRandomExamples::randomAsLocalVariable, - ) - } - - @Test - fun randomAsFieldTest() { - checkAllCombinations( - MockRandomExamples::randomAsField, - ) - } - - @Test - fun randomAsParameterTest() { - checkAllCombinations( - MockRandomExamples::randomAsParameter, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/FileWithTopLevelFunctionsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/FileWithTopLevelFunctionsTest.kt deleted file mode 100644 index 6af41eb6d4..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/FileWithTopLevelFunctionsTest.kt +++ /dev/null @@ -1,43 +0,0 @@ -package org.utbot.examples.codegen - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker -import kotlin.reflect.KFunction3 - -@Suppress("UNCHECKED_CAST") -internal class FileWithTopLevelFunctionsTest : UtValueTestCaseChecker(testClass = FileWithTopLevelFunctionsReflectHelper.clazz.kotlin) { - @Test - fun topLevelSumTest() { - check( - ::topLevelSum, - eq(1), - ) - } - - @Test - fun extensionOnBasicTypeTest() { - check( - Int::extensionOnBasicType, - eq(1), - ) - } - - @Test - fun extensionOnCustomClassTest() { - check( - // NB: cast is important here because we need to treat receiver as an argument to be able to check its content in matchers - CustomClass::extensionOnCustomClass as KFunction3<*, CustomClass, CustomClass, Boolean>, - eq(2), - { receiver, argument, result -> receiver === argument && result == true }, - { receiver, argument, result -> receiver !== argument && result == false }, - additionalDependencies = dependenciesForClassExtensions - ) - } - - companion object { - // Compilation of extension methods for ref objects produces call to - // `kotlin.jvm.internal.Intrinsics::checkNotNullParameter`, so we need to add it to dependencies - val dependenciesForClassExtensions = arrayOf>(kotlin.jvm.internal.Intrinsics::class.java) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt deleted file mode 100644 index 2133cf2ef8..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/JavaAssertTest.kt +++ /dev/null @@ -1,21 +0,0 @@ -package org.utbot.examples.codegen - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker -import org.utbot.testing.isException - -class JavaAssertTest : UtValueTestCaseChecker( - testClass = JavaAssert::class, - testCodeGeneration = false -) { - @Test - fun testAssertPositive() { - checkWithException( - JavaAssert::assertPositive, - eq(2), - { value, result -> value > 0 && result.isSuccess && result.getOrNull() == value }, - { value, result -> value <= 0 && result.isException() } - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/VoidStaticMethodsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/VoidStaticMethodsTest.kt deleted file mode 100644 index 42af7ff925..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/VoidStaticMethodsTest.kt +++ /dev/null @@ -1,36 +0,0 @@ -package org.utbot.examples.codegen - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.DoNotCalculate -import org.utbot.testing.UtValueTestCaseChecker - -class VoidStaticMethodsTest : UtValueTestCaseChecker( - testClass = VoidStaticMethodsTestingClass::class) { - @Test - fun testInvokeChangeStaticFieldMethod() { - check( - VoidStaticMethodsTestingClass::invokeChangeStaticFieldMethod, - eq(2), - coverage = DoNotCalculate - ) - } - - @Test - fun testInvokeThrowExceptionMethod() { - check( - VoidStaticMethodsTestingClass::invokeThrowExceptionMethod, - eq(3), - coverage = DoNotCalculate - ) - } - - @Test - fun testInvokeAnotherThrowExceptionMethod() { - check( - VoidStaticMethodsTestingClass::invokeAnotherThrowExceptionMethod, - eq(2), - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithCrossReferenceRelationshipTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithCrossReferenceRelationshipTest.kt deleted file mode 100644 index 1e962818ed..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithCrossReferenceRelationshipTest.kt +++ /dev/null @@ -1,26 +0,0 @@ -package org.utbot.examples.codegen.deepequals - -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq -import org.utbot.testing.CodeGeneration -import org.utbot.testing.DoNotCalculate -import org.utbot.testing.UtValueTestCaseChecker - -class ClassWithCrossReferenceRelationshipTest : UtValueTestCaseChecker( - testClass = ClassWithCrossReferenceRelationship::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testClassWithCrossReferenceRelationship() { - check( - ClassWithCrossReferenceRelationship::returnFirstClass, - eq(2), - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithNullableFieldTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithNullableFieldTest.kt deleted file mode 100644 index 4dbf645bd8..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/ClassWithNullableFieldTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -package org.utbot.examples.codegen.deepequals - -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq - -class ClassWithNullableFieldTest : UtValueTestCaseChecker( - testClass = ClassWithNullableField::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testClassWithNullableFieldInCompound() { - check( - ClassWithNullableField::returnCompoundWithNullableField, - eq(2), - coverage = DoNotCalculate - ) - } - - @Test - fun testClassWithNullableFieldInGreatCompound() { - check( - ClassWithNullableField::returnGreatCompoundWithNullableField, - eq(3), - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/DeepEqualsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/DeepEqualsTest.kt deleted file mode 100644 index 9d206c61d4..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/deepequals/DeepEqualsTest.kt +++ /dev/null @@ -1,164 +0,0 @@ -package org.utbot.examples.codegen.deepequals - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -// TODO failed Kotlin compilation (generics) SAT-1332 -class DeepEqualsTest : UtValueTestCaseChecker( - testClass = DeepEqualsTestingClass::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testReturnList() { - check( - DeepEqualsTestingClass::returnList, - eq(1), - coverage = DoNotCalculate - ) - } - - @Test - fun testReturnSet() { - check( - DeepEqualsTestingClass::returnSet, - eq(1), - coverage = DoNotCalculate - ) - } - - @Test - fun testReturnMap() { - check( - DeepEqualsTestingClass::returnMap, - eq(1), - coverage = DoNotCalculate - ) - } - - @Test - fun testReturnArray() { - check( - DeepEqualsTestingClass::returnArray, - eq(1), - coverage = DoNotCalculate - ) - } - - @Test - @Disabled("We do not support 2d generics containers right now") - fun testReturn2DList() { - check( - DeepEqualsTestingClass::return2DList, - eq(1), - coverage = DoNotCalculate - ) - } - - @Test - @Disabled("We do not support 2d generics containers right now") - fun testReturn2DSet() { - check( - DeepEqualsTestingClass::return2DSet, - eq(1), - coverage = DoNotCalculate - ) - } - - @Test - @Disabled("We do not support 2d generics containers right now") - fun testReturn2DMap() { - check( - DeepEqualsTestingClass::return2DMap, - eq(1), - coverage = DoNotCalculate - ) - } - - @Test - @Disabled("We do not support 2d generics containers right now") - fun testIntegers2DList() { - check( - DeepEqualsTestingClass::returnIntegers2DList, - eq(1), - coverage = DoNotCalculate - ) - } - - @Test - fun testReturn2DArray() { - check( - DeepEqualsTestingClass::return2DArray, - eq(1), - coverage = DoNotCalculate - ) - } - - @Test - fun testReturnCommonClass() { - check( - DeepEqualsTestingClass::returnCommonClass, - eq(1), - coverage = DoNotCalculate - ) - } - - @Test - fun testTriangle() { - check( - DeepEqualsTestingClass::returnTriangle, - eq(1), - coverage = DoNotCalculate - ) - } - - @Test - fun testQuadrilateral() { - check( - DeepEqualsTestingClass::returnQuadrilateralFromNode, - eq(1), - coverage = DoNotCalculate - ) - } - - @Test - fun testIntMultiArray() { - check( - DeepEqualsTestingClass::fillIntMultiArrayWithConstValue, - eq(3), - coverage = DoNotCalculate - ) - } - - @Test - fun testDoubleMultiArray() { - check( - DeepEqualsTestingClass::fillDoubleMultiArrayWithConstValue, - eq(3), - coverage = DoNotCalculate - ) - } - - @Test - fun testIntegerWrapperMultiArray() { - check( - DeepEqualsTestingClass::fillIntegerWrapperMultiArrayWithConstValue, - eq(3), - coverage = DoNotCalculate - ) - } - - @Test - fun testDoubleWrapperMultiArray() { - check( - DeepEqualsTestingClass::fillDoubleWrapperMultiArrayWithConstValue, - eq(3), - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt deleted file mode 100644 index 200047ea44..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/codegen/modifiers/ClassWithPrivateMutableFieldOfPrivateTypeTest.kt +++ /dev/null @@ -1,41 +0,0 @@ -package org.utbot.examples.codegen.modifiers - -import org.junit.jupiter.api.Test -import org.utbot.common.withAccessibility -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.framework.plugin.api.FieldId -import org.utbot.framework.plugin.api.util.id -import org.utbot.framework.plugin.api.util.jField -import org.utbot.testcheckers.eq -import org.utbot.testing.Compilation -import org.utbot.testing.UtValueTestCaseChecker - -// TODO failed Kotlin tests execution with non-nullable expected field -class ClassWithPrivateMutableFieldOfPrivateTypeTest : UtValueTestCaseChecker( - testClass = ClassWithPrivateMutableFieldOfPrivateType::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, Compilation) - ) -) { - @Test - fun testChangePrivateMutableFieldWithPrivateType() { - checkAllMutationsWithThis( - ClassWithPrivateMutableFieldOfPrivateType::changePrivateMutableFieldWithPrivateType, - eq(1), - { thisBefore, _, thisAfter, _, r -> - val privateMutableField = FieldId( - ClassWithPrivateMutableFieldOfPrivateType::class.id, - "privateMutableField" - ).jField - - val (privateFieldBeforeValue, privateFieldAfterValue) = privateMutableField.withAccessibility { - privateMutableField.get(thisBefore) to privateMutableField.get(thisAfter) - } - - privateFieldBeforeValue == null && privateFieldAfterValue != null && r == 0 - } - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt deleted file mode 100644 index bcc5df047d..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt +++ /dev/null @@ -1,76 +0,0 @@ -package org.utbot.examples.collections - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.framework.plugin.api.FieldId -import org.utbot.framework.plugin.api.UtConcreteValue -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class CustomerExamplesTest: UtValueTestCaseChecker( - testClass = CustomerExamples::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA, lastStage = TestExecution, parameterizedModeLastStage = Compilation), - TestLastStage(CodegenLanguage.KOTLIN, lastStage = CodeGeneration) - ) -) { - @Test - fun testSimpleExample() { - checkStatics( - CustomerExamples::simpleExample, - eq(2), - { key, statics, r -> - val hashMap = statics.extractSingleStaticMap() - key !in hashMap && r == 2 - }, - { key, statics, r -> - val hashMap = statics.extractSingleStaticMap() - key in hashMap && r == 1 - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testStaticMap() { - checkStaticsWithThis( - CustomerExamples::staticMap, - ignoreExecutionsNumber, - { _, a, _, _, _, _ -> a == null }, - { t, _, _, _, _, _ -> t.c == null }, - { _, a, _, _, _, _ -> a.b == null }, - { t, a, _, _, _, r -> a.foo() > 1 && t.c.x < 3 && r == 1 }, - { t, a, key, _, statics, r -> - val hashMap = statics.extractSingleStaticMap() - - val firstConditionNegation = !(a.foo() > 1 && t.c.x < 3) - val secondCondition = a.b.bar() < 3 && key in hashMap - - firstConditionNegation && secondCondition && r == 2 - }, - { t, a, key, x, statics, r -> - val hashMap = statics.extractSingleStaticMap() - - val firstConditionNegation = !(a.foo() > 1 && t.c.x < 3) - val secondConditionNegation = !(a.b.bar() < 3 && key in hashMap) - val thirdCondition = t.c.x > 5 && t.foo(x) < 10 - - firstConditionNegation && secondConditionNegation && thirdCondition && r == 3 - }, - { t, a, key, x, statics, r -> - val hashMap = statics.extractSingleStaticMap() - - val firstConditionNegation = !(a.foo() > 1 && t.c.x < 3) - val secondConditionNegation = !(a.b.bar() < 3 && key in hashMap) - val thirdConditionNegation = !(t.c.x > 5 && t.foo(x) < 10) - - firstConditionNegation && secondConditionNegation && thirdConditionNegation && r == 4 - }, - // TODO JIRA:1588 - coverage = DoNotCalculate - ) - } - - private fun Map>.extractSingleStaticMap() = - values.singleOrNull()?.value as? HashMap<*, *> ?: emptyMap() -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/GenericListsExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/GenericListsExampleTest.kt deleted file mode 100644 index fbabf6523c..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/GenericListsExampleTest.kt +++ /dev/null @@ -1,160 +0,0 @@ -package org.utbot.examples.collections - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -// TODO disabled tests should be fixes with SAT-1441 -internal class GenericListsExampleTest : UtValueTestCaseChecker( - testClass = GenericListsExample::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - @Disabled("Doesn't find branches without NPE") - fun testListOfListsOfT() { - check( - GenericListsExample::listOfListsOfT, - eq(-1) - ) - } - - @Test - @Disabled("Problems with memory") - fun testListOfComparable() { - check( - GenericListsExample::listOfComparable, - eq(1), - { v, r -> v != null && v.size > 1 && v[0] != null && v.all { it is Comparable<*> || it == null } && v == r }, - coverage = DoNotCalculate - ) - } - - @Test - fun testListOfT() { - check( - GenericListsExample::listOfT, - eq(1), - { v, r -> v != null && v.size >= 2 && v[0] != null && v == r }, - coverage = DoNotCalculate - ) - } - - @Test - @Disabled("Wrong number of matchers") - fun testListOfTArray() { - check( - GenericListsExample::listOfTArray, - eq(1) - ) - } - - @Test - @Disabled("JIRA:1446") - fun testListOfExtendsTArray() { - check( - GenericListsExample::listOfExtendsTArray, - eq(-1) - ) - } - - @Test - @Disabled("java.lang.ClassCastException: java.util.ArraysParallelSortHelpers\$FJShort\$Merger cannot be cast to [I") - fun testListOfPrimitiveArrayInheritors() { - check( - GenericListsExample::listOfPrimitiveArrayInheritors, - eq(-1) - ) - } - - @Test - @Disabled("JIRA:1620") - fun createWildcard() { - check( - GenericListsExample<*>::wildcard, - eq(4), - { v, r -> v == null && r?.isEmpty() == true }, - { v, r -> v != null && v.size == 1 && v[0] != null && v == r && v.all { it is Number || it == null } }, - { v, r -> v != null && (v.size != 1 || v[0] == null) && v == r && v.all { it is Number || it == null } }, - coverage = DoNotCalculate - ) - } - - @Suppress("NestedLambdaShadowedImplicitParameter") - @Test - @Disabled("unexpected empty nested list") - fun createListOfLists() { - check( - GenericListsExample<*>::listOfLists, - eq(1), - { v, r -> - val valueCondition = v != null && v[0] != null && v[0].isNotEmpty() - val typeCondition = v.all { (it is List<*> && it.all { it is Int || it == null }) || it == null } - - valueCondition && typeCondition && v == r - }, - coverage = DoNotCalculate - ) - } - - @Test - fun createWildcardWithOnlyQuestionMark() { - check( - GenericListsExample<*>::wildcardWithOnlyQuestionMark, - eq(3), - { v, r -> v == null && r?.isEmpty() == true }, - { v, r -> v.size == 1 && v == r }, - { v, r -> v.size != 1 && v == r }, - coverage = DoNotCalculate - ) - } - - - @Test - fun testGenericWithArrayOfPrimitives() { - check( - GenericListsExample<*>::genericWithArrayOfPrimitives, - eq(1), - { v, _ -> - val valueCondition = v != null && v.size >= 2 && v[0] != null && v[0].isNotEmpty() && v[0][0] != 0L - val typeCondition = v.all { it is LongArray || it == null } - - valueCondition && typeCondition - }, - coverage = DoNotCalculate - ) - } - - - @Test - fun testGenericWithObject() { - check( - GenericListsExample<*>::genericWithObject, - eq(1), - { v, r -> v != null && v.size >= 2 && v[0] != null && v[0] is Long && v == r }, - coverage = DoNotCalculate - ) - } - - - @Test - fun testGenericWithArrayOfArrays() { - check( - GenericListsExample<*>::genericWithArrayOfArrays, - eq(1), - { v, _ -> - val valueCondition = v != null && v.size >= 2 && v[0] != null && v[0].isNotEmpty() && v[0][0] != null - val typeCondition = v.all { - (it is Array<*> && it.isArrayOf>() && it.all { it.isArrayOf() || it == null}) || it == null - } - - valueCondition && typeCondition - }, - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/LinkedListsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/LinkedListsTest.kt deleted file mode 100644 index ca667af7e9..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/LinkedListsTest.kt +++ /dev/null @@ -1,261 +0,0 @@ -package org.utbot.examples.collections - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -// TODO failed Kotlin compilation (generics) SAT-1332 -internal class LinkedListsTest : UtValueTestCaseChecker( - testClass = LinkedLists::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - - @Test - fun testSet() { - check( - LinkedLists::set, - eq(3), - { l, _ -> l == null }, - { l, _ -> l.size <= 2 }, - { l, r -> l.size > 2 && r == 1 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testOffer() { - check( - LinkedLists::offer, - eq(3), - { l, _ -> l == null }, - { l, r -> l != null && l.size <= 1 && r == l }, - { l, r -> l != null && l.size > 1 && r == l + 1 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testOfferLast() { - check( - LinkedLists::offerLast, - eq(3), - { l, _ -> l == null }, - { l, r -> l != null && l.size <= 1 && r == l }, - { l, r -> l != null && l.size > 1 && r == l + 1 }, - coverage = DoNotCalculate - ) - } - - - @Test - fun testAddLast() { - check( - LinkedLists::addLast, - eq(3), - { l, _ -> l == null }, - { l, r -> l != null && l.size <= 1 && r == l }, - { l, r -> l != null && l.size > 1 && (r == l + 1) }, - coverage = DoNotCalculate - ) - } - - @Test - fun testPush() { - check( - LinkedLists::push, - eq(3), - { l, _ -> l == null }, - { l, r -> l != null && l.size <= 1 && r == l }, - { l, r -> l != null && l.size > 1 && r == listOf(1) + l }, - coverage = DoNotCalculate - ) - } - - @Test - fun testOfferFirst() { - check( - LinkedLists::offerFirst, - eq(3), - { l, _ -> l == null }, - { l, r -> l != null && l.size <= 1 && r == l }, - { l, r -> l != null && l.size > 1 && r == listOf(1) + l }, - coverage = DoNotCalculate - ) - } - - @Test - fun testAddFirst() { - check( - LinkedLists::addFirst, - eq(3), - { l, _ -> l == null }, - { l, r -> l != null && l.size <= 1 && r == l }, - { l, r -> l != null && l.size > 1 && r!!.size == l.size + 1 && r[0] == 1 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testPeek() { - checkWithException( - LinkedLists::peek, - eq(3), - { l, _ -> l == null }, - { l, r -> l != null && (l.isEmpty() || l.first() == null) && r.isException() }, - { l, r -> l != null && l.isNotEmpty() && r.getOrNull() == l[0] }, - coverage = DoNotCalculate - ) - } - - @Test - fun testPeekFirst() { - checkWithException( - LinkedLists::peekFirst, - eq(3), - { l, _ -> l == null }, - { l, r -> l != null && (l.isEmpty() || l.first() == null) && r.isException() }, - { l, r -> l != null && l.isNotEmpty() && r.getOrNull() == l[0] }, - coverage = DoNotCalculate - ) - } - - @Test - fun testPeekLast() { - checkWithException( - LinkedLists::peekLast, - eq(3), - { l, _ -> l == null }, - { l, r -> l != null && (l.isEmpty() || l.last() == null) && r.isException() }, - { l, r -> l != null && l.isNotEmpty() && r.getOrNull() == l.last() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testElement() { - checkWithException( - LinkedLists::element, - eq(4), - { l, _ -> l == null }, - { l, r -> l != null && l.isEmpty() && r.isException() }, - { l, r -> l != null && l.isNotEmpty() && l[0] == null && r.isException() }, - { l, r -> l != null && l.isNotEmpty() && l[0] != null && r.getOrNull() == l[0] }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetFirst() { - checkWithException( - LinkedLists::getFirst, - eq(4), - { l, _ -> l == null }, - { l, r -> l != null && l.isEmpty() && r.isException() }, - { l, _ -> l != null && l.isNotEmpty() && l[0] == null }, - { l, r -> l != null && l.isNotEmpty() && r.getOrNull() == l[0] }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetLast() { - checkWithException( - LinkedLists::getLast, - eq(4), - { l, _ -> l == null }, - { l, r -> l != null && l.isEmpty() && r.isException() }, - { l, _ -> l != null && l.isNotEmpty() && l.last() == null }, - { l, r -> l != null && l.isNotEmpty() && r.getOrNull() == l.last() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testPoll() { - checkWithException( - LinkedLists::poll, - eq(5), - { l, _ -> l == null }, - { l, r -> l != null && l.isEmpty() && r.isException() }, - { l, r -> l != null && l.size == 1 && r.getOrNull() == l }, - { l, _ -> l != null && l.size > 1 && l.first() == null }, - { l, r -> l != null && l.size > 1 && r.getOrNull() == l.subList(1, l.size) }, - coverage = DoNotCalculate - ) - } - - @Test - fun testPollFirst() { - checkWithException( - LinkedLists::pollFirst, - eq(5), - { l, _ -> l == null }, - { l, r -> l != null && l.isEmpty() && r.isException() }, - { l, r -> l != null && l.size == 1 && r.getOrNull() == l }, - { l, _ -> l != null && l.size > 1 && l.first() == null }, - { l, r -> l != null && l.size > 1 && r.getOrNull() == l.subList(1, l.size) }, - coverage = DoNotCalculate - ) - } - - @Test - fun testPollLast() { - checkWithException( - LinkedLists::pollLast, - eq(5), - { l, _ -> l == null }, - { l, r -> l != null && l.isEmpty() && r.isException() }, - { l, r -> l != null && l.size == 1 && r.getOrNull() == l }, - { l, _ -> l != null && l.size > 1 && l.last() == null }, - { l, r -> l != null && l.size > 1 && r.getOrNull() == l.subList(0, l.size - 1) }, - coverage = DoNotCalculate - ) - } - - @Test - fun testRemove() { - checkWithException( - LinkedLists::removeFirst, - eq(5), - { l, _ -> l == null }, - { l, r -> l != null && l.isEmpty() && r.isException() }, - { l, r -> l != null && l.size == 1 && r.getOrNull() == l }, - { l, _ -> l != null && l.size > 1 && l.first() == null }, - { l, r -> l != null && l.size > 1 && r.getOrNull() == l.subList(1, l.size) }, - coverage = DoNotCalculate - ) - } - - @Test - fun testRemoveFirst() { - checkWithException( - LinkedLists::removeFirst, - eq(5), - { l, _ -> l == null }, - { l, r -> l != null && l.isEmpty() && r.isException() }, - { l, r -> l != null && l.size == 1 && r.getOrNull() == l }, - { l, _ -> l != null && l.size > 1 && l.first() == null }, - { l, r -> l != null && l.size > 1 && r.getOrNull() == l.subList(1, l.size) }, - coverage = DoNotCalculate - ) - } - - @Test - fun testRemoveLast() { - checkWithException( - LinkedLists::removeLast, - eq(5), - { l, _ -> l == null }, - { l, r -> l != null && l.isEmpty() && r.isException() }, - { l, r -> l != null && l.size == 1 && r.getOrNull() == l }, - { l, _ -> l != null && l.size > 1 && l.last() == null }, - { l, r -> l != null && l.size > 1 && r.getOrNull() == l.subList(0, l.size - 1) }, - coverage = DoNotCalculate - ) - } - -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListAlgorithmsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListAlgorithmsTest.kt deleted file mode 100644 index ef1083217e..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListAlgorithmsTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -package org.utbot.examples.collections - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.CodeGeneration -import org.utbot.testing.UtValueTestCaseChecker -import org.utbot.testing.atLeast - -// TODO failed Kotlin compilation SAT-1332 -class ListAlgorithmsTest : UtValueTestCaseChecker( - testClass = ListAlgorithms::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - - @Test - fun testMergeLists() { - check( - ListAlgorithms::mergeListsInplace, - eq(4), - { a, b, r -> b.subList(0, b.size - 1).any { a.last() < it } && r != null && r == r.sorted() }, - { a, b, r -> (a.subList(0, a.size - 1).any { b.last() <= it } || a.any { ai -> b.any { ai < it } }) && r != null && r == r.sorted() }, - { a, b, r -> a[0] < b[0] && r != null && r == r.sorted() }, - { a, b, r -> a[0] >= b[0] && r != null && r == r.sorted() }, - coverage = atLeast(94) - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListIteratorsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListIteratorsTest.kt deleted file mode 100644 index a8274f04df..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListIteratorsTest.kt +++ /dev/null @@ -1,108 +0,0 @@ -package org.utbot.examples.collections - -import org.junit.jupiter.api.Disabled -import org.utbot.framework.plugin.api.CodegenLanguage -import kotlin.math.min -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -// TODO failed Kotlin compilation (generics) SAT-1332 -internal class ListIteratorsTest : UtValueTestCaseChecker( - testClass = ListIterators::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - - @Test - fun testIterate() { - check( - ListIterators::iterate, - eq(3), - { l, _ -> l == null }, - { l, result -> l.isEmpty() && result == l }, - { l, result -> l.isNotEmpty() && result == l }, - coverage = DoNotCalculate - ) - } - - @Test - fun testIterateReversed() { - check( - ListIterators::iterateReversed, - eq(3), - { l, _ -> l == null }, - { l, result -> l.isEmpty() && result == l }, - { l, result -> l.isNotEmpty() && result == l.reversed() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testIterateForEach() { - check( - ListIterators::iterateForEach, - eq(4), - { l, _ -> l == null }, - { l, result -> l.isEmpty() && result == 0 }, - { l, _ -> l.isNotEmpty() && l.any { it == null } }, - { l, result -> l.isNotEmpty() && result == l.sum() }, - coverage = DoNotCalculate - ) - } - - @Test - @Disabled("Java 11 transition") - fun testAddElements() { - check( - ListIterators::addElements, - eq(5), - { l, _, _ -> l == null }, - { l, _, result -> l != null && l.isEmpty() && result == l }, - { l, arr, _ -> l != null && l.size > 0 && arr == null }, - { l, arr, _ -> l != null && arr != null && l.isNotEmpty() && arr.isEmpty() }, - { l, arr, _ -> l != null && arr != null && l.size > arr.size }, - coverage = DoNotCalculate - ) - } - - @Test - fun testSetElements() { - check( - ListIterators::setElements, - eq(5), - { l, _, _ -> l == null }, - { l, _, result -> l != null && l.isEmpty() && result == l }, - { l, arr, _ -> l != null && arr != null && l.size > arr.size }, - { l, arr, _ -> l != null && l.size > 0 && arr == null }, - { l, arr, result -> l != null && arr != null && l.size <= arr.size && result == arr.asList().take(l.size) }, - coverage = DoNotCalculate - ) - } - - @Test - fun testRemoveElements() { - check( - ListIterators::removeElements, - ignoreExecutionsNumber, // the exact number of the executions depends on the decisions made by PathSelector - // so we can have either six results or seven, depending on the [pathSelectorType] - // from UtSettings - { l, _, _ -> l == null }, - { l, i, _ -> l != null && i <= 0 }, - { l, i, _ -> l != null && l.isEmpty() && i > 0 }, - { l, i, _ -> l != null && i > 0 && l.subList(0, min(i, l.size)).any { it !is Int } }, - { l, i, _ -> l != null && i > 0 && l.subList(0, min(i, l.size)).any { it == null } }, - { l, i, _ -> l != null && l.isNotEmpty() && i > 0 }, - { l, i, result -> - require(l != null) - - val precondition = l.isNotEmpty() && i > 0 && l.subList(0, i).all { it is Int } - val postcondition = result == (l.subList(0, i - 1) + l.subList(min(l.size, i), l.size)) - - precondition && postcondition - }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListWrapperReturnsVoidTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListWrapperReturnsVoidTest.kt deleted file mode 100644 index d4c5cae8dc..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListWrapperReturnsVoidTest.kt +++ /dev/null @@ -1,43 +0,0 @@ -package org.utbot.examples.collections - -import org.junit.jupiter.api.Disabled -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -// TODO failed Kotlin compilation ($ in function names, generics) SAT-1220 SAT-1332 -@Disabled("Java 11 transition") -internal class ListWrapperReturnsVoidTest : UtValueTestCaseChecker( - testClass = ListWrapperReturnsVoidExample::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testRunForEach() { - checkWithException( - ListWrapperReturnsVoidExample::runForEach, - eq(4), - { l, r -> l == null && r.isException() }, - { l, r -> l.isEmpty() && r.getOrThrow() == 0 }, - { l, r -> l.isNotEmpty() && l.all { it != null } && r.getOrThrow() == 0 }, - { l, r -> l.isNotEmpty() && l.any { it == null } && r.getOrThrow() > 0 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testSumPositiveForEach() { - checkWithException( - ListWrapperReturnsVoidExample::sumPositiveForEach, - eq(5), - { l, r -> l == null && r.isException() }, - { l, r -> l.isEmpty() && r.getOrThrow() == 0 }, - { l, r -> l.isNotEmpty() && l.any { it == null } && r.isException() }, - { l, r -> l.isNotEmpty() && l.any { it <= 0 } && r.getOrThrow() == l.filter { it > 0 }.sum() }, - { l, r -> l.isNotEmpty() && l.any { it > 0 } && r.getOrThrow() == l.filter { it > 0 }.sum() } - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart1Test.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart1Test.kt deleted file mode 100644 index 397276453e..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart1Test.kt +++ /dev/null @@ -1,30 +0,0 @@ -package org.utbot.examples.collections - -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testing.CodeGeneration -import org.utbot.testing.UtValueTestCaseChecker -import org.utbot.testing.ignoreExecutionsNumber - -// TODO failed Kotlin compilation SAT-1332 -@Disabled -internal class ListsPart1Test : UtValueTestCaseChecker( - testClass = Lists::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testIterableContains() { - check( - Lists::iterableContains, - ignoreExecutionsNumber, - { iterable, _ -> iterable == null }, - { iterable, r -> 1 in iterable && r == true }, - { iterable, r -> 1 !in iterable && r == false }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart2Test.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart2Test.kt deleted file mode 100644 index 616ec2e4a7..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart2Test.kt +++ /dev/null @@ -1,27 +0,0 @@ -package org.utbot.examples.collections - -import org.junit.jupiter.api.Disabled -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test - -// TODO failed Kotlin compilation SAT-1332 -@Disabled -internal class ListsPart2Test : UtValueTestCaseChecker( - testClass = Lists::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testCollectionContains() { - check( - Lists::collectionContains, - ignoreExecutionsNumber, - { collection, _ -> collection == null }, - { collection, r -> 1 in collection && r == true }, - { collection, r -> 1 !in collection && r == false }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart3Test.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart3Test.kt deleted file mode 100644 index d7ac68b90a..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/ListsPart3Test.kt +++ /dev/null @@ -1,246 +0,0 @@ -package org.utbot.examples.collections - -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 - -// TODO failed Kotlin compilation SAT-1332 -internal class ListsPart3Test : UtValueTestCaseChecker( - testClass = Lists::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun createTest() { - check( - Lists::create, - 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 - ) - } - - @Test - fun testBigListFromParameters() { - check( - Lists::bigListFromParameters, - eq(1), - { list, r -> list.size == r && list.size == 11 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetNonEmptyCollection() { - check( - Lists::getNonEmptyCollection, - eq(3), - { collection, _ -> collection == null }, - { collection, r -> collection.isEmpty() && r == null }, - { collection, r -> collection.isNotEmpty() && collection == r }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetFromAnotherListToArray() { - check( - Lists::getFromAnotherListToArray, - eq(4), - { l, _ -> l == null }, - { 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 - ) - } - - @Test - fun addElementsTest() { - check( - Lists::addElements, - eq(5), - { list, _, _ -> list == null }, - { list, a, _ -> list != null && list.size >= 2 && a == null }, - { list, _, r -> list.size < 2 && r == list }, - { list, a, r -> list.size >= 2 && a.size < 2 && r == list }, - { list, a, r -> - require(r != null) - - val sizeConstraint = list.size >= 2 && a.size >= 2 && r.size == list.size + a.size - val content = r.mapIndexed { i, it -> if (i < r.size) it == r[i] else it == a[i - r.size] }.all { it } - - sizeConstraint && content - }, - coverage = DoNotCalculate - ) - } - - @Test - fun removeElementsTest() { - checkWithException( - Lists::removeElements, - between(7..8), - { 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() }, - { list, i, j, r -> - require(list != null && list[i] != null) - - val listConstraints = i >= 0 && list.size > i && (list.size <= j + 1 || j < 0) - val resultConstraint = r.isException() - - listConstraints && resultConstraint - }, - { list, i, j, r -> - require(list != null && list[i] != null) - - val k = j + if (i <= j) 1 else 0 - val indicesConstraint = i >= 0 && list.size > i && j >= 0 && list.size > j + 1 - val contentConstraint = list[i] != null && list[k] == null - val resultConstraint = r.isException() - - indicesConstraint && contentConstraint && resultConstraint - }, - { list, i, j, r -> - require(list != null) - - val k = j + if (i <= j) 1 else 0 - - val precondition = i >= 0 && list.size > i && j >= 0 && list.size > j + 1 && list[i] < list[k] - val postcondition = r.getOrNull() == list[i] - - precondition && postcondition - }, - { list, i, j, r -> - require(list != null) - - val k = j + if (i <= j) 1 else 0 - - val precondition = i >= 0 && list.size > i && j >= 0 && list.size > j + 1 && list[i] >= list[k] - val postcondition = r.getOrNull() == list[k] - - precondition && postcondition - }, - coverage = DoNotCalculate - ) - } - - @Test - fun createArrayWithDifferentTypeTest() { - check( - Lists::createWithDifferentType, - 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 - ) - } - - @Test - fun getElementsTest() { - check( - Lists::getElements, - eq(4), - { x, _ -> x == null }, - { 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 - ) - } - - @Test - fun setElementsTest() { - check( - Lists::setElements, - eq(3), - { 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 - ) - } - - @Test - fun testClear() { - check( - Lists::clear, - eq(3), - { list, _ -> list == null }, - { list, r -> list.size >= 2 && r == emptyList() }, - { list, r -> list.size < 2 && r == emptyList() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testAddAll() { - check( - Lists::addAll, - eq(3), - { list, _, _ -> list == null }, - { list, i, r -> - list != null && list.isEmpty() && r != null && r.size == 1 && r[0] == i - }, - { list, i, r -> - list != null && list.isNotEmpty() && r != null && r.size == 1 + list.size && r == listOf(i) + list - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testAddAllInIndex() { - check( - Lists::addAllByIndex, - eq(4), - { list, i, _ -> list == null && i >= 0 }, - { list, i, _ -> list == null && i < 0 }, - { list, i, r -> list != null && i >= list.size && r == list }, - { list, i, r -> - list != null && i in 0..list.lastIndex && r == list.toMutableList().apply { addAll(i, listOf(0, 1)) } - }, - coverage = DoNotCalculate - ) - } - - @Test - @Disabled("TODO: add choosing proper type in list wrapper") - fun testRemoveFromList() { - checkWithException( - Lists::removeFromList, - ge(4), - { list, _, r -> list == null && r.isException() }, - { list, _, r -> list != null && list.isEmpty() && r.isException() }, - { list, i, r -> - require(list != null && list.lastOrNull() != null) - - list.isNotEmpty() && (i < 0 || i >= list.size) && r.isException() - }, - { list, i, r -> - require(list != null && list.lastOrNull() != null) - - val changedList = list.toMutableList().apply { - set(i, last()) - removeLast() - } - - val precondition = list.isNotEmpty() && i >= 0 && i < list.size - val postcondition = changedList == r.getOrNull() - - precondition && postcondition - }, - // TODO: add branches with conditions (list is LinkedList) and (list !is ArrayList && list !is LinkedList) - coverage = DoNotCalculate - ) - } - -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapEntrySetTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapEntrySetTest.kt deleted file mode 100644 index 4c9bd82989..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapEntrySetTest.kt +++ /dev/null @@ -1,172 +0,0 @@ -package org.utbot.examples.collections - -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 - -// TODO failed Kotlin compilation SAT-1332 -class MapEntrySetTest : UtValueTestCaseChecker( - testClass = MapEntrySet::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - @Disabled("JIRA:1443") - fun testRemoveFromEntrySet() { - checkWithException( - MapEntrySet::removeFromEntrySet, - between(3..7), - { map, _, _, result -> map == null && result.isException() }, - { map, i, j, result -> map.entries.none { it.key == i && it.value == j } && result.getOrNull() == map }, - { map, i, j, result -> - val resultMap = result.getOrNull()!! - val mapContainsIJ = map.entries.any { it.key == i && it.value == j } - val mapContainsAllEntriesFromResult = map.entries.containsAll(resultMap.entries) - val resultDoesntContainIJ = - resultMap.entries.size == map.entries.size - 1 && resultMap.entries.none { it.key == i && it.value == j } - mapContainsIJ && mapContainsAllEntriesFromResult && resultDoesntContainIJ - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testAddToEntrySet() { - checkWithException( - MapEntrySet::addToEntrySet, - between(2..4), - { map, result -> map == null && result.isException() }, - { map, result -> map != null && result.isException() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetFromEntrySet() { - check( - MapEntrySet::getFromEntrySet, - between(3..7), - { 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 - ) - } - - @Test - fun testIteratorHasNext() { - check( - MapEntrySet::iteratorHasNext, - between(3..4), - { map, _ -> map == null }, - { map, result -> map.entries.isEmpty() && result == 0 }, - { map, result -> map.entries.isNotEmpty() && result == map.entries.size }, - coverage = DoNotCalculate - ) - } - - @Test - fun testIteratorNext() { - checkWithException( - MapEntrySet::iteratorNext, - between(3..5), - { 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 - { map, result -> - val resultEntry = result.getOrNull()!! - val (entryKey, entryValue) = map.entries.first() - val (resultKey, resultValue) = resultEntry - map.entries.isNotEmpty() && entryKey == resultKey && entryValue == resultValue - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testIteratorRemove() { - checkWithException( - MapEntrySet::iteratorRemove, - between(3..4), - { 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 - { map, result -> - val resultMap = result.getOrNull()!! - val mapContainsAllEntriesInResult = map.entries.containsAll(resultMap.entries) - val resultDoesntContainFirstEntry = - resultMap.entries.size == map.entries.size - 1 && map.entries.first() !in resultMap.entries - map.entries.isNotEmpty() && mapContainsAllEntriesInResult && resultDoesntContainFirstEntry - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testIteratorRemoveOnIndex() { - checkWithException( - MapEntrySet::iteratorRemoveOnIndex, - ge(5), - { _, i, result -> i == 0 && result.isSuccess && result.getOrNull() == null }, - { map, _, result -> map == null && result.isException() }, - { map, i, result -> map != null && i < 0 && result.isException() }, - { map, i, result -> i > map.entries.size && result.isException() }, - // test should work as long as default class for map is LinkedHashMap - { map, i, result -> - val resultMap = result.getOrNull()!! - val iInIndexRange = i in 0..map.entries.size - val mapContainsAllEntriesInResult = map.entries.containsAll(resultMap.entries) - val resultDoesntContainIthEntry = map.entries.toList()[i - 1] !in resultMap.entries - iInIndexRange && mapContainsAllEntriesInResult && resultDoesntContainIthEntry - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testIterateForEach() { - check( - MapEntrySet::iterateForEach, - between(3..5), - { map, _ -> map == null }, - { map, _ -> null in map.values }, - { map, result -> result!![0] == map.keys.sum() && result[1] == map.values.sum() }, - coverage = DoNotCalculate - ) - } - - - @Test - fun testIterateWithIterator() { - withPushingStateFromPathSelectorForConcrete { - checkWithException( - MapEntrySet::iterateWithIterator, - ignoreExecutionsNumber, - { map, result -> map == null && result.isException() }, - { map, result -> map.isEmpty() && result.getOrThrow().contentEquals(intArrayOf(0, 0)) }, - { map, result -> map.size % 2 == 1 && result.isException() }, - { map, result -> - val evenEntryHasNullKey = map.keys.indexOf(null) % 2 == 0 - evenEntryHasNullKey && result.isException() - }, - { map, result -> - val twoElementsOrMore = map.size > 1 - val oddEntryHasNullKey = map.values.indexOf(null) % 2 == 1 - twoElementsOrMore && oddEntryHasNullKey && result.isException() - }, - { 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 } - mapIsNotEmptyAndSizeIsEven && arrayResult[0] == evenKeysSum && arrayResult[1] == oddValuesSum - }, - ) - } - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapKeySetTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapKeySetTest.kt deleted file mode 100644 index 92aa202c2e..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapKeySetTest.kt +++ /dev/null @@ -1,161 +0,0 @@ -package org.utbot.examples.collections - -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.testcheckers.withPushingStateFromPathSelectorForConcrete -import org.utbot.testcheckers.withoutMinimization - -// TODO failed Kotlin compilation SAT-1332 -class MapKeySetTest : UtValueTestCaseChecker( - testClass = MapKeySet::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testRemoveFromKeySet() { - withoutMinimization { // TODO: JIRA:1506 - checkWithException( - MapKeySet::removeFromKeySet, - ignoreExecutionsNumber, - { map, _, result -> map == null && result.isException() }, - { map, i, result -> i !in map.keys && result.getOrNull() == map }, // one of these will be minimized - { map, i, result -> // one of these will be minimized - val resultMap = result.getOrNull()!! - val mapKeysContainsI = i in map.keys - val mapContainsAllKeysInResult = map.keys.containsAll(resultMap.keys) - val resultDoesntContainI = resultMap.keys.size == map.keys.size - 1 && i !in resultMap.keys - mapKeysContainsI && mapContainsAllKeysInResult && resultDoesntContainI - }, - ) - } - } - - @Test - fun testAddToKeySet() { - checkWithException( - MapKeySet::addToKeySet, - between(2..4), - { map, result -> map == null && result.isException() }, - { map, result -> map != null && result.isException() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetFromKeySet() { - withoutMinimization { // TODO: JIRA:1506 - check( - MapKeySet::getFromKeySet, - ignoreExecutionsNumber, // branches with null keys may appear - { 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 - ) - } - } - - @Test - fun testIteratorHasNext() { - check( - MapKeySet::iteratorHasNext, - between(3..4), - { map, _ -> map == null }, - { map, result -> map.keys.isEmpty() && result == 0 }, - { map, result -> map.keys.isNotEmpty() && result == map.keys.size }, - coverage = DoNotCalculate - ) - } - - @Test - fun testIteratorNext() { - withPushingStateFromPathSelectorForConcrete { - checkWithException( - MapKeySet::iteratorNext, - between(3..4), - { 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 - ) - } - } - - @Test - fun testIteratorRemove() { - checkWithException( - MapKeySet::iteratorRemove, - between(3..4), - { 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 -> - val resultMap = result.getOrNull()!! - val mapContainsAllKeysInResult = map.keys.isNotEmpty() && map.keys.containsAll(resultMap.keys) - val resultDoesntContainFirstKey = resultMap.keys.size == map.keys.size - 1 && map.keys.first() !in resultMap.keys - mapContainsAllKeysInResult && resultDoesntContainFirstKey - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testIteratorRemoveOnIndex() { - checkWithException( - MapKeySet::iteratorRemoveOnIndex, - ge(5), - { _, i, result -> i == 0 && result.isSuccess && result.getOrNull() == null }, - { map, _, result -> map == null && result.isException() }, - { map, i, result -> map != null && i < 0 && result.isException() }, - { map, i, result -> i > map.keys.size && result.isException() }, - // test should work as long as default class for map is LinkedHashMap - { map, i, result -> - val resultMap = result.getOrNull()!! - val iInIndexRange = i in 0..map.keys.size - val mapContainsAllKeysInResult = map.keys.containsAll(resultMap.keys) - val resultDoesntContainIthKey = map.keys.toList()[i - 1] !in resultMap.keys - iInIndexRange && mapContainsAllKeysInResult && resultDoesntContainIthKey - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testIterateForEach() { - check( - MapKeySet::iterateForEach, - ignoreExecutionsNumber, - { map, _ -> map == null }, - { map, _ -> map != null && null in map.keys }, - { map, result -> map != null && result == map.keys.sum() }, - ) - } - - @Test - fun testIterateWithIterator() { - check( - MapKeySet::iterateWithIterator, - ignoreExecutionsNumber, - { map, _ -> map == null }, - { map, _ -> map != null && null in map.keys }, - { map, result -> map != null && result == map.keys.sum() }, - ) - } - - @Test - fun testNullKey() { - check( - MapKeySet::nullKey, - eq(3), - { map, _ -> map == null }, - { map, result -> map != null && null in map.keys && map[null] == result }, - { map, _ -> map != null && null !in map.keys } - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapValuesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapValuesTest.kt deleted file mode 100644 index cd92dfb0b8..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapValuesTest.kt +++ /dev/null @@ -1,179 +0,0 @@ -package org.utbot.examples.collections - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.ge -import org.utbot.testcheckers.withoutMinimization - -// TODO failed Kotlin compilation SAT-1332 -class MapValuesTest : UtValueTestCaseChecker( - testClass = MapValues::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testRemoveFromValues() { - withoutMinimization { // TODO: JIRA:1506 - checkWithException( - MapValues::removeFromValues, - ignoreExecutionsNumber, - { map, _, result -> map == null && result.isException() }, - { map, i, result -> i !in map.values && result.getOrNull() == map }, - { map, i, result -> - val resultMap = result.getOrNull()!! - - val iInMapValues = i in map.values - val iWasDeletedFromValues = - resultMap.values.filter { it == i }.size == map.values.filter { it == i }.size - 1 - - val firstKeyAssociatedWithI = map.keys.first { map[it] == i } - val firstKeyAssociatedWIthIWasDeleted = firstKeyAssociatedWithI !in resultMap.keys - - val getCountExceptI: Collection.() -> Map = - { this.filter { it != i }.filterNotNull().groupingBy { it }.eachCount() } - val mapContainsAllValuesFromResult = - map.values.getCountExceptI() == resultMap.values.getCountExceptI() - - iInMapValues && iWasDeletedFromValues && firstKeyAssociatedWIthIWasDeleted && mapContainsAllValuesFromResult - }, - ) - } - } - - @Test - fun testAddToValues() { - checkWithException( - MapValues::addToValues, - between(2..4), - { map, result -> map == null && result.isException() }, - { map, result -> map != null && result.isException() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetFromValues() { - withoutMinimization { - check( - MapValues::getFromValues, - ignoreExecutionsNumber, - { map, _, _ -> map == null }, - { map, i, result -> i !in map.values && result == 1 }, - { map, i, result -> i in map.values && result == 1 }, - coverage = AtLeast(90) // unreachable else branch in MUT - ) - } - } - - @Test - fun testIteratorHasNext() { - check( - MapValues::iteratorHasNext, - between(3..4), - { map, _ -> map == null }, - { map, result -> map.values.isEmpty() && result == 0 }, - { map, result -> map.values.isNotEmpty() && result == map.values.size }, - coverage = DoNotCalculate - ) - } - - @Test - fun testIteratorNext() { - checkWithException( - MapValues::iteratorNext, - between(3..4), - { 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 - // { map, result -> map != null && map.values.isEmpty() && result.isException() }, - { map, result -> map != null && map.values.first() == null && result.isException() }, - // as map is LinkedHashmap by default this matcher would be correct - { map, result -> map != null && map.values.isNotEmpty() && result.getOrNull() == map.values.first() }, - ) - } - - @Test - fun testIteratorRemove() { - checkWithException( - MapValues::iteratorRemove, - between(3..4), - { 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 - { map, result -> - val resultMap = result.getOrNull()!! - val firstValue = map.values.first() - - val getCountsExceptFirstValue: Collection.() -> Map = - { this.filter { it != firstValue }.filterNotNull().groupingBy { it }.eachCount() } - val mapContainsAllValuesFromResult = - map.values.getCountsExceptFirstValue() == resultMap.values.getCountsExceptFirstValue() - - val firstValueWasDeleted = - resultMap.values.filter { it == firstValue }.size == map.values.filter { it == firstValue }.size - 1 - - val keyAssociatedWithFirstValueWasDeleted = - map.keys.first { map[it] == firstValue } !in resultMap.keys - - mapContainsAllValuesFromResult && firstValueWasDeleted && keyAssociatedWithFirstValueWasDeleted - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testIteratorRemoveOnIndex() { - checkWithException( - MapValues::iteratorRemoveOnIndex, - ge(5), - { _, i, result -> i == 0 && result.isSuccess && result.getOrNull() == null }, - { map, _, result -> map == null && result.isException() }, - { map, i, result -> map != null && i < 0 && result.isException() }, - { map, i, result -> i > map.values.size && result.isException() }, - { map, i, result -> - val iInIndexRange = i in 1..map.size - val ithValue = map.values.toList()[i - 1] - val resultMap = result.getOrNull()!! - - val getCountsExceptIthValue: Collection.() -> Map = - { this.filter { it != ithValue }.filterNotNull().groupingBy { it }.eachCount() } - val mapContainsAllValuesFromResult = - map.values.getCountsExceptIthValue() == resultMap.values.getCountsExceptIthValue() - val ithValueWasDeleted = - resultMap.values.filter { it == ithValue }.size == map.values.filter { it == ithValue }.size - 1 - val keyAssociatedWIthIthValueWasDeleted = - map.keys.filter { map[it] == ithValue }.any { it !in resultMap.keys } - - iInIndexRange && mapContainsAllValuesFromResult && ithValueWasDeleted && keyAssociatedWIthIthValueWasDeleted - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testIterateForEach() { - check( - MapValues::iterateForEach, - between(3..5), - { map, _ -> map == null }, - { map, _ -> null in map.values }, - { map, result -> map != null && result == map.values.sum() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testIterateWithIterator() { - check( - MapValues::iterateWithIterator, - between(3..5), - { 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-testing/src/test/kotlin/org/utbot/examples/collections/MapsPart1Test.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapsPart1Test.kt deleted file mode 100644 index 4f73aec84b..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapsPart1Test.kt +++ /dev/null @@ -1,382 +0,0 @@ -package org.utbot.examples.collections - -import org.junit.jupiter.api.Tag -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.withoutMinimization - -// TODO failed Kotlin compilation ($ in names, generics) SAT-1220 SAT-1332 -internal class MapsPart1Test : UtValueTestCaseChecker( - testClass = Maps::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testPutElementIfAbsent() { - withoutMinimization { // TODO: JIRA:1506 - check( - Maps::putElementIfAbsent, - ignoreExecutionsNumber, - { map, _, _, _ -> map == null }, - { 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 - }, - coverage = AtLeast(90) // unreachable else branch in MUT - ) - } - } - - @Test - fun testReplaceEntry() { - check( - Maps::replaceEntry, - between(3..6), - { 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 - }, - coverage = DoNotCalculate - ) - } - - @Test - fun createTest() { - check( - Maps::create, - 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, 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 { - 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 }, - ) - } - } - - // 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 - ) - } - } - - @Test - fun testFindAllChars() { - check( - Maps::countChars, - eq(3), - { s, _ -> s == null }, - { s, result -> s == "" && result!!.isEmpty() }, - { s, result -> s != "" && result == s.groupingBy { it }.eachCount() }, - coverage = DoNotCalculate - ) - } - - @Test - fun putElementsTest() { - check( - Maps::putElements, - ge(5), - { 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() - && result == map.toMutableMap().apply { putAll(array.map { it to it }) } - }, - coverage = DoNotCalculate - ) - } - - @Test - fun removeEntries() { - check( - Maps::removeElements, - ge(6), - { 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 - ) - } - - @Test - fun createWithDifferentTypeTest() { - check( - Maps::createWithDifferentType, - 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 - ) - } - - @Test - fun removeCustomObjectTest() { - check( - Maps::removeCustomObject, - ge(3), - { 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 - ) - } - - @Test - @Tag("slow") // it takes about 20 minutes to execute this test - fun testMapOperator() { - withPushingStateFromPathSelectorForConcrete { - check( - Maps::mapOperator, - ignoreExecutionsNumber - ) - } - } - - @Test - fun testComputeValue() { - check( - Maps::computeValue, - between(3..5), - { 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 - }, - { 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 - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testComputeValueWithMocks() { - check( - Maps::computeValue, - between(3..5), - { 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 - }, - { 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 - }, - mockStrategy = MockStrategyApi.OTHER_PACKAGES, // checks that we do not generate mocks for lambda classes - coverage = DoNotCalculate - ) - } - - @Test - fun testComputeValueIfAbsent() { - check( - Maps::computeValueIfAbsent, - between(3..5), - { 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 - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testComputeValueIfPresent() { - check( - Maps::computeValueIfPresent, - between(3..5), - { 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 - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testClearEntries() { - check( - Maps::clearEntries, - between(3..4), - { map, _ -> map == null }, - { map, result -> map.isEmpty() && result == 0 }, - { map, result -> map.isNotEmpty() && result == 1 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testContainsKey() { - check( - Maps::containsKey, - between(3..5), - { map, _, _ -> map == null }, - { map, key, result -> key !in map && result == 0 }, - { map, key, result -> key in map && result == 1 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testContainsValue() { - check( - Maps::containsValue, - between(3..6), - { map, _, _ -> map == null }, - { map, value, result -> value !in map.values && result == 0 }, - { map, value, result -> value in map.values && result == 1 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetOrDefaultElement() { - check( - Maps::getOrDefaultElement, - between(4..6), - { 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 - ) - } - - @Test - fun testRemoveKeyWithValue() { - check( - Maps::removeKeyWithValue, - ge(6), - { 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 - ) - } - - @Test - fun testReplaceAllEntries() { - check( - Maps::replaceAllEntries, - between(5..6), - { map, _ -> map == null }, - { map, result -> map.isEmpty() && result == null }, - { map, _ -> map.isNotEmpty() && map.containsValue(null) }, - { map, result -> - val precondition = map.isNotEmpty() && !map.containsValue(null) - val firstBranchInLambdaExists = map.entries.any { it.key > it.value } - val valuesWereReplaced = - result == map.mapValues { if (it.key > it.value) it.value + 1 else it.value - 1 } - precondition && firstBranchInLambdaExists && valuesWereReplaced - }, - { map, result -> - val precondition = map.isNotEmpty() && !map.containsValue(null) - val secondBranchInLambdaExists = map.entries.any { it.key <= it.value } - val valuesWereReplaced = - 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() } - ) - } - } - @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 } - ) - } - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapsPart2Test.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapsPart2Test.kt deleted file mode 100644 index 12a0c585e4..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/MapsPart2Test.kt +++ /dev/null @@ -1,87 +0,0 @@ -package org.utbot.examples.collections - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.ge -import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete -import org.utbot.testcheckers.withoutMinimization - -// TODO failed Kotlin compilation ($ in names, generics) SAT-1220 SAT-1332 -internal class MapsPart2Test : UtValueTestCaseChecker( - testClass = Maps::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testReplaceEntryWithValue() { - withPushingStateFromPathSelectorForConcrete { - check( - Maps::replaceEntryWithValue, - ge(6), - { 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 - ) - } - } - - @Test - fun testMerge() { - withoutMinimization { // TODO: JIRA:1506 - checkWithException( - Maps::merge, - ge(5), - { map, _, _, result -> map == null && result.isException() }, - { map, _, value, result -> map != null && value == null && result.isException() }, - { map, key, value, result -> - val resultMap = result.getOrNull()!! - val entryWasPut = resultMap.entries.all { it.key == key && it.value == value || it in map.entries } - key !in map && value != null && entryWasPut - }, - { map, key, value, result -> - val resultMap = result.getOrNull()!! - val valueInMapIsNull = key in map && map[key] == null - val valueWasReplaced = resultMap[key] == value - val otherValuesWerentTouched = resultMap.entries.all { it.key == key || it in map.entries } - value != null && valueInMapIsNull && valueWasReplaced && otherValuesWerentTouched - }, - { map, key, value, result -> - val resultMap = result.getOrNull()!! - val valueInMapIsNotNull = map[key] != null - val valueWasMerged = resultMap[key] == map[key]!! + value - val otherValuesWerentTouched = resultMap.entries.all { it.key == key || it in map.entries } - value != null && valueInMapIsNotNull && valueWasMerged && otherValuesWerentTouched - }, - coverage = DoNotCalculate - ) - } - } - - @Test - fun testPutAllEntries() { - withPushingStateFromPathSelectorForConcrete { - check( - Maps::putAllEntries, - ge(5), - { map, _, _ -> map == null }, - { map, other, _ -> map != null && other == null }, - { map, other, result -> map != null && other != null && map.keys.containsAll(other.keys) && result == 0 }, - { map, other, result -> map != null && other != null && other.keys.all { it !in map.keys } && result == 1 }, - { map, other, result -> - val notNull = map != null && other != null - val mapContainsAtLeastOneKeyOfOther = other.keys.any { it in map.keys } - val mapDoesNotContainAllKeysOfOther = !map.keys.containsAll(other.keys) - notNull && mapContainsAtLeastOneKeyOfOther && mapDoesNotContainAllKeysOfOther && result == 2 - }, - coverage = DoNotCalculate - ) - } - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt deleted file mode 100644 index fab2ca1d57..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt +++ /dev/null @@ -1,489 +0,0 @@ -package org.utbot.examples.collections - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import java.util.* - -class OptionalsTest : UtValueTestCaseChecker( - Optionals::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - - - @Test - fun testCreate() { - checkWithException( - Optionals::create, - eq(2), - { value, result -> value == null && result.isException() }, - { value, result -> value != null && result.getOrNull()!!.get() == value }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCreateInt() { - check( - Optionals::createInt, - eq(1), - { value, result -> result!!.asInt == value }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCreateLong() { - check( - Optionals::createLong, - eq(1), - { value, result -> result!!.asLong == value }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCreateDouble() { - check( - Optionals::createDouble, - eq(1), - { value, result -> result!!.asDouble == value || result.asDouble.isNaN() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCreateNullable() { - checkStatics( - Optionals::createNullable, - eq(2), - { value, _, result -> value == null && result === Optional.empty() }, - { value, _, result -> value != null && result!!.get() == value }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCreateEmpty() { - checkStatics( - Optionals::createEmpty, - eq(1), - { _, result -> result === Optional.empty() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCreateIntEmpty() { - checkStatics( - Optionals::createIntEmpty, - eq(1), - { _, result -> result === OptionalInt.empty() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCreateLongEmpty() { - checkStatics( - Optionals::createLongEmpty, - eq(1), - { _, result -> result === OptionalLong.empty() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCreateDoubleEmpty() { - checkStatics( - Optionals::createDoubleEmpty, - eq(1), - { _, result -> result === OptionalDouble.empty() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetValue() { - checkStatics( - Optionals::getValue, - eq(3), - { optional, _, _ -> optional == null }, - { optional, _, result -> optional != null && optional === Optional.empty() && result == null }, - { optional, _, result -> optional != null && result == optional.get() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetIntValue() { - checkStatics( - Optionals::getIntValue, - eq(3), - { optional, _, _ -> optional == null }, - { optional, _, result -> optional != null && optional === OptionalInt.empty() && result == null }, - { optional, _, result -> optional != null && result == optional.asInt }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetLongValue() { - checkStatics( - Optionals::getLongValue, - eq(3), - { optional, _, _ -> optional == null }, - { optional, _, result -> optional != null && optional === OptionalLong.empty() && result == null }, - { optional, _, result -> optional != null && result == optional.asLong }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetDoubleValue() { - checkStatics( - Optionals::getDoubleValue, - eq(3), - { optional, _, _ -> optional == null }, - { optional, _, result -> optional != null && optional === OptionalDouble.empty() && result == null }, - { optional, _, result -> optional != null && result == optional.asDouble }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetWithIsPresent() { - checkStatics( - Optionals::getWithIsPresent, - eq(3), - { optional, _, _ -> optional == null }, - { optional, _, result -> optional === Optional.empty() && result == null }, - { optional, _, result -> optional.get() == result }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCountIfPresent() { - checkStatics( - Optionals::countIfPresent, - eq(3), - { optional, _, _ -> optional == null }, - { optional, _, result -> optional === Optional.empty() && result == 0 }, - { optional, _, result -> optional.get() == result }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCountIntIfPresent() { - checkStatics( - Optionals::countIntIfPresent, - ignoreExecutionsNumber, - { optional, _, _ -> optional == null }, - { optional, _, result -> optional === OptionalInt.empty() && result == 0 }, - { optional, _, result -> optional.asInt == result }, - ) - } - - @Test - fun testCountLongIfPresent() { - checkStatics( - Optionals::countLongIfPresent, - ignoreExecutionsNumber, - { optional, _, _ -> optional == null }, - { optional, _, result -> optional === OptionalLong.empty() && result == 0L }, - { optional, _, result -> optional.asLong == result }, - ) - } - - @Test - fun testCountDoubleIfPresent() { - checkStatics( - Optionals::countDoubleIfPresent, - ignoreExecutionsNumber, - { optional, _, _ -> optional == null }, - { optional, _, result -> optional === OptionalDouble.empty() && result == 0.0 }, - { optional, _, result -> optional.asDouble == result }, - ) - } - - @Test - fun testFilterLessThanZero() { - checkStatics( - Optionals::filterLessThanZero, - eq(4), - { optional, _, _ -> optional == null }, - { optional, _, result -> optional === Optional.empty() && result === optional }, - { optional, _, result -> optional.get() >= 0 && result == optional }, - { optional, _, result -> optional.get() < 0 && result === Optional.empty() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testAbsNotNull() { - checkStatics( - Optionals::absNotNull, - eq(4), - { optional, _, _ -> optional == null }, - { optional, _, result -> optional === Optional.empty() && result === optional }, - { optional, _, result -> optional.get() < 0 && result!!.get() == -optional.get() }, - { optional, _, result -> optional.get() >= 0 && result == optional }, - coverage = DoNotCalculate - ) - } - - @Test - fun testMapLessThanZeroToNull() { - checkStatics( - Optionals::mapLessThanZeroToNull, - eq(4), - { optional, _, _ -> optional == null }, - { optional, _, result -> optional === Optional.empty() && result === optional }, - { optional, _, result -> optional.get() < 0 && result === Optional.empty() }, - { optional, _, result -> optional.get() >= 0 && result == optional }, - coverage = DoNotCalculate - ) - } - - @Test - fun testFlatAbsNotNull() { - checkStatics( - Optionals::flatAbsNotNull, - eq(4), - { optional, _, _ -> optional == null }, - { optional, _, result -> optional === Optional.empty() && result === optional }, - { optional, _, result -> optional.get() < 0 && result!!.get() == -optional.get() }, - { optional, _, result -> optional.get() >= 0 && result == optional }, - coverage = DoNotCalculate - ) - } - - @Test - fun testFlatMapWithNull() { - checkStatics( - Optionals::flatMapWithNull, - eq(5), - { optional, _, _ -> optional == null }, - { optional, _, result -> optional === Optional.empty() && result === optional }, - { optional, _, result -> optional.get() < 0 && result === Optional.empty() }, - { optional, _, result -> optional.get() > 0 && result == optional }, - { optional, _, result -> optional.get() == 0 && result == null }, - coverage = DoNotCalculate - ) - } - - @Test - fun testLeftOrElseRight() { - checkStatics( - Optionals::leftOrElseRight, - eq(3), - { left, _, _, _ -> left == null }, - { left, right, _, result -> left === Optional.empty() && result == right }, - { left, _, _, result -> left.isPresent && result == left.get() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testLeftIntOrElseRight() { - checkStatics( - Optionals::leftIntOrElseRight, - eq(3), - { left, _, _, _ -> left == null }, - { left, right, _, result -> left === OptionalInt.empty() && result == right }, - { left, _, _, result -> left.isPresent && result == left.asInt }, - coverage = DoNotCalculate - ) - } - - - @Test - fun testLeftLongOrElseRight() { - checkStatics( - Optionals::leftLongOrElseRight, - eq(3), - { left, _, _, _ -> left == null }, - { left, right, _, result -> left === OptionalLong.empty() && result == right }, - { left, _, _, result -> left.isPresent && result == left.asLong }, - coverage = DoNotCalculate - ) - } - - - @Test - fun testLeftDoubleOrElseRight() { - checkStatics( - Optionals::leftDoubleOrElseRight, - eq(3), - { left, _, _, _ -> left == null }, - { left, right, _, result -> left === OptionalDouble.empty() && (result == right || result!!.isNaN() && right.isNaN()) }, - { left, _, _, result -> left.isPresent && (result == left.asDouble || result!!.isNaN() && left.asDouble.isNaN()) }, - coverage = DoNotCalculate - ) - } - - - @Test - fun testLeftOrElseGetOne() { - checkStatics( - Optionals::leftOrElseGetOne, - eq(3), - { left, _, _ -> left == null }, - { left, _, result -> left === Optional.empty() && result == 1 }, - { left, _, result -> left.isPresent && result == left.get() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testLeftIntOrElseGetOne() { - checkStatics( - Optionals::leftIntOrElseGetOne, - eq(3), - { left, _, _ -> left == null }, - { left, _, result -> left === OptionalInt.empty() && result == 1 }, - { left, _, result -> left.isPresent && result == left.asInt }, - coverage = DoNotCalculate - ) - } - - @Test - fun testLeftLongOrElseGetOne() { - checkStatics( - Optionals::leftLongOrElseGetOne, - eq(3), - { left, _, _ -> left == null }, - { left, _, result -> left === OptionalLong.empty() && result == 1L }, - { left, _, result -> left.isPresent && result == left.asLong }, - coverage = DoNotCalculate - ) - } - - @Test - fun testLeftDoubleOrElseGetOne() { - checkStatics( - Optionals::leftDoubleOrElseGetOne, - eq(3), - { left, _, _ -> left == null }, - { left, _, result -> left === OptionalDouble.empty() && result == 1.0 }, - { left, _, result -> left.isPresent && result == left.asDouble }, - coverage = DoNotCalculate - ) - } - - @Test - fun testLeftOrElseThrow() { - checkStatics( - Optionals::leftOrElseThrow, - eq(3), - { left, _, _ -> left == null }, - { left, _, result -> left === Optional.empty() && result == null }, - { left, _, result -> left.isPresent && result == left.get() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testLeftIntOrElseThrow() { - checkStatics( - Optionals::leftIntOrElseThrow, - eq(3), - { left, _, _ -> left == null }, - { left, _, result -> left === OptionalInt.empty() && result == null }, - { left, _, result -> left.isPresent && result == left.asInt }, - coverage = DoNotCalculate - ) - } - - @Test - fun testLeftLongOrElseThrow() { - checkStatics( - Optionals::leftLongOrElseThrow, - eq(3), - { left, _, _ -> left == null }, - { left, _, result -> left === OptionalLong.empty() && result == null }, - { left, _, result -> left.isPresent && result == left.asLong }, - coverage = DoNotCalculate - ) - } - - @Test - fun testLeftDoubleOrElseThrow() { - checkStatics( - Optionals::leftDoubleOrElseThrow, - eq(3), - { left, _, _ -> left == null }, - { left, _, result -> left === OptionalDouble.empty() && result == null }, - { left, _, result -> left.isPresent && result == left.asDouble }, - coverage = DoNotCalculate - ) - } - - @Test - fun testEqualOptionals() { - check( - Optionals::equalOptionals, - between(4..7), - { left, _, result -> left == null && result == null }, - { left, right, result -> left != null && left != right && !result!! }, - { left, right, result -> left != null && left === right && !left.isPresent && !right.isPresent && result!! }, - { left, right, result -> left != null && left == right && left.isPresent && right.isPresent && result!! }, - coverage = DoNotCalculate - ) - } - - @Test - fun testEqualOptionalsInt() { - check( - Optionals::equalOptionalsInt, - between(4..8), - { left, _, result -> left == null && result == null }, - { left, right, result -> left != null && left != right && !result!! }, - { left, right, result -> left != null && left === right && !left.isPresent && !right.isPresent && result!! }, - { left, right, result -> left != null && left == right && left.isPresent && right.isPresent && result!! }, - coverage = DoNotCalculate - ) - } - - @Test - fun testEqualOptionalsLong() { - check( - Optionals::equalOptionalsLong, - between(4..8), - { left, _, result -> left == null && result == null }, - { left, right, result -> left != null && left != right && !result!! }, - { left, right, result -> left != null && left === right && !left.isPresent && !right.isPresent && result!! }, - { left, right, result -> left != null && left == right && left.isPresent && right.isPresent && result!! }, - coverage = DoNotCalculate - ) - } - - @Test - fun testEqualOptionalsDouble() { - check( - Optionals::equalOptionalsDouble, - between(4..8), - { left, _, result -> left == null && result == null }, - { left, right, result -> left != null && left != right && !result!! }, - { left, right, result -> left != null && left === right && !left.isPresent && !right.isPresent && result!! }, - { left, right, result -> left != null && left == right && left.isPresent && right.isPresent && result!! }, - coverage = DoNotCalculate - ) - } - - @Test - fun testOptionalOfPositive() { - check( - Optionals::optionalOfPositive, - eq(2), - { value, result -> value > 0 && result != null && result.isPresent && result.get() == value }, - { value, result -> value <= 0 && result != null && !result.isPresent } - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/QueueUsagesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/QueueUsagesTest.kt deleted file mode 100644 index 8822b05365..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/QueueUsagesTest.kt +++ /dev/null @@ -1,127 +0,0 @@ -package org.utbot.examples.collections - -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq -import org.utbot.testing.CodeGeneration -import org.utbot.testing.UtValueTestCaseChecker -import org.utbot.testing.isException - -class QueueUsagesTest : UtValueTestCaseChecker( - testClass = QueueUsages::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testCreateArrayDeque() { - checkWithException( - QueueUsages::createArrayDeque, - eq(3), - { init, next, r -> init == null && next == null && r.isException() }, - { init, next, r -> init != null && next == null && r.isException() }, - { init, next, r -> init != null && next != null && r.getOrNull() == 2 }, - ) - } - - @Test - fun testCreateLinkedList() { - checkWithException( - QueueUsages::createLinkedList, - eq(1), - { _, _, r -> r.getOrNull()!! == 2 }, - ) - } - - @Test - fun testCreateLinkedBlockingDeque() { - checkWithException( - QueueUsages::createLinkedBlockingDeque, - eq(3), - { init, next, r -> init == null && next == null && r.isException() }, - { init, next, r -> init != null && next == null && r.isException() }, - { init, next, r -> init != null && next != null && r.getOrNull() == 2 }, - ) - } - - @Test - fun testContainsQueue() { - checkWithException( - QueueUsages::containsQueue, - eq(3), - { q, _, r -> q == null && r.isException() }, - { q, x, r -> x in q && r.getOrNull() == 1 }, - { q, x, r -> x !in q && r.getOrNull() == 0 }, - ) - } - - @Test - fun testAddQueue() { - checkWithException( - QueueUsages::addQueue, - eq(3), - { q, _, r -> q == null && r.isException() }, - { q, x, r -> q != null && x in r.getOrNull()!! }, - { q, x, r -> q != null && x == null && r.isException() }, ) - } - - @Test - fun testAddAllQueue() { - checkWithException( - QueueUsages::addAllQueue, - eq(3), - { q, _, r -> q == null && r.isException() }, - { q, x, r -> q != null && x in r.getOrNull()!! }, // we can cover this line with x == null or x != null - { q, x, r -> q != null && x == null && r.isException() }, - ) - } - - @Test - fun testCastQueueToDeque() { - check( - QueueUsages::castQueueToDeque, - eq(2), - { q, r -> q !is java.util.Deque<*> && r == null }, - { q, r -> q is java.util.Deque<*> && r is java.util.Deque<*> }, - ) - } - - @Test - fun testCheckSubtypesOfQueue() { - check( - QueueUsages::checkSubtypesOfQueue, - eq(4), - { q, r -> q == null && r == 0 }, - { q, r -> q is java.util.LinkedList<*> && r == 1 }, - { q, r -> q is java.util.ArrayDeque<*> && r == 2 }, - { q, r -> q !is java.util.LinkedList<*> && q !is java.util.ArrayDeque && r == 3 } - ) - } - - @Test - @Disabled("TODO: Related to https://github.com/UnitTestBot/UTBotJava/issues/820") - fun testCheckSubtypesOfQueueWithUsage() { - check( - QueueUsages::checkSubtypesOfQueueWithUsage, - eq(4), - { q, r -> q == null && r == 0 }, - { q, r -> q is java.util.LinkedList<*> && r == 1 }, - { q, r -> q is java.util.ArrayDeque<*> && r == 2 }, - { q, r -> q !is java.util.LinkedList<*> && q !is java.util.ArrayDeque && r == 3 } // this is uncovered - ) - } - - @Test - fun testAddConcurrentLinkedQueue() { - checkWithException( - QueueUsages::addConcurrentLinkedQueue, - eq(3), - { q, _, r -> q == null && r.isException() }, - { q, x, r -> q != null && x != null && x in r.getOrNull()!! }, - { q, x, r -> q != null && x == null && r.isException() }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/SetIteratorsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/SetIteratorsTest.kt deleted file mode 100644 index 21c9945b94..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/SetIteratorsTest.kt +++ /dev/null @@ -1,98 +0,0 @@ -package org.utbot.examples.collections - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.ge - -// TODO failed Kotlin compilation SAT-1332 -class SetIteratorsTest : UtValueTestCaseChecker( - testClass = SetIterators::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testIteratorHasNext() { - check( - SetIterators::iteratorHasNext, - between(3..4), - { set, _ -> set == null }, - { set, result -> set.isEmpty() && result == 0 }, - { set, result -> set.isNotEmpty() && result == set.size }, - ) - } - - @Test - fun testIteratorNext() { - checkWithException( - SetIterators::iteratorNext, - between(3..4), - { 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 - { set, result -> set != null && set.isNotEmpty() && result.getOrNull() == set.first() }, - ) - } - - @Test - fun testIteratorRemove() { - checkWithException( - SetIterators::iteratorRemove, - between(3..4), - { set, result -> set == null && result.isException() }, - { set, result -> set.isEmpty() && result.isException() }, - // test should work as long as default class for set is LinkedHashSet - { set, result -> - val firstElement = set.first() - val resultSet = result.getOrNull()!! - val resultDoesntContainFirstElement = resultSet.size == set.size - 1 && firstElement !in resultSet - set.isNotEmpty() && set.containsAll(resultSet) && resultDoesntContainFirstElement - }, - ) - } - - @Test - fun testIteratorRemoveOnIndex() { - checkWithException( - SetIterators::iteratorRemoveOnIndex, - ge(5), - { _, i, result -> i == 0 && result.isSuccess && result.getOrNull() == null }, - { set, _, result -> set == null && result.isException() }, - { set, i, result -> set != null && i < 0 && result.isException() }, - { set, i, result -> i > set.size && result.isException() }, - // test should work as long as default class for set is LinkedHashSet - { set, i, result -> - val ithElement = set.toList()[i - 1] - val resultSet = result.getOrNull()!! - val iInIndexRange = i in 0..set.size - val resultDoesntContainIthElement = resultSet.size == set.size - 1 && ithElement !in resultSet - iInIndexRange && set.containsAll(resultSet) && resultDoesntContainIthElement - }, - ) - } - - @Test - fun testIterateForEach() { - check( - SetIterators::iterateForEach, - ignoreExecutionsNumber, - { set, _ -> set == null }, - { set, _ -> set != null && null in set }, - { set, result -> set != null && result == set.sum() }, - ) - } - - - @Test - fun testIterateWithIterator() { - check( - SetIterators::iterateWithIterator, - ignoreExecutionsNumber, - { set, _ -> set == null }, - { set, _ -> set != null && null in set }, - { set, result -> set != null && result == set.sum() }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/SetsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/collections/SetsTest.kt deleted file mode 100644 index 4e368f8085..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/collections/SetsTest.kt +++ /dev/null @@ -1,239 +0,0 @@ -package org.utbot.examples.collections - -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 - -// TODO failed Kotlin compilation SAT-1332 -internal class SetsTest : UtValueTestCaseChecker( - testClass = Sets::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun createTest() { - check( - Sets::create, - 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()) }, - ) - } - - @Test - fun testSetContainsInteger() { - check( - Sets::setContainsInteger, - ignoreExecutionsNumber, - { set, _, _, _ -> set == null }, - { set, a, _, r -> 1 + a in set && r != null && 1 + a !in r && set.remove(1 + a) && r == set }, - { set, a, _, r -> 1 + a !in set && set.isEmpty() && r == null }, - { set, a, b, r -> 1 + a !in set && set.isNotEmpty() && r != null && r == set && 4 + a + b !in r }, - ) - } - - @Test - @Disabled("Does not find positive branches JIRA:1529") - fun testSetContains() { - check( - Sets::setContains, - eq(-1), - ) - } - - @Test - fun testSimpleContains() { - check( - Sets::simpleContains, - ignoreExecutionsNumber, - { set, _ -> set == null }, - { set, r -> set != null && "aaa" in set && r == true }, - { set, r -> set != null && "aaa" !in set && r == false } - ) - } - - @Test - @Disabled("Same problem from testSetContains JIRA:1529") - fun testMoreComplicatedContains() { - check( - Sets::moreComplicatedContains, - eq(-1), // TODO how many branches do we have? - ) - } - - - @Test - fun testFindAllChars() { - check( - Sets::findAllChars, - eq(3), - { s, _ -> s == null }, - { s, result -> s == "" && result!!.isEmpty() }, - { s, result -> s != "" && result == s.toCollection(mutableSetOf()) }, - ) - } - - @Test - fun testRemoveSpace() { - val resultFun = { set: Set -> listOf(' ', '\t', '\r', '\n').intersect(set).size } - check( - Sets::removeSpace, - ge(3), - { set, _ -> set == null }, - { set, res -> ' ' in set && resultFun(set) == res }, - { set, res -> '\t' in set && resultFun(set) == res }, - { set, res -> '\n' in set && resultFun(set) == res }, - { set, res -> '\r' in set && resultFun(set) == res }, - { set, res -> ' ' !in set && resultFun(set) == res }, - { set, res -> '\t' !in set && resultFun(set) == res }, - { set, res -> '\n' !in set && resultFun(set) == res }, - { set, res -> '\r' !in set && resultFun(set) == res }, - ) - } - - @Test - fun addElementsTest() { - check( - Sets::addElements, - ge(5), - { set, _, _ -> set == null }, - { set, a, _ -> set != null && set.isNotEmpty() && a == null }, - { set, _, r -> set.isEmpty() && r == set }, - { set, a, r -> set.isNotEmpty() && a.isEmpty() && r == set }, - { set, a, r -> - set.size >= 1 && a.isNotEmpty() && r == set.toMutableSet().apply { addAll(a.toTypedArray()) } - }, - ) - } - - @Test - fun removeElementsTest() { - check( - Sets::removeElements, - between(6..8), - { 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 }, - { set, i, j, res -> set != null && set.size >= 1 && i in set && (j !in set || j == i) && res == 3 }, - { set, i, j, res -> set != null && set.size >= 2 && i in set && j in set && i > j && res == 2 }, - { set, i, j, res -> set != null && set.size >= 2 && i in set && j in set && i < j && res == 1 }, - coverage = AtLeast(94) // unreachable branch - ) - } - - @Test - fun createWithDifferentTypeTest() { - check( - Sets::createWithDifferentType, - eq(2), - { seed, r -> seed % 2 != 0 && r is java.util.LinkedHashSet }, - { seed, r -> seed % 2 == 0 && r !is java.util.LinkedHashSet && r is java.util.HashSet }, - ) - } - - @Test - fun removeCustomObjectTest() { - withoutMinimization { // TODO: JIRA:1506 - check( - Sets::removeCustomObject, - ge(4), - { set, _, _ -> set == null }, - { set, _, result -> set.isEmpty() && result == 0 }, - { set, i, result -> set.isNotEmpty() && CustomClass(i) !in set && result == 0 }, - { set, i, result -> set.isNotEmpty() && CustomClass(i) in set && result == 1 }, - ) - } - } - - @Test - fun testAddAllElements() { - withPushingStateFromPathSelectorForConcrete { - check( - Sets::addAllElements, - ignoreExecutionsNumber, - { set, _, _ -> set == null }, - { set, other, _ -> set != null && other == null }, - { set, other, result -> set.containsAll(other) && result == 0 }, - { set, other, result -> !set.containsAll(other) && result == 1 }, - // TODO: Cannot find branch with result == 2 - { set, other, result -> !set.containsAll(other) && other.any { it in set } && result == 2 }, - ) - } - } - - @Test - fun testRemoveAllElements() { - withPushingStateFromPathSelectorForConcrete { - check( - Sets::removeAllElements, - ignoreExecutionsNumber, - { set, _, _ -> set == null }, - { set, other, _ -> set != null && other == null }, - { set, other, result -> other.all { it !in set } && result == 0 }, - { set, other, result -> set.containsAll(other) && result == 1 }, - //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 - ) - } - } - - @Test - fun testRetainAllElements() { - check( - Sets::retainAllElements, - ge(4), - { set, _, _ -> set == null }, - { set, other, _ -> set != null && other == null }, - { set, other, result -> other.containsAll(set) && result == 1 }, - { set, other, result -> set.any { it !in other } && result == 0 }, - ) - } - - @Test - fun testContainsAllElements() { - check( - Sets::containsAllElements, - ge(5), - { set, _, _ -> set == null }, - { set, other, _ -> set != null && other == null }, - { set, other, result -> set.isEmpty() || other.isEmpty() && result == -1 }, - { set, other, result -> set.isNotEmpty() && other.isNotEmpty() && set.containsAll(other) && result == 1 }, - { set, other, result -> set.isNotEmpty() && other.isNotEmpty() && !set.containsAll(other) && result == 0 }, - ) - } - - - @Test - fun testClearElements() { - check( - Sets::clearElements, - eq(3), - { set, _ -> set == null }, - { set, result -> set.isEmpty() && result == 0 }, - { set, result -> set.isNotEmpty() && result == 1 }, - coverage = AtLeast(85) // unreachable final return - ) - } - - - @Test - fun testContainsElement() { - check( - Sets::containsElement, - between(3..5), - { set, _, _ -> set == null }, - { set, i, result -> i !in set && result == 0 }, - { set, i, result -> i in set && result == 1 }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/ConditionsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/ConditionsTest.kt deleted file mode 100644 index 4cd9376ef9..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/ConditionsTest.kt +++ /dev/null @@ -1,55 +0,0 @@ -package org.utbot.examples.controlflow - -import org.utbot.framework.plugin.api.DocCodeStmt -import org.utbot.framework.plugin.api.DocPreTagStatement -import org.utbot.framework.plugin.api.DocRegularStmt -import org.utbot.framework.plugin.api.DocStatement -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class ConditionsTest : UtValueTestCaseChecker(testClass = Conditions::class) { - @Test - fun testSimpleCondition() { - val conditionSummary = listOf( - DocPreTagStatement( - listOf( - DocRegularStmt("Test "), - DocRegularStmt("executes conditions:\n"), - DocRegularStmt(" "), - DocCodeStmt("(condition): True"), - DocRegularStmt("\n"), - DocRegularStmt("returns from: "), - DocCodeStmt("return 1;"), - DocRegularStmt("\n"), - ) - ) - ) - check( - Conditions::simpleCondition, - eq(2), - { condition, r -> !condition && r == 0 }, - { condition, r -> condition && r == 1 }, - summaryTextChecks = listOf( - keyContain(DocCodeStmt("(condition): True")), - keyContain(DocCodeStmt("(condition): False")), - keyMatch(conditionSummary) - ), - summaryNameChecks = listOf( - keyMatch("testSimpleCondition_Condition"), - keyMatch("testSimpleCondition_NotCondition"), - ), - summaryDisplayNameChecks = listOf( - keyContain("condition : True"), - keyContain("condition : False"), - ) - ) - } - - @Test - fun testIfLastStatement() { - checkWithException( - Conditions::emptyBranches, - ignoreExecutionsNumber, - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/CycleDependedConditionTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/CycleDependedConditionTest.kt deleted file mode 100644 index c0dc060e96..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/CycleDependedConditionTest.kt +++ /dev/null @@ -1,117 +0,0 @@ -package org.utbot.examples.controlflow - -import org.utbot.framework.plugin.api.DocCodeStmt -import org.utbot.framework.plugin.api.DocPreTagStatement -import org.utbot.framework.plugin.api.DocRegularStmt -import org.utbot.framework.plugin.api.DocStatement -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class CycleDependedConditionTest : UtValueTestCaseChecker(testClass = CycleDependedCondition::class) { - @Test - fun testCycleDependedOneCondition() { - val conditionSummary = listOf( - DocPreTagStatement( - listOf( - DocRegularStmt("Test "), - DocRegularStmt("does not iterate "), - DocCodeStmt("for(int i = 0; i < x; i++)"), - DocRegularStmt(", "), - DocRegularStmt("returns from: "), - DocCodeStmt("return 0;"), - DocRegularStmt("\n"), - ) - ) - ) - check( - CycleDependedCondition::oneCondition, - eq(3), - { x, r -> x <= 0 && r == 0 }, - { x, r -> x in 1..2 && r == 0 }, - { x, r -> x > 2 && r == 1 }, - summaryTextChecks = listOf( - keyContain(DocCodeStmt("(i == 2): True")), - keyContain(DocCodeStmt("(i == 2): False")), - keyMatch(conditionSummary) - ), - summaryNameChecks = listOf( - keyMatch("testOneCondition_IEquals2"), - keyMatch("testOneCondition_INotEquals2"), - keyMatch("testOneCondition_ReturnZero"), - ), - summaryDisplayNameChecks = listOf( - keyContain("i == 2 : True"), - keyContain("i == 2 : False"), - keyContain("return 0"), - ) - ) - } - - @Test - fun testCycleDependedTwoCondition() { - val conditionSummary = listOf( - DocPreTagStatement( - listOf( - DocRegularStmt("Test "), - DocRegularStmt("does not iterate "), - DocCodeStmt("for(int i = 0; i < x; i++)"), - DocRegularStmt(", "), - DocRegularStmt("returns from: "), - DocCodeStmt("return 0;"), - DocRegularStmt("\n"), - ) - ) - ) - check( - CycleDependedCondition::twoCondition, - eq(4), - { x, r -> x <= 0 && r == 0 }, - { x, r -> x in 1..3 && r == 0 }, - { x, r -> x == 4 && r == 1 }, - { x, r -> x >= 5 && r == 0 }, - summaryTextChecks = listOf( - keyContain(DocCodeStmt("(x == 4): False")), - keyContain(DocCodeStmt("(i > 2): True")), - keyContain(DocCodeStmt("(i > 2): False")), - keyMatch(conditionSummary) - ), - summaryNameChecks = listOf( - keyMatch("testTwoCondition_XNotEquals4"), - keyMatch("testTwoCondition_XEquals4"), - keyMatch("testTwoCondition_ILessOrEqual2"), - keyMatch("testTwoCondition_ReturnZero"), - ), - summaryDisplayNameChecks = listOf( - keyContain("x == 4 : False"), - keyContain("x == 4 : True"), - keyContain("i > 2 : False"), - keyContain("return 0"), - ) - ) - } - - - @Test - fun testCycleDependedThreeCondition() { - check( - CycleDependedCondition::threeCondition, - eq(4), - { x, r -> x <= 0 && r == 0 }, - { x, r -> x in 1..5 && r == 0 }, - { x, r -> x == 6 || x > 8 && r == 1 }, - { x, r -> x == 7 && r == 0 } - ) - } - - - @Test - fun testCycleDependedOneConditionHigherNumber() { - check( - CycleDependedCondition::oneConditionHigherNumber, - eq(3), - { x, r -> x <= 0 && r == 0 }, - { x, r -> x in 1..100 && r == 0 }, - { x, r -> x > 100 && r == 1 && r == 1 } - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt deleted file mode 100644 index 878ecb6ca5..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt +++ /dev/null @@ -1,216 +0,0 @@ -package org.utbot.examples.controlflow - -import org.utbot.framework.plugin.api.DocCodeStmt -import org.utbot.framework.plugin.api.DocPreTagStatement -import org.utbot.framework.plugin.api.DocRegularStmt -import org.utbot.framework.plugin.api.DocStatement -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class CyclesTest : UtValueTestCaseChecker(testClass = Cycles::class) { - @Test - fun testForCycle() { - check( - Cycles::forCycle, - eq(3), - { x, r -> x <= 0 && r == -1 }, - { x, r -> x in 1..5 && r == -1 }, - { x, r -> x > 5 && r == 1 } - ) - } - - @Test - fun testForCycleFour() { - val cycleSummary = listOf( - DocPreTagStatement( - listOf( - DocRegularStmt("Test "), - DocRegularStmt("does not iterate "), - DocCodeStmt("for(int i = 0; i < x; i++)"), - DocRegularStmt(", "), - DocRegularStmt("returns from: "), - DocCodeStmt("return -1;"), - DocRegularStmt("\n"), - ) - ) - ) - check( - Cycles::forCycleFour, - eq(3), - { x, r -> x <= 0 && r == -1 }, - { x, r -> x in 1..4 && r == -1 }, - { x, r -> x > 4 && r == 1 }, - summaryTextChecks = listOf( - keyContain(DocCodeStmt("(i > 4): True")), - keyContain(DocCodeStmt("(i > 4): False")), - keyMatch(cycleSummary) - ), - summaryNameChecks = listOf( - keyMatch("testForCycleFour_IGreaterThan4"), - keyMatch("testForCycleFour_ILessOrEqual4"), - keyMatch("testForCycleFour_ReturnNegative1") - ), - summaryDisplayNameChecks = listOf( - keyContain("i > 4 : True"), - keyContain("i > 4 : False"), - keyContain("return -1") - ) - ) - } - - @Test - fun testForCycleJayHorn() { - check( - Cycles::forCycleFromJayHorn, - eq(2), - { x, r -> x <= 0 && r == 0 }, - { x, r -> x > 0 && r == 2 * x } - ) - } - - @Test - fun testFiniteCycle() { - check( - Cycles::finiteCycle, - eq(2), - { x, r -> x % 519 == 0 && (r as Int) % 519 == 0 }, - { x, r -> x % 519 != 0 && (r as Int) % 519 == 0 } - ) - } - - @Test - fun testWhileCycle() { - check( - Cycles::whileCycle, - eq(2), - { x, r -> x <= 0 && r == 0 }, - { x, r -> x > 0 && r == (0 until x).sum() } - ) - } - - @Test - fun testCallInnerWhile() { - check( - Cycles::callInnerWhile, - between(1..2), - { x, r -> x >= 42 && r == Cycles().callInnerWhile(x) }, - summaryTextChecks = listOf( - keyContain(DocCodeStmt("return innerWhile(value, 42);")), - ), - summaryNameChecks = listOf( - keyMatch("testCallInnerWhile_IterateWhileLoop") - ) - ) - } - - @Test - fun testInnerLoop() { - val innerLoopSummary1 = arrayOf( - DocRegularStmt("Test "), - DocRegularStmt("calls "), - DocRegularStmt("CycleDependedCondition::twoCondition"), - DocRegularStmt(",\n there it "), - DocRegularStmt("iterates the loop "), - DocRegularStmt(""), - DocCodeStmt("for(int i = 0; i < x; i++)"), - DocRegularStmt(" "), - DocRegularStmt("once"), - DocRegularStmt(""), - DocRegularStmt(". "), - DocRegularStmt("\n Test "), -// DocRegularStmt("afterwards "), - DocRegularStmt("returns from: "), - DocCodeStmt("return 0;"), - DocRegularStmt("\n "), - DocRegularStmt("\nTest "), -// DocRegularStmt("afterwards "), - DocRegularStmt("returns from: "), - DocCodeStmt("return cycleDependedCondition.twoCondition(value);"), - DocRegularStmt("\n"), - ) - val innerLoopSummary2 = arrayOf( - DocRegularStmt("Test "), - DocRegularStmt("calls "), - DocRegularStmt("CycleDependedCondition::twoCondition"), - DocRegularStmt(",\n there it "), - DocRegularStmt("iterates the loop "), - DocRegularStmt(""), - DocCodeStmt("for(int i = 0; i < x; i++)"), - DocRegularStmt(" "), - DocRegularStmt("4 times"), - DocRegularStmt(""), - DocRegularStmt(",\n "), - DocRegularStmt(" "), - DocRegularStmt("inside this loop, the test "), - DocRegularStmt("executes conditions:\n "), - DocRegularStmt(""), - DocCodeStmt("(i > 2): True"), - DocRegularStmt(",\n "), - DocCodeStmt("(x == 4): True"), - DocRegularStmt("\n returns from: "), - DocCodeStmt("return 1;"), - DocRegularStmt("\nTest "), -// DocRegularStmt("afterwards "), - DocRegularStmt("returns from: "), - DocCodeStmt("return cycleDependedCondition.twoCondition(value);"), - DocRegularStmt("\n"), - ) - val innerLoopSummary3 = arrayOf( - DocRegularStmt("Test "), - DocRegularStmt("calls "), - DocRegularStmt("CycleDependedCondition::twoCondition"), - DocRegularStmt(",\n there it "), - DocRegularStmt("iterates the loop "), - DocCodeStmt("for(int i = 0; i < x; i++)"), - DocRegularStmt("5 times"), - DocRegularStmt("inside this loop, the test "), - DocRegularStmt("executes conditions:\n "), - DocCodeStmt("(x == 4): False"), - DocRegularStmt("\n Test "), - DocRegularStmt("returns from: "), - DocCodeStmt("return 0;"), - DocCodeStmt("return cycleDependedCondition.twoCondition(value);"), - ) - check( - Cycles::innerLoop, - ignoreExecutionsNumber, - { x, r -> x in 1..3 && r == 0 }, - { x, r -> x == 4 && r == 1 }, - { x, r -> x >= 5 && r == 0 }, - // TODO JIRA:1442 -/* summaryTextChecks = listOf( - keyContain(*innerLoopSummary1), - keyContain(*innerLoopSummary2), - keyContain(*innerLoopSummary3) - ), - summaryNameChecks = listOf( - keyMatch("testInnerLoop_ReturnZero"), - keyMatch("testInnerLoop_XEquals4"), - keyMatch("testInnerLoop_XNotEquals4") - )*/ - ) - } - - @Test - fun testDivideByZeroCheckWithCycles() { - checkWithException( - Cycles::divideByZeroCheckWithCycles, - eq(3), - { n, _, r -> n < 5 && r.isException() }, - { n, x, r -> n >= 5 && x == 0 && r.isException() }, - { n, x, r -> n >= 5 && x != 0 && r.getOrNull() == Cycles().divideByZeroCheckWithCycles(n, x) } - ) - } - - @Test - fun moveToExceptionTest() { - checkWithException( - Cycles::moveToException, - eq(3), - { x, r -> x < 400 && r.isException() }, - { x, r -> x > 400 && r.isException() }, - { x, r -> x == 400 && r.isException() }, - coverage = atLeast(85) - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/SwitchTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/SwitchTest.kt deleted file mode 100644 index 381c097be9..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/controlflow/SwitchTest.kt +++ /dev/null @@ -1,88 +0,0 @@ -package org.utbot.examples.controlflow - -import org.utbot.framework.plugin.api.DocCodeStmt -import org.utbot.framework.plugin.api.DocPreTagStatement -import org.utbot.framework.plugin.api.DocRegularStmt -import org.utbot.framework.plugin.api.DocStatement -import java.math.RoundingMode.CEILING -import java.math.RoundingMode.DOWN -import java.math.RoundingMode.HALF_DOWN -import java.math.RoundingMode.HALF_EVEN -import java.math.RoundingMode.HALF_UP -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testcheckers.ge -import org.utbot.testcheckers.withoutMinimization - -internal class SwitchTest : UtValueTestCaseChecker(testClass = Switch::class) { - @Test - fun testSimpleSwitch() { - val switchCaseSummary = listOf( - DocPreTagStatement( - listOf( - DocRegularStmt("Test "), - DocRegularStmt("activates switch case: "), - DocCodeStmt("default"), - DocRegularStmt(", "), - DocRegularStmt("returns from: "), - DocCodeStmt("return -1;"), - DocRegularStmt("\n"), - ) - ) - ) - check( - Switch::simpleSwitch, - ge(4), - { x, r -> x == 10 && r == 10 }, - { x, r -> (x == 11 || x == 12) && r == 12 }, // fall-through has it's own branch - { x, r -> x == 13 && r == 13 }, - { x, r -> x !in 10..13 && r == -1 }, // one for default is enough - summaryTextChecks = listOf( - keyContain(DocCodeStmt("return 10;")), - keyContain(DocCodeStmt("return 12;")), - keyContain(DocCodeStmt("return 12;")), - keyContain(DocCodeStmt("return 13;")), - keyMatch(switchCaseSummary) - ), - summaryNameChecks = listOf( - keyMatch("testSimpleSwitch_Return10"), - keyMatch("testSimpleSwitch_Return13"), - keyMatch("testSimpleSwitch_ReturnNegative1"), - ), - summaryDisplayNameChecks = listOf( - keyMatch("switch(x) case: 10 -> return 10"), - keyMatch("switch(x) case: 13 -> return 13"), - keyMatch("switch(x) case: Default -> return -1"), - ) - ) - } - - @Test - fun testLookupSwitch() { - check( - Switch::lookupSwitch, - ge(4), - { x, r -> x == 0 && r == 0 }, - { x, r -> (x == 10 || x == 20) && r == 20 }, // fall-through has it's own branch - { x, r -> x == 30 && r == 30 }, - { x, r -> x !in setOf(0, 10, 20, 30) && r == -1 } // one for default is enough - ) - } - - @Test - fun testEnumSwitch() { - withoutMinimization { // TODO: JIRA:1506 - check( - Switch::enumSwitch, - eq(7), - { m, r -> m == null && r == null }, // NPE - { m, r -> m == HALF_DOWN && r == 1 }, // We will minimize two of these branches - { m, r -> m == HALF_EVEN && r == 1 }, // We will minimize two of these branches - { m, r -> m == HALF_UP && r == 1 }, // We will minimize two of these branches - { m, r -> m == DOWN && r == 2 }, - { m, r -> m == CEILING && r == 3 }, - { m, r -> m !in setOf(HALF_DOWN, HALF_EVEN, HALF_UP, DOWN, CEILING) && r == -1 }, - ) - } - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/enums/ClassWithEnumTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/enums/ClassWithEnumTest.kt deleted file mode 100644 index a6d62721ca..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/enums/ClassWithEnumTest.kt +++ /dev/null @@ -1,194 +0,0 @@ -package org.utbot.examples.enums - -import org.utbot.examples.enums.ClassWithEnum.StatusEnum.ERROR -import org.utbot.examples.enums.ClassWithEnum.StatusEnum.READY -import org.utbot.framework.plugin.api.FieldId -import org.utbot.framework.plugin.api.util.id -import org.junit.jupiter.api.Disabled -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 - -class ClassWithEnumTest : UtValueTestCaseChecker(testClass = ClassWithEnum::class) { - @Test - fun testOrdinal() { - withoutConcrete { - checkAllCombinations(ClassWithEnum::useOrdinal) - } - } - - @Test - fun testGetter() { - check( - ClassWithEnum::useGetter, - eq(2), - { s, r -> s == null && r == -1 }, - { s, r -> s != null && r == 0 }, - ) - } - - @Test - fun testDifficultIfBranch() { - check( - ClassWithEnum::useEnumInDifficultIf, - eq(2), - { s, r -> s.equals("TRYIF", ignoreCase = true) && r == 1 }, - { s, r -> !s.equals("TRYIF", ignoreCase = true) && r == 2 }, - ) - } - - @Test - @Disabled("TODO JIRA:1686") - fun testNullParameter() { - check( - ClassWithEnum::nullEnumAsParameter, - eq(3), - { e, _ -> e == null }, - { e, r -> e == READY && r == 0 }, - { e, r -> e == ERROR && r == -1 }, - ) - } - - @Test - @Disabled("TODO JIRA:1686") - fun testNullField() { - checkWithException( - ClassWithEnum::nullField, - eq(3), - { e, r -> e == null && r.isException() }, - { e, r -> e == ERROR && r.isException() }, - { e, r -> e == READY && r.getOrNull()!! == 3 && READY.s.length == 3 }, - ) - } - - @Test - @Disabled("TODO JIRA:1686") - fun testChangeEnum() { - checkWithException( - ClassWithEnum::changeEnum, - eq(3), - { e, r -> e == null && r.isException() }, - { e, r -> e == READY && r.getOrNull()!! == ERROR.ordinal }, - { e, r -> e == ERROR && r.getOrNull()!! == READY.ordinal }, - ) - } - - @Test - fun testChangeMutableField() { - // TODO testing code generation for this method is disabled because we need to restore original field state - // should be enabled after solving JIRA:1648 - withEnabledTestingCodeGeneration(testCodeGeneration = false) { - checkWithException( - ClassWithEnum::changeMutableField, - eq(2), - { e, r -> e == READY && r.getOrNull()!! == 2 }, - { e, r -> (e == null || e == ERROR) && r.getOrNull()!! == -2 }, - ) - } - } - - @Test - @Disabled("TODO JIRA:1686") - fun testCheckName() { - check( - ClassWithEnum::checkName, - eq(3), - { s, _ -> s == null }, - { s, r -> s == READY.name && r == ERROR.name }, - { s, r -> s != READY.name && r == READY.name }, - ) - } - - @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 - } - ) - } - - @Test - fun testEnumValues() { - checkStaticMethod( - ClassWithEnum.StatusEnum::values, - eq(1), - { r -> r.contentEquals(arrayOf(READY, ERROR)) }, - ) - } - - @Test - fun testFromCode() { - checkStaticMethod( - ClassWithEnum.StatusEnum::fromCode, - eq(3), - { code, r -> code == 10 && r == READY }, - { code, r -> code == -10 && r == ERROR }, - { code, r -> code !in setOf(10, -10) && r == null }, // IllegalArgumentException - ) - } - - @Test - fun testFromIsReady() { - checkStaticMethod( - ClassWithEnum.StatusEnum::fromIsReady, - eq(2), - { isFirst, r -> isFirst && r == READY }, - { isFirst, r -> !isFirst && r == ERROR }, - ) - } - - @Test - @Disabled("TODO JIRA:1450") - fun testPublicGetCodeMethod() { - checkWithThis( - ClassWithEnum.StatusEnum::publicGetCode, - eq(2), - { enumInstance, r -> enumInstance == READY && r == 10 }, - { enumInstance, r -> enumInstance == ERROR && r == -10 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testImplementingInterfaceEnumInDifficultBranch() { - withPushingStateFromPathSelectorForConcrete { - check( - ClassWithEnum::implementingInterfaceEnumInDifficultBranch, - eq(2), - { s, r -> s.equals("SUCCESS", ignoreCase = true) && r == 0 }, - { s, r -> !s.equals("SUCCESS", ignoreCase = true) && r == 2 }, - ) - } - } - - @Test - fun testAffectSystemStaticAndUseInitEnumFromIt() { - check( - ClassWithEnum::affectSystemStaticAndInitEnumFromItAndReturnField, - eq(1), - { r -> r == true }, - coverage = DoNotCalculate - ) - } - - @Test - fun testAffectSystemStaticAndInitEnumFromItAndGetItFromEnumFun() { - check( - ClassWithEnum::affectSystemStaticAndInitEnumFromItAndGetItFromEnumFun, - eq(1), - { r -> r == true }, - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/enums/ComplexEnumExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/enums/ComplexEnumExamplesTest.kt deleted file mode 100644 index e0d35726a4..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/enums/ComplexEnumExamplesTest.kt +++ /dev/null @@ -1,106 +0,0 @@ -package org.utbot.examples.enums - -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.examples.enums.ComplexEnumExamples.Color -import org.utbot.examples.enums.ComplexEnumExamples.Color.BLUE -import org.utbot.examples.enums.ComplexEnumExamples.Color.GREEN -import org.utbot.examples.enums.ComplexEnumExamples.Color.RED -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq - -class ComplexEnumExamplesTest : UtValueTestCaseChecker( - testClass = ComplexEnumExamples::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testEnumToEnumMapCountValues() { - check( - ComplexEnumExamples::enumToEnumMapCountValues, - ignoreExecutionsNumber, - { m, r -> m.isEmpty() && r == 0 }, - { m, r -> m.isNotEmpty() && !m.values.contains(RED) && r == 0 }, - { m, r -> m.isNotEmpty() && m.values.contains(RED) && m.values.count { it == RED } == r } - ) - } - - @Test - fun testEnumToEnumMapCountKeys() { - check( - ComplexEnumExamples::enumToEnumMapCountKeys, - ignoreExecutionsNumber, - { m, r -> m.isEmpty() && r == 0 }, - { m, r -> m.isNotEmpty() && !m.keys.contains(GREEN) && !m.keys.contains(BLUE) && r == 0 }, - { m, r -> m.isNotEmpty() && m.keys.intersect(setOf(BLUE, GREEN)).isNotEmpty() && m.keys.count { it == BLUE || it == GREEN } == r } - ) - } - - @Test - fun testEnumToEnumMapCountMatches() { - check( - ComplexEnumExamples::enumToEnumMapCountMatches, - ignoreExecutionsNumber, - { m, r -> m.isEmpty() && r == 0 }, - { m, r -> m.entries.count { it.key == it.value } == r } - ) - } - - @Test - fun testCountEqualColors() { - check( - ComplexEnumExamples::countEqualColors, - ignoreExecutionsNumber, - { a, b, c, r -> a == b && a == c && r == 3 }, - { a, b, c, r -> setOf(a, b, c).size == 2 && r == 2 }, - { a, b, c, r -> a != b && b != c && a != c && r == 1 } - ) - } - - @Test - fun testCountNullColors() { - check( - ComplexEnumExamples::countNullColors, - eq(3), - { a, b, r -> a == null && b == null && r == 2 }, - { a, b, r -> (a == null) != (b == null) && r == 1 }, - { a, b, r -> a != null && b != null && r == 0 }, - ) - } - - @Test - @Disabled("TODO: nested anonymous classes are not supported: https://github.com/UnitTestBot/UTBotJava/issues/617") - fun testFindState() { - check( - ComplexEnumExamples::findState, - ignoreExecutionsNumber, - { c, r -> c in setOf(0, 127, 255) && r != null && r.code == c } - ) - } - - @Test - fun testCountValuesInArray() { - fun Color.isCorrectlyCounted(inputs: Array, counts: Map): Boolean = - inputs.count { it == this } == (counts[this] ?: 0) - - check( - ComplexEnumExamples::countValuesInArray, - ignoreExecutionsNumber, - { cs, r -> cs.isEmpty() && r != null && r.isEmpty() }, - { cs, r -> cs.toList().isEmpty() && r != null && r.isEmpty() }, - { cs, r -> cs.toList().isNotEmpty() && r != null && Color.values().all { it.isCorrectlyCounted(cs, r) } } - ) - } - - @Test - fun testCountRedInArray() { - check( - ComplexEnumExamples::countRedInArray, - eq(3), - { colors, result -> colors.count { it == RED } == result } - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/ExceptionClusteringChecker.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/ExceptionClusteringChecker.kt deleted file mode 100644 index 4e67505768..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/ExceptionClusteringChecker.kt +++ /dev/null @@ -1,57 +0,0 @@ -package org.utbot.examples.exceptions - -import org.utbot.framework.plugin.api.UtExecutionSuccess -import org.utbot.framework.plugin.api.UtExplicitlyThrownException -import org.utbot.framework.plugin.api.UtImplicitlyThrownException -import org.utbot.framework.plugin.api.UtModel -import org.utbot.framework.plugin.api.UtTimeoutException -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.ge -import org.utbot.testing.UtModelTestCaseChecker -import org.utbot.testing.ignoreExecutionsNumber -import org.utbot.testing.primitiveValue - -internal class ExceptionClusteringChecker : - UtModelTestCaseChecker(testClass = ExceptionClusteringExamples::class) { - /** - * Difference is in throwing unchecked exceptions - for method under test is [UtExpectedCheckedThrow]. - */ - @Test - fun testDifferentExceptions() { - check( - ExceptionClusteringExamples::differentExceptions, - ignoreExecutionsNumber, - { i, r -> i.int() == 0 && r is UtImplicitlyThrownException && r.exception is ArithmeticException }, - { i, r -> i.int() == 1 && r is UtExplicitlyThrownException && r.exception is MyCheckedException }, - { i, r -> i.int() == 2 && r is UtExplicitlyThrownException && r.exception is IllegalArgumentException }, - { i, r -> i.int() !in 0..2 && r is UtExecutionSuccess && r.model.int() == 2 * i.int() }, - ) - } - - /** - * Difference is in throwing unchecked exceptions - for nested call it is [UtUnexpectedUncheckedThrow]. - */ - @Test - fun testDifferentExceptionsInNestedCall() { - check( - ExceptionClusteringExamples::differentExceptionsInNestedCall, - ignoreExecutionsNumber, - { i, r -> i.int() == 0 && r is UtImplicitlyThrownException && r.exception is ArithmeticException }, - { i, r -> i.int() == 1 && r is UtExplicitlyThrownException && r.exception is MyCheckedException }, - { i, r -> i.int() == 2 && r is UtExplicitlyThrownException && r.exception is IllegalArgumentException }, - { i, r -> i.int() !in 0..2 && r is UtExecutionSuccess && r.model.int() == 2 * i.int() }, - ) - } - - @Test - fun testSleepingMoreThanDefaultTimeout() { - check( - ExceptionClusteringExamples::sleepingMoreThanDefaultTimeout, - ge(1), - { _, r -> r is UtTimeoutException }, // we will minimize one of these: i <= 0 or i > 0 - ) - } -} - -private fun UtModel.int(): Int = this.primitiveValue() - diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/ExceptionExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/ExceptionExamplesTest.kt deleted file mode 100644 index 29b62857fa..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/ExceptionExamplesTest.kt +++ /dev/null @@ -1,135 +0,0 @@ -package org.utbot.examples.exceptions - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testcheckers.withoutConcrete - -internal class ExceptionExamplesTest : UtValueTestCaseChecker( - testClass = ExceptionExamples::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) // TODO: fails because we construct lists with generics - ) -) { - @Test - fun testInitAnArray() { - check( - ExceptionExamples::initAnArray, - ignoreExecutionsNumber, - { n, r -> n < 0 && r == -2 }, - { n, r -> n == 0 || n == 1 && r == -3 }, - { n, r -> n > 1 && r == 2 * n + 3 }, - coverage = atLeast(80) - ) - } - - @Test - fun testNestedExceptions() { - check( - ExceptionExamples::nestedExceptions, - eq(3), - { i, r -> i < 0 && r == -100 }, - { i, r -> i > 0 && r == 100 }, - { i, r -> i == 0 && r == 0 }, - ) - } - - @Test - fun testDoNotCatchNested() { - checkWithException( - ExceptionExamples::doNotCatchNested, - eq(3), - { i, r -> i < 0 && r.isException() }, - { i, r -> i > 0 && r.isException() }, - { i, r -> i == 0 && r.getOrThrow() == 0 }, - ) - } - - @Test - fun testFinallyThrowing() { - checkWithException( - ExceptionExamples::finallyThrowing, - eq(2), - { i, r -> i <= 0 && r.isException() }, - { i, r -> i > 0 && r.isException() }, - ) - } - - @Test - fun testFinallyChanging() { - check( - ExceptionExamples::finallyChanging, - eq(2), - { i, r -> i * 2 <= 0 && r == i * 2 + 10 }, - { i, r -> i * 2 > 0 && r == i * 2 + 110 }, - coverage = atLeast(80) // differs from JaCoCo - ) - } - - @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 - ) - } - - @Test - fun testCreateException() { - check( - ExceptionExamples::createException, - eq(1), - { r -> r is java.lang.IllegalArgumentException }, - ) - } - - /** - * Used for path generation check in [org.utbot.engine.Traverser.fullPath] - */ - @Test - fun testCatchDeepNestedThrow() { - checkWithException( - ExceptionExamples::catchDeepNestedThrow, - eq(2), - { i, r -> i < 0 && r.isException() }, - { i, r -> i >= 0 && r.getOrThrow() == i }, - coverage = atLeast(66) // because of unexpected exception thrown - ) - } - - /** - * Covers [#656](https://github.com/UnitTestBot/UTBotJava/issues/656). - */ - @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) - ) - } - } - - /** - * Used for path generation check in [org.utbot.engine.Traverser.fullPath] - */ - @Test - fun testDontCatchDeepNestedThrow() { - checkWithException( - ExceptionExamples::dontCatchDeepNestedThrow, - eq(2), - { i, r -> i < 0 && r.isException() }, - { i, r -> i >= 0 && r.getOrThrow() == i }, - coverage = atLeast(66) // because of unexpected exception thrown - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/JvmCrashExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/JvmCrashExamplesTest.kt deleted file mode 100644 index 6a9449d4f7..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/exceptions/JvmCrashExamplesTest.kt +++ /dev/null @@ -1,41 +0,0 @@ -package org.utbot.examples.exceptions - -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testcheckers.withoutSandbox -import org.utbot.testing.DoNotCalculate -import org.utbot.testing.UtValueTestCaseChecker - -internal class JvmCrashExamplesTest : UtValueTestCaseChecker(testClass = JvmCrashExamples::class) { - @Test - @Disabled("JIRA:1527") - fun testExit() { - check( - JvmCrashExamples::exit, - eq(2) - ) - } - - @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 - ) - } - } - - @Test - fun testCrashPrivileged() { - check( - JvmCrashExamples::crashPrivileged, - 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-testing/src/test/kotlin/org/utbot/examples/invokes/InvokeExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/InvokeExampleTest.kt deleted file mode 100644 index 44ec7ceb69..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/InvokeExampleTest.kt +++ /dev/null @@ -1,212 +0,0 @@ -package org.utbot.examples.invokes - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class InvokeExampleTest : UtValueTestCaseChecker(testClass = InvokeExample::class) { - @Test - fun testSimpleFormula() { - check( - InvokeExample::simpleFormula, - eq(3), - { fst, _, _ -> fst < 100 }, - { _, snd, _ -> snd < 100 }, - { fst, snd, r -> fst >= 100 && snd >= 100 && r == (fst + 5) * (snd / 2) }, - ) - } - - @Test - fun testChangeObjectValueByMethod() { - check( - InvokeExample::changeObjectValueByMethod, - eq(2), - { o, _ -> o == null }, - { o, r -> o != null && r?.value == 4 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testParticularValue() { - check( - InvokeExample::particularValue, - eq(3), - { o, _ -> o == null }, - { o, _ -> o != null && o.value < 0 }, - { o, r -> o != null && o.value >= 0 && r?.value == 12 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCreateObjectFromValue() { - check( - InvokeExample::createObjectFromValue, - eq(2), - { value, r -> value == 0 && r?.value == 1 }, - { value, r -> value != 0 && r?.value == value } - ) - } - - @Test - fun testGetNullOrValue() { - check( - InvokeExample::getNullOrValue, - eq(3), - { o, _ -> o == null }, - { o, r -> o != null && o.value < 100 && r == null }, - { o, r -> o != null && o.value >= 100 && r?.value == 5 }, - coverage = DoNotCalculate - ) - } - - - @Test - fun testConstraintsFromOutside() { - check( - InvokeExample::constraintsFromOutside, - eq(3), - { value, r -> value >= 0 && r == value }, - { value, r -> value == Int.MIN_VALUE && r == 0 }, - { value, r -> value < 0 && value != Int.MIN_VALUE && r == -value }, - coverage = DoNotCalculate - ) - } - - - @Test - fun testConstraintsFromInside() { - check( - InvokeExample::constraintsFromInside, - eq(3), - { value, r -> value >= 0 && r == 1 }, - { value, r -> value == Int.MIN_VALUE && r == 1 }, - { value, r -> value < 0 && value != Int.MIN_VALUE && r == 1 }, - ) - } - - @Test - fun testAlwaysNPE() { - checkWithException( - InvokeExample::alwaysNPE, - eq(4), - { o, r -> o == null && r.isException() }, - { o, r -> o != null && o.value == 0 && r.isException() }, - { o, r -> o != null && o.value < 0 && r.isException() }, - { o, r -> o != null && o.value > 0 && r.isException() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testExceptionInNestedMethod() { - checkWithException( - InvokeExample::exceptionInNestedMethod, - eq(3), - { o, _, r -> o == null && r.isException() }, - { o, value, r -> o != null && value < 0 && r.isException() }, - { o, value, r -> o != null && value >= 0 && value == (r.getOrNull() as InvokeClass).value }, - coverage = DoNotCalculate - ) - } - - @Test - fun testFewNestedExceptions() { - checkWithException( - InvokeExample::fewNestedException, - eq(5), - { o, _, r -> o == null && r.isException() }, - { o, value, r -> o != null && value < 10 && r.isException() }, - { o, value, r -> o != null && value in 10..99 && r.isException() }, - { o, value, r -> o != null && value in 100..9999 && r.isException() }, - { o, value, r -> o != null && value >= 10000 && value == (r.getOrNull() as InvokeClass).value }, - coverage = DoNotCalculate - ) - } - - @Test - fun testDivBy() { - checkWithException( - InvokeExample::divBy, - eq(4), - { o, _, r -> o == null && r.isException() }, - { o, _, r -> o != null && o.value < 1000 && r.isException() }, - { o, den, r -> o != null && o.value >= 1000 && den == 0 && r.isException() }, - { o, den, r -> o != null && o.value >= 1000 && den != 0 && r.getOrNull() == o.value / den }, - coverage = DoNotCalculate - ) - } - - @Test - fun testUpdateValue() { - check( - InvokeExample::updateValue, - eq(4), - { o, _, _ -> o == null }, - { o, _, r -> o != null && o.value > 0 && r != null && r.value > 0 }, - { o, value, r -> o != null && o.value <= 0 && value > 0 && r?.value == value }, - { o, value, _ -> o != null && o.value <= 0 && value <= 0 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testNullAsParameter() { - check( - InvokeExample::nullAsParameter, - eq(1), - coverage = DoNotCalculate - ) - } - - @Test - fun testChangeArrayWithAssignFromMethod() { - check( - InvokeExample::changeArrayWithAssignFromMethod, - eq(3), - { a, _ -> a == null }, - { a, r -> a != null && a.isEmpty() && r != null && r.isEmpty() }, - { a, r -> - require(a != null && r != null) - a.isNotEmpty() && r.size == a.size && a.map { it + 5 } == r.toList() && !a.contentEquals(r) - } - ) - } - - @Test - fun testChangeArrayByMethod() { - check( - InvokeExample::changeArrayByMethod, - ignoreExecutionsNumber, - { a, _ -> a == null }, - { a, r -> a != null && a.isNotEmpty() && r != null && r.size == a.size && a.map { it + 5 } == r.toList() } - ) - } - - @Test - fun testArrayCopyExample() { - check( - InvokeExample::arrayCopyExample, - eq(5), - { a, _ -> a == null }, - { a, _ -> a != null && a.size < 3 }, - { a, r -> a != null && a.size >= 3 && a[0] <= a[1] && r == null }, - { a, r -> a != null && a.size >= 3 && a[0] > a[1] && a[1] <= a[2] && r == null }, - { a, r -> a != null && a.size >= 3 && a[0] > a[1] && a[1] > a[2] && r.contentEquals(a) }, - coverage = DoNotCalculate - ) - } - - @Test - fun testUpdateValues() { - check( - InvokeExample::updateValues, - eq(4), - { fst, _, _ -> fst == null }, - { fst, snd, _ -> fst != null && snd == null }, - { fst, snd, r -> fst != null && snd != null && fst !== snd && r == 1 }, - { fst, snd, _ -> fst != null && snd != null && fst === snd }, - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/NativeExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/NativeExampleTest.kt deleted file mode 100644 index 9949638cb1..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/NativeExampleTest.kt +++ /dev/null @@ -1,52 +0,0 @@ -package org.utbot.examples.invokes - -import kotlin.math.ln -import kotlin.math.sqrt -import org.junit.jupiter.api.Tag -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testcheckers.ge - -internal class NativeExampleTest : UtValueTestCaseChecker(testClass = NativeExample::class) { - @Test - fun testPartialEx() { - check( - NativeExample::partialExecution, - ge(1), - coverage = atLeast(50) - ) - } - - @Test - fun testUnreachableNativeCall() { - check( - NativeExample::unreachableNativeCall, - eq(2), - { d, r -> !d.isNaN() && r == 1 }, - { d, r -> d.isNaN() && r == 2 }, - coverage = atLeast(50) - ) - } - - @Test - @Tag("slow") - fun testSubstitution() { - check( - NativeExample::substitution, - ignoreExecutionsNumber, - { x, r -> x > 4 && r == 1 }, - { x, r -> sqrt(x) <= 2 && r == 0 } - ) - } - - @Test - fun testUnreachableBranch() { - check( - NativeExample::unreachableBranch, - ge(2), - { x, r -> x.isNaN() && r == 1 }, - { x, r -> (!ln(x).isNaN() || x < 0) && r == 2 }, - coverage = atLeast(66) - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/SimpleInterfaceExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/SimpleInterfaceExampleTest.kt deleted file mode 100644 index 98e19a19b8..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/SimpleInterfaceExampleTest.kt +++ /dev/null @@ -1,40 +0,0 @@ -package org.utbot.examples.invokes - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker - -internal class SimpleInterfaceExampleTest : UtValueTestCaseChecker( - testClass = SimpleInterfaceExample::class -) { - @Test - fun testOverrideMethod() { - check( - SimpleInterfaceExample::overrideMethod, - eq(3), - { o, _, _ -> o == null }, - { o, v, r -> o is SimpleInterfaceImpl && r == v + 2 }, - { o, v, r -> o is Realization && r == v + 5 } - ) - } - - @Test - fun testDefaultMethod() { - check( - SimpleInterfaceExample::defaultMethod, - eq(2), - { o, _, _ -> o == null }, - { o, v, r -> o != null && r == v - 5 } - ) - } - - @Test - fun testInvokeMethodFromImplementor() { - check( - SimpleInterfaceExample::invokeMethodFromImplementor, - eq(2), - { o, _ -> o == null }, - { o, r -> o != null && r == 10 }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/StaticInvokeExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/StaticInvokeExampleTest.kt deleted file mode 100644 index 5c75b0f0cb..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/StaticInvokeExampleTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package org.utbot.examples.invokes - -import kotlin.math.max -import org.junit.jupiter.api.Test -import org.utbot.testing.UtValueTestCaseChecker -import org.utbot.testing.between - -internal class StaticInvokeExampleTest : UtValueTestCaseChecker(testClass = StaticInvokeExample::class) { - // TODO: inline local variables when types inference bug in Kotlin fixed - @Test - fun testMaxForThree() { - val method = StaticInvokeExample::maxForThree - checkStaticMethod( - method, - between(2..3), // two executions can cover all branches - { x, y, _, _ -> x > y }, - { x, y, _, _ -> x <= y }, - { x, y, z, _ -> max(x, y.toInt()) > z }, - { x, y, z, _ -> max(x, y.toInt()) <= z }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/VirtualInvokeExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/VirtualInvokeExampleTest.kt deleted file mode 100644 index 05f4395083..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/invokes/VirtualInvokeExampleTest.kt +++ /dev/null @@ -1,145 +0,0 @@ -@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") - -package org.utbot.examples.invokes - -import java.lang.Boolean -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class VirtualInvokeExampleTest : UtValueTestCaseChecker(testClass = VirtualInvokeExample::class) { - @Test - fun testSimpleVirtualInvoke() { - checkWithException( - VirtualInvokeExample::simpleVirtualInvoke, - eq(3), - { v, r -> v < 0 && r.getOrNull() == -2 }, - { v, r -> v == 0 && r.isException() }, - { v, r -> v > 0 && r.getOrNull() == 1 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testVirtualNative() { - check( - VirtualInvokeExample::virtualNative, - eq(1), - { r -> r == Boolean::class.java.modifiers } - ) - } - - @Test - fun testGetSigners() { - check( - VirtualInvokeExample::virtualNativeArray, - eq(1), - ) - } - - @Test - fun testObjectFromOutside() { - checkWithException( - VirtualInvokeExample::objectFromOutside, - eq(7), - { o, _, r -> o == null && r.isException() }, - { o, v, r -> o != null && o is VirtualInvokeClassSucc && v < 0 && r.getOrNull() == -1 }, - { o, v, r -> o != null && o is VirtualInvokeClassSucc && v == 0 && r.getOrNull() == 0 }, - { o, v, r -> o != null && o is VirtualInvokeClassSucc && v > 0 && r.getOrNull() == 1 }, - { o, v, r -> o != null && o !is VirtualInvokeClassSucc && v < 0 && r.getOrNull() == 2 }, - { o, v, r -> o != null && o !is VirtualInvokeClassSucc && v == 0 && r.isException() }, - { o, v, r -> o != null && o !is VirtualInvokeClassSucc && v > 0 && r.getOrNull() == 1 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testDoubleCall() { - check( - VirtualInvokeExample::doubleCall, - eq(2), - { obj, _ -> obj == null }, - { obj, r -> obj != null && obj.returnX(obj) == r }, - coverage = DoNotCalculate - ) - } - - @Test - fun testYetAnotherObjectFromOutside() { - checkWithException( - VirtualInvokeExample::yetAnotherObjectFromOutside, - eq(3), - { o, r -> o == null && r.isException() }, - { o, r -> o != null && o !is VirtualInvokeClassSucc && r.getOrNull() == 1 }, - { o, r -> o != null && o is VirtualInvokeClassSucc && r.getOrNull() == 2 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testTwoObjects() { - checkWithException( - VirtualInvokeExample::twoObjects, - eq(3), - { o, r -> o == null && r.isException() }, - { o, r -> o != null && o is VirtualInvokeClassSucc && r.getOrNull() == 1 }, - { o, r -> o != null && o !is VirtualInvokeClassSucc && r.getOrNull() == 2 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testNestedVirtualInvoke() { - checkWithException( - VirtualInvokeExample::nestedVirtualInvoke, - eq(3), - { o, r -> o == null && r.isException() }, - { o, r -> o != null && o !is VirtualInvokeClassSucc && r.getOrNull() == 1 }, - { o, r -> o != null && o is VirtualInvokeClassSucc && r.getOrNull() == 2 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testAbstractClassInstanceFromOutsideWithoutOverrideMethods() { - check( - VirtualInvokeExample::abstractClassInstanceFromOutsideWithoutOverrideMethods, - eq(2), - { o, _ -> o == null }, - { o, r -> o is VirtualInvokeAbstractClassSucc && r == 1 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testAbstractClassInstanceFromOutside() { - check( - VirtualInvokeExample::abstractClassInstanceFromOutside, - eq(2), - { o, _ -> o == null }, - { o, r -> o is VirtualInvokeAbstractClassSucc && r == 2 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testNullValueInReturnValue() { - check( - VirtualInvokeExample::nullValueInReturnValue, - eq(3), - { o, _ -> o == null }, - { o, _ -> o is VirtualInvokeClassSucc }, - { o, r -> o is VirtualInvokeClass && r == 10L }, - coverage = DoNotCalculate - ) - } - - @Test - fun testQuasiImplementationInvoke() { - check( - VirtualInvokeExample::quasiImplementationInvoke, - eq(1), - { result -> result == 0 }, - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/CustomPredicateExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/CustomPredicateExampleTest.kt deleted file mode 100644 index 868273353e..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/CustomPredicateExampleTest.kt +++ /dev/null @@ -1,77 +0,0 @@ -package org.utbot.examples.lambda - -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq - -class CustomPredicateExampleTest : UtValueTestCaseChecker( - testClass = CustomPredicateExample::class, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - // TODO: https://github.com/UnitTestBot/UTBotJava/issues/88 (generics in Kotlin) - // At the moment, when we create an instance of a functional interface via lambda (through reflection), - // we need to do a type cast (e.g. `obj as Predicate`), but since generics are not supported yet, - // we use a raw type (e.g. `Predicate`) instead (which is not allowed in Kotlin). - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testNoCapturedValuesPredicateCheck() { - checkWithException( - CustomPredicateExample::noCapturedValuesPredicateCheck, - 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 - ) - } - - @Test - fun testCapturedLocalVariablePredicateCheck() { - checkWithException( - CustomPredicateExample::capturedLocalVariablePredicateCheck, - 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 - ) - } - - @Test - fun testCapturedParameterPredicateCheck() { - checkWithException( - CustomPredicateExample::capturedParameterPredicateCheck, - 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 - ) - } - - @Test - fun testCapturedStaticFieldPredicateCheck() { - checkWithException( - 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() }, - 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 - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/PredicateNotExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/PredicateNotExampleTest.kt deleted file mode 100644 index 739cff5964..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/PredicateNotExampleTest.kt +++ /dev/null @@ -1,19 +0,0 @@ -package org.utbot.examples.lambda - -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker - -class PredicateNotExampleTest : UtValueTestCaseChecker(testClass = PredicateNotExample::class) { - @Test - @Disabled("TODO flaky 0 executions at GitHub runners https://github.com/UnitTestBot/UTBotJava/issues/999") - fun testPredicateNotExample() { - check( - PredicateNotExample::predicateNotExample, - eq(2), - { a, r -> a == 5 && r == false }, - { a, r -> a != 5 && r == true }, - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt deleted file mode 100644 index 2c893b55b6..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/lambda/SimpleLambdaExamplesTest.kt +++ /dev/null @@ -1,35 +0,0 @@ -package org.utbot.examples.lambda - -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq - -// TODO failed Kotlin compilation (generics) SAT-1332 -class SimpleLambdaExamplesTest : UtValueTestCaseChecker( - testClass = SimpleLambdaExamples::class, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration), - ) -) { - @Test - fun testBiFunctionLambdaExample() { - checkWithException( - SimpleLambdaExamples::biFunctionLambdaExample, - eq(2), - { _, b, r -> b == 0 && r.isException() }, - { a, b, r -> b != 0 && r.getOrThrow() == a / b }, - ) - } - - @Test - fun testChoosePredicate() { - check( - SimpleLambdaExamples::choosePredicate, - eq(2), - { b, r -> b && !r!!.test(null) && r.test(0) }, - { b, r -> !b && r!!.test(null) && !r.test(0) }, - coverage = DoNotCalculate // coverage could not be calculated since method result is lambda - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/make/symbolic/ClassWithComplicatedMethodsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/make/symbolic/ClassWithComplicatedMethodsTest.kt deleted file mode 100644 index 083220f4c5..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/make/symbolic/ClassWithComplicatedMethodsTest.kt +++ /dev/null @@ -1,95 +0,0 @@ -package org.utbot.examples.make.symbolic - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.framework.plugin.api.MockStrategyApi -import kotlin.math.abs -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 - -// This class is substituted with ComplicatedMethodsSubstitutionsStorage -// but we cannot do in code generation. -// For this reason code generation executions are disabled -internal class ClassWithComplicatedMethodsTest : UtValueTestCaseChecker( - testClass = ClassWithComplicatedMethods::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA, Compilation), - TestLastStage(CodegenLanguage.KOTLIN, Compilation) - ) -) { - @Test - @Disabled("[SAT-1419]") - fun testApplyMethodWithSideEffectAndReturn() { - checkMocksAndInstrumentation( - ClassWithComplicatedMethods::applyMethodWithSideEffectAndReturn, - eq(2), - { x, mocks, instr, r -> - x > 0 && mocks.isEmpty() && instr.isEmpty() && sqrt(x.toDouble()) == x.toDouble() && r!!.a == 2821 - }, - { x, mocks, instr, r -> - x > 0 && mocks.isEmpty() && instr.isEmpty() && sqrt(x.toDouble()) != x.toDouble() && r!!.a == 10 - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCreateWithOriginalConstructor() { - checkMocksAndInstrumentation( - ClassWithComplicatedMethods::createWithOriginalConstructor, - eq(1), - { a, b, mocks, instr, r -> a > 10 && b > 10 && r!!.a == a + b && mocks.isEmpty() && instr.isEmpty() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCreateWithSubstitutedConstructor() { - withoutConcrete { // TODO: concrete execution can't handle this - checkMocksAndInstrumentation( - ClassWithComplicatedMethods::createWithSubstitutedConstructor, - eq(1), - { a, b, mocks, instr, r -> a < 0 && b < 0 && r!!.a == (a + b).toInt() && mocks.isEmpty() && instr.isEmpty() }, - coverage = DoNotCalculate - ) - } - } - - @Test - fun testSqrt2() { - 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 - checkMocksAndInstrumentation( - ClassWithComplicatedMethods::returnSubstitutedMethod, - eq(1), - { x, mocks, instr, r -> x > 100 && mocks.isEmpty() && instr.isEmpty() && r != null && r.a == x }, - coverage = DoNotCalculate - ) - } - } - - @Test - fun testAssumesWithMocks() { - checkMocksAndInstrumentation( - ClassWithComplicatedMethods::assumesWithMocks, - eq(1), - { x, mocks, instr, r -> x in 6..7 && r == 1 && mocks.isEmpty() && instr.isEmpty() }, - coverage = DoNotCalculate, - mockStrategy = MockStrategyApi.OTHER_CLASSES - ) - } - - private val eps = 1e-8 -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/math/BitOperatorsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/math/BitOperatorsTest.kt deleted file mode 100644 index a54b0146dc..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/math/BitOperatorsTest.kt +++ /dev/null @@ -1,175 +0,0 @@ -package org.utbot.examples.math - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class BitOperatorsTest : UtValueTestCaseChecker(testClass = BitOperators::class) { - @Test - fun testComplement() { - check( - BitOperators::complement, - eq(2), - { x, r -> x == -2 && r == true }, - { x, r -> x != -2 && r == false } - ) - } - - @Test - fun testXor() { - check( - BitOperators::xor, - eq(2), - { x, y, r -> x == y && r == true }, - { x, y, r -> x != y && r == false } - ) - } - - @Test - fun testOr() { - check( - BitOperators::or, - eq(2), - { x, r -> x < 16 && (x and 0xfffffff8.toInt()) == 8 && r == true }, - { x, r -> x >= 16 || (x and 0xfffffff8.toInt()) != 8 && r == false } - ) - } - - @Test - @kotlin.ExperimentalStdlibApi - fun testAnd() { - check( - BitOperators::and, - eq(2), - { x, r -> x.countOneBits() <= 1 && r == true }, - { x, r -> x.countOneBits() > 1 && r == false } - ) - } - - @Test - fun testBooleanNot() { - check( - BitOperators::booleanNot, - eq(3), - { a, b, r -> a && b && r == 100 }, - { a, b, r -> a && !b && r == 200 }, - { a, b, r -> !a && !b && r == 200 }, - coverage = atLeast(91) - ) - } - - @Test - fun testBooleanXor() { - check( - BitOperators::booleanXor, - eq(1) - ) - } - - @Test - fun testBooleanOr() { - check( - BitOperators::booleanOr, - eq(1) - ) - } - - @Test - fun testBooleanAnd() { - check( - BitOperators::booleanAnd, - eq(1) - ) - } - - @Test - fun testBooleanXorCompare() { - check( - BitOperators::booleanXorCompare, - eq(2), - { a, b, r -> a != b && r == 1 }, - { a, b, r -> a == b && r == 0 } - ) - } - - @Test - fun testShl() { - check( - BitOperators::shl, - eq(2), - { x, r -> x == 1 && r == true }, - { x, r -> x != 1 && r == false } - ) - } - - @Test - fun testShlLong() { - check( - BitOperators::shlLong, - eq(2), - { x, r -> x == 1L && r == true }, - { x, r -> x != 1L && r == false } - ) - } - - @Test - fun testShlWithBigLongShift() { - check( - BitOperators::shlWithBigLongShift, - eq(3), - { shift, r -> shift < 40 && r == 1 }, - { shift, r -> shift >= 40 && shift and 0b11111 == 4L && r == 2 }, - { shift, r -> shift >= 40 && shift and 0b11111 != 4L && r == 3 }, - ) - } - - @Test - fun testShr() { - check( - BitOperators::shr, - eq(2), - { x, r -> x shr 1 == 1 && r == true }, - { x, r -> x shr 1 != 1 && r == false } - ) - } - - @Test - fun testShrLong() { - check( - BitOperators::shrLong, - eq(2), - { x, r -> x shr 1 == 1L && r == true }, - { x, r -> x shr 1 != 1L && r == false } - ) - } - - @Test - fun testUshr() { - check( - BitOperators::ushr, - eq(2), - { x, r -> x ushr 1 == 1 && r == true }, - { x, r -> x ushr 1 != 1 && r == false } - ) - } - - @Test - fun testUshrLong() { - check( - BitOperators::ushrLong, - eq(2), - { x, r -> x ushr 1 == 1L && r == true }, - { x, r -> x ushr 1 != 1L && r == false } - ) - } - - @Test - fun testSign() { - check( - BitOperators::sign, - eq(3), - { x, r -> x > 0 && r == 1 }, - { x, r -> x == 0 && r == 0 }, - { x, r -> x < 0 && r == -1 } - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/math/DivRemExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/math/DivRemExamplesTest.kt deleted file mode 100644 index acd9124d5d..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/math/DivRemExamplesTest.kt +++ /dev/null @@ -1,78 +0,0 @@ -package org.utbot.examples.math - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker -import org.utbot.testing.isException - -internal class DivRemExamplesTest : UtValueTestCaseChecker(testClass = DivRemExamples::class) { - @Test - fun testDiv() { - checkWithException( - DivRemExamples::div, - eq(2), - { _, y, r -> y == 0 && r.isException() }, - { x, y, r -> y != 0 && r.getOrNull() == x / y } - ) - } - - @Test - fun testRem() { - checkWithException( - DivRemExamples::rem, - eq(2), - { _, y, r -> y == 0 && r.isException() }, - { x, y, r -> y != 0 && r.getOrNull() == x % y } - ) - } - - @Test - fun testRemPositiveConditional() { - checkWithException( - DivRemExamples::remPositiveConditional, - eq(3), - { d, r -> d == 0 && r.isException() }, - { d, r -> d != 0 && 11 % d == 2 && r.getOrNull() == true }, - { d, r -> d != 0 && 11 % d != 2 && r.getOrNull() == false } - ) - } - - @Test - fun testRemNegativeConditional() { - checkWithException( - DivRemExamples::remNegativeConditional, - eq(3), - { d, r -> d == 0 && r.isException() }, - { d, r -> d != 0 && -11 % d == -2 && r.getOrNull() == true }, - { d, r -> d != 0 && -11 % d != -2 && r.getOrNull() == false } - ) - } - - @Test - fun testRemWithConditions() { - checkWithException( - DivRemExamples::remWithConditions, - eq(4), - { d, r -> d < 0 && r.getOrNull() == false }, - { d, r -> d == 0 && r.isException() }, - { d, r -> d > 0 && -11 % d == -2 && r.getOrNull() == true }, - { d, r -> d > 0 && -11 % d != -2 && r.getOrNull() == false } - ) - } - - @Test - fun testRemDoubles() { - check( - DivRemExamples::remDoubles, - eq(1) - ) - } - - @Test - fun testRemDoubleInt() { - check( - DivRemExamples::remDoubleInt, - eq(1) - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/math/DoubleFunctionsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/math/DoubleFunctionsTest.kt deleted file mode 100644 index a69f6565f2..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/math/DoubleFunctionsTest.kt +++ /dev/null @@ -1,61 +0,0 @@ -package org.utbot.examples.math - -import kotlin.math.abs -import kotlin.math.hypot -import org.junit.jupiter.api.Tag -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.DoNotCalculate -import org.utbot.testing.UtValueTestCaseChecker -import org.utbot.testing.isException - -@Suppress("SimplifyNegatedBinaryExpression") -internal class DoubleFunctionsTest : UtValueTestCaseChecker(testClass = DoubleFunctions::class) { - @Test - @Tag("slow") - fun testHypo() { - check( - DoubleFunctions::hypo, - eq(1), - { a, b, r -> a > 1 && a < 10 && b > 1 && b < 10 && abs(r!! - hypot(a, b)) < 1e-5 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testMax() { - check( - DoubleFunctions::max, - eq(2), - { a, b, r -> a > b && r == a }, - { a, b, r -> !(a > b) && (r == b || r!!.isNaN()) } - ) - } - - @Test - @Tag("slow") - fun testCircleSquare() { - checkWithException( - DoubleFunctions::circleSquare, - eq(5), - { radius, r -> radius < 0 && r.isException() }, - { radius, r -> radius > 10000 && r.isException() }, - { radius, r -> radius.isNaN() && r.isException() }, - { radius, r -> Math.PI * radius * radius <= 777.85 && r.getOrNull() == 0.0 }, - { radius, r -> Math.PI * radius * radius > 777.85 && abs(777.85 - r.getOrNull()!!) >= 1e-5 } - ) - } - - @Test - @Tag("slow") - fun testNumberOfRootsInSquareFunction() { - check( - DoubleFunctions::numberOfRootsInSquareFunction, - eq(3), // sometimes solver substitutes a = nan || b = nan || c = nan || some combination of 0 and inf - { a, b, c, r -> !(b * b - 4 * a * c >= 0) && r == 0 }, - { a, b, c, r -> b * b - 4 * a * c == 0.0 && r == 1 }, - { a, b, c, r -> b * b - 4 * a * c > 0 && r == 2 }, - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt deleted file mode 100644 index 4adc79d13b..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt +++ /dev/null @@ -1,282 +0,0 @@ -package org.utbot.examples.math - -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.examples.algorithms.Sort -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq -import org.utbot.testcheckers.withSolverTimeoutInMillis -import org.utbot.testcheckers.withTreatingOverflowAsError -import kotlin.math.floor -import kotlin.math.sqrt - -internal class OverflowAsErrorTest : UtValueTestCaseChecker( - testClass = OverflowExamples::class, - testCodeGeneration = true, - // Don't launch tests, because ArithmeticException will be expected, but it is not supposed to be actually thrown. - // ArithmeticException acts as a sign of Overflow. - listOf( - TestLastStage(CodegenLanguage.JAVA, Compilation), - TestLastStage(CodegenLanguage.KOTLIN, Compilation), - ) -) { - @Test - fun testIntOverflow() { - withTreatingOverflowAsError { - checkWithException( - OverflowExamples::intOverflow, - eq(5), - { x, _, r -> x * x * x <= 0 && x > 0 && r.isException() }, // through overflow - { x, _, r -> x * x * x <= 0 && x > 0 && r.isException() }, // through overflow (2nd '*') - { x, _, r -> x * x * x >= 0 && x >= 0 && r.getOrNull() == 0 }, - { x, y, r -> x * x * x > 0 && x > 0 && y == 10 && r.getOrNull() == 1 }, - { x, y, r -> x * x * x > 0 && x > 0 && y != 10 && r.getOrNull() == 0 }, - coverage = AtLeast(90), - ) - } - } - - @Test - fun testByteAddOverflow() { - withTreatingOverflowAsError { - checkWithException( - OverflowExamples::byteAddOverflow, - eq(2), - { _, _, r -> !r.isException() }, - { x, y, r -> - val negOverflow = ((x + y).toByte() >= 0 && x < 0 && y < 0) - val posOverflow = ((x + y).toByte() <= 0 && x > 0 && y > 0) - (negOverflow || posOverflow) && r.isException() - }, // through overflow - ) - } - } - - @Test - fun testByteSubOverflow() { - withTreatingOverflowAsError { - checkWithException( - OverflowExamples::byteSubOverflow, - eq(2), - { _, _, r -> !r.isException() }, - { x, y, r -> - val negOverflow = ((x - y).toByte() >= 0 && x < 0 && y > 0) - val posOverflow = ((x - y).toByte() <= 0 && x > 0 && y < 0) - (negOverflow || posOverflow) && r.isException() - }, // through overflow - ) - } - } - - @Test - fun testByteMulOverflow() { - withTreatingOverflowAsError { - checkWithException( - OverflowExamples::byteMulOverflow, - eq(2), - { _, _, r -> !r.isException() }, - { _, _, r -> r.isException() }, // through overflow - ) - } - } - - @Test - fun testShortAddOverflow() { - withTreatingOverflowAsError { - checkWithException( - OverflowExamples::shortAddOverflow, - eq(2), - { _, _, r -> !r.isException() }, - { x, y, r -> - val negOverflow = ((x + y).toShort() >= 0 && x < 0 && y < 0) - val posOverflow = ((x + y).toShort() <= 0 && x > 0 && y > 0) - (negOverflow || posOverflow) && r.isException() - }, // through overflow - ) - } - } - - @Test - fun testShortSubOverflow() { - withTreatingOverflowAsError { - checkWithException( - OverflowExamples::shortSubOverflow, - eq(2), - { _, _, r -> !r.isException() }, - { x, y, r -> - val negOverflow = ((x - y).toShort() >= 0 && x < 0 && y > 0) - val posOverflow = ((x - y).toShort() <= 0 && x > 0 && y < 0) - (negOverflow || posOverflow) && r.isException() - }, // through overflow - ) - } - } - - @Test - fun testShortMulOverflow() { - withTreatingOverflowAsError { - checkWithException( - OverflowExamples::shortMulOverflow, - eq(2), - { _, _, r -> !r.isException() }, - { _, _, r -> r.isException() }, // through overflow - ) - } - } - - @Test - fun testIntAddOverflow() { - withTreatingOverflowAsError { - checkWithException( - OverflowExamples::intAddOverflow, - eq(2), - { _, _, r -> !r.isException() }, - { x, y, r -> - val negOverflow = ((x + y) >= 0 && x < 0 && y < 0) - val posOverflow = ((x + y) <= 0 && x > 0 && y > 0) - (negOverflow || posOverflow) && r.isException() - }, // through overflow - ) - } - } - - @Test - fun testIntSubOverflow() { - withTreatingOverflowAsError { - checkWithException( - OverflowExamples::intSubOverflow, - eq(2), - { _, _, r -> !r.isException() }, - { x, y, r -> - val negOverflow = ((x - y) >= 0 && x < 0 && y > 0) - val posOverflow = ((x - y) <= 0 && x > 0 && y < 0) - (negOverflow || posOverflow) && r.isException() - }, // through overflow - ) - } - } - - @Test - fun testIntMulOverflow() { - // This test has solver timeout. - // Reason: softConstraints, containing limits for Int values, hang solver. - // With solver timeout softConstraints are dropped and hard constraints are SAT for overflow. - withSolverTimeoutInMillis(timeoutInMillis = 1000) { - withTreatingOverflowAsError { - checkWithException( - OverflowExamples::intMulOverflow, - eq(2), - { _, _, r -> !r.isException() }, - { _, _, r -> r.isException() }, // through overflow - ) - } - } - } - - @Test - fun testLongAddOverflow() { - withTreatingOverflowAsError { - checkWithException( - OverflowExamples::longAddOverflow, - eq(2), - { _, _, r -> !r.isException() }, - { x, y, r -> - val negOverflow = ((x + y) >= 0 && x < 0 && y < 0) - val posOverflow = ((x + y) <= 0 && x > 0 && y > 0) - (negOverflow || posOverflow) && r.isException() - }, // through overflow - ) - } - } - - @Test - fun testLongSubOverflow() { - withTreatingOverflowAsError { - checkWithException( - OverflowExamples::longSubOverflow, - eq(2), - { _, _, r -> !r.isException() }, - { x, y, r -> - val negOverflow = ((x - y) >= 0 && x < 0 && y > 0) - val posOverflow = ((x - y) <= 0 && x > 0 && y < 0) - (negOverflow || posOverflow) && r.isException() - }, // through overflow - ) - } - } - - @Test - @Disabled("Flaky branch count mismatch (1 instead of 2)") - fun testLongMulOverflow() { - // This test has solver timeout. - // Reason: softConstraints, containing limits for Int values, hang solver. - // With solver timeout softConstraints are dropped and hard constraints are SAT for overflow. - withSolverTimeoutInMillis(timeoutInMillis = 2000) { - withTreatingOverflowAsError { - checkWithException( - OverflowExamples::longMulOverflow, - eq(2), - { _, _, r -> !r.isException() }, - { _, _, r -> r.isException() }, // through overflow - ) - } - } - } - - @Test - fun testIncOverflow() { - withTreatingOverflowAsError { - checkWithException( - OverflowExamples::incOverflow, - eq(2), - { _, r -> !r.isException() }, - { _, r -> r.isException() }, // through overflow - ) - } - } - - @Test - fun testIntCubeOverflow() { - val sqrtIntMax = floor(sqrt(Int.MAX_VALUE.toDouble())).toInt() - withTreatingOverflowAsError { - checkWithException( - OverflowExamples::intCubeOverflow, - eq(3), - { _, r -> !r.isException() }, - // Can't use abs(x) below, because abs(Int.MIN_VALUE) == Int.MIN_VALUE. - // (Int.MAX_VALUE shr 16) is the border of square overflow and cube overflow. - // Int.MAX_VALUE.toDouble().pow(1/3.toDouble()) - { x, r -> (x > -sqrtIntMax && x < sqrtIntMax) && r.isException() }, // through overflow - { x, r -> (x <= -sqrtIntMax || x >= sqrtIntMax) && r.isException() }, // through overflow - ) - } - } - -// Generated Kotlin code does not compile, so disabled for now - @Test - @Disabled - fun testQuickSort() { - withTreatingOverflowAsError { - checkWithException( - Sort::quickSort, - ignoreExecutionsNumber, - { _, _, _, r -> !r.isException() }, - { _, _, _, r -> r.isException() }, // through overflow - ) - } - } - - @Test - fun testIntOverflowWithoutError() { - check( - OverflowExamples::intOverflow, - eq(6), - { x, _, r -> x * x * x <= 0 && x <= 0 && r == 0 }, - { x, _, r -> x * x * x > 0 && x <= 0 && r == 0 }, // through overflow - { x, y, r -> x * x * x > 0 && x > 0 && y != 10 && r == 0 }, - { x, y, r -> x * x * x > 0 && x > 0 && y == 10 && r == 1 }, - { x, y, r -> x * x * x <= 0 && x > 0 && y != 20 && r == 0 }, // through overflow - { x, y, r -> x * x * x <= 0 && x > 0 && y == 20 && r == 2 } // through overflow - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/LoggerExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/LoggerExampleTest.kt deleted file mode 100644 index 9655f9119a..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/LoggerExampleTest.kt +++ /dev/null @@ -1,58 +0,0 @@ -package org.utbot.examples.mixed - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.framework.plugin.api.UtConcreteValue -import org.utbot.framework.plugin.api.UtInstrumentation -import org.utbot.framework.plugin.api.UtModel -import org.utbot.framework.plugin.api.UtStaticMethodInstrumentation -import org.utbot.framework.plugin.api.isNull -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.CodeGeneration -import org.utbot.testing.DoNotCalculate -import org.utbot.testing.UtValueTestCaseChecker - -internal class LoggerExampleTest : UtValueTestCaseChecker( - testClass = LoggerExample::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testExample() { - checkMocksAndInstrumentation( - LoggerExample::example, - eq(2), - { _, instrumentation, _ -> theOnlyStaticMockValue(instrumentation).isNull() }, - { mocks, instrumentation, r -> mocks.size == 3 && instrumentation.size == 1 && r == 15 }, - additionalDependencies = arrayOf(org.slf4j.Logger::class.java), - coverage = DoNotCalculate - ) - } - - @Test - fun testLoggerUsage() { - checkMocksAndInstrumentation( - LoggerExample::loggerUsage, - eq(3), - { _, instrumentation, _ -> theOnlyStaticMockValue(instrumentation).isNull() }, - { mocks, instrumentation, r -> - (mocks.single().values.single() as UtConcreteValue<*>).value == false && instrumentation.size == 1 && r == 2 - }, - { mocks, instrumentation, r -> - (mocks.single().values.single() as UtConcreteValue<*>).value == true && instrumentation.size == 1 && r == 1 - }, - additionalDependencies = arrayOf(org.slf4j.Logger::class.java), - coverage = DoNotCalculate - ) - } - - private fun theOnlyStaticMockValue(instrumentation: List): UtModel = - instrumentation - .filterIsInstance() - .single() - .values - .single() -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/MonitorUsageTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/MonitorUsageTest.kt deleted file mode 100644 index 09974c3c22..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/MonitorUsageTest.kt +++ /dev/null @@ -1,19 +0,0 @@ -package org.utbot.examples.mixed - -import org.junit.jupiter.api.Test -import org.utbot.testing.UtValueTestCaseChecker -import org.utbot.testing.atLeast -import org.utbot.testing.ignoreExecutionsNumber - -internal class MonitorUsageTest : UtValueTestCaseChecker(testClass = MonitorUsage::class) { - @Test - fun testSimpleMonitor() { - check( - MonitorUsage::simpleMonitor, - ignoreExecutionsNumber, - { x, r -> x <= 0 && r == 0 }, - { x, r -> x > 0 && x <= Int.MAX_VALUE - 1 && r == 1 }, - coverage = atLeast(81) // differs from JaCoCo - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/OverloadTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/OverloadTest.kt deleted file mode 100644 index b6012d8d8b..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/OverloadTest.kt +++ /dev/null @@ -1,29 +0,0 @@ -package org.utbot.examples.mixed - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker - -internal class OverloadTest : UtValueTestCaseChecker(testClass = Overload::class) { - @Test - fun testSignOneParam() { - check( - Overload::sign, - eq(3), - { x, r -> x < 0 && r == -1 }, - { x, r -> x == 0 && r == 0 }, - { x, r -> x > 0 && r == 1 } - ) - } - - @Test - fun testSignTwoParams() { - check( - Overload::sign, - eq(3), - { x, y, r -> x + y < 0 && r == -1 }, - { x, y, r -> x + y == 0 && r == 0 }, - { x, y, r -> x + y > 0 && r == 1 } - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt deleted file mode 100644 index 9e6f07c623..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt +++ /dev/null @@ -1,39 +0,0 @@ -package org.utbot.examples.mixed - -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq - -// TODO parameterized tests disabled due to https://github.com/UnitTestBot/UTBotJava/issues/1266 -internal class PrivateConstructorExampleTest : UtValueTestCaseChecker( - testClass = PrivateConstructorExample::class, - pipelines = listOf( - TestLastStage( - CodegenLanguage.JAVA, - parameterizedModeLastStage = Compilation - ), - TestLastStage( - CodegenLanguage.KOTLIN, - parameterizedModeLastStage = Compilation - ) - ) -) { - - /** - * Two branches need to be covered: - * 1. argument must be <= a - b, - * 2. argument must be > a - b - * - * a and b are fields of the class under test - */ - @Test - fun testLimitedSub() { - checkWithThis( - PrivateConstructorExample::limitedSub, - eq(2), - { caller, limit, r -> caller.a - caller.b >= limit && r == caller.a - caller.b }, - { caller, limit, r -> caller.a - caller.b < limit && r == limit }, - coverage = DoNotCalculate // TODO: Method coverage with `this` parameter isn't supported - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/SimpleNoConditionTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/SimpleNoConditionTest.kt deleted file mode 100644 index 8bddaa3e66..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/SimpleNoConditionTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -package org.utbot.examples.mixed - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker - -internal class SimpleNoConditionTest : UtValueTestCaseChecker(testClass = SimpleNoCondition::class) { - - @Test - fun testNoConditionAdd() { - check( - SimpleNoCondition::basicAdd, - eq(1) - ) - } - - @Test - fun testNoConditionPow() { - check( - SimpleNoCondition::basicXorInt, - eq(1) - ) - } - - @Test - fun testNoConditionPowBoolean() { - check( - SimpleNoCondition::basicXorBoolean, - eq(1) - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/SimplifierTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/SimplifierTest.kt deleted file mode 100644 index 0092e68eab..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/SimplifierTest.kt +++ /dev/null @@ -1,20 +0,0 @@ -package org.utbot.examples.mixed - - - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.DoNotCalculate -import org.utbot.testing.UtValueTestCaseChecker - -internal class SimplifierTest: UtValueTestCaseChecker(testClass = Simplifier::class) { - @Test - fun testSimplifyAdditionWithZero() { - check( - Simplifier::simplifyAdditionWithZero, - eq(1), - { fst, r -> r != null && r.x == fst.shortValue.toInt() }, - coverage = DoNotCalculate // because of assumes - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/StaticInitializerExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/StaticInitializerExampleTest.kt deleted file mode 100644 index e5b15f10fa..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/StaticInitializerExampleTest.kt +++ /dev/null @@ -1,31 +0,0 @@ -package org.utbot.examples.mixed - -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.examples.StaticInitializerExample - -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker - -@Disabled("Unknown build failure") -internal class StaticInitializerExampleTest : UtValueTestCaseChecker(testClass = StaticInitializerExample::class) { - @Test - fun testPositive() { - check( - StaticInitializerExample::positive, - eq(2), - { i, r -> i > 0 && r == true }, - { i, r -> i <= 0 && r == false }, - ) - } - - @Test - fun testNegative() { - check( - StaticInitializerExample::negative, - eq(2), - { i, r -> i < 0 && r == true }, - { i, r -> i >= 0 && r == false }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt deleted file mode 100644 index 40cfd0945d..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt +++ /dev/null @@ -1,42 +0,0 @@ -package org.utbot.examples.mixed - - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class StaticMethodExamplesTest : UtValueTestCaseChecker(testClass = StaticMethodExamples::class) { - // TODO: inline local variables when types inference bug in Kotlin fixed - @Test - fun testComplement() { - val method = StaticMethodExamples::complement - checkStaticMethod( - method, - eq(2), - { x, r -> x == -2 && r == true }, - { x, r -> x != -2 && r == false } - ) - } - - @Test - fun testMax2() { - val method = StaticMethodExamples::max2 - checkStaticMethod( - method, - eq(2), - { x, y, r -> x > y && r == x }, - { x, y, r -> x <= y && r == y.toInt() } - ) - } - - @Test - fun testSum() { - val method = StaticMethodExamples::sum - checkStaticMethod( - method, - eq(3), - { x, y, z, r -> x + y + z < -20 && r == (x + y + z).toLong() * 2 }, - { x, y, z, r -> x + y + z > 20 && r == (x + y + z).toLong() * 2 }, - { x, y, z, r -> x + y + z in -20..20 && r == (x + y + z).toLong() } - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt deleted file mode 100644 index 5fa176228b..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt +++ /dev/null @@ -1,363 +0,0 @@ -package org.utbot.examples.mock - - - - - -import org.utbot.examples.mock.provider.Provider -import org.utbot.examples.mock.service.impl.ExampleClass -import org.utbot.examples.mock.service.impl.ServiceWithArguments - - -import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class ArgumentsMockTest : UtValueTestCaseChecker(testClass = ServiceWithArguments::class) { - @Test - fun testMockForArguments_callMultipleMethods() { - checkMocksAndInstrumentation( - ServiceWithArguments::callMultipleMethods, - eq(3), - { provider, _, _, _ -> provider == null }, - { _, mocks, _, r -> - val firstMockConstraint = mocks[0].mocksMethod(Provider::provideInteger) - val secondMockConstraint = mocks[1].mocksMethod(Provider::provideLong) - val valueConstraint = mocks[0].value() < mocks[1].value() - val mockedValues = mocks.all { it.isParameter(1) } - - firstMockConstraint && secondMockConstraint && valueConstraint && mockedValues && r == 1 - }, - { _, mocks, _, r -> - val firstMockConstraint = mocks[0].mocksMethod(Provider::provideInteger) - val secondMockConstraint = mocks[1].mocksMethod(Provider::provideLong) - val valueConstraint = mocks[0].value() >= mocks[1].value() - val mockedValue = mocks.all { it.isParameter(1) } - - firstMockConstraint && secondMockConstraint && valueConstraint && mockedValue && r == 0 - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForArguments_IntArgument() { - checkMocksAndInstrumentation( - ServiceWithArguments::calculateBasedOnIntArgument, - eq(3), - { provider, _, _, _, _ -> provider == null }, - { _, _, mocks, _, r -> - val singleMock = mocks.single() - - val mocksMethod = singleMock.mocksMethod(Provider::provideGiven) - val valueConstraint = singleMock.value(0) < singleMock.value(1) - val paramConstraint = singleMock.isParameter(1) - - mocksMethod && valueConstraint && paramConstraint && r == 1 - }, - { _, _, mocks, _, r -> - val singleMock = mocks.single() - - val mocksMethod = singleMock.mocksMethod(Provider::provideGiven) - val valueConstraint = singleMock.value(0) >= singleMock.value(1) - val paramConstraint = singleMock.isParameter(1) - - mocksMethod && valueConstraint && paramConstraint && r == 0 - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForArguments_BooleanPrimitive() { - checkMocksAndInstrumentation( - ServiceWithArguments::calculateBasedOnBoolean, - eq(3), - { provider, _, _, _ -> provider == null }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideBoolean) && value() && isParameter(1) && r == 1 - } - }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideBoolean) && !value() && isParameter(1) && r == 0 - } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForArguments_inconsistentBoolean() { - checkMocksAndInstrumentation( - ServiceWithArguments::inconsistentBoolean, - eq(4), - { provider, _, _, _ -> provider == null }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideBoolean) && !value() && isParameter(1) && r == 0 - } - }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideBoolean) && value(0) && value(1) && isParameter(1) && r == 0 - } - }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideBoolean) && value(0) && !value(1) && isParameter(1) && r == 1 - } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - - @Test - fun testMockForArguments_CharacterPrimitive() { - checkMocksAndInstrumentation( - ServiceWithArguments::calculateBasedOnCharacter, - eq(3), - { provider, _, _, _ -> provider == null }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideCharacter) && value() > 'a' && isParameter(1) && r == 1 - } - }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideCharacter) && value() <= 'a' && isParameter(1) && r == 0 - } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForArguments_BytePrimitive() { - checkMocksAndInstrumentation( - ServiceWithArguments::calculateBasedOnByte, - eq(3), - { provider, _, _, _ -> provider == null }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideByte) && value() > 5 && isParameter(1) && r == 1 - } - }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideByte) && value() <= 5 && isParameter(1) && r == 0 - } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForArguments_ShortPrimitive() { - checkMocksAndInstrumentation( - ServiceWithArguments::calculateBasedOnShort, - eq(3), - { provider, _, _, _ -> provider == null }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideShort) && value() > 5 && isParameter(1) && r == 1 - } - }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideShort) && value() <= 5 && isParameter(1) && r == 0 - } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForArguments_IntPrimitive() { - checkMocksAndInstrumentation( - ServiceWithArguments::calculateBasedOnInteger, - eq(3), - { provider, _, _, _ -> provider == null }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideInteger) && value() > 5 && isParameter(1) && r == 1 - } - }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideInteger) && value() <= 5 && isParameter(1) && r == 0 - } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForArguments_LongPrimitive() { - checkMocksAndInstrumentation( - ServiceWithArguments::calculateBasedOnLong, - eq(3), - { provider, _, _, _ -> provider == null }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideLong) && value() > 5 && isParameter(1) && r == 1 - } - }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideLong) && value() <= 5 && isParameter(1) && r == 0 - } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Suppress("SimplifyNegatedBinaryExpression") - @Test - fun testMockForArguments_FloatPrimitive() { - checkMocksAndInstrumentation( - ServiceWithArguments::calculateBasedOnFloat, - eq(3), - { provider, _, _, _ -> provider == null }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideFloat) && value() > 1f && isParameter(1) && r == 1 - } - }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideFloat) && !(value() > 1f) && isParameter(1) && r == 0 - } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Suppress("SimplifyNegatedBinaryExpression") - @Test - fun testMockForArguments_DoublePrimitive() { - checkMocksAndInstrumentation( - ServiceWithArguments::calculateBasedOnDouble, - eq(3), - { provider, _, _, _ -> provider == null }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideDouble) && value() > 1.0 && isParameter(1) && r == 1 - } - }, - { _, mocks, _, r -> - mocks.single().run { - mocksMethod(Provider::provideDouble) && !(value() > 1.0) && isParameter(1) && r == 0 - } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForArguments_returnObject() { - checkMocksAndInstrumentation( - ServiceWithArguments::calculateBasedOnObject, - eq(4), - { provider, _, _, _ -> provider == null }, - { _, mocks, _, _ -> - mocks.single().run { - mocksMethod(Provider::provideObject) && value() == null && isParameter(1) - } - }, - { _, mocks, _, r -> - val mockConstraint = mocks.single().run { - mocksMethod(Provider::provideObject) && value().field == 0 && isParameter(1) - } - - mockConstraint && r == 1 - }, - { _, mocks, _, r -> - val mockConstraint = mocks.single().run { - mocksMethod(Provider::provideObject) && value().field != 0 && isParameter(1) - } - - mockConstraint && r == 0 - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForArguments_overloadedMethods() { - checkMocksAndInstrumentation( - ServiceWithArguments::calculateBasedOnOverloadedMethods, - eq(3), - { provider, _, _, _, r -> provider == null && r == null }, - { _, _, mocks, _, r -> - val zeroMockConstraint = mocks[0].run { - val mockFunc: Provider.() -> Int = Provider::provideOverloaded - val overloadedFunc: Provider.(Int) -> Int = Provider::provideOverloaded - mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) && isParameter(1) - } - val firstMockConstraint = mocks[1].run { - val mockFunc: Provider.(Int) -> Int = Provider::provideOverloaded - val overloadedFunc: Provider.() -> Int = Provider::provideOverloaded - mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) && isParameter(1) - } - - zeroMockConstraint && firstMockConstraint && mocks[0].value() < mocks[1].value() && r == 1 - }, - - { _, _, mocks, _, r -> - val zeroMockConstraint = mocks[0].run { - val mockFunc: Provider.() -> Int = Provider::provideOverloaded - val overloadedFunc: Provider.(Int) -> Int = Provider::provideOverloaded - mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) && isParameter(1) - } - val firstMockConstraint = mocks[1].run { - val mockFunc: Provider.(Int) -> Int = Provider::provideOverloaded - val overloadedFunc: Provider.() -> Int = Provider::provideOverloaded - mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) && isParameter(1) - } - - zeroMockConstraint && firstMockConstraint && mocks[0].value() >= mocks[1].value() && r == 0 - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForArguments_objectArguments() { - checkMocksAndInstrumentation( - ServiceWithArguments::calculateBasedOnObjectArgument, - between(3..4), - { provider, _, mocks, _, r -> provider == null && mocks.isEmpty() && r == null }, // NPE - { _, obj, _, _, _ -> obj != null }, - { _, _, mocks, _, r -> - val mockConstraint = mocks.single().run { - mocksMethod(Provider::provideGivenObject) && value() < 1 && isParameter(1) - } - mockConstraint && r == 1 - }, - { _, _, mocks, _, r -> - val mockConstraint = mocks.single().run { - mocksMethod(Provider::provideGivenObject) && value() >= 1 && isParameter(1) - } - mockConstraint && r == 0 - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt deleted file mode 100644 index 5c4a3a24d0..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt +++ /dev/null @@ -1,59 +0,0 @@ -package org.utbot.examples.mock - - - -import org.utbot.framework.plugin.api.MockStrategyApi -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class CommonMocksExampleTest: UtValueTestCaseChecker(testClass = CommonMocksExample::class) { - @Test - fun testMockInterfaceWithoutImplementors() { - checkMocks( - CommonMocksExample::mockInterfaceWithoutImplementors, - eq(2), - { v, mocks, _ -> v == null && mocks.isEmpty() }, - { _, mocks, _ -> mocks.singleOrNull() != null }, - coverage = DoNotCalculate - ) - } - - // TODO JIRA:1449 - @Test - fun testDoNotMockEquals() { - checkMocks( - CommonMocksExample::doNotMockEquals, - eq(2), - { fst, _, mocks, _ -> fst == null && mocks.isEmpty() }, - { _, _, mocks, _ -> mocks.isEmpty() }, // should be changed to not null fst when 1449 will be finished - mockStrategy = MockStrategyApi.OTHER_PACKAGES, - coverage = DoNotCalculate - ) - } - - // TODO JIRA:1449 - @Test - fun testNextValue() { - checkMocks( - CommonMocksExample::nextValue, - eq(4), - // node == null -> NPE - // node.next == null -> NPE - // node == node.next - // node.next.value == node.value + 1 - mockStrategy = MockStrategyApi.OTHER_CLASSES, - coverage = DoNotCalculate - ) - } - - @Test - fun testClinitMockExample() { - check( - CommonMocksExample::clinitMockExample, - eq(1), - { r -> r == -420 }, - mockStrategy = MockStrategyApi.OTHER_CLASSES, - coverage = DoNotCalculate - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt deleted file mode 100644 index 14a4c754d7..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt +++ /dev/null @@ -1,290 +0,0 @@ -package org.utbot.examples.mock - -import org.utbot.examples.mock.provider.Provider -import org.utbot.examples.mock.service.impl.ExampleClass -import org.utbot.examples.mock.service.impl.ServiceWithField -import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq - -internal class FieldMockTest : UtValueTestCaseChecker( - testClass = ServiceWithField::class, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA, lastStage = TestExecution, parameterizedModeLastStage = Compilation), - TestLastStage(CodegenLanguage.KOTLIN, lastStage = TestExecution) - ) -) { - @Test - fun testMockForField_callMultipleMethods() { - checkMocksAndInstrumentation( - ServiceWithField::callMultipleMethods, - eq(3), - { _, _, r -> r == null }, - { mocks, _, r -> - val zeroMock = mocks[0].mocksMethod(Provider::provideInteger) - val firstMock = mocks[1].mocksMethod(Provider::provideLong) - val valueConstraint = mocks[0].value() < mocks[1].value() - - zeroMock && firstMock && valueConstraint && r == 1 - }, - { mocks, _, r -> - val zeroMock = mocks[0].mocksMethod(Provider::provideInteger) - val firstMock = mocks[1].mocksMethod(Provider::provideLong) - val valueConstraint = mocks[0].value() >= mocks[1].value() - - zeroMock && firstMock && valueConstraint && r == 0 - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForField_IntArgument() { - checkMocksAndInstrumentation( - ServiceWithField::calculateBasedOnIntArgument, - eq(3), - { _, _, _, r -> r == null }, - { _, mocks, _, _ -> - mocks.single().run { - mocksMethod(Provider::provideGiven) && value(0) < value(1) - } - }, - { _, mocks, _, _ -> - mocks.single().run { - mocksMethod(Provider::provideGiven) && value(0) >= value(1) - } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForField_BooleanPrimitive() { - checkMocksAndInstrumentation( - ServiceWithField::calculateBasedOnBoolean, - eq(3), - { _, _, r -> r == null }, - { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideBoolean) && value() } }, - { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideBoolean) && !value() } }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForField_inconsistentBoolean() { - checkMocksAndInstrumentation( - ServiceWithField::inconsistentBoolean, - eq(4), - { _, _, r -> r == null }, - { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideBoolean) && !value() } }, - { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideBoolean) && value(0) && value(1) } }, - { mocks, _, _ -> - mocks.single().run { mocksMethod(Provider::provideBoolean) && value(0) && !value(1) } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - - @Test - fun testMockForField_CharacterPrimitive() { - checkMocksAndInstrumentation( - ServiceWithField::calculateBasedOnCharacter, - eq(3), - { _, _, r -> r == null }, - { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideCharacter) && value() > 'a' } }, - { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideCharacter) && value() <= 'a' } }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForField_BytePrimitive() { - checkMocksAndInstrumentation( - ServiceWithField::calculateBasedOnByte, - eq(3), - { _, _, r -> r == null }, - { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideByte) && value() > 5 } }, - { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideByte) && value() <= 5 } }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForField_ShortPrimitive() { - checkMocksAndInstrumentation( - ServiceWithField::calculateBasedOnShort, - eq(3), - { _, _, r -> r == null }, - { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideShort) && value() > 5 } }, - { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideShort) && value() <= 5 } }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForField_IntPrimitive() { - checkMocksAndInstrumentation( - ServiceWithField::calculateBasedOnInteger, - eq(3), - { _, _, r -> r == null }, - { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideInteger) && value() > 5 } }, - { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideInteger) && value() <= 5 } }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForField_LongPrimitive() { - checkMocksAndInstrumentation( - ServiceWithField::calculateBasedOnLong, - eq(3), - { _, _, r -> r == null }, - { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideLong) && value() > 5 } }, - { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideLong) && value() <= 5 } }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForField_FloatPrimitive() { - checkMocksAndInstrumentation( - ServiceWithField::calculateBasedOnFloat, - eq(3), - { _, _, r -> r == null }, - { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideFloat) && value() > 1f } }, - { mocks, _, _ -> - mocks.single().run { - mocksMethod(Provider::provideFloat) && value().isNaN() || value() <= 1f - } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForField_DoublePrimitive() { - checkMocksAndInstrumentation( - ServiceWithField::calculateBasedOnDouble, - eq(3), - { _, _, r -> r == null }, - { mocks, _, _ -> mocks.single().run { mocksMethod(Provider::provideDouble) && value() > 1.0 } }, - { mocks, _, _ -> - mocks.single().run { - mocksMethod(Provider::provideDouble) && value().isNaN() || value() <= 1.0 - } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForField_returnObject() { - checkMocksAndInstrumentation( - ServiceWithField::calculateBasedOnObject, - eq(4), - { _, _, r -> r == null }, - { mocks, _, _ -> - mocks.single().run { - mocksMethod(Provider::provideObject) && value() == null - } - }, - { mocks, _, result -> - val mockConstraint = mocks.single().run { - mocksMethod(Provider::provideObject) && value().field == 0 - } - - mockConstraint && result == 1 - }, - { mocks, _, result -> - val mockConstraint = mocks.single().run { - mocksMethod(Provider::provideObject) && - value().field != 0 - } - - mockConstraint && result == 0 - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForField_overloadedMethods() { - checkMocksAndInstrumentation( - ServiceWithField::calculateBasedOnOverloadedMethods, - eq(3), - { _, _, _, r -> r == null }, - { _, mocks, _, result -> - val zeroMockConstraint = mocks[0].run { - val mockFunc: Provider.() -> Int = Provider::provideOverloaded - val overloadedFunc: Provider.(Int) -> Int = Provider::provideOverloaded - mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) - } - val firstMockConstraint = mocks[1].run { - val mockFunc: Provider.(Int) -> Int = Provider::provideOverloaded - val overloadedFunc: Provider.() -> Int = Provider::provideOverloaded - mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) - } - val valueConstraint = mocks[0].value() < mocks[1].value() - - zeroMockConstraint && firstMockConstraint && valueConstraint && result == 1 - }, - { _, mocks, _, result -> - val zeroMockConstraint = mocks[0].run { - val mockFunc: Provider.() -> Int = Provider::provideOverloaded - val overloadedFunc: Provider.(Int) -> Int = Provider::provideOverloaded - mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) - } - val firstMockConstraint = mocks[1].run { - val mockFunc: Provider.(Int) -> Int = Provider::provideOverloaded - val overloadedFunc: Provider.() -> Int = Provider::provideOverloaded - mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) - } - val valueConstraint = mocks[0].value() >= mocks[1].value() - - zeroMockConstraint && firstMockConstraint && valueConstraint && result == 0 - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForField_objectArguments() { - checkMocksAndInstrumentation( - ServiceWithField::calculateBasedOnObjectArgument, - between(3..4), - { _, _, _, r -> r == null }, - { obj, _, _, _ -> obj == null }, - { obj, _, _, _ -> obj != null }, - { _, mocks, _, r -> - val mockConstraint = mocks.single().run { - mocksMethod(Provider::provideGivenObject) && value() < 1 - } - mockConstraint && r == 1 - }, - { _, mocks, _, r -> - val mockConstraint = mocks.single().run { - mocksMethod(Provider::provideGivenObject) && value() >= 1 - } - - mockConstraint && r == 0 - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/InnerMockWithFieldChecker.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/InnerMockWithFieldChecker.kt deleted file mode 100644 index 30a746e0c1..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/InnerMockWithFieldChecker.kt +++ /dev/null @@ -1,52 +0,0 @@ -package org.utbot.examples.mock - -import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES -import org.utbot.framework.plugin.api.UtModel -import org.utbot.framework.plugin.api.isMockModel -import org.utbot.framework.plugin.api.isNotNull -import org.utbot.framework.plugin.api.isNull -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtModelTestCaseChecker -import org.utbot.testing.getOrThrow -import org.utbot.testing.primitiveValue - -internal class InnerMockWithFieldChecker : UtModelTestCaseChecker(testClass = InnerMockWithFieldExample::class) { - @Test - fun testCheckAndUpdate() { - checkStatic( - InnerMockWithFieldExample::checkAndUpdate, - eq(4), - { example, r -> example.isNull() && r.isException() }, - { example, r -> example.isNotNull() && example.stamp.isNull() && r.isException() }, - { example, r -> - val result = r.getOrThrow() - val isMockModels = example.stamp.isMockModel() && result.isMockModel() - val stampConstraint = example.stamp.initial > example.stamp.version - val postcondition = result.initial == example.stamp.initial && result.version == result.initial - - isMockModels && stampConstraint && postcondition - }, - { example, r -> - val result = r.getOrThrow() - val stamp = example.stamp - - val isMockModels = stamp.isMockModel() && result.isMockModel() - val stampConstraint = stamp.initial <= stamp.version - val postcondition = result.initial == stamp.initial && result.version == stamp.version + 1 - - isMockModels && stampConstraint && postcondition - }, - mockStrategy = OTHER_PACKAGES - ) - } - - private val UtModel.stamp: UtModel - get() = findField("stamp") - - private val UtModel.initial: Int - get() = findField("initial").primitiveValue() - - private val UtModel.version: Int - get() = findField("version").primitiveValue() -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockFinalClassTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockFinalClassTest.kt deleted file mode 100644 index 72165ec696..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockFinalClassTest.kt +++ /dev/null @@ -1,34 +0,0 @@ -package org.utbot.examples.mock - -import org.utbot.examples.mock.others.FinalClass -import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_CLASSES -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.ge -import org.utbot.testing.* - -internal class MockFinalClassTest : UtValueTestCaseChecker( - testClass = MockFinalClassExample::class, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA, lastStage = TestExecution, parameterizedModeLastStage = Compilation), - TestLastStage(CodegenLanguage.KOTLIN, lastStage = TestExecution) - ) -) { - @Test - fun testFinalClass() { - checkMocks( - MockFinalClassExample::useFinalClass, - ge(2), - { mocks, r -> - val intProvider = mocks.singleMock("intProvider", FinalClass::provideInt) - intProvider.value(0) == 1 && r == 1 - }, - { mocks, r -> - val intProvider = mocks.singleMock("intProvider", FinalClass::provideInt) - intProvider.value(0) != 1 && r == 2 - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_CLASSES - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt deleted file mode 100644 index 7b5662bd82..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt +++ /dev/null @@ -1,146 +0,0 @@ -package org.utbot.examples.mock - -import org.utbot.framework.plugin.api.UtCompositeModel -import org.utbot.framework.plugin.api.UtNewInstanceInstrumentation -import java.util.Random -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq - -// TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 -internal class MockRandomTest : UtValueTestCaseChecker( - testClass = MockRandomExamples::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA, lastStage = TestExecution, parameterizedModeLastStage = Compilation), - TestLastStage(CodegenLanguage.KOTLIN, lastStage = CodeGeneration) - ) -) { - @Test - fun testRandomAsParameter() { - val method: Random.() -> Int = Random::nextInt - checkMocks( - MockRandomExamples::randomAsParameter, - eq(3), - { random, _, _, r -> random == null && r == null }, // NPE - { random, threshold, mocks, r -> - val mock = mocks.single() - assert(mock.isParameter(1) && mock.mocksMethod(method)) - val nextInt = mock.value() - - random == null && nextInt > threshold && r == threshold + 1 - }, - { random, threshold, mocks, r -> - val mock = mocks.single() - assert(mock.isParameter(1) && mock.mocksMethod(method)) - val nextInt = mock.value() - - random == null && nextInt <= threshold && r == nextInt - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testRandomAsField() { - val method: Random.() -> Int = Random::nextInt - checkMocks( - MockRandomExamples::randomAsField, - eq(3), - { _, _, r -> r == null }, // NPE - { threshold, mocks, r -> - val mock = mocks.singleMock("random", method) - val nextInt = mock.value() - - nextInt > threshold && r == threshold + 1 - }, - { threshold, mocks, r -> - val mock = mocks.singleMock("random", method) - val nextInt = mock.value() - - nextInt <= threshold && r == nextInt - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testRandomAsLocalVariable() { - checkMocksAndInstrumentation( - MockRandomExamples::randomAsLocalVariable, - eq(2), - { _, instrumentation, r -> - val mockInstances = instrumentation - .filterIsInstance() - .single { it.classId.name == "java.util.Random" } - .instances - //TODO: support any UtModel here after SAT-1135 is completed - .filterIsInstance() - - assert(mockInstances.size == 2) - - val firstMockValues = mockInstances[0].mockValues("nextInt") - val secondMockValues = mockInstances[1].mockValues("nextInt") - - val sizes = firstMockValues.size == 2 && secondMockValues.size == 2 - val valueConstraint = firstMockValues[0] + firstMockValues[1] + secondMockValues[0] > 1000 - val resultConstraint = r == secondMockValues[1] - - sizes && valueConstraint && resultConstraint - }, - { _, instrumentation, r -> - val mockInstances = instrumentation - .filterIsInstance() - .single { it.classId.name == "java.util.Random" } - .instances - .filterIsInstance() - - assert(mockInstances.size == 3) - - val firstMockValues = mockInstances[0].mockValues("nextInt") - val secondMockValues = mockInstances[1].mockValues("nextInt") - val thirdMockValues = mockInstances[2].mockValues("nextInt") - - val sizes = firstMockValues.size == 2 && secondMockValues.size == 1 && thirdMockValues.size == 1 - val valueConstraint = firstMockValues[0] + firstMockValues[1] + secondMockValues[0] <= 1000 - val resultConstraint = r == thirdMockValues[0] - - sizes && valueConstraint && resultConstraint - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testUseSecureRandom() { - checkMocksAndInstrumentation( - MockRandomExamples::useSecureRandom, - eq(2), - { _, instrumentation, r -> - val mock = instrumentation - .filterIsInstance() - .single { it.classId.name == "java.security.SecureRandom" } - .instances - .filterIsInstance() - .single() - - val values = mock.mockValues("nextInt") - - values.size == 1 && values[0] > 1000 && r == 1 - }, - { _, instrumentation, r -> - val mock = instrumentation - .filterIsInstance() - .single { it.classId.name == "java.security.SecureRandom" } - .instances - .filterIsInstance() - .single() - - val values = mock.mockValues("nextInt") - - values.size == 2 && values[0] <= 1000 && r == values[1] - }, - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockReturnObjectExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockReturnObjectExampleTest.kt deleted file mode 100644 index 3120626749..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockReturnObjectExampleTest.kt +++ /dev/null @@ -1,69 +0,0 @@ -package org.utbot.examples.mock - -import org.junit.jupiter.api.Disabled -import org.utbot.examples.mock.others.Generator -import org.utbot.examples.mock.others.Locator -import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.* - -internal class MockReturnObjectExampleTest : UtValueTestCaseChecker(testClass = MockReturnObjectExample::class) { - @Test - @Disabled("Java 11 transition") - fun testMockReturnObject() { - checkMocks( - MockReturnObjectExample::calculate, - eq(6), // 4 NPE - // NPE, privateLocator is null - { _, mocks, r -> - val privateLocator = mocks.singleMockOrNull("privateLocator", Locator::locate) - privateLocator == null && r == null - }, - // NPE, privateLocator.locate() returns null - { _, mocks, r -> - val generator = mocks.singleMock("privateLocator", Locator::locate).value() - generator == null && r == null - }, - // NPE, publicLocator is null - { _, mocks, r -> - val publicLocator = mocks.singleMockOrNull("publicLocator", Locator::locate) - publicLocator == null && r == null - }, - // NPE, publicLocator.locate() returns null - { _, mocks, r -> - val generator = mocks.singleMock("publicLocator", Locator::locate).value() - generator == null && r == null - }, - { threshold, mocks, r -> - val mockId1 = mocks.singleMock("privateLocator", Locator::locate).mockValue().id - val mockId2 = mocks.singleMock("publicLocator", Locator::locate).mockValue().id - - val mock1 = mocks.singleMock(mockId1, Generator::generateInt) - val mock2 = mocks.singleMock(mockId2, Generator::generateInt) - - val (index1, index2) = if (mock1.values.size > 1) 0 to 1 else 0 to 0 - val value1 = mock1.value(index1) - val value2 = mock2.value(index2) - - - threshold < value1 + value2 && r == threshold - }, - { threshold, mocks, r -> - val mockId1 = mocks.singleMock("privateLocator", Locator::locate).mockValue().id - val mockId2 = mocks.singleMock("publicLocator", Locator::locate).mockValue().id - - val mock1 = mocks.singleMock(mockId1, Generator::generateInt) - val mock2 = mocks.singleMock(mockId2, Generator::generateInt) - - val (index1, index2) = if (mock1.values.size > 1) 0 to 1 else 0 to 0 - val value1 = mock1.value(index1) - val value2 = mock2.value(index2) - - threshold >= value1 + value2 && r == value1 + value2 + 1 - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockStaticFieldExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockStaticFieldExampleTest.kt deleted file mode 100644 index 2c1188af36..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockStaticFieldExampleTest.kt +++ /dev/null @@ -1,71 +0,0 @@ -package org.utbot.examples.mock - -import org.utbot.examples.mock.others.Generator -import org.utbot.framework.plugin.api.FieldMockTarget -import org.utbot.framework.plugin.api.MockInfo -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.testing.* - -internal class MockStaticFieldExampleTest : UtValueTestCaseChecker(testClass = MockStaticFieldExample::class) { - - @Test - fun testMockStaticField() { - withoutConcrete { // TODO JIRA:1420 - checkMocks( - MockStaticFieldExample::calculate, - eq(4), // 2 NPE - // NPE, privateGenerator is null - { _, mocks, r -> - val privateGenerator = mocks.singleMockOrNull("privateGenerator", Generator::generateInt) - privateGenerator == null && r == null - }, - // NPE, publicGenerator is null - { _, mocks, r -> - val publicGenerator = mocks.singleMockOrNull("publicGenerator", Generator::generateInt) - publicGenerator == null && r == null - }, - { threshold, mocks, r -> - val mock1 = mocks.singleMock("privateGenerator", Generator::generateInt) - val mock2 = mocks.singleMock("publicGenerator", Generator::generateInt) - - val (index1, index2) = if (mock1.values.size > 1) 0 to 1 else 0 to 0 - - val value1 = mock1.value(index1) - val value2 = mock2.value(index2) - - val firstMockConstraint = mock1.mocksStaticField(MockStaticFieldExample::class) - val secondMockConstraint = mock2.mocksStaticField(MockStaticFieldExample::class) - val resultConstraint = threshold < value1 + value2 && r == threshold - - firstMockConstraint && secondMockConstraint && resultConstraint - }, - { threshold, mocks, r -> - val mock1 = mocks.singleMock("privateGenerator", Generator::generateInt) - val mock2 = mocks.singleMock("publicGenerator", Generator::generateInt) - - val (index1, index2) = if (mock1.values.size > 1) 0 to 1 else 0 to 0 - - val value1 = mock1.value(index1) - val value2 = mock2.value(index2) - - val firstMockConstraint = mock1.mocksStaticField(MockStaticFieldExample::class) - val secondMockConstraint = mock2.mocksStaticField(MockStaticFieldExample::class) - val resultConstraint = threshold >= value1 + value2 && r == value1 + value2 + 1 - - firstMockConstraint && secondMockConstraint && resultConstraint - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - } - - private fun MockInfo.mocksStaticField(kClass: KClass<*>) = when (val mock = mock) { - is FieldMockTarget -> mock.ownerClassName == kClass.qualifiedName && mock.owner == null - else -> false - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt deleted file mode 100644 index 821435ca21..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt +++ /dev/null @@ -1,46 +0,0 @@ -package org.utbot.examples.mock - -import org.utbot.framework.plugin.api.MockStrategyApi -import org.utbot.framework.plugin.api.UtPrimitiveModel -import org.utbot.framework.util.singleModel -import org.utbot.framework.util.singleStaticMethod -import org.utbot.framework.util.singleValue -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq - -// TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 -internal class MockStaticMethodExampleTest : UtValueTestCaseChecker( - testClass = MockStaticMethodExample::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA, lastStage = TestExecution, parameterizedModeLastStage = Compilation), - TestLastStage(CodegenLanguage.KOTLIN, lastStage = CodeGeneration) - ) -) { - @Test - fun testUseStaticMethod() { - checkMocksAndInstrumentation( - MockStaticMethodExample::useStaticMethod, - eq(2), - { _, instrumentation, r -> - val mockValue = instrumentation - .singleStaticMethod("nextRandomInt") - .singleModel() - .singleValue() as Int - - mockValue > 50 && r == 100 - }, - { _, instrumentation, r -> - val mockValue = instrumentation - .singleStaticMethod("nextRandomInt") - .singleModel() - .singleValue() as Int - - mockValue <= 50 && r == 0 - }, - coverage = DoNotCalculate, - mockStrategy = MockStrategyApi.OTHER_PACKAGES - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockWithFieldChecker.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockWithFieldChecker.kt deleted file mode 100644 index 397981d54e..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockWithFieldChecker.kt +++ /dev/null @@ -1,47 +0,0 @@ -package org.utbot.examples.mock - -import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES -import org.utbot.framework.plugin.api.UtModel -import org.utbot.framework.plugin.api.isMockModel -import org.utbot.framework.plugin.api.isNull -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtModelTestCaseChecker -import org.utbot.testing.getOrThrow -import org.utbot.testing.primitiveValue - -internal class MockWithFieldChecker : UtModelTestCaseChecker(testClass = MockWithFieldExample::class) { - @Test - fun testCheckAndUpdate() { - check( - MockWithFieldExample::checkAndUpdate, - eq(3), - { stamp, r -> stamp.isNull() && r.isException() }, - { stamp, r -> - val result = r.getOrThrow() - - val mockModels = stamp.isMockModel() && result.isMockModel() - val stampValues = stamp.initial > stamp.version - val resultConstraint = result.initial == stamp.initial && result.version == result.initial - - mockModels && stampValues && resultConstraint - }, - { stamp, r -> - val result = r.getOrThrow() - - val mockModels = stamp.isMockModel() && result.isMockModel() - val stampValues = stamp.initial <= stamp.version - val resultConstraint = result.initial == stamp.initial && result.version == stamp.version + 1 - - mockModels && stampValues && resultConstraint - }, - mockStrategy = OTHER_PACKAGES - ) - } - - private val UtModel.initial: Int - get() = findField("initial").primitiveValue() - - private val UtModel.version: Int - get() = findField("version").primitiveValue() -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockWithSideEffectExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockWithSideEffectExampleTest.kt deleted file mode 100644 index 1fba9e414b..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/MockWithSideEffectExampleTest.kt +++ /dev/null @@ -1,66 +0,0 @@ -package org.utbot.examples.mock - -import org.utbot.framework.plugin.api.MockStrategyApi -import org.junit.Test -import org.utbot.testcheckers.eq - -internal class MockWithSideEffectExampleTest : UtValueTestCaseChecker(testClass = MockWithSideEffectExample::class) { - @Test - fun testSideEffect() { - checkWithException( - MockWithSideEffectExample::checkSideEffect, - eq(3), - { _, r -> r.isException() }, - { _, r -> r.getOrNull() == false }, - { _, r -> r.getOrNull() == true }, - coverage = DoNotCalculate, - mockStrategy = MockStrategyApi.OTHER_PACKAGES - ) - } - - @Test - fun testSideEffectWithoutMocks() { - checkWithException( - MockWithSideEffectExample::checkSideEffect, - eq(2), - { _, r -> r.isException() }, - { _, r -> r.getOrNull() == true }, - coverage = DoNotCalculate, - mockStrategy = MockStrategyApi.NO_MOCKS - ) - } - - @Test - fun testSideEffectElimination() { - checkWithException( - MockWithSideEffectExample::checkSideEffectElimination, - eq(1), - { _, r -> r.getOrNull() == true }, - coverage = DoNotCalculate, - mockStrategy = MockStrategyApi.OTHER_PACKAGES - ) - } - - @Test - fun testStaticMethodSideEffectElimination() { - checkWithException( - MockWithSideEffectExample::checkStaticMethodSideEffectElimination, - eq(1), - { _, r -> r.getOrNull() == true }, - coverage = DoNotCalculate, - mockStrategy = MockStrategyApi.OTHER_PACKAGES - ) - } - - @Test - fun testStaticMethodSideEffectEliminationWithoutMocks() { - checkWithException( - MockWithSideEffectExample::checkStaticMethodSideEffectElimination, - eq(1), - { _, r -> r.getOrNull() == false }, - coverage = DoNotCalculate, - mockStrategy = MockStrategyApi.NO_MOCKS - ) - } - -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt deleted file mode 100644 index 9246daad57..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt +++ /dev/null @@ -1,277 +0,0 @@ -package org.utbot.examples.mock - -import org.utbot.examples.mock.provider.Provider -import org.utbot.examples.mock.service.impl.ExampleClass -import org.utbot.examples.mock.service.impl.ServiceWithStaticField - - -import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class StaticFieldMockTest : UtValueTestCaseChecker(testClass = ServiceWithStaticField::class) { - - @Test - fun testMockForStaticField_callMultipleMethods() { - checkMocks( - ServiceWithStaticField::callMultipleMethods, - eq(3), - { _, r -> r == null }, - { mocks, _ -> - val firstMockConstraint = mocks[0].mocksMethod(Provider::provideInteger) - val secondMockConstraint = mocks[1].mocksMethod(Provider::provideLong) - val resultConstraint = mocks[0].value() < mocks[1].value() - - firstMockConstraint && secondMockConstraint && resultConstraint - }, - { mocks, _ -> - val firstMockConstraint = mocks[0].mocksMethod(Provider::provideInteger) - val secondMockConstraint = mocks[1].mocksMethod(Provider::provideLong) - val resultConstraint = mocks[0].value() >= mocks[1].value() - - firstMockConstraint && secondMockConstraint && resultConstraint - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForStaticField_IntArgument() { - checkMocks( - ServiceWithStaticField::calculateBasedOnIntArgument, - eq(3), - { _, _, r -> r == null }, - { _, mocks, _ -> - mocks.single().run { - mocksMethod(Provider::provideGiven) && value(0) < value(1) - } - }, - { _, mocks, _ -> - mocks.single().run { - mocksMethod(Provider::provideGiven) && value(0) >= value(1) - } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForStaticField_BooleanPrimitive() { - checkMocks( - ServiceWithStaticField::calculateBasedOnBoolean, - eq(3), - { _, r -> r == null }, - { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideBoolean) && value() } }, - { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideBoolean) && !value() } }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForStaticField_inconsistentBoolean() { - checkMocks( - ServiceWithStaticField::inconsistentBoolean, - eq(4), - { _, r -> r == null }, - { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideBoolean) && !value() } }, - { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideBoolean) && value(0) && value(1) } }, - { mocks, _ -> - mocks.single().run { mocksMethod(Provider::provideBoolean) && value(0) && !value(1) } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - - @Test - fun testMockForStaticField_CharacterPrimitive() { - checkMocks( - ServiceWithStaticField::calculateBasedOnCharacter, - eq(3), - { _, r -> r == null }, - { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideCharacter) && value() > 'a' } }, - { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideCharacter) && value() <= 'a' } }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForStaticField_BytePrimitive() { - checkMocks( - ServiceWithStaticField::calculateBasedOnByte, - eq(3), - { _, r -> r == null }, - { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideByte) && value() > 5 } }, - { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideByte) && value() <= 5 } }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForStaticField_ShortPrimitive() { - checkMocks( - ServiceWithStaticField::calculateBasedOnShort, - eq(3), - { _, r -> r == null }, - { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideShort) && value() > 5 } }, - { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideShort) && value() <= 5 } }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForStaticField_IntPrimitive() { - checkMocks( - ServiceWithStaticField::calculateBasedOnInteger, - eq(3), - { _, r -> r == null }, - { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideInteger) && value() > 5 } }, - { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideInteger) && value() <= 5 } }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForStaticField_LongPrimitive() { - checkMocks( - ServiceWithStaticField::calculateBasedOnLong, - eq(3), - { _, r -> r == null }, - { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideLong) && value() > 5 } }, - { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideLong) && value() <= 5 } }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForStaticField_FloatPrimitive() { - checkMocks( - ServiceWithStaticField::calculateBasedOnFloat, - eq(3), - { _, r -> r == null }, - { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideFloat) && value() > 1f } }, - { mocks, _ -> - mocks.single().run { - mocksMethod(Provider::provideFloat) && value().isNaN() || value() <= 1f - } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForStaticField_DoublePrimitive() { - checkMocks( - ServiceWithStaticField::calculateBasedOnDouble, - eq(3), - { _, r -> r == null }, - { mocks, _ -> mocks.single().run { mocksMethod(Provider::provideDouble) && value() > 1.0 } }, - { mocks, _ -> - mocks.single().run { - mocksMethod(Provider::provideDouble) && value().isNaN() || value() <= 1.0 - } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForStaticField_returnObject() { - checkMocks( - ServiceWithStaticField::calculateBasedOnObject, - eq(4), - { _, r -> r == null }, - { mocks, _ -> - mocks.single().run { - mocksMethod(Provider::provideObject) && value() == null - } - }, - { mocks, result -> - val mockConstraint = mocks.single().run { - mocksMethod(Provider::provideObject) && value().field == 0 - } - mockConstraint && result == 1 - }, - { mocks, result -> - val mockConstraint = mocks.single().run { - mocksMethod(Provider::provideObject) && value().field != 0 - } - mockConstraint && result == 0 - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForStaticField_overloadedMethods() { - checkMocks( - ServiceWithStaticField::calculateBasedOnOverloadedMethods, - eq(3), - { _, _, r -> r == null }, - { _, mocks, result -> - val zeroMockConstraint = mocks[0].run { - val mockFunc: Provider.() -> Int = Provider::provideOverloaded - val overloadedFunc: Provider.(Int) -> Int = Provider::provideOverloaded - mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) - } - val firstMockConstraint = mocks[1].run { - val mockFunc: Provider.(Int) -> Int = Provider::provideOverloaded - val overloadedFunc: Provider.() -> Int = Provider::provideOverloaded - mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) - } - val valueConstraint = mocks[0].value() < mocks[1].value() - - zeroMockConstraint && firstMockConstraint && valueConstraint && result == 1 - }, - - { _, mocks, result -> - val zeroMockConstraint = mocks[0].run { - val mockFunc: Provider.() -> Int = Provider::provideOverloaded - val overloadedFunc: Provider.(Int) -> Int = Provider::provideOverloaded - mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) - } - val firstMockConstraint = mocks[1].run { - val mockFunc: Provider.(Int) -> Int = Provider::provideOverloaded - val overloadedFunc: Provider.() -> Int = Provider::provideOverloaded - mocksMethod(mockFunc) && !mocksMethod(overloadedFunc) - } - val valueConstraint = mocks[0].value() >= mocks[1].value() - - zeroMockConstraint && firstMockConstraint && valueConstraint && result == 0 - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } - - @Test - fun testMockForStaticField_objectArguments() { - checkMocks( - ServiceWithStaticField::calculateBasedOnObjectArgument, - eq(4), - { _, _, r -> r == null }, - { obj, _, _ -> obj == null }, - { obj, _, _ -> obj != null }, - { _, mocks, _ -> - mocks.single().run { mocksMethod(Provider::provideGivenObject) && value() < 1 } - }, - { _, mocks, _ -> - mocks.single().run { mocksMethod(Provider::provideGivenObject) && value() >= 1 } - }, - coverage = DoNotCalculate, - mockStrategy = OTHER_PACKAGES - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/UseNetworkTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/UseNetworkTest.kt deleted file mode 100644 index f481cb78be..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/UseNetworkTest.kt +++ /dev/null @@ -1,57 +0,0 @@ -package org.utbot.examples.mock - -import org.utbot.framework.plugin.api.MockStrategyApi -import org.utbot.framework.plugin.api.UtConcreteValue -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq - -internal class UseNetworkTest : UtValueTestCaseChecker(testClass = UseNetwork::class) { - @Test - fun testReadBytes() { - val method = UseNetwork::readBytes - checkStaticMethodWithException( - method, - eq(5), - { _, network, r -> network == null && r.isException() }, - { _, _, r -> r.getOrNull() == 0 }, - { pkg, _, r -> pkg == null && r.isException() }, - { pkg, _, r -> pkg.isEmpty() && r.isException() }, - { pkg, _, r -> pkg.isNotEmpty() && (r.isException() || r.getOrNull()!! > 0) }, - mockStrategy = MockStrategyApi.OTHER_PACKAGES, - coverage = DoNotCalculate - ) - } - - @Test - fun testReadBytesWithMocks() { - val method = UseNetwork::readBytes - checkMocksInStaticMethod( - method, - eq(5), - { packet, _, _, _ -> packet == null }, - { _, network, _, _ -> network == null }, - { _, _, mocks, r -> (mocks.single().values.single() as UtConcreteValue<*>).value == -1 && r == 0 }, - { packet, _, mocks, _ -> - require(packet != null) - - val mockConstraint = (mocks.single().values.single() as UtConcreteValue<*>).value != -1 - val sizeConstraint = packet.isEmpty() - - mockConstraint && sizeConstraint - }, - { packet, _, mocks, r -> - require(packet != null) - - val values = mocks.single().values.map { (it as UtConcreteValue<*>).value } - val mockConstraint = values.dropLast(1).all { it != -1 } && values.last() == -1 - val sizeConstraint = packet.size >= values.lastIndex - - mockConstraint && sizeConstraint && r == values.lastIndex - - }, - mockStrategy = MockStrategyApi.OTHER_PACKAGES, - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/aliasing/AliasingInParamsExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/aliasing/AliasingInParamsExampleTest.kt deleted file mode 100644 index c0ce27528f..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/aliasing/AliasingInParamsExampleTest.kt +++ /dev/null @@ -1,31 +0,0 @@ -package org.utbot.examples.mock.aliasing - -import org.utbot.framework.plugin.api.MockStrategyApi -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class AliasingInParamsExampleTest : UtValueTestCaseChecker(testClass = AliasingInParamsExample::class) { - @Test - fun testExamplePackageBased() { - check( - AliasingInParamsExample::example, - eq(1), - { fst, snd, x, r -> fst != snd && x == r }, - coverage = DoNotCalculate, - mockStrategy = MockStrategyApi.OTHER_PACKAGES - ) - } - - @Test - fun testExample() { - check( - AliasingInParamsExample::example, - eq(2), - { fst, snd, x, r -> fst == snd && x == r }, - { fst, snd, x, r -> fst != snd && x == r }, - coverage = DoNotCalculate, - mockStrategy = MockStrategyApi.NO_MOCKS - ) - } - -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt deleted file mode 100644 index 2499893bf3..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt +++ /dev/null @@ -1,38 +0,0 @@ -package org.utbot.examples.mock.model - -import org.utbot.examples.mock.provider.impl.ProviderImpl -import org.utbot.examples.mock.service.impl.ServiceWithField - -import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES -import org.utbot.framework.plugin.api.UtModel -import org.utbot.framework.plugin.api.isNotNull -import org.utbot.framework.plugin.api.isNull -import org.junit.jupiter.api.Test - -import org.utbot.testcheckers.eq - -internal class FieldMockChecker : UtModelTestCaseChecker(testClass = ServiceWithField::class) { - @Test - fun testMockForField_IntPrimitive() { - checkStatic( - ServiceWithField::staticCalculateBasedOnInteger, - eq(4), - { service, r -> service.isNull() && r.isException() }, - { service, r -> service.provider.isNull() && r.isException() }, - { service, r -> - service.provider.isNotNull() && - service.provider.mocksMethod(ProviderImpl::provideInteger)!!.single() - .primitiveValue() > 5 && r.primitiveValue() == 1 - }, - { service, r -> - service.provider.isNotNull() && - service.provider.mocksMethod(ProviderImpl::provideInteger)!!.single() - .primitiveValue() <= 5 && r.primitiveValue() == 0 - }, - mockStrategy = OTHER_PACKAGES - ) - } - - private val UtModel.provider: UtModel - get() = this.findField("provider") -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/model/UseNetworkModelBasedTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/mock/model/UseNetworkModelBasedTest.kt deleted file mode 100644 index dcdd58e4d0..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/mock/model/UseNetworkModelBasedTest.kt +++ /dev/null @@ -1,28 +0,0 @@ -package org.utbot.examples.mock.model - - -import org.utbot.examples.mock.UseNetwork -import org.utbot.framework.plugin.api.MockStrategyApi -import org.utbot.framework.plugin.api.UtCompositeModel -import org.utbot.framework.plugin.api.UtVoidModel -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtModelTestCaseChecker - -internal class UseNetworkModelBasedTest : UtModelTestCaseChecker(testClass = UseNetwork::class) { - @Test - fun testMockVoidMethod() { - check( - UseNetwork::mockVoidMethod, - eq(1), - { network, _ -> - require(network is UtCompositeModel) - - val mock = network.mocks.values.single().single() - - mock is UtVoidModel - }, - mockStrategy = MockStrategyApi.OTHER_PACKAGES - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/models/CompositeModelMinimizationChecker.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/models/CompositeModelMinimizationChecker.kt deleted file mode 100644 index cb2556af49..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/models/CompositeModelMinimizationChecker.kt +++ /dev/null @@ -1,78 +0,0 @@ -package org.utbot.examples.models - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.framework.plugin.api.FieldId -import org.utbot.framework.plugin.api.UtAssembleModel -import org.utbot.framework.plugin.api.UtCompositeModel -import org.utbot.framework.plugin.api.UtModel -import org.utbot.framework.plugin.api.UtReferenceModel -import org.junit.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.CodeGeneration -import org.utbot.testing.UtModelTestCaseChecker - -internal class CompositeModelMinimizationChecker : UtModelTestCaseChecker( - testClass = CompositeModelMinimizationExample::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - private fun UtModel.getFieldsOrNull(): Map? = when(this) { - is UtAssembleModel -> origin?.fields - is UtCompositeModel -> fields - else -> null - } - - private fun UtModel.hasInitializedFields(): Boolean = getFieldsOrNull()?.isNotEmpty() == true - private fun UtModel.isNotInitialized(): Boolean = getFieldsOrNull()?.isEmpty() == true - - @Test - fun singleNotNullArgumentInitializationRequiredTest() { - check( - CompositeModelMinimizationExample::singleNotNullArgumentInitializationRequired, - eq(2), - { o, _ -> o.hasInitializedFields() } - ) - } - - @Test - fun sameArgumentsInitializationRequiredTest() { - check( - CompositeModelMinimizationExample::sameArgumentsInitializationRequired, - eq(3), - { a, b, _ -> - a as UtReferenceModel - b as UtReferenceModel - a.id == b.id && a.hasInitializedFields() && b.hasInitializedFields() - } - ) - } - - @Test - fun distinctNotNullArgumentsSecondInitializationNotExpected() { - check( - CompositeModelMinimizationExample::distinctNotNullArgumentsSecondInitializationNotExpected, - eq(2), - { a, b, _ -> - a as UtReferenceModel - b as UtReferenceModel - a.hasInitializedFields() && b.isNotInitialized() - } - ) - } - - @Test - fun distinctNotNullArgumentsInitializationRequired() { - check( - CompositeModelMinimizationExample::distinctNotNullArgumentsInitializationRequired, - eq(2), - { a, b, _ -> - a as UtReferenceModel - b as UtReferenceModel - a.hasInitializedFields() && b.hasInitializedFields() - } - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/models/ModelsIdEqualityChecker.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/models/ModelsIdEqualityChecker.kt deleted file mode 100644 index 8e50a4b48b..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/models/ModelsIdEqualityChecker.kt +++ /dev/null @@ -1,143 +0,0 @@ -package org.utbot.examples.models - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.framework.plugin.api.UtArrayModel -import org.utbot.framework.plugin.api.UtAssembleModel -import org.utbot.framework.plugin.api.UtDirectSetFieldModel -import org.utbot.framework.plugin.api.UtExecutionSuccess -import org.utbot.framework.plugin.api.UtReferenceModel -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -// TODO failed Kotlin compilation SAT-1332 -internal class ModelsIdEqualityChecker : UtModelTestCaseChecker( - testClass = ModelsIdEqualityExample::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testObjectItself() { - check( - ModelsIdEqualityExample::objectItself, - eq(1), - { o, r -> (o as UtReferenceModel).id == ((r as UtExecutionSuccess).model as UtReferenceModel).id } - ) - } - - @Test - fun testRefField() { - check( - ModelsIdEqualityExample::refField, - eq(1), - { o, r -> - val resultId = ((r as UtExecutionSuccess).model as UtReferenceModel).id - val fieldId = (o as UtAssembleModel).findFieldId() - fieldId == resultId - } - ) - } - - @Test - fun testArrayField() { - check( - ModelsIdEqualityExample::arrayField, - eq(1), - { o, r -> - val resultId = ((r as UtExecutionSuccess).model as UtReferenceModel).id - val fieldId = (o as UtAssembleModel).findFieldId() - fieldId == resultId - } - ) - } - - @Test - fun testArrayItself() { - check( - ModelsIdEqualityExample::arrayItself, - eq(1), - { o, r -> (o as? UtReferenceModel)?.id == ((r as UtExecutionSuccess).model as? UtReferenceModel)?.id } - ) - } - - @Test - fun testSubArray() { - check( - ModelsIdEqualityExample::subArray, - eq(1), - { array, r -> - val resultId = ((r as UtExecutionSuccess).model as UtReferenceModel).id - val arrayId = (array as UtArrayModel).findElementId(0) - resultId == arrayId - } - ) - } - - @Test - fun testSubRefArray() { - check( - ModelsIdEqualityExample::subRefArray, - eq(1), - { array, r -> - val resultId = ((r as UtExecutionSuccess).model as UtReferenceModel).id - val arrayId = (array as UtArrayModel).findElementId(0) - resultId == arrayId - } - ) - } - - @Test - fun testWrapperExample() { - check( - ModelsIdEqualityExample::wrapperExample, - eq(1), - { o, r -> (o as? UtReferenceModel)?.id == ((r as UtExecutionSuccess).model as? UtReferenceModel)?.id } - ) - } - - @Test - fun testObjectFromArray() { - check( - ModelsIdEqualityExample::objectFromArray, - eq(1), - { array, r -> - val resultId = ((r as UtExecutionSuccess).model as UtReferenceModel).id - val objectId = (array as UtArrayModel).findElementId(0) - resultId == objectId - } - ) - } - - @Test - fun testObjectAndStatic() { - checkStaticsAfter( - ModelsIdEqualityExample::staticSetter, - eq(1), - { obj, statics, r -> - val resultId = ((r as UtExecutionSuccess).model as UtReferenceModel).id - val objectId = (obj as UtReferenceModel).id - val staticId = (statics.values.single() as UtReferenceModel).id - resultId == objectId && resultId == staticId - } - ) - - } - - private fun UtReferenceModel.findFieldId(): Int? { - this as UtAssembleModel - val fieldModel = this.modificationsChain - .filterIsInstance() - .single() - .fieldModel - return (fieldModel as UtReferenceModel).id - } - - private fun UtArrayModel.findElementId(index: Int) = - if (index in stores.keys) { - (stores[index] as UtReferenceModel).id - } else { - (constModel as UtReferenceModel).id - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/natives/NativeExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/natives/NativeExamplesTest.kt deleted file mode 100644 index 4b7bd42a9e..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/natives/NativeExamplesTest.kt +++ /dev/null @@ -1,39 +0,0 @@ -package org.utbot.examples.natives - -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq -import org.utbot.testcheckers.ge -import org.utbot.testcheckers.withSolverTimeoutInMillis - -// TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 -internal class NativeExamplesTest : UtValueTestCaseChecker( - testClass = NativeExamples::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - - @Test - fun testFindAndPrintSum() { - // TODO related to the https://github.com/UnitTestBot/UTBotJava/issues/131 - withSolverTimeoutInMillis(5000) { - check( - NativeExamples::findAndPrintSum, - ge(1), - coverage = DoNotCalculate, - ) - } - } - - @Test - fun testFindSumWithMathRandom() { - check( - NativeExamples::findSumWithMathRandom, - eq(1), - coverage = DoNotCalculate, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt deleted file mode 100644 index efab9304b1..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt +++ /dev/null @@ -1,57 +0,0 @@ -package org.utbot.examples.objects - -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq - -class AnonymousClassesExampleTest : UtValueTestCaseChecker( - testClass = AnonymousClassesExample::class, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA, lastStage = TestExecution, parameterizedModeLastStage = Compilation), - TestLastStage(CodegenLanguage.KOTLIN, lastStage = TestExecution) - ) -) { - @Test - fun testAnonymousClassAsParam() { - checkWithException( - AnonymousClassesExample::anonymousClassAsParam, - eq(3), - { abstractAnonymousClass, r -> abstractAnonymousClass == null && r.isException() }, - { abstractAnonymousClass, r -> abstractAnonymousClass != null && r.getOrNull() == 0 }, - { abstractAnonymousClass, r -> abstractAnonymousClass != null && abstractAnonymousClass::class.java.isAnonymousClass && r.getOrNull() == 42 }, - coverage = Full - ) - } - - @Test - fun testNonFinalAnonymousStatic() { - checkStaticsAndException( - AnonymousClassesExample::nonFinalAnonymousStatic, - eq(3), - { statics, r -> statics.values.single().value == null && r.isException() }, - { _, r -> r.getOrNull() == 0 }, - { _, r -> r.getOrNull() == 42 }, - coverage = Full - ) - } - - @Test - fun testAnonymousClassAsStatic() { - check( - AnonymousClassesExample::anonymousClassAsStatic, - eq(1), - { r -> r == 42 }, - coverage = Full - ) - } - - @Test - fun testAnonymousClassAsResult() { - check( - AnonymousClassesExample::anonymousClassAsResult, - eq(1), - { abstractAnonymousClass -> abstractAnonymousClass != null && abstractAnonymousClass::class.java.isAnonymousClass }, - coverage = Full - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ClassRefTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ClassRefTest.kt deleted file mode 100644 index 6382bc09c5..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ClassRefTest.kt +++ /dev/null @@ -1,137 +0,0 @@ -@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") - -package org.utbot.examples.objects - -import org.utbot.framework.plugin.api.CodegenLanguage -import java.lang.Boolean -import kotlin.Array -import kotlin.Suppress -import kotlin.arrayOf -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class ClassRefTest : UtValueTestCaseChecker( - testClass = ClassRef::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - // TODO: SAT-1457 Restore Kotlin codegen for a group of tests with type casts - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testTakeBooleanClassRef() { - check( - ClassRef::takeBooleanClassRef, - eq(1), - { r -> r == Boolean.TYPE } - ) - } - - @Test - fun testTakeClassRef() { - check( - ClassRef::takeClassRef, - eq(1), - { r -> r == ClassRef::class.java } - ) - } - - @Test - fun testTakeClassRefFromParam() { - check( - ClassRef::takeClassRefFromParam, - eq(2), - { classRef, _ -> classRef == null }, - { classRef, r -> r == classRef.javaClass } - ) - } - - - @Test - fun testTakeArrayClassRef() { - check( - ClassRef::takeArrayClassRef, - eq(1), - { r -> r == arrayOf()::class.java } - ) - } - - @Test - fun testTwoDimArrayClassRef() { - check( - ClassRef::twoDimArrayClassRef, - eq(1), - { r -> r == arrayOf>()::class.java } - ) - } - - @Test - fun testTwoDimArrayClassRefFromParam() { - check( - ClassRef::twoDimArrayClassRefFromParam, - eq(2), - { array, _ -> array == null }, - { array, r -> r == array::class.java } - ) - } - - @Test - fun testTakeConstantClassRef() { - check( - ClassRef::takeConstantClassRef, - eq(1), - { r -> r == ClassRef::class.java } - ) - } - - @Test - fun testEqualityOnClassRef() { - check( - ClassRef::equalityOnClassRef, - eq(1), - { r -> r == true }, - coverage = atLeast(50) // we cannot find a way to have different class references - ) - } - - @Test - fun testEqualityOnStringClassRef() { - check( - ClassRef::equalityOnStringClassRef, - eq(1), - { r -> r == true }, - coverage = atLeast(50) // we cannot find a way to have different class references - ) - } - - @Test - fun testEqualityOnArrayClassRef() { - check( - ClassRef::equalityOnArrayClassRef, - eq(1), - { r -> r == true }, - coverage = atLeast(50) // we cannot find a way to have different class references - ) - } - - @Test - fun testTwoDimensionalArrayClassRef() { - check( - ClassRef::twoDimensionalArrayClassRef, - eq(1), - { r -> r == true }, - coverage = atLeast(50) - ) - } - - @Test - fun testEqualityOnGenericClassRef() { - check( - ClassRef::equalityOnGenericClassRef, - eq(1), - { r -> r == true }, - coverage = atLeast(50) // we cannot find a way to have different class references - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ClassWithClassRefTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ClassWithClassRefTest.kt deleted file mode 100644 index d081c8c0a3..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ClassWithClassRefTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -package org.utbot.examples.objects - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testcheckers.withoutConcrete - -// TODO Kotlin compilation SAT-1332 -// Code generation executions fail due we cannot analyze strings properly for now -internal class ClassWithClassRefTest : UtValueTestCaseChecker( - testClass = ClassWithClassRef::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA, Compilation), // TODO JIRA:1479 - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - // 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" - checkWithThisAndException( - ClassWithClassRef::classRefName, - eq(2), - { instance, r -> instance.someListClass == null && r.isException() }, - { instance, r -> instance.someListClass != null && r.getOrNull() == "" }, - coverage = DoNotCalculate // TODO: Method coverage with `this` parameter isn't supported - ) - } - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/HiddenFieldAccessModifiersTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/HiddenFieldAccessModifiersTest.kt deleted file mode 100644 index c9ef29e55e..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/HiddenFieldAccessModifiersTest.kt +++ /dev/null @@ -1,20 +0,0 @@ -package org.utbot.examples.objects - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker - -internal class HiddenFieldAccessModifiersTest : UtValueTestCaseChecker(testClass = HiddenFieldAccessModifiersExample::class) { - @Test - fun testCheckSuperFieldEqualsOne() { - withEnabledTestingCodeGeneration(testCodeGeneration = true) { - check( - HiddenFieldAccessModifiersExample::checkSuperFieldEqualsOne, - eq(3), - { o, _ -> o == null }, - { _, r -> r == true }, - { _, r -> r == false }, - ) - } - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt deleted file mode 100644 index 41d2edfbfb..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt +++ /dev/null @@ -1,34 +0,0 @@ -package org.utbot.examples.objects - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class HiddenFieldExampleTest : UtValueTestCaseChecker(testClass = HiddenFieldExample::class) { - @Test - fun testCheckHiddenField() { - check( - HiddenFieldExample::checkHiddenField, - eq(4), - { o, _ -> o == null }, - { o, r -> o != null && o.a != 1 && r == 2 }, - { o, r -> o != null && o.a == 1 && o.b != 2 && r == 2 }, - { o, r -> o != null && o.a == 1 && o.b == 2 && r == 1 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCheckSuccField() { - withEnabledTestingCodeGeneration(testCodeGeneration = true) { - check( - HiddenFieldExample::checkSuccField, - eq(5), - { o, _ -> o == null }, - { o, r -> o.a == 1 && r == 1 }, - { o, r -> o.a != 1 && o.b == 2.0 && r == 2 }, - { o, r -> o.a != 1 && o.b != 2.0 && (o as HiddenFieldSuperClass).b == 3 && r == 3 }, - { o, r -> o.a != 1 && o.b != 2.0 && (o as HiddenFieldSuperClass).b != 3 && r == 4 }, - ) - } - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ModelMinimizationExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ModelMinimizationExamplesTest.kt deleted file mode 100644 index 80ab112c2b..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ModelMinimizationExamplesTest.kt +++ /dev/null @@ -1,131 +0,0 @@ -package org.utbot.examples.objects - -import org.junit.Test -import org.utbot.testcheckers.eq - -internal class ModelMinimizationExamplesTest : UtValueTestCaseChecker(testClass = ModelMinimizationExamples::class) { - @Test - fun singleValueComparisonTest() { - check( - ModelMinimizationExamples::singleValueComparison, - eq(4), - { quad, _ -> quad == null }, // NPE - { quad, _ -> quad.a == null }, // NPE - { quad, r -> quad.a.value == 0 && r == true }, - { quad, r -> quad.a.value != 0 && r == false } - ) - } - - @Test - fun singleValueComparisonNotNullTest() { - check( - ModelMinimizationExamples::singleValueComparisonNotNull, - eq(2), - { quad, r -> quad.a.value == 0 && r == true }, - { quad, r -> quad.a.value != 0 && r == false }, - coverage = DoNotCalculate // TODO: JIRA:1688 - ) - } - - @Test - fun conditionCheckANeTest() { - // Parameters `a` and `b` should be not null. - // Parameters `a` and `b` should be distinct instances. - // The field `a.value` is used and should be initialized. - // The field `b.value` is not used and should not be initialized to avoid redundancy. - check( - ModelMinimizationExamples::conditionCheckANe, - eq(3), - { a, _, r -> a.value == 42 && r == true }, - { a, _, r -> a.value <= 0 && r == true }, - { a, _, r -> a.value > 0 && a.value != 42 && r == false}, - coverage = DoNotCalculate // TODO: JIRA:1688 - ) - } - - @Test - fun conditionCheckAEqTest() { - // Parameters `a` and `b` should be not null. - // Parameters `a` and `b` should refer to the same instance. - // The field `a.value` is used and should be initialized. - // The field `b.value` is not used but should be implicitly initialized, as `b` is `a` restored from cache. - check( - ModelMinimizationExamples::conditionCheckAEq, - eq(3), - { a, _, r -> a.value == 42 && r == true }, - { a, _, r -> a.value <= 0 && r == true }, - { a, _, r -> a.value > 0 && a.value != 42 && r == false}, - coverage = DoNotCalculate // TODO: JIRA:1688 - ) - } - - @Test - fun conditionCheckBNeTest() { - // Parameters `a` and `b` should be not null. - // Parameters `a` and `b` should be distinct instances. - // The field `a.value` is not used and should not be initialized to avoid redundancy. - // The field `b.value` is used and should be initialized. - check( - ModelMinimizationExamples::conditionCheckBNe, - eq(3), - { _, b, r -> b.value == 42 && r == true }, - { _, b, r -> b.value <= 0 && r == true }, - { _, b, r -> b.value > 0 && b.value != 42 && r == false}, - coverage = DoNotCalculate // TODO: JIRA:1688 - ) - } - - @Test - fun conditionCheckBEqTest() { - // Parameters `a` and `b` should be not null. - // Parameters `a` and `b` should refer to the same instance. - // The field `a.value` is not used but should be initialized, as `b.value` is used, and `a === b`. - // The field `b.value` is used and should be initialized. - // `a` should be initialized even if its model is created first and stored in the cache. - // Note: `a` and `b` might have different `addr` but they will have the same `concreteAddr`. - check( - ModelMinimizationExamples::conditionCheckBEq, - eq(3), - { _, b, r -> b.value == 42 && r == true }, - { _, b, r -> b.value <= 0 && r == true }, - { _, b, r -> b.value > 0 && b.value != 42 && r == false}, - coverage = DoNotCalculate // TODO: JIRA:1688 - ) - } - - @Test - fun conditionCheckNoNullabilityConstraintTest() { - // Note: in this test we have no constraints on the second argument, so it becomes `null`. - check( - ModelMinimizationExamples::conditionCheckNoNullabilityConstraintExample, - eq(4), - { a, _, _ -> a == null }, // NPE - { a, _, r -> a.value == 42 && r == true }, - { a, _, r -> a.value <= 0 && r == true }, - { a, _, r -> a.value > 0 && a.value != 42 && r == false} - ) - } - - @Test - fun firstArrayElementContainsSentinelTest() { - check( - ModelMinimizationExamples::firstArrayElementContainsSentinel, - eq(2), - { values, r -> values[0].value == 42 && r == true }, - { values, r -> values[0].value != 42 && r == false }, - coverage = DoNotCalculate // TODO: JIRA:1688 - ) - } - - @Test - fun multipleConstraintsTest() { - check( - ModelMinimizationExamples::multipleConstraintsExample, - eq(3), - { a, _, _, r -> a.value == 42 && r == 1 }, - { a, b, _, r -> a.value != 42 && b.value == 73 && r == 2 }, - { a, b, _, r -> a.value != 42 && b.value != 73 && r == 3 }, - coverage = DoNotCalculate // TODO: JIRA:1688 - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithFinalStaticTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithFinalStaticTest.kt deleted file mode 100644 index 4f2e04c94c..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithFinalStaticTest.kt +++ /dev/null @@ -1,26 +0,0 @@ -package org.utbot.examples.objects - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -class ObjectWithFinalStaticTest : UtValueTestCaseChecker( - testClass = ObjectWithFinalStatic::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testParameterEqualsFinalStatic() { - checkStatics( - ObjectWithFinalStatic::parameterEqualsFinalStatic, - eq(2), - { key, _, statics, result -> key != statics.singleValue() as Int && result == -420 }, - // matcher checks equality by value, but branch is executed if objects are equal by reference - { key, i, statics, result -> key == statics.singleValue() && i == result }, - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesClassTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesClassTest.kt deleted file mode 100644 index aa568046f5..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesClassTest.kt +++ /dev/null @@ -1,34 +0,0 @@ -package org.utbot.examples.objects - -import kotlin.reflect.KFunction0 -import kotlin.reflect.KFunction3 -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class ObjectWithPrimitivesClassTest : UtValueTestCaseChecker(testClass = ObjectWithPrimitivesClass::class) { - @Test - fun testDefaultConstructor() { - val method: KFunction0 = ::ObjectWithPrimitivesClass - checkStaticMethod( - method, - eq(1), - // TODO: SAT-933 Add support for constructor testing") - // { instance -> instance is ObjectWithPrimitivesClass }, - coverage = DoNotCalculate - ) - } - - @Test - fun testConstructorWithParams() { - val method: KFunction3 = ::ObjectWithPrimitivesClass - checkStaticMethod( - method, - eq(1), - // TODO: SAT-933 Add support for constructor testing") -// { x, y, weight, instance -> -// instance is ObjectWithPrimitivesClass && instance.x == x && instance.y == y && instance.weight == weight -// }, - coverage = DoNotCalculate - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt deleted file mode 100644 index bff483ad3f..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt +++ /dev/null @@ -1,266 +0,0 @@ -package org.utbot.examples.objects - -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class ObjectWithPrimitivesExampleTest : UtValueTestCaseChecker(testClass = ObjectWithPrimitivesExample::class) { - @Test - fun testMax() { - checkWithException( - ObjectWithPrimitivesExample::max, - eq(7), - { fst, _, r -> fst == null && r.isException() }, - { _, snd, r -> snd == null && r.isException() }, - { fst, snd, r -> fst != null && snd != null && fst.x > snd.x && fst.y > snd.y && r.getOrNull()!! == fst }, - { fst, snd, r -> fst != null && snd != null && fst.x > snd.x && fst.y <= snd.y && r.getOrNull()!! == fst }, - { fst, snd, r -> fst != null && snd != null && fst.x < snd.x && fst.y < snd.y && r.getOrNull()!! == snd }, - { fst, snd, r -> fst != null && snd != null && fst.x == snd.x && r.getOrNull()!! == fst }, - { fst, snd, r -> fst != null && snd != null && fst.y == snd.y && r.getOrNull()!! == fst }, - coverage = DoNotCalculate - ) - } - - @Test - fun testIgnoredInputParameters() { - check( - ObjectWithPrimitivesExample::ignoredInputParameters, - eq(1), - { fst, snd, r -> fst == null && snd == null && r != null } - ) - } - - @Test - fun testExample() { - check( - ObjectWithPrimitivesExample::example, - eq(3), - { v, _ -> v == null }, - { v, r -> v != null && v.x == 1 && r?.x == 1 }, - { v, r -> v != null && v.x != 1 && r?.x == 1 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testExampleMutation() { - checkParamsMutations( - ObjectWithPrimitivesExample::example, - ignoreExecutionsNumber, - { valueBefore, valueAfter -> valueBefore.x != 0 && valueAfter.x == 1 } - ) - } - - @Test - fun testDefaultValueForSuperclassFields() { - check( - ObjectWithPrimitivesExample::defaultValueForSuperclassFields, - eq(1), - { r -> r != null && r.x == 0 && r.y == 0 && r.weight == 0.0 && r.valueByDefault == 5 && r.anotherX == 0 }, - coverage = atLeast(50) - ) - } - - @Test - @Disabled("TODO JIRA:1594") - fun testCreateObject() { - checkWithException( - ObjectWithPrimitivesExample::createObject, - eq(3), - { _, _, o, r -> o == null && r.isException() }, - { _, _, o, r -> o != null && o.weight < 0 && r.isException() }, - { a, b, o, r -> - val result = r.getOrNull()!! - - val objectConstraint = o != null && (o.weight >= 0 || o.weight.isNaN()) - val resultConstraint = result.x == a + 5 && result.y == b + 6 - val postcondition = result.weight == o.weight || result.weight.isNaN() && o.weight.isNaN() - - objectConstraint && resultConstraint && postcondition - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testMemory() { - checkWithException( - ObjectWithPrimitivesExample::memory, - eq(4), - { o, v, r -> o == null && v > 0 && r.isException() }, - { o, v, r -> - val resultValue = r.getOrNull() - val objectToCompare = if (resultValue is ObjectWithPrimitivesClassSucc) { - ObjectWithPrimitivesClassSucc(1, 2, 1.2, resultValue.anotherX) - } else { - ObjectWithPrimitivesClass(1, 2, 1.2) - } - objectToCompare.valueByDefault = resultValue!!.valueByDefault - - o != null && v > 0 && resultValue == objectToCompare - }, - { o, v, r -> o == null && v <= 0 && r.isException() }, - { o, v, r -> - val resultValue = r.getOrNull() - val objectToCompare = if (resultValue is ObjectWithPrimitivesClassSucc) { - ObjectWithPrimitivesClassSucc(-1, -2, -1.2, resultValue.anotherX) - } else { - ObjectWithPrimitivesClass(-1, -2, -1.2) - } - objectToCompare.valueByDefault = resultValue!!.valueByDefault - - o != null && v <= 0 && resultValue == objectToCompare - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCompareWithNull() { - check( - ObjectWithPrimitivesExample::compareWithNull, - eq(3), - { fst, _, r -> fst == null && r == 1 }, - { fst, snd, r -> fst != null && snd == null && r == 2 }, - { fst, snd, r -> fst != null && snd != null && r == 3 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCompareTwoNullObjects() { - check( - ObjectWithPrimitivesExample::compareTwoNullObjects, - eq(1), - coverage = DoNotCalculate - ) - } - - @Test - fun testNullExample() { - check( - ObjectWithPrimitivesExample::nullExample, - eq(4), - { o, _ -> o == null }, - { o, r -> o != null && o.x != 0 && r != null }, - { o, r -> o != null && o.x == 0 && o.y != 0 && r != null }, - { o, r -> o != null && o.x == 0 && o.y == 0 && r == null }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCompareTwoOuterObjects() { - checkWithException( - ObjectWithPrimitivesExample::compareTwoOuterObjects, - eq(4), - { x, _, r -> x == null && r.isException() }, - { x, y, r -> x != null && y == null && r.isException() }, - { x, y, r -> x != null && y != null && x === y && r.getOrNull() == true }, - { x, y, r -> x != null && y != null && x !== y && r.getOrNull() == false } - ) - } - - @Test - fun testCompareObjectWithArgument() { - check( - ObjectWithPrimitivesExample::compareObjectWithArgument, - eq(1), - coverage = DoNotCalculate - ) - } - - @Test - fun testCompareTwoDifferentObjects() { - check( - ObjectWithPrimitivesExample::compareTwoDifferentObjects, - eq(1), - coverage = DoNotCalculate - ) - } - - - @Test - fun testCompareTwoIdenticalObjectsFromArguments() { - checkWithException( - ObjectWithPrimitivesExample::compareTwoIdenticalObjectsFromArguments, - eq(4), - { fst, _, r -> fst == null && r.isException() }, - { _, snd, r -> snd == null && r.isException() }, - { fst, snd, r -> fst != null && snd != null && r.getOrNull() == 1 }, - { fst, snd, r -> fst != null && snd != null && r.getOrNull() == 2 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCompareTwoRefEqualObjects() { - check( - ObjectWithPrimitivesExample::compareTwoRefEqualObjects, - eq(1), - coverage = DoNotCalculate - ) - } - - @Test - fun testGetOrDefault() { - checkWithException( - ObjectWithPrimitivesExample::getOrDefault, - ignoreExecutionsNumber, - { _, d, r -> d == null && r.isException() }, - { _, d, r -> d != null && d.x == 0 && d.y == 0 && r.isException() }, - { o, d, r -> o == null && (d.x != 0 || d.y != 0) && r.getOrNull() == d }, - { o, d, r -> o != null && (d.x != 0 || d.y != 0) && r.getOrNull() == o }, - ) - } - - @Test - fun testInheritorsFields() { - checkWithException( - ObjectWithPrimitivesExample::inheritorsFields, - eq(3), - { fst, _, r -> fst == null && r.isException() }, - { fst, snd, r -> fst != null && snd == null && r.isException() }, - { fst, snd, r -> fst != null && snd != null && r.getOrNull() == 1 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCreateWithConstructor() { - check( - ObjectWithPrimitivesExample::createWithConstructor, - eq(1), - { x, y, r -> r != null && r.x == x + 1 && r.y == y + 2 && r.weight == 3.3 } - ) - } - - @Test - fun testCreateWithSuperConstructor() { - check( - ObjectWithPrimitivesExample::createWithSuperConstructor, - eq(1), - { x, y, anotherX, r -> - r != null && r.x == x + 1 && r.y == y + 2 && r.weight == 3.3 && r.anotherX == anotherX + 4 - } - ) - } - - @Test - fun testFieldWithDefaultValue() { - check( - ObjectWithPrimitivesExample::fieldWithDefaultValue, - eq(1), - { x, y, r -> r != null && r.x == x && r.y == y && r.weight == 3.3 && r.valueByDefault == 5 } - ) - } - - @Test - fun testValueByDefault() { - check( - ObjectWithPrimitivesExample::valueByDefault, - eq(1), - { r -> r == 5 } - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt deleted file mode 100644 index 1d331f9d0d..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt +++ /dev/null @@ -1,154 +0,0 @@ -package org.utbot.examples.objects - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class ObjectWithRefFieldsExampleTest : UtValueTestCaseChecker(testClass = ObjectWithRefFieldExample::class) { - @Test - fun testDefaultValue() { - check( - ObjectWithRefFieldExample::defaultValue, - eq(1), - { r -> r != null && r.x == 0 && r.y == 0 && r.weight == 0.0 && r.arrayField == null && r.refField == null }, - coverage = atLeast(50) - ) - } - - @Test - fun testWriteToRefTypeField() { - check( - ObjectWithRefFieldExample::writeToRefTypeField, - eq(4), - { _, v, _ -> v != 42 }, - { o, v, _ -> v == 42 && o == null }, - { o, v, _ -> v == 42 && o != null && o.refField != null }, - { o, v, r -> - v == 42 && o != null && o.refField == null && r != null && r.refField.a == v && r.refField.b == 2 * v - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testDefaultFieldValues() { - check( - ObjectWithRefFieldExample::defaultFieldValues, - eq(1), - { r -> - r != null && r.x == 0 && r.y == 0 && r.weight == 0.0 && r.refField == null && r.arrayField == null - } - ) - } - - @Test - fun testReadFromRefTypeField() { - check( - ObjectWithRefFieldExample::readFromRefTypeField, - eq(4), - { o, _ -> o == null }, - { o, _ -> o != null && o.refField == null }, - { o, r -> o?.refField != null && o.refField.a <= 0 && r == -1 }, - { o, r -> o?.refField != null && o.refField.a > 0 && o.refField.a == r } - ) - } - - @Test - fun testWriteToArrayField() { - check( - ObjectWithRefFieldExample::writeToArrayField, - eq(3), - { _, length, _ -> length < 3 }, - { o, length, _ -> length >= 3 && o == null }, - { o, length, r -> - require(r != null) - - val array = r.arrayField - - val preconditions = length >= 3 && o != null - val contentConstraint = array.dropLast(1) == (1 until length).toList() && array.last() == 100 - - preconditions && contentConstraint - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testReadFromArrayField() { - check( - ObjectWithRefFieldExample::readFromArrayField, - eq(5), - { o, _, _ -> o == null }, - { o, _, _ -> o != null && o.arrayField == null }, - { o, _, _ -> o?.arrayField != null && o.arrayField.size < 3 }, - { o, v, r -> o?.arrayField != null && o.arrayField.size >= 3 && o.arrayField[2] == v && r == 1 }, - { o, v, r -> o?.arrayField != null && o.arrayField.size >= 3 && o.arrayField[2] != v && r == 2 } - ) - } - - @Test - fun testCompareTwoDifferentObjectsFromArguments() { - check( - ObjectWithRefFieldExample::compareTwoDifferentObjectsFromArguments, - ignoreExecutionsNumber, - { fst, _, _ -> fst == null }, - { fst, snd, _ -> fst != null && fst.x > 0 && snd == null }, - { fst, snd, _ -> fst != null && fst.x <= 0 && snd == null }, - { fst, snd, r -> fst != null && snd != null && fst.x > 0 && snd.x < 0 && r == 1 }, - { fst, snd, r -> fst != null && snd != null && ((fst.x > 0 && snd.x >= 0) || fst.x <= 0) && fst === snd && r == 2 }, - { fst, snd, r -> fst != null && snd != null && (fst.x <= 0 || (fst.x > 0 && snd.x >= 0)) && fst !== snd && r == 3 }, - coverage = atLeast(87) - ) - } - - @Test - fun testCompareTwoObjectsWithNullRefField() { - checkWithException( - ObjectWithRefFieldExample::compareTwoObjectsWithNullRefField, - eq(4), - { fst, _, r -> fst == null && r.isException() }, - { fst, snd, r -> fst != null && snd == null && r.isException() }, - { fst, snd, r -> fst != null && snd != null && r.getOrNull() == 1 /* && fst == snd by ref */ }, - { fst, snd, r -> fst != null && snd != null && r.getOrNull() == 2 /* && fst != snd by ref */ }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCompareTwoObjectsWithDifferentRefField() { - checkWithException( - ObjectWithRefFieldExample::compareTwoObjectsWithDifferentRefField, - eq(4), - { fst, _, _, r -> fst == null && r.isException() }, - { fst, snd, _, r -> fst != null && snd == null && r.isException() }, - { fst, snd, _, r -> fst != null && snd != null && r.getOrNull() == 1 /* fst == snd by ref */ }, - { fst, snd, _, r -> fst != null && snd != null && r.getOrNull() == 2 /* fst != snd by ref */ }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCompareTwoObjectsWithTheDifferentRefField() { - checkWithException( - ObjectWithRefFieldExample::compareTwoObjectsWithDifferentRefField, - eq(4), - { fst, _, r -> fst == null && r.isException() }, - { fst, snd, r -> fst != null && snd == null && r.isException() }, - { fst, snd, r -> fst != null && snd != null && fst.refField === snd.refField && r.getOrNull() == true }, - { fst, snd, r -> fst != null && snd != null && fst.refField !== snd.refField && r.getOrNull() == false } - ) - } - - @Test - fun testCompareTwoObjectsWithTheSameRefField() { - checkWithException( - ObjectWithRefFieldExample::compareTwoObjectsWithTheSameRefField, - eq(4), - { fst, _, r -> fst == null && r.isException() }, - { fst, snd, r -> fst != null && snd == null && r.isException() }, - { fst, snd, r -> fst != null && snd != null && r.getOrNull() == 1 /* && fst == snd by ref */ }, - { fst, snd, r -> fst != null && snd != null && r.getOrNull() == 2 /* && fst != snd by ref */ }, - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt deleted file mode 100644 index 6af50704af..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt +++ /dev/null @@ -1,186 +0,0 @@ -package org.utbot.examples.objects - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class ObjectWithStaticFieldsExampleTest : UtValueTestCaseChecker(testClass = ObjectWithStaticFieldsExample::class) { - @Test - fun testReadFromStaticArray() { - checkStatics( - ObjectWithStaticFieldsExample::readFromStaticArray, - eq(6), - { _, statics, _ -> statics.singleValue() == null }, - { _, statics, _ -> (statics.singleValue() as IntArray).size < 5 }, - { _, statics, _ -> (statics.singleValue() as IntArray)[1] != 1 }, - { _, statics, _ -> - val array = statics.singleValue() as IntArray - array[1] == 1 && array[2] != 2 - }, - { o, statics, _ -> - val array = statics.singleValue() as IntArray - o == null && array[1] == 1 && array[2] == 2 - }, - { o, statics, r -> - val array = statics.singleValue() as IntArray - r as ObjectWithStaticFieldsClass - o != null && array[1] == 1 && array[2] == 2 && r.x == array[1] && r.y == array[2] - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testSetStaticField() { - checkStaticsAfter( - ObjectWithStaticFieldsExample::setStaticField, - eq(4), - { o, _, _ -> o == null }, - { o, _, _ -> o != null && o.x < 100 }, - { o, _, _ -> o != null && o.x >= 100 && o.y < 150 }, - { o, staticsAfter, r -> - val staticValue = staticsAfter.singleValue() as Int - - val objectCondition = o != null && o.x >= 100 && o.y >= 150 && r?.x == o.x * o.y && r.y == o.y - val staticCondition = staticValue == o.y * o.x - val connection = r!!.x == staticValue - - objectCondition && staticCondition && connection - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetStaticField() { - checkStatics( - ObjectWithStaticFieldsExample::getStaticField, - eq(3), - { o, _, _ -> o == null }, - { o, statics, _ -> o != null && statics.singleValue() as Int != 3 }, - { o, statics, r -> o != null && statics.singleValue() as Int == 3 && r != null && r.x == 3 }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetStaticFieldWithDefaultValue() { - checkStatics( - ObjectWithStaticFieldsExample::getStaticFieldWithDefaultValue, - eq(1), - { statics, r -> statics.singleValue() == r } - ) - } - - @Test - fun testStaticFieldInInvoke() { - checkMutationsAndResult( - ObjectWithStaticFieldsExample::staticFieldInInvoke, - eq(1), - { staticsBefore, staticsAfter, r -> - val defaultValue = staticsBefore.findByName("defaultValue") - staticsAfter.findByName("staticValue") == defaultValue && r == defaultValue - } - ) - } - - @Test - fun testStaticFieldAfterStateInInvoke() { - checkMutationsAndResult( - ObjectWithStaticFieldsExample::staticFieldInInvoke, - eq(1), - { staticsBefore, staticsAfter, r -> - val defaultValue = staticsBefore.findByName("defaultValue") - val staticValue = staticsAfter.findByName("staticValue") - - defaultValue == staticValue && r == defaultValue - } - ) - } - - @Test - fun testStaticFieldArrayMax() { - checkMutationsAndResult( - ObjectWithStaticFieldsExample::staticFieldArrayMax, - eq(4), - { staticsBefore, _, _ -> (staticsBefore.values.single().value as Int) < 0 }, - { staticsBefore, staticsAfter, _ -> - val defaultValue = staticsBefore.findByName("defaultValue") as Int - val staticArray = staticsAfter.findByName("staticArrayValue") as IntArray - - defaultValue == 0 && staticArray.isEmpty() - }, - { staticsBefore, staticsAfter, r -> - val defaultValue = staticsBefore.findByName("defaultValue") as Int - val staticArray = staticsAfter.findByName("staticArrayValue") as IntArray - - val contentCondition = staticArray.zip(staticArray.indices).all { it.first == defaultValue + it.second } - val maxValue = staticArray.maxOrNull() - - staticArray.size == 1 && contentCondition && maxValue == r - }, - { staticsBefore, staticsAfter, r -> - val defaultValue = staticsBefore.findByName("defaultValue") as Int - val staticArray = staticsAfter.findByName("staticArrayValue") as IntArray - - val contentCondition = staticArray.zip(staticArray.indices).all { it.first == defaultValue + it.second } - val maxValue = staticArray.maxOrNull() - - staticArray.size > 1 && contentCondition && maxValue == r - }, - ) - } - - @Test - fun testInitializedArrayWithCycle() { - checkStatics( - ObjectWithStaticFieldsExample::initializedArrayWithCycle, - ignoreExecutionsNumber, - { n, _, r -> n < 0 && r == Double.NEGATIVE_INFINITY }, - { _, statics, _ -> statics.singleValue() == null }, - { n, statics, _ -> n > 0 && (statics.singleValue() as IntArray).lastIndex < n }, - { n, statics, r -> - r!!.toInt() == (1 until n).fold(1) { a, b -> a * b } * (statics.singleValue() as IntArray)[n] - }, - ) - } - - @Test - fun testBigStaticArray() { - checkStatics( - ObjectWithStaticFieldsExample::bigStaticArray, - eq(3), - { statics, _ -> statics.singleValue() == null }, - { statics, _ -> (statics.singleValue() as IntArray).lastIndex < 10 }, - { statics, r -> (statics.singleValue() as IntArray)[10] == r } - ) - } - - @Test - fun testModifyStatic() { - checkStaticMethodMutationAndResult( - ObjectWithStaticFieldsExample::modifyStatic, - eq(2), - { staticsBefore, staticsAfter, _ -> staticsBefore.singleValue() == 41 && staticsAfter.singleValue() == 42 }, - { staticsBefore, staticsAfter, _ -> - staticsBefore.singleValue() != 41 && staticsAfter.singleValue() == staticsBefore.singleValue() - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testResetNonFinalFields() { - checkMutationsAndResult( - ObjectWithStaticFieldsExample::resetNonFinalFields, - eq(2), - { staticsBefore, staticsAfter, r -> - staticsBefore.singleValue() == 42 && staticsAfter.singleValue() == 43 && r == 43 - }, - { staticsBefore, staticsAfter, r -> - val value = staticsBefore.singleValue() - value !in 42..43 && staticsAfter.singleValue() == value && r == value - }, - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithThrowableConstructorTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithThrowableConstructorTest.kt deleted file mode 100644 index 297bf4c932..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/ObjectWithThrowableConstructorTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package org.utbot.examples.objects - -import kotlin.reflect.KFunction2 -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.DoNotCalculate -import org.utbot.testing.UtValueTestCaseChecker - -internal class ObjectWithThrowableConstructorTest : UtValueTestCaseChecker(testClass = ObjectWithThrowableConstructor::class) { - @Test - @Disabled("SAT-1500 Support verification of UtAssembleModel for possible exceptions") - fun testThrowableConstructor() { - val method: KFunction2 = ::ObjectWithThrowableConstructor - checkStaticMethod( - method, - eq(2), - // TODO: SAT-933 Add support for constructor testing - coverage = DoNotCalculate - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt deleted file mode 100644 index 985bc1ee4e..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt +++ /dev/null @@ -1,21 +0,0 @@ -package org.utbot.examples.objects - - - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker -import org.utbot.testing.isException - -internal class PrivateFieldsTest : UtValueTestCaseChecker(testClass = PrivateFields::class) { - @Test - fun testAccessWithGetter() { - checkWithException( - PrivateFields::accessWithGetter, - eq(3), - { x, r -> x == null && r.isException() }, - { x, r -> x.a == 1 && r.getOrNull() == true }, - { x, r -> x.a != 1 && r.getOrNull() == false }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/RecursiveTypeTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/RecursiveTypeTest.kt deleted file mode 100644 index e1dc21ad88..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/RecursiveTypeTest.kt +++ /dev/null @@ -1,36 +0,0 @@ -package org.utbot.examples.objects - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.DoNotCalculate -import org.utbot.testing.UtValueTestCaseChecker - -internal class RecursiveTypeTest : UtValueTestCaseChecker(testClass = RecursiveType::class) { - @Test - fun testNextValue() { - check( - RecursiveType::nextValue, - eq(5), - { _, value, _ -> value == 0 }, - { node, _, _ -> node == null }, - { node, _, _ -> node != null && node.next == null }, - { node, value, r -> node?.next != null && node.next.value != value && r == null }, - { node, value, r -> node?.next != null && node.next.value == value && r != null && r.value == value }, - coverage = DoNotCalculate - ) - } - - @Test - fun testWriteObjectFieldTest() { - check( - RecursiveType::writeObjectField, - eq(3), - { node, _ -> node == null }, - { node, r -> - node != null && node.next == null && r?.next != null && r.next.value == RecursiveTypeClass().value + 1 - }, - { node, r -> node?.next != null && r?.next != null && node.next.value + 1 == r.next.value }, - coverage = DoNotCalculate - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt deleted file mode 100644 index 67bad2c9f3..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt +++ /dev/null @@ -1,100 +0,0 @@ -package org.utbot.examples.objects - -import org.utbot.framework.plugin.api.DocCodeStmt -import org.utbot.framework.plugin.api.DocPreTagStatement -import org.utbot.framework.plugin.api.DocRegularStmt -import org.utbot.framework.plugin.api.DocStatement -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class SimpleClassExampleTest : UtValueTestCaseChecker(testClass = SimpleClassExample::class) { - @Test - fun simpleConditionTest() { - check( - SimpleClassExample::simpleCondition, - eq(4), - { c, _ -> c == null }, // NPE - { c, r -> c.a >= 5 && r == 3 }, - { c, r -> c.a < 5 && c.b <= 10 && r == 3 }, - { c, r -> c.a < 5 && c.b > 10 && r == 0 }, - coverage = DoNotCalculate // otherwise we overwrite original values - ) - } - - /** - * Additional bytecode instructions between IFs, because of random, makes different order of executing the branches, - * that affects their number. Changing random seed in PathSelector can explore 6th branch - * - * @see multipleFieldAccessesTest - */ - @Test - fun singleFieldAccessTest() { - check( - SimpleClassExample::singleFieldAccess, - between(5..6), // could be 6 - { c, _ -> c == null }, // NPE - { c, r -> c.a == 3 && c.b != 5 && r == 2 }, - { c, r -> c.a == 3 && c.b == 5 && r == 1 }, - { c, r -> c.a == 2 && c.b != 3 && r == 2 }, - { c, r -> c.a == 2 && c.b == 3 && r == 0 } - ) - } - - /** - * Additional bytecode instructions between IFs, because of random, makes different order of executing the branches, - * that affects their number - */ - @Test - fun multipleFieldAccessesTest() { - check( - SimpleClassExample::multipleFieldAccesses, - eq(6), - { c, _ -> c == null }, // NPE - { c, r -> c.a != 2 && c.a != 3 && r == 2 }, // this one appears - { c, r -> c.a == 3 && c.b != 5 && r == 2 }, - { c, r -> c.a == 3 && c.b == 5 && r == 1 }, - { c, r -> c.a == 2 && c.b != 3 && r == 2 }, - { c, r -> c.a == 2 && c.b == 3 && r == 0 } - ) - } - - @Test - fun immutableFieldAccessTest() { - val immutableFieldAccessSummary = listOf( - DocPreTagStatement( - listOf( - DocRegularStmt("Test "), - DocRegularStmt("executes conditions:\n"), - DocRegularStmt(" "), - DocCodeStmt("(c.b == 10): True"), - DocRegularStmt("\n"), - DocRegularStmt("returns from: "), - DocCodeStmt("return 0;"), - DocRegularStmt("\n"), - ) - ) - ) - checkWithException( - SimpleClassExample::immutableFieldAccess, - eq(3), - { c, r -> c == null && r.isException() }, - { c, r -> c.b == 10 && r.getOrNull() == 0 }, - { c, r -> c.b != 10 && r.getOrNull() == 1 }, - summaryTextChecks = listOf( - keyContain(DocRegularStmt("throws NullPointerException in: c.b == 10")), - keyContain(DocCodeStmt("(c.b == 10): False")), - keyMatch(immutableFieldAccessSummary) - ), - summaryNameChecks = listOf( - keyMatch("testImmutableFieldAccess_ThrowNullPointerException"), - keyMatch("testImmutableFieldAccess_CBNotEquals10"), - keyMatch("testImmutableFieldAccess_CBEquals10") - ), - summaryDisplayNameChecks = listOf( - keyContain("NullPointerException", "c.b == 10"), - keyContain("c.b == 10 : False"), - keyContain("c.b == 10 : True") - ) - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/SimpleClassMultiInstanceExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/objects/SimpleClassMultiInstanceExampleTest.kt deleted file mode 100644 index d7d427cd5e..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/objects/SimpleClassMultiInstanceExampleTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package org.utbot.examples.objects - -import org.junit.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq -import org.utbot.testing.DoNotCalculate -import org.utbot.testing.UtValueTestCaseChecker - -internal class SimpleClassMultiInstanceExampleTest : UtValueTestCaseChecker(testClass = - SimpleClassMultiInstanceExample::class) { - @Test - fun singleObjectChangeTest() { - check( - SimpleClassMultiInstanceExample::singleObjectChange, - eq(3), - { first, _, _ -> first == null }, // NPE - { first, _, r -> first.a < 5 && r == 3 }, - { first, _, r -> first.a >= 5 && r == first.b }, - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/ByteExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/ByteExamplesTest.kt deleted file mode 100644 index 4b709e11f5..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/ByteExamplesTest.kt +++ /dev/null @@ -1,39 +0,0 @@ -package org.utbot.examples.primitives - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker - -internal class ByteExamplesTest : UtValueTestCaseChecker(testClass = ByteExamples::class) { - @Test - fun testNegByte() { - check( - ByteExamples::negByte, - eq(2), - { b, r -> b > 0 && r == 0 }, - { b, r -> b <= 0 && r == 1 }, - ) - } - - @Test - fun testNegConstByte() { - check( - ByteExamples::negConstByte, - eq(3), - { b, r -> b <= -10 && r == 1 }, - { b, r -> b in -9..9 && r == 0 }, - { b, r -> b >= 10 && r == 1 }, - ) - } - - @Test - fun testSumTwoBytes() { - check( - ByteExamples::sumTwoBytes, - eq(3), - { a, b, r -> a + b > Byte.MAX_VALUE && r == 1 }, - { a, b, r -> a + b < Byte.MIN_VALUE && r == 2 }, - { a, b, r -> a + b in Byte.MIN_VALUE..Byte.MAX_VALUE && r == 3 }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/CharExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/CharExamplesTest.kt deleted file mode 100644 index c93b615eb9..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/CharExamplesTest.kt +++ /dev/null @@ -1,52 +0,0 @@ -package org.utbot.examples.primitives - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker -import org.utbot.testing.isException - -internal class CharExamplesTest : UtValueTestCaseChecker(testClass = CharExamples::class) { - @Test - fun testCharDiv() { - checkWithException( - CharExamples::charDiv, - eq(2), - { _, b, r -> b == '\u0000' && r.isException() }, - { a, b, r -> b != '\u0000' && r.getOrNull() == a.toInt() / b.toInt() } - ) - } - - @Test - fun testCharNeg() { - check( - CharExamples::charNeg, - eq(2), - { c, r -> c !in '\u0000'..'\uC350' && r == 1 }, - { c, r -> c in '\u0000'..'\uC350' && r == 2 }, - ) - } - - @Test - fun testByteToChar() { - check( - CharExamples::byteToChar, - eq(5), - { b, r -> b == (-1).toByte() && r == -1 }, - { b, r -> b == (-128).toByte() && r == -128 }, - { b, r -> b == 0.toByte() && r == 0 }, - { b, r -> b == 127.toByte() && r == 127 }, - { b, r -> b != (-1).toByte() && b != (-128).toByte() && b != 0.toByte() && b != 127.toByte() && r == 200 }, - ) - } - - @Test - fun testUpdateObject() { - checkWithException( - CharExamples::updateObject, - eq(3), - { obj, _, r -> obj == null && r.isException() }, - { obj, i, r -> obj != null && i <= 50000 && r.getOrNull()!!.c == '\u0444' }, - { obj, i, r -> obj != null && i.toChar() > 50000.toChar() && r.getOrNull()?.c == i.toChar() }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/DoubleExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/DoubleExamplesTest.kt deleted file mode 100644 index 157d5be275..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/DoubleExamplesTest.kt +++ /dev/null @@ -1,161 +0,0 @@ -package org.utbot.examples.primitives - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker - -@Suppress("SimplifyNegatedBinaryExpression") -internal class DoubleExamplesTest : UtValueTestCaseChecker(testClass = DoubleExamples::class) { - @Test - fun testCompareSum() { - check( - DoubleExamples::compareSum, - eq(2), - { a, b, r -> a + b > 5.6 && r == 1.0 }, - { a, b, r -> (a + b).isNaN() || a + b <= 5.6 && r == 0.0 } - ) - } - - @Test - fun testCompare() { - check( - DoubleExamples::compare, - eq(2), - { a, b, r -> a > b && r == 1.0 }, - { a, b, r -> !(a > b) && r == 0.0 } - ) - } - - @Test - fun testCompareWithDiv() { - check( - DoubleExamples::compareWithDiv, - eq(2), // only two branches because division by zero is not an error with doubles - { a, b, r -> a / (a + 0.5) > b && r == 1.0 }, - { a, b, r -> !(a / (a + 0.5) > b) && r == 0.0 } - ) - } - - @Test - fun testSimpleSum() { - check( - DoubleExamples::simpleSum, - eq(4), - { a, b, r -> (a + b).isNaN() && r == 0.0 }, - { a, b, r -> a + 1.1 + b > 10.1 && a + 1.1 + b < 11.125 && r == 1.1 }, - { a, b, r -> a + 1.1 + b <= 10.1 && r == 1.2 }, - { a, b, r -> a + 1.1 + b >= 11.125 && r == 1.2 } - ) - } - - @Test - fun testSum() { - check( - DoubleExamples::sum, - eq(4), - { a, b, r -> (a + b).isNaN() && r == 0.0 }, - { a, b, r -> a + 0.123124 + b > 11.123124 && a + b + 0.123124 < 11.125 && r == 1.1 }, - { a, b, r -> a + 0.123124 + b <= 11.123124 && r == 1.2 }, - { a, b, r -> a + 0.123124 + b >= 11.125 && r == 1.2 } - ) - } - - @Test - fun testSimpleMul() { - check( - DoubleExamples::simpleMul, - eq(4), - { a, b, r -> (a * b).isNaN() && r == 0.0 }, - { a, b, r -> a * b > 33.1 && a * b < 33.875 && r == 1.1 }, - { a, b, r -> a * b <= 33.1 && r == 1.2 }, - { a, b, r -> a * b >= 33.875 && r == 1.2 } - ) - } - - @Test - fun testMul() { - check( - DoubleExamples::mul, - eq(6), - { a, b, r -> (a * b).isNaN() && r == 0.0 }, // 0 * inf || a == nan || b == nan - { a, b, r -> !(a * b > 33.32) && !(a * b > 33.333) && r == 1.3 }, // 1.3, 1-1 false, 2-1 false - { a, b, r -> a * b == 33.333 && r == 1.3 }, // 1.3, 1-1 true, 1-2 false, 2-1 false - { a, b, r -> a * b > 33.32 && a * b < 33.333 && r == 1.1 }, // 1.1, 1st true - { a, b, r -> a * b > 33.333 && a * b < 33.7592 && r == 1.2 }, // 1.2, 1st false, 2nd true - { a, b, r -> a * b >= 33.7592 && r == 1.3 } // 1.3, 1-1 false, 2-1 true, 2-2 false - ) - } - - @Test - fun testCheckNonInteger() { - check( - DoubleExamples::checkNonInteger, - eq(3), - { a, r -> !(a > 0.1) && r == 0.0 }, - { a, r -> a > 0.1 && !(a < 0.9) && r == 0.0 }, - { a, r -> a > 0.1 && a < 0.9 && r == 1.0 } - ) - } - - @Test - fun testDiv() { - check( - DoubleExamples::div, - eq(1), - { a, b, c, r -> r == (a + b) / c || (r!!.isNaN() && (a + b + c).isNaN()) } - ) - } - - @Test - fun testSimpleEquation() { - check( - DoubleExamples::simpleEquation, - eq(2), - { x, r -> x + x + x - 9 == x + 3 && r == 0 }, - { x, r -> x + x + x - 9 != x + 3 && r == 1 } - ) - } - - @Test - fun testSimpleNonLinearEquation() { - check( - DoubleExamples::simpleNonLinearEquation, - eq(2), - { x, r -> 3 * x - 9 == x + 3 && r == 0 }, - { x, r -> 3 * x - 9 != x + 3 && r == 1 } - ) - } - - @Test - fun testCheckNaN() { - check( - DoubleExamples::checkNaN, - eq(4), - { d, r -> !d.isNaN() && d < 0 && r == -1 }, - { d, r -> !d.isNaN() && d == 0.0 && r == 0 }, - { d, r -> !d.isNaN() && d > 0 && r == 1 }, - { d, r -> d.isNaN() && r == 100 } - ) - } - - @Test - fun testUnaryMinus() { - check( - DoubleExamples::unaryMinus, - eq(2), - { d, r -> !d.isNaN() && -d < 0 && r == -1 }, - { d, r -> d.isNaN() || -d >= 0 && r == 0 } - ) - } - - @Test - fun testDoubleInfinity() { - check( - DoubleExamples::doubleInfinity, - eq(3), - { d, r -> d == Double.POSITIVE_INFINITY && r == 1 }, - { d, r -> d == Double.NEGATIVE_INFINITY && r == 2 }, - { d, r -> !d.isInfinite() && r == 3 }, - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/FloatExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/FloatExamplesTest.kt deleted file mode 100644 index 87baa7a2a3..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/FloatExamplesTest.kt +++ /dev/null @@ -1,18 +0,0 @@ -package org.utbot.examples.primitives - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker - -internal class FloatExamplesTest : UtValueTestCaseChecker(testClass = FloatExamples::class) { - @Test - fun testFloatInfinity() { - check( - FloatExamples::floatInfinity, - eq(3), - { f, r -> f == Float.POSITIVE_INFINITY && r == 1 }, - { f, r -> f == Float.NEGATIVE_INFINITY && r == 2 }, - { f, r -> !f.isInfinite() && r == 3 }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt deleted file mode 100644 index ba51507276..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt +++ /dev/null @@ -1,119 +0,0 @@ -package org.utbot.examples.primitives - -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test - -import org.utbot.testcheckers.eq - -@Suppress("ConvertTwoComparisonsToRangeCheck") -internal class IntExamplesTest : UtValueTestCaseChecker(testClass = IntExamples::class) { - @Test - @Disabled("SAT-1009 [JAVA] Engine can't analyze isInteger") - fun testIsInteger() { - val method = IntExamples::isInteger - checkStaticMethod( - method, - eq(2), - { value, r -> runCatching { Integer.valueOf(value) }.isSuccess && r == true }, - { value, r -> runCatching { Integer.valueOf(value) }.isFailure && r == false }, - ) - } - - @Test - fun testMax() { - check( - IntExamples::max, - eq(2), - { x, y, r -> x > y && r == x }, - { x, y, r -> x <= y && r == y } - ) - } - - @Test - fun testPreferableLt() { - check( - IntExamples::preferableLt, - eq(2), - { x, r -> x == 41 && r == 41 }, - { x, r -> x == 42 && r == 42 } - ) - } - - @Test - fun testPreferableLe() { - check( - IntExamples::preferableLe, - eq(2), - { x, r -> x == 42 && r == 42 }, - { x, r -> x == 43 && r == 43 } - ) - } - - @Test - fun testPreferableGe() { - check( - IntExamples::preferableGe, - eq(2), - { x, r -> x == 42 && r == 42 }, - { x, r -> x == 41 && r == 41 } - ) - } - - @Test - fun testPreferableGt() { - check( - IntExamples::preferableGt, - eq(2), - { x, r -> x == 43 && r == 43 }, - { x, r -> x == 42 && r == 42 } - ) - } - - - @Test - fun testCompare() { - check( - IntExamples::complexCompare, - eq(6), - { a, b, r -> a < b && b < 11 && r == 0 }, - { a, b, r -> a < b && b > 11 && r == 1 }, - { a, b, r -> a == b && b == 11 && r == 3 }, - { a, b, r -> a == b && b != 11 && r == 6 }, - { a, b, r -> a < b && b == 11 && r == 6 }, - { a, b, r -> a > b && r == 6 } - ) - } - - @Test - fun testComplexCondition() { - check( - IntExamples::complexCondition, - eq(3), - { _, b, r -> b + 10 >= b + 22 && r == 0 }, // negative overflow, result = 1 - { a, b, r -> b + 10 < b + 22 && b + 22 >= a + b + 10 && r == 0 }, - { a, b, r -> b + 10 < b + 22 && b + 22 < a + b + 10 && r == 1 } // overflow involved - ) - } - - @Test - fun testOrderCheck() { - check( - IntExamples::orderCheck, - eq(3), - { first, second, _, r -> first >= second && r == false }, - { first, second, third, r -> first < second && second >= third && r == false }, - { first, second, third, r -> first < second && second < third && r == true } - ) - } - - @Test - fun testOrderCheckWithMethods() { - check( - IntExamples::orderCheckWithMethods, - eq(3), - { first, second, _, r -> first >= second && r == false }, - { first, second, third, r -> first < second && second >= third && r == false }, - { first, second, third, r -> first < second && second < third && r == true } - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt deleted file mode 100644 index a5ee5eda7e..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt +++ /dev/null @@ -1,138 +0,0 @@ -package org.utbot.examples.recursion - -import org.utbot.framework.plugin.api.DocCodeStmt -import org.utbot.framework.plugin.api.DocPreTagStatement -import org.utbot.framework.plugin.api.DocRegularStmt -import org.utbot.framework.plugin.api.DocStatement -import kotlin.math.pow -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq -import org.utbot.testcheckers.ge - -// TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 -internal class RecursionTest : UtValueTestCaseChecker( - testClass = Recursion::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testFactorial() { - val factorialSummary = listOf( - DocPreTagStatement( - listOf( - DocRegularStmt("Test "), - DocRegularStmt("returns from: "), - DocCodeStmt("return 1;"), - DocRegularStmt("\n"), - ) - ) - ) - - checkWithException( - Recursion::factorial, - eq(3), - { x, r -> x < 0 && r.isException() }, - { x, r -> x == 0 && r.getOrNull() == 1 }, - { x, r -> x > 0 && r.getOrNull() == (1..x).reduce { a, b -> a * b } }, - summaryTextChecks = listOf( - keyContain(DocCodeStmt("(n < 0): True")), - keyMatch(factorialSummary), - keyContain(DocCodeStmt("(n == 0): False")) - ), - summaryNameChecks = listOf( - keyMatch("testFactorial_NLessThanZero"), - keyMatch("testFactorial_Return1"), - keyMatch("testFactorial_NNotEqualsZero") - ), - summaryDisplayNameChecks = listOf( - keyMatch("-> return 1"), - keyMatch("n < 0 -> ThrowIllegalArgumentException"), - keyMatch("-> return 1") - ) - ) - } - - @Test - fun testFib() { - checkWithException( - Recursion::fib, - eq(4), - { x, r -> x < 0 && r.isException() }, - { x, r -> x == 0 && r.getOrNull() == 0 }, - { x, r -> x == 1 && r.getOrNull() == 1 }, - { x, r -> x > 1 && r.getOrNull() == Recursion().fib(x) } - ) - } - - @Test - @Disabled("Freezes the execution when snd != 0 JIRA:1293") - fun testSum() { - check( - Recursion::sum, - eq(2), - { x, y, r -> y == 0 && r == x }, - { x, y, r -> y != 0 && r == x + y } - ) - } - - @Test - fun testPow() { - checkWithException( - Recursion::pow, - eq(4), - { _, y, r -> y < 0 && r.isException() }, - { _, y, r -> y == 0 && r.getOrNull() == 1 }, - { x, y, r -> y % 2 == 1 && r.getOrNull() == x.toDouble().pow(y.toDouble()).toInt() }, - { x, y, r -> y % 2 != 1 && r.getOrNull() == x.toDouble().pow(y.toDouble()).toInt() } - ) - } - - @Test - fun infiniteRecursionTest() { - checkWithException( - Recursion::infiniteRecursion, - eq(2), - { x, r -> x > 10000 && r.isException() }, - { x, r -> x <= 10000 && r.isException() }, - coverage = atLeast(50) - ) - } - - @Test - fun vertexSumTest() { - check( - Recursion::vertexSum, - between(2..3), - { x, _ -> x <= 10 }, - { x, _ -> x > 10 } - ) - } - - @Test - fun recursionWithExceptionTest() { - checkWithException( - Recursion::recursionWithException, - ge(3), - { x, r -> x < 42 && r.isException() }, - { x, r -> x == 42 && r.isException() }, - { x, r -> x > 42 && r.isException() }, - coverage = atLeast(50) - ) - } - - @Test - fun recursionLoopTest() { - check( - Recursion::firstMethod, - eq(2), - { x, _ -> x < 4 }, - { x, _ -> x >= 4 }, - coverage = atLeast(50) - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/statics/substitution/StaticsSubstitutionTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/statics/substitution/StaticsSubstitutionTest.kt deleted file mode 100644 index 0b97f4e0c7..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/statics/substitution/StaticsSubstitutionTest.kt +++ /dev/null @@ -1,30 +0,0 @@ -package org.utbot.examples.statics.substitution - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testcheckers.withoutSubstituteStaticsWithSymbolicVariable - -class StaticsSubstitutionTest : UtValueTestCaseChecker(testClass = StaticSubstitutionExamples::class) { - - @Test - fun lessThanZeroWithSubstitution() { - check( - StaticSubstitutionExamples::lessThanZero, - eq(2), - { r -> r != 0 }, - { r -> r == 0 }, - ) - } - - @Test - fun lessThanZeroWithoutSubstitution() { - withoutSubstituteStaticsWithSymbolicVariable { - checkWithoutStaticsSubstitution( - StaticSubstitutionExamples::lessThanZero, - eq(1), - { r -> r != 0 }, - coverage = DoNotCalculate, - ) - } - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt deleted file mode 100644 index ddbe69d720..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt +++ /dev/null @@ -1,67 +0,0 @@ -package org.utbot.examples.stdlib - -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Tag -import org.junit.jupiter.api.Test - - -import org.utbot.testcheckers.eq -import org.utbot.testcheckers.withUsingReflectionForMaximizingCoverage -import java.util.Date - -@Disabled("Java 11 transition -- these tests seems to take too much time and memory") -class DateExampleTest : UtValueTestCaseChecker(testClass = DateExample::class) { - @Suppress("SpellCheckingInspection") - @Tag("slow") - @Test - fun testGetTimeWithNpeChecksForNonPublicFields() { - withUsingReflectionForMaximizingCoverage(maximizeCoverage = true) { - checkWithException( - DateExample::getTime, - eq(5), - *commonMatchers, - { date: Date?, r: Result -> - val cdate = date!!.getDeclaredFieldValue("cdate") - val calendarDate = cdate!!.getDeclaredFieldValue("date") - - calendarDate == null && r.isException() - }, - { date: Date?, r: Result -> - val cdate = date!!.getDeclaredFieldValue("cdate") - val calendarDate = cdate!!.getDeclaredFieldValue("date") - - val gcal = date.getDeclaredFieldValue("gcal") - - val normalized = calendarDate!!.getDeclaredFieldValue("normalized") as Boolean - val gregorianYear = calendarDate.getDeclaredFieldValue("gregorianYear") as Int - - gcal == null && !normalized && gregorianYear >= 1582 && r.isException() - } - ) - } - } - - @Test - fun testGetTimeWithoutReflection() { - withUsingReflectionForMaximizingCoverage(maximizeCoverage = false) { - checkWithException( - DateExample::getTime, - eq(3), - *commonMatchers - ) - } - } - - private val commonMatchers = arrayOf( - { date: Date?, r: Result -> date == null && r.isException() }, - { date: Date?, r: Result -> date != null && date.time == 100L && r.getOrThrow() }, - { date: Date?, r: Result -> date != null && date.time != 100L && !r.getOrThrow() } - ) - - private fun Any.getDeclaredFieldValue(fieldName: String): Any? { - val declaredField = javaClass.getDeclaredField(fieldName) - declaredField.isAccessible = true - - return declaredField.get(this) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt deleted file mode 100644 index b3bed63f70..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt +++ /dev/null @@ -1,462 +0,0 @@ -package org.utbot.examples.stream - -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Tag -import org.junit.jupiter.api.Test - - - - - - - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq -import org.utbot.testcheckers.withoutConcrete - - -import java.util.Optional -import java.util.stream.Stream -import kotlin.streams.toList - -// TODO 1 instruction is always uncovered https://github.com/UnitTestBot/UTBotJava/issues/193 -// TODO failed Kotlin compilation (generics) JIRA:1332 -class BaseStreamExampleTest : UtValueTestCaseChecker( - testClass = BaseStreamExample::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testReturningStreamAsParameterExample() { - withoutConcrete { - check( - BaseStreamExample::returningStreamAsParameterExample, - eq(1), - { s, r -> s != null && s.toList() == r!!.toList() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - } - - @Test - fun testFilterExample() { - check( - BaseStreamExample::filterExample, - ignoreExecutionsNumber, - { c, r -> null !in c && r == false }, - { c, r -> null in c && r == true }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMapExample() { - checkWithException( - BaseStreamExample::mapExample, - ignoreExecutionsNumber, - { c, r -> null in c && r.isException() }, - { c, r -> r.getOrThrow().contentEquals(c.map { it * 2 }.toTypedArray()) }, - coverage = AtLeast(90) - ) - } - - @Test - @Tag("slow") - fun testMapToIntExample() { - checkWithException( - BaseStreamExample::mapToIntExample, - ignoreExecutionsNumber, - { c, r -> null in c && r.isException() }, - { c, r -> r.getOrThrow().contentEquals(c.map { it.toInt() }.toIntArray()) }, - coverage = AtLeast(90) - ) - } - - @Test - @Tag("slow") - fun testMapToLongExample() { - checkWithException( - BaseStreamExample::mapToLongExample, - ignoreExecutionsNumber, - { c, r -> null in c && r.isException() }, - { c, r -> r.getOrThrow().contentEquals(c.map { it.toLong() }.toLongArray()) }, - coverage = AtLeast(90) - ) - } - - @Test - @Tag("slow") - fun testMapToDoubleExample() { - checkWithException( - BaseStreamExample::mapToDoubleExample, - ignoreExecutionsNumber, - { c, r -> null in c && r.isException() }, - { c, r -> r.getOrThrow().contentEquals(c.map { it.toDouble() }.toDoubleArray()) }, - coverage = AtLeast(90) - ) - } - - @Test - fun testFlatMapExample() { - check( - BaseStreamExample::flatMapExample, - ignoreExecutionsNumber, - { c, r -> r.contentEquals(c.flatMap { listOf(it, it) }.toTypedArray()) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - @Tag("slow") - fun testFlatMapToIntExample() { - check( - BaseStreamExample::flatMapToIntExample, - ignoreExecutionsNumber, - { c, r -> r.contentEquals(c.flatMap { listOf(it?.toInt() ?: 0, it?.toInt() ?: 0) }.toIntArray()) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testFlatMapToLongExample() { - check( - BaseStreamExample::flatMapToLongExample, - ignoreExecutionsNumber, - { c, r -> r.contentEquals(c.flatMap { listOf(it?.toLong() ?: 0L, it?.toLong() ?: 0L) }.toLongArray()) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testFlatMapToDoubleExample() { - check( - BaseStreamExample::flatMapToDoubleExample, - ignoreExecutionsNumber, - { c, r -> r.contentEquals(c.flatMap { listOf(it?.toDouble() ?: 0.0, it?.toDouble() ?: 0.0) }.toDoubleArray()) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - @Tag("slow") - fun testDistinctExample() { - check( - BaseStreamExample::distinctExample, - ignoreExecutionsNumber, - { c, r -> c == c.distinct() && r == false }, - { c, r -> c != c.distinct() && r == true }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - @Tag("slow") - // TODO slow sorting https://github.com/UnitTestBot/UTBotJava/issues/188 - fun testSortedExample() { - check( - BaseStreamExample::sortedExample, - ignoreExecutionsNumber, - { c, r -> c.last() < c.first() && r!!.asSequence().isSorted() }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - - @Test - fun testPeekExample() { - checkThisAndStaticsAfter( - BaseStreamExample::peekExample, - ignoreExecutionsNumber, - *streamConsumerStaticsMatchers, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testLimitExample() { - check( - BaseStreamExample::limitExample, - ignoreExecutionsNumber, - { c, r -> c.size <= 5 && c.toTypedArray().contentEquals(r) }, - { c, r -> c.size > 5 && c.take(5).toTypedArray().contentEquals(r) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testSkipExample() { - check( - BaseStreamExample::skipExample, - ignoreExecutionsNumber, - { c, r -> c.size > 5 && c.drop(5).toTypedArray().contentEquals(r) }, - { c, r -> c.size <= 5 && r!!.isEmpty() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testForEachExample() { - checkThisAndStaticsAfter( - BaseStreamExample::forEachExample, - ignoreExecutionsNumber, - *streamConsumerStaticsMatchers, - coverage = AtLeast(92) - ) - } - - @Test - fun testToArrayExample() { - check( - BaseStreamExample::toArrayExample, - eq(2), - { c, r -> c.toTypedArray().contentEquals(r) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testReduceExample() { - check( - BaseStreamExample::reduceExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == 42 }, - { c, r -> c.isNotEmpty() && r == c.sum() + 42 }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testOptionalReduceExample() { - checkWithException( - BaseStreamExample::optionalReduceExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r.getOrThrow() == Optional.empty() }, - { c, r -> c.isNotEmpty() && c.single() == null && r.isException() }, - { c, r -> c.isNotEmpty() && r.getOrThrow() == Optional.of(c.sum()) }, - coverage = DoNotCalculate // TODO 2 instructions are uncovered https://github.com/UnitTestBot/UTBotJava/issues/193 - ) - } - - @Test - fun testComplexReduceExample() { - check( - BaseStreamExample::complexReduceExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && c.sumOf { it.toDouble() } + 42.0 == r }, - { c: List, r -> c.isNotEmpty() && c.sumOf { it?.toDouble() ?: 0.0 } + 42.0 == r }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - @Disabled("TODO zero executions https://github.com/UnitTestBot/UTBotJava/issues/207") - fun testCollectorExample() { - check( - BaseStreamExample::collectorExample, - ignoreExecutionsNumber, - { c, r -> c.toSet() == r }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testCollectExample() { - checkWithException( - BaseStreamExample::collectExample, - ignoreExecutionsNumber, // 3 executions instead of 2 expected - { c, r -> null in c && r.isException() }, - { c, r -> null !in c && c.sum() == r.getOrThrow() }, - coverage = DoNotCalculate // TODO 2 instructions are uncovered https://github.com/UnitTestBot/UTBotJava/issues/193 - ) - } - - @Test - fun testMinExample() { - checkWithException( - BaseStreamExample::minExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r.getOrThrow() == Optional.empty() }, - { c, r -> c.isNotEmpty() && c.all { it == null } && r.isException() }, - { c, r -> c.isNotEmpty() && r.getOrThrow() == Optional.of(c.minOrNull()!!) }, - coverage = DoNotCalculate // TODO 2 instructions are uncovered https://github.com/UnitTestBot/UTBotJava/issues/193 - ) - } - - @Test - fun testMaxExample() { - checkWithException( - BaseStreamExample::maxExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r.getOrThrow() == Optional.empty() }, - { c, r -> c.isNotEmpty() && c.all { it == null } && r.isException() }, - { c, r -> c.isNotEmpty() && r.getOrThrow() == Optional.of(c.maxOrNull()!!) }, - coverage = DoNotCalculate // TODO 2 instructions are uncovered https://github.com/UnitTestBot/UTBotJava/issues/193 - ) - } - - @Test - fun testCountExample() { - check( - BaseStreamExample::countExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == 0L }, - { c, r -> c.isNotEmpty() && c.size.toLong() == r }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testAnyMatchExample() { - check( - BaseStreamExample::anyMatchExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == false }, - { c, r -> c.isNotEmpty() && c.all { it == null } && r == true }, - { c, r -> c.isNotEmpty() && c.first() != null && c.last() == null && r == true }, - { c, r -> c.isNotEmpty() && c.first() == null && c.last() != null && r == true }, - { c, r -> c.isNotEmpty() && c.none { it == null } && r == false }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - - @Test - fun testAllMatchExample() { - check( - BaseStreamExample::allMatchExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == true }, - { c, r -> c.isNotEmpty() && c.all { it == null } && r == true }, - { c, r -> c.isNotEmpty() && c.first() != null && c.last() == null && r == false }, - { c, r -> c.isNotEmpty() && c.first() == null && c.last() != null && r == false }, - { c, r -> c.isNotEmpty() && c.none { it == null } && r == false }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - - @Test - fun testNoneMatchExample() { - check( - BaseStreamExample::noneMatchExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == true }, - { c, r -> c.isNotEmpty() && c.all { it == null } && r == false }, - { c, r -> c.isNotEmpty() && c.first() != null && c.last() == null && r == false }, - { c, r -> c.isNotEmpty() && c.first() == null && c.last() != null && r == false }, - { c, r -> c.isNotEmpty() && c.none { it == null } && r == true }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - - @Test - fun testFindFirstExample() { - checkWithException( - BaseStreamExample::findFirstExample, - eq(3), - { c, r -> c.isEmpty() && r.getOrThrow() == Optional.empty() }, - { c: List, r -> c.isNotEmpty() && c.first() == null && r.isException() }, - { c, r -> c.isNotEmpty() && r.getOrThrow() == Optional.of(c.first()) }, - coverage = DoNotCalculate - ) - } - - @Test - fun testIteratorExample() { - checkWithException( - BaseStreamExample::iteratorSumExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r.getOrThrow() == 0 }, - { c, r -> null in c && r.isException() }, - { c, r -> c.isNotEmpty() && null !in c && r.getOrThrow() == c.sum() }, - coverage = AtLeast(75) - ) - } - - @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) - ) - } - } - - @Test - fun testClosedStreamExample() { - checkWithException( - BaseStreamExample::closedStreamExample, - eq(1), - { _, r -> r.isException() }, - coverage = DoNotCalculate - ) - } - - @Test - fun testCustomCollectionStreamExample() { - check( - BaseStreamExample::customCollectionStreamExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == 0L }, - { c, r -> c.isNotEmpty() && c.size.toLong() == r }, - coverage = DoNotCalculate // TODO failed coverage calculation - ) - } - - @Test - fun testAnyCollectionStreamExample() { - check( - BaseStreamExample::anyCollectionStreamExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == 0L }, - { c, r -> c.isNotEmpty() && c.size.toLong() == r }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testGenerateExample() { - check( - BaseStreamExample::generateExample, - ignoreExecutionsNumber, - { r -> r!!.contentEquals(Array(10) { 42 }) }, - coverage = Full - ) - } - - @Test - fun testIterateExample() { - check( - BaseStreamExample::iterateExample, - ignoreExecutionsNumber, - { r -> r!!.contentEquals(Array(10) { i -> 42 + i }) }, - coverage = Full - ) - } - - @Test - fun testConcatExample() { - check( - BaseStreamExample::concatExample, - ignoreExecutionsNumber, - { r -> r!!.contentEquals(Array(10) { 42 } + Array(10) { i -> 42 + i }) }, - coverage = Full - ) - } -} - -internal val streamConsumerStaticsMatchers = arrayOf( - { _: Any, c: List, _: StaticsType, _: Int? -> null in c }, - { _: Any, c: List, statics: StaticsType, r: Int? -> - val x = statics.values.single().value as Int - - r!! + c.sumOf { it ?: 0 } == x - } -) - -internal fun > Sequence.isSorted(): Boolean = zipWithNext { a, b -> a <= b }.all { it } diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/stream/DoubleStreamExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/stream/DoubleStreamExampleTest.kt deleted file mode 100644 index 71062b8b82..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/stream/DoubleStreamExampleTest.kt +++ /dev/null @@ -1,534 +0,0 @@ -package org.utbot.examples.stream - -import org.junit.jupiter.api.Tag -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 java.util.OptionalDouble -import java.util.stream.DoubleStream -import kotlin.streams.toList - -// TODO failed Kotlin compilation (generics) JIRA:1332 -@Tag("slow") // we do not really need to always use this test in CI because it is almost the same as BaseStreamExampleTest -class DoubleStreamExampleTest : UtValueTestCaseChecker( - testClass = DoubleStreamExample::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testReturningStreamAsParameterExample() { - withoutConcrete { - check( - DoubleStreamExample::returningStreamAsParameterExample, - eq(1), - { s, r -> s != null && s.toList() == r!!.toList() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - } - - @Test - fun testUseParameterStream() { - check( - DoubleStreamExample::useParameterStream, - eq(2), - { s, r -> s.toArray().isEmpty() && r == 0 }, - { s, r -> s.toArray().let { - it.isNotEmpty() && r == it.size } - }, - coverage = AtLeast(94) - ) - } - - @Test - fun testFilterExample() { - check( - DoubleStreamExample::filterExample, - ignoreExecutionsNumber, - { c, r -> null !in c && r == false }, - { c, r -> null in c && r == true }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMapExample() { - check( - DoubleStreamExample::mapExample, - ignoreExecutionsNumber, - { c, r -> null in c && r.contentEquals(c.doubles { it?.toDouble()?.times(2) ?: 0.0 }) }, - { c: List, r -> null !in c && r.contentEquals(c.doubles { it?.toDouble()?.times(2) ?: 0.0 }) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMapToObjExample() { - check( - DoubleStreamExample::mapToObjExample, - ignoreExecutionsNumber, - { c, r -> - val intArrays = c.doubles().map { it.let { i -> doubleArrayOf(i, i) } }.toTypedArray() - - null in c && intArrays.zip(r as Array) - .all { it.first.contentEquals(it.second as DoubleArray?) } - }, - { c: List, r -> - val intArrays = c.doubles().map { it.let { i -> doubleArrayOf(i, i) } }.toTypedArray() - - null !in c && intArrays.zip(r as Array) - .all { it.first.contentEquals(it.second as DoubleArray?) } - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMapToIntExample() { - check( - DoubleStreamExample::mapToIntExample, - ignoreExecutionsNumber, - { c, r -> - val ints = c.doubles().map { it.toInt() }.toIntArray() - - null in c && ints.contentEquals(r) - }, - { c: List, r -> - val ints = c.doubles().map { it.toInt() }.toIntArray() - - null !in c && ints.contentEquals(r) - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMapToLongExample() { - check( - DoubleStreamExample::mapToLongExample, - ignoreExecutionsNumber, - { c, r -> - val longs = c.doubles().map { it.toLong() }.toLongArray() - - null in c && longs.contentEquals(r) - }, - { c: List, r -> - val longs = c.doubles().map { it.toLong() }.toLongArray() - - null !in c && longs.contentEquals(r) - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testFlatMapExample() { - check( - DoubleStreamExample::flatMapExample, - ignoreExecutionsNumber, - { c, r -> - val intLists = c.mapNotNull { - it.toDouble().let { i -> listOf(i, i) } - } - - r!!.contentEquals(intLists.flatten().toDoubleArray()) - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testDistinctExample() { - check( - DoubleStreamExample::distinctExample, - ignoreExecutionsNumber, - { c, r -> - val doubles = c.doubles() - - doubles.contentEquals(doubles.distinct().toDoubleArray()) && r == false - }, - { c, r -> - val doubles = c.doubles() - - !doubles.contentEquals(doubles.distinct().toDoubleArray()) && r == true - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - @Tag("slow") - // TODO slow sorting https://github.com/UnitTestBot/UTBotJava/issues/188 - fun testSortedExample() { - check( - DoubleStreamExample::sortedExample, - ignoreExecutionsNumber, - { c, r -> c.last() < c.first() && r!!.asSequence().isSorted() }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - - @Test - fun testPeekExample() { - checkThisAndStaticsAfter( - DoubleStreamExample::peekExample, - ignoreExecutionsNumber, - *streamConsumerStaticsMatchers, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testLimitExample() { - check( - DoubleStreamExample::limitExample, - ignoreExecutionsNumber, - { c, r -> c.size <= 2 && c.doubles().contentEquals(r) }, - { c, r -> c.size > 2 && c.take(2).doubles().contentEquals(r) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testSkipExample() { - check( - DoubleStreamExample::skipExample, - ignoreExecutionsNumber, - { c, r -> c.size > 2 && c.drop(2).doubles().contentEquals(r) }, - { c, r -> c.size <= 2 && r!!.isEmpty() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testForEachExample() { - checkThisAndStaticsAfter( - DoubleStreamExample::forEachExample, - ignoreExecutionsNumber, - *streamConsumerStaticsMatchers, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testToArrayExample() { - check( - DoubleStreamExample::toArrayExample, - ignoreExecutionsNumber, - { c, r -> c.doubles().contentEquals(r) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testReduceExample() { - check( - DoubleStreamExample::reduceExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == 42.0 }, - { c: List, r -> c.isNotEmpty() && r == c.filterNotNull().sum() + 42.0 }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testOptionalReduceExample() { - checkWithException( - DoubleStreamExample::optionalReduceExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r.getOrThrow() == OptionalDouble.empty() }, - { c: List, r -> - c.isNotEmpty() && r.getOrThrow() == OptionalDouble.of( - c.filterNotNull().sum().toDouble() - ) - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testSumExample() { - check( - DoubleStreamExample::sumExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == 0.0 }, - { c, r -> c.isNotEmpty() && c.filterNotNull().sum().toDouble() == r }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMinExample() { - checkWithException( - DoubleStreamExample::minExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r.getOrThrow() == OptionalDouble.empty() }, - { c, r -> - c.isNotEmpty() && r.getOrThrow() == OptionalDouble.of(c.mapNotNull { it.toDouble() }.minOrNull()!!) - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMaxExample() { - checkWithException( - DoubleStreamExample::maxExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r.getOrThrow() == OptionalDouble.empty() }, - { c, r -> - c.isNotEmpty() && r.getOrThrow() == OptionalDouble.of(c.mapNotNull { it.toDouble() }.maxOrNull()!!) - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testCountExample() { - check( - DoubleStreamExample::countExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == 0L }, - { c, r -> c.isNotEmpty() && c.size.toLong() == r }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testAverageExample() { - check( - DoubleStreamExample::averageExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == OptionalDouble.empty() }, - { c, r -> c.isNotEmpty() && c.mapNotNull { it.toDouble() }.average() == r!!.asDouble }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @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 - - 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 - - val doubles = c.doubles() - - val allStatisticsAreCorrect = sum == doubles.sum() && - count == doubles.size.toLong() && - min == doubles.minOrNull() && - max == doubles.maxOrNull() - - c.isNotEmpty() && allStatisticsAreCorrect - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - } - - @Test - fun testAnyMatchExample() { - // TODO exceeds even default step limit 3500 => too slow - withPathSelectorStepsLimit(2000) { - check( - DoubleStreamExample::anyMatchExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == false }, - { c, r -> c.isNotEmpty() && c.doubles().all { it == 0.0 } && r == false }, - { c, r -> - val doubles = c.doubles() - - c.isNotEmpty() && doubles.first() != 0.0 && doubles.last() == 0.0 && r == true - }, - { c, r -> - val doubles = c.doubles() - - c.isNotEmpty() && doubles.first() == 0.0 && doubles.last() != 0.0 && r == true - }, - { c, r -> - val doubles = c.doubles() - - c.isNotEmpty() && doubles.none { it == 0.0 } && r == true - }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - } - - @Test - fun testAllMatchExample() { - // TODO exceeds even default step limit 3500 => too slow - withPathSelectorStepsLimit(2000) { - check( - DoubleStreamExample::allMatchExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == true }, - { c, r -> c.isNotEmpty() && c.doubles().all { it == 0.0 } && r == false }, - { c, r -> - val doubles = c.doubles() - - c.isNotEmpty() && doubles.first() != 0.0 && doubles.last() == 0.0 && r == false - }, - { c, r -> - val doubles = c.doubles() - - c.isNotEmpty() && doubles.first() == 0.0 && doubles.last() != 0.0 && r == false - }, - { c, r -> - val doubles = c.doubles() - - c.isNotEmpty() && doubles.none { it == 0.0 } && r == true - }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - } - - @Test - fun testNoneMatchExample() { - // TODO exceeds even default step limit 3500 => too slow - withPathSelectorStepsLimit(2000) { - check( - DoubleStreamExample::noneMatchExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == true }, - { c, r -> c.isNotEmpty() && c.doubles().all { it == 0.0 } && r == true }, - { c, r -> - val doubles = c.doubles() - - c.isNotEmpty() && doubles.first() != 0.0 && doubles.last() == 0.0 && r == false - }, - { c, r -> - val doubles = c.doubles() - - c.isNotEmpty() && doubles.first() == 0.0 && doubles.last() != 0.0 && r == false - }, - { c, r -> - val doubles = c.doubles() - - c.isNotEmpty() && doubles.none { it == 0.0 } && r == false - }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - } - - @Test - fun testFindFirstExample() { - check( - DoubleStreamExample::findFirstExample, - eq(3), - { c, r -> c.isEmpty() && r == OptionalDouble.empty() }, - { c, r -> c.isNotEmpty() && r == OptionalDouble.of(c.doubles().first()) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testBoxedExample() { - check( - DoubleStreamExample::boxedExample, - ignoreExecutionsNumber, - { c, r -> c.doubles().toList() == r!!.toList() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testIteratorExample() { - // TODO exceeds even default step limit 3500 => too slow - withPathSelectorStepsLimit(1000) { - check( - DoubleStreamExample::iteratorSumExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == 0.0 }, - { c: List, r -> c.isNotEmpty() && c.doubles().sum() == r }, - coverage = AtLeast(76) - ) - } - } - - @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) - ) - } - } - - @Test - fun testClosedStreamExample() { - // TODO exceeds even default step limit 3500 => too slow - withPathSelectorStepsLimit(500) { - checkWithException( - DoubleStreamExample::closedStreamExample, - ignoreExecutionsNumber, - { _, r -> r.isException() }, - coverage = AtLeast(88) - ) - } - } - - @Test - fun testGenerateExample() { - check( - DoubleStreamExample::generateExample, - ignoreExecutionsNumber, - { r -> r!!.contentEquals(DoubleArray(10) { 42.0 }) }, - coverage = Full - ) - } - - @Test - fun testIterateExample() { - check( - DoubleStreamExample::iterateExample, - ignoreExecutionsNumber, - { r -> r!!.contentEquals(DoubleArray(10) { i -> 42.0 + i }) }, - coverage = Full - ) - } - - @Test - fun testConcatExample() { - check( - DoubleStreamExample::concatExample, - ignoreExecutionsNumber, - { r -> r!!.contentEquals(DoubleArray(10) { 42.0 } + DoubleArray(10) { i -> 42.0 + i }) }, - coverage = Full - ) - } -} - -private fun List.doubles(mapping: (Short?) -> Double = { it?.toDouble() ?: 0.0 }): DoubleArray = - map { mapping(it) }.toDoubleArray() diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/stream/IntStreamExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/stream/IntStreamExampleTest.kt deleted file mode 100644 index 89a8b5d69e..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/stream/IntStreamExampleTest.kt +++ /dev/null @@ -1,565 +0,0 @@ -package org.utbot.examples.stream - -import org.junit.jupiter.api.Tag -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 java.util.OptionalDouble -import java.util.OptionalInt -import java.util.stream.IntStream -import kotlin.streams.toList - -// TODO failed Kotlin compilation (generics) JIRA:1332 -@Tag("slow") // we do not really need to always use this test in CI because it is almost the same as BaseStreamExampleTest -class IntStreamExampleTest : UtValueTestCaseChecker( - testClass = IntStreamExample::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testReturningStreamAsParameterExample() { - withoutConcrete { - check( - IntStreamExample::returningStreamAsParameterExample, - eq(1), - { s, r -> s != null && s.toList() == r!!.toList() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - } - - @Test - fun testUseParameterStream() { - check( - IntStreamExample::useParameterStream, - eq(2), - { s, r -> s.toArray().isEmpty() && r == 0 }, - { s, r -> s.toArray().let { - it.isNotEmpty() && r == it.size } - }, - coverage = AtLeast(94) - ) - } - - @Test - fun testFilterExample() { - check( - IntStreamExample::filterExample, - ignoreExecutionsNumber, - { c, r -> null !in c && r == false }, - { c, r -> null in c && r == true }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMapExample() { - check( - IntStreamExample::mapExample, - ignoreExecutionsNumber, - { c, r -> null in c && r.contentEquals(c.ints { it?.toInt()?.times(2) ?: 0 }) }, - { c: List, r -> null !in c && r.contentEquals(c.ints { it?.toInt()?.times(2) ?: 0 }) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMapToObjExample() { - check( - IntStreamExample::mapToObjExample, - ignoreExecutionsNumber, - { c, r -> - val intArrays = c.ints().map { it.let { i -> intArrayOf(i, i) } }.toTypedArray() - - null in c && intArrays.zip(r as Array).all { it.first.contentEquals(it.second as IntArray?) } - }, - { c: List, r -> - val intArrays = c.ints().map { it.let { i -> intArrayOf(i, i) } }.toTypedArray() - - null !in c && intArrays.zip(r as Array).all { it.first.contentEquals(it.second as IntArray?) } - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMapToLongExample() { - check( - IntStreamExample::mapToLongExample, - ignoreExecutionsNumber, - { c, r -> - val longs = c.ints().map { it.toLong() * 2 }.toLongArray() - - null in c && longs.contentEquals(r) - }, - { c: List, r -> - val longs = c.ints().map { it.toLong() * 2 }.toLongArray() - - null !in c && longs.contentEquals(r) - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMapToDoubleExample() { - check( - IntStreamExample::mapToDoubleExample, - ignoreExecutionsNumber, - { c, r -> - val doubles = c.ints().map { it.toDouble() / 2 }.toDoubleArray() - - null in c && doubles.contentEquals(r) - }, - { c: List, r -> - val doubles = c.filterNotNull().map { it.toDouble() / 2 }.toDoubleArray() - - null !in c && doubles.contentEquals(r) - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testFlatMapExample() { - check( - IntStreamExample::flatMapExample, - ignoreExecutionsNumber, - { c, r -> - val intLists = c.mapNotNull { - it.toInt().let { i -> listOf(i, i) } - } - - r!!.contentEquals(intLists.flatten().toIntArray()) - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testDistinctExample() { - check( - IntStreamExample::distinctExample, - ignoreExecutionsNumber, - { c, r -> - val ints = c.ints() - - ints.contentEquals(ints.distinct().toIntArray()) && r == false - }, - { c, r -> - val ints = c.ints() - - !ints.contentEquals(ints.distinct().toIntArray()) && r == true - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - @Tag("slow") - // TODO slow sorting https://github.com/UnitTestBot/UTBotJava/issues/188 - fun testSortedExample() { - check( - IntStreamExample::sortedExample, - ignoreExecutionsNumber, - { c, r -> c.last() < c.first() && r!!.asSequence().isSorted() }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - - @Test - fun testPeekExample() { - checkThisAndStaticsAfter( - IntStreamExample::peekExample, - ignoreExecutionsNumber, - *streamConsumerStaticsMatchers, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testLimitExample() { - check( - IntStreamExample::limitExample, - ignoreExecutionsNumber, - { c, r -> c.size <= 2 && c.ints().contentEquals(r) }, - { c, r -> c.size > 2 && c.take(2).ints().contentEquals(r) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testSkipExample() { - check( - IntStreamExample::skipExample, - ignoreExecutionsNumber, - { c, r -> c.size > 2 && c.drop(2).ints().contentEquals(r) }, - { c, r -> c.size <= 2 && r!!.isEmpty() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testForEachExample() { - checkThisAndStaticsAfter( - IntStreamExample::forEachExample, - ignoreExecutionsNumber, - *streamConsumerStaticsMatchers, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testToArrayExample() { - check( - IntStreamExample::toArrayExample, - ignoreExecutionsNumber, - { c, r -> c.ints().contentEquals(r) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testReduceExample() { - check( - IntStreamExample::reduceExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == 42 }, - { c: List, r -> c.isNotEmpty() && r == c.filterNotNull().sum() + 42 }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testOptionalReduceExample() { - checkWithException( - IntStreamExample::optionalReduceExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r.getOrThrow() == OptionalInt.empty() }, - { c: List, r -> c.isNotEmpty() && r.getOrThrow() == OptionalInt.of(c.filterNotNull().sum()) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testSumExample() { - check( - IntStreamExample::sumExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == 0 }, - { c, r -> c.isNotEmpty() && c.filterNotNull().sum() == r }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMinExample() { - checkWithException( - IntStreamExample::minExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r.getOrThrow() == OptionalInt.empty() }, - { c, r -> c.isNotEmpty() && r.getOrThrow() == OptionalInt.of(c.mapNotNull { it.toInt() }.minOrNull()!!) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMaxExample() { - checkWithException( - IntStreamExample::maxExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r.getOrThrow() == OptionalInt.empty() }, - { c, r -> c.isNotEmpty() && r.getOrThrow() == OptionalInt.of(c.mapNotNull { it.toInt() }.maxOrNull()!!) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testCountExample() { - check( - IntStreamExample::countExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == 0L }, - { c, r -> c.isNotEmpty() && c.size.toLong() == r }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testAverageExample() { - check( - IntStreamExample::averageExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == OptionalDouble.empty() }, - { c, r -> c.isNotEmpty() && c.mapNotNull { it.toInt() }.average() == r!!.asDouble }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @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 - - 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 - - val ints = c.ints() - - val allStatisticsAreCorrect = sum == ints.sum().toLong() && - count == ints.size.toLong() && - min == ints.minOrNull() && - max == ints.maxOrNull() - - c.isNotEmpty() && allStatisticsAreCorrect - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - } - - @Test - fun testAnyMatchExample() { - // TODO exceeds even default step limit 3500 => too slow - withPathSelectorStepsLimit(2000) { - check( - IntStreamExample::anyMatchExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == false }, - { c, r -> c.isNotEmpty() && c.ints().all { it == 0 } && r == false }, - { c, r -> - val ints = c.ints() - - c.isNotEmpty() && ints.first() != 0 && ints.last() == 0 && r == true - }, - { c, r -> - val ints = c.ints() - - c.isNotEmpty() && ints.first() == 0 && ints.last() != 0 && r == true - }, - { c, r -> - val ints = c.ints() - - c.isNotEmpty() && ints.none { it == 0 } && r == true - }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - } - - @Test - fun testAllMatchExample() { - // TODO exceeds even default step limit 3500 => too slow - withPathSelectorStepsLimit(2000) { - check( - IntStreamExample::allMatchExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == true }, - { c, r -> c.isNotEmpty() && c.ints().all { it == 0 } && r == false }, - { c, r -> - val ints = c.ints() - - c.isNotEmpty() && ints.first() != 0 && ints.last() == 0 && r == false - }, - { c, r -> - val ints = c.ints() - - c.isNotEmpty() && ints.first() == 0 && ints.last() != 0 && r == false - }, - { c, r -> - val ints = c.ints() - - c.isNotEmpty() && ints.none { it == 0 } && r == true - }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - } - - @Test - fun testNoneMatchExample() { - // TODO exceeds even default step limit 3500 => too slow - withPathSelectorStepsLimit(2000) { - check( - IntStreamExample::noneMatchExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == true }, - { c, r -> c.isNotEmpty() && c.ints().all { it == 0 } && r == true }, - { c, r -> - val ints = c.ints() - - c.isNotEmpty() && ints.first() != 0 && ints.last() == 0 && r == false - }, - { c, r -> - val ints = c.ints() - - c.isNotEmpty() && ints.first() == 0 && ints.last() != 0 && r == false - }, - { c, r -> - val ints = c.ints() - - c.isNotEmpty() && ints.none { it == 0 } && r == false - }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - } - - @Test - fun testFindFirstExample() { - check( - IntStreamExample::findFirstExample, - eq(3), - { c, r -> c.isEmpty() && r == OptionalInt.empty() }, - { c, r -> c.isNotEmpty() && r == OptionalInt.of(c.ints().first()) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testAsLongStreamExample() { - check( - IntStreamExample::asLongStreamExample, - ignoreExecutionsNumber, - { c, r -> c.ints().map { it.toLong() }.toList() == r!!.toList() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testAsDoubleStreamExample() { - check( - IntStreamExample::asDoubleStreamExample, - ignoreExecutionsNumber, - { c, r -> c.ints().map { it.toDouble() }.toList() == r!!.toList() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testBoxedExample() { - check( - IntStreamExample::boxedExample, - ignoreExecutionsNumber, - { c, r -> c.ints().toList() == r!!.toList() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testIteratorExample() { - // TODO exceeds even default step limit 3500 => too slow - withPathSelectorStepsLimit(1000) { - check( - IntStreamExample::iteratorSumExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == 0 }, - { c: List, r -> c.isNotEmpty() && c.ints().sum() == r }, - coverage = AtLeast(76) - ) - } - } - - @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) - ) - } - } - - @Test - fun testClosedStreamExample() { - // TODO exceeds even default step limit 3500 => too slow - withPathSelectorStepsLimit(500) { - checkWithException( - IntStreamExample::closedStreamExample, - ignoreExecutionsNumber, - { _, r -> r.isException() }, - coverage = AtLeast(88) - ) - } - } - - @Test - fun testGenerateExample() { - check( - IntStreamExample::generateExample, - ignoreExecutionsNumber, - { r -> r!!.contentEquals(IntArray(10) { 42 }) }, - coverage = Full - ) - } - - @Test - fun testIterateExample() { - check( - IntStreamExample::iterateExample, - ignoreExecutionsNumber, - { r -> r!!.contentEquals(IntArray(10) { i -> 42 + i }) }, - coverage = Full - ) - } - - @Test - fun testConcatExample() { - check( - IntStreamExample::concatExample, - ignoreExecutionsNumber, - { r -> r!!.contentEquals(IntArray(10) { 42 } + IntArray(10) { i -> 42 + i }) }, - coverage = Full - ) - } - - @Test - fun testRangeExample() { - check( - IntStreamExample::rangeExample, - ignoreExecutionsNumber, - { r -> r!!.contentEquals(IntArray(10) { it }) }, - coverage = Full - ) - } - - @Test - fun testRangeClosedExample() { - check( - IntStreamExample::rangeClosedExample, - ignoreExecutionsNumber, - { r -> r!!.contentEquals(IntArray(11) { it }) }, - coverage = Full - ) - } -} - -private fun List.ints(mapping: (Short?) -> Int = { it?.toInt() ?: 0 }): IntArray = - map { mapping(it) }.toIntArray() diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/stream/LongStreamExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/stream/LongStreamExampleTest.kt deleted file mode 100644 index 7cac365890..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/stream/LongStreamExampleTest.kt +++ /dev/null @@ -1,559 +0,0 @@ -package org.utbot.examples.stream - -import org.junit.jupiter.api.Tag -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 java.util.OptionalDouble -import java.util.OptionalLong -import java.util.stream.LongStream -import kotlin.streams.toList - -// TODO failed Kotlin compilation (generics) JIRA:1332 -@Tag("slow") // we do not really need to always use this test in CI because it is almost the same as BaseStreamExampleTest -class LongStreamExampleTest : UtValueTestCaseChecker( - testClass = LongStreamExample::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testReturningStreamAsParameterExample() { - withoutConcrete { - check( - LongStreamExample::returningStreamAsParameterExample, - eq(1), - { s, r -> s != null && s.toList() == r!!.toList() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - } - - @Test - fun testUseParameterStream() { - check( - LongStreamExample::useParameterStream, - eq(2), - { s, r -> s.toArray().isEmpty() && r == 0 }, - { s, r -> s.toArray().let { - it.isNotEmpty() && r == it.size } - }, - coverage = AtLeast(94) - ) - } - - @Test - fun testFilterExample() { - check( - LongStreamExample::filterExample, - ignoreExecutionsNumber, - { c, r -> null !in c && r == false }, - { c, r -> null in c && r == true }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMapExample() { - check( - LongStreamExample::mapExample, - ignoreExecutionsNumber, - { c, r -> null in c && r.contentEquals(c.longs { it?.toLong()?.times(2) ?: 0L }) }, - { c: List, r -> null !in c && r.contentEquals(c.longs { it?.toLong()?.times(2) ?: 0L }) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMapToObjExample() { - check( - LongStreamExample::mapToObjExample, - ignoreExecutionsNumber, - { c, r -> - val intArrays = c.longs().map { it.let { i -> longArrayOf(i, i) } }.toTypedArray() - - null in c && intArrays.zip(r as Array).all { it.first.contentEquals(it.second as LongArray?) } - }, - { c: List, r -> - val intArrays = c.longs().map { it.let { i -> longArrayOf(i, i) } }.toTypedArray() - - null !in c && intArrays.zip(r as Array).all { it.first.contentEquals(it.second as LongArray?) } - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMapToIntExample() { - check( - LongStreamExample::mapToIntExample, - ignoreExecutionsNumber, - { c, r -> - val ints = c.longs().map { it.toInt() }.toIntArray() - - null in c && ints.contentEquals(r) - }, - { c: List, r -> - val ints = c.longs().map { it.toInt() }.toIntArray() - - null !in c && ints.contentEquals(r) - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMapToDoubleExample() { - check( - LongStreamExample::mapToDoubleExample, - ignoreExecutionsNumber, - { c, r -> - val doubles = c.longs().map { it.toDouble() / 2 }.toDoubleArray() - - null in c && doubles.contentEquals(r) - }, - { c: List, r -> - val doubles = c.filterNotNull().map { it.toDouble() / 2 }.toDoubleArray() - - null !in c && doubles.contentEquals(r) - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testFlatMapExample() { - check( - LongStreamExample::flatMapExample, - ignoreExecutionsNumber, - { c, r -> - val intLists = c.map { - (it?.toLong() ?: 0L).let { i -> listOf(i, i) } - } - - r!!.contentEquals(intLists.flatten().toLongArray()) - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testDistinctExample() { - check( - LongStreamExample::distinctExample, - ignoreExecutionsNumber, - { c, r -> - val longs = c.longs() - - longs.contentEquals(longs.distinct().toLongArray()) && r == false - }, - { c, r -> - val longs = c.longs() - - !longs.contentEquals(longs.distinct().toLongArray()) && r == true - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - @Tag("slow") - // TODO slow sorting https://github.com/UnitTestBot/UTBotJava/issues/188 - fun testSortedExample() { - check( - LongStreamExample::sortedExample, - ignoreExecutionsNumber, - { c, r -> c.last() < c.first() && r!!.asSequence().isSorted() }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - - @Test - fun testPeekExample() { - checkThisAndStaticsAfter( - LongStreamExample::peekExample, - ignoreExecutionsNumber, - *streamConsumerStaticsMatchers, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testLimitExample() { - check( - LongStreamExample::limitExample, - ignoreExecutionsNumber, - { c, r -> c.size <= 2 && c.longs().contentEquals(r) }, - { c, r -> c.size > 2 && c.take(2).longs().contentEquals(r) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testSkipExample() { - check( - LongStreamExample::skipExample, - ignoreExecutionsNumber, - { c, r -> c.size > 2 && c.drop(2).longs().contentEquals(r) }, - { c, r -> c.size <= 2 && r!!.isEmpty() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testForEachExample() { - checkThisAndStaticsAfter( - LongStreamExample::forEachExample, - ignoreExecutionsNumber, - *streamConsumerStaticsMatchers, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testToArrayExample() { - check( - LongStreamExample::toArrayExample, - ignoreExecutionsNumber, - { c, r -> c.longs().contentEquals(r) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testReduceExample() { - check( - LongStreamExample::reduceExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == 42L }, - { c: List, r -> c.isNotEmpty() && r == c.filterNotNull().sum() + 42L }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testOptionalReduceExample() { - checkWithException( - LongStreamExample::optionalReduceExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r.getOrThrow() == OptionalLong.empty() }, - { c: List, r -> - c.isNotEmpty() && r.getOrThrow() == OptionalLong.of( - c.filterNotNull().sum().toLong() - ) - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testSumExample() { - check( - LongStreamExample::sumExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == 0L }, - { c, r -> c.isNotEmpty() && c.filterNotNull().sum().toLong() == r }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMinExample() { - checkWithException( - LongStreamExample::minExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r.getOrThrow() == OptionalLong.empty() }, - { c, r -> c.isNotEmpty() && r.getOrThrow() == OptionalLong.of(c.mapNotNull { it.toLong() }.minOrNull()!!) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testMaxExample() { - checkWithException( - LongStreamExample::maxExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r.getOrThrow() == OptionalLong.empty() }, - { c, r -> c.isNotEmpty() && r.getOrThrow() == OptionalLong.of(c.mapNotNull { it.toLong() }.maxOrNull()!!) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testCountExample() { - check( - LongStreamExample::countExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == 0L }, - { c, r -> c.isNotEmpty() && c.size.toLong() == r }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testAverageExample() { - check( - LongStreamExample::averageExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == OptionalDouble.empty() }, - { c, r -> c.isNotEmpty() && c.mapNotNull { it.toLong() }.average() == r!!.asDouble }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @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 - - 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 - - val longs = c.longs() - - val allStatisticsAreCorrect = sum == longs.sum() && - count == longs.size.toLong() && - min == longs.minOrNull() && - max == longs.maxOrNull() - - c.isNotEmpty() && allStatisticsAreCorrect - }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - } - - @Test - fun testAnyMatchExample() { - // TODO exceeds even default step limit 3500 => too slow - withPathSelectorStepsLimit(2000) { - check( - LongStreamExample::anyMatchExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == false }, - { c, r -> c.isNotEmpty() && c.longs().all { it == 0L } && r == false }, - { c, r -> - val longs = c.longs() - - c.isNotEmpty() && longs.first() != 0L && longs.last() == 0L && r == true - }, - { c, r -> - val longs = c.longs() - - c.isNotEmpty() && longs.first() == 0L && longs.last() != 0L && r == true - }, - { c, r -> - val longs = c.longs() - - c.isNotEmpty() && longs.none { it == 0L } && r == true - }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - } - - @Test - fun testAllMatchExample() { - // TODO exceeds even default step limit 3500 => too slow - withPathSelectorStepsLimit(2000) { - check( - LongStreamExample::allMatchExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == true }, - { c, r -> c.isNotEmpty() && c.longs().all { it == 0L } && r == false }, - { c, r -> - val longs = c.longs() - - c.isNotEmpty() && longs.first() != 0L && longs.last() == 0L && r == false - }, - { c, r -> - val longs = c.longs() - - c.isNotEmpty() && longs.first() == 0L && longs.last() != 0L && r == false - }, - { c, r -> - val longs = c.longs() - - c.isNotEmpty() && longs.none { it == 0L } && r == true - }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - } - - @Test - fun testNoneMatchExample() { - // TODO exceeds even default step limit 3500 => too slow - withPathSelectorStepsLimit(2000) { - check( - LongStreamExample::noneMatchExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == true }, - { c, r -> c.isNotEmpty() && c.longs().all { it == 0L } && r == true }, - { c, r -> - val longs = c.longs() - - c.isNotEmpty() && longs.first() != 0L && longs.last() == 0L && r == false - }, - { c, r -> - val longs = c.longs() - - c.isNotEmpty() && longs.first() == 0L && longs.last() != 0L && r == false - }, - { c, r -> - val longs = c.longs() - - c.isNotEmpty() && longs.none { it == 0L } && r == false - }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - } - - @Test - fun testFindFirstExample() { - check( - LongStreamExample::findFirstExample, - eq(3), - { c, r -> c.isEmpty() && r == OptionalLong.empty() }, - { c, r -> c.isNotEmpty() && r == OptionalLong.of(c.longs().first()) }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testAsDoubleStreamExample() { - check( - LongStreamExample::asDoubleStreamExample, - ignoreExecutionsNumber, - { c, r -> c.longs().map { it.toDouble() }.toList() == r!!.toList() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testBoxedExample() { - check( - LongStreamExample::boxedExample, - ignoreExecutionsNumber, - { c, r -> c.longs().toList() == r!!.toList() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testIteratorExample() { - // TODO exceeds even default step limit 3500 => too slow - withPathSelectorStepsLimit(1000) { - check( - LongStreamExample::iteratorSumExample, - ignoreExecutionsNumber, - { c, r -> c.isEmpty() && r == 0L }, - { c: List, r -> c.isNotEmpty() && c.longs().sum() == r }, - coverage = AtLeast(76) - ) - } - } - - @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) - ) - } - } - - @Test - fun testClosedStreamExample() { - // TODO exceeds even default step limit 3500 => too slow - withPathSelectorStepsLimit(500) { - checkWithException( - LongStreamExample::closedStreamExample, - ignoreExecutionsNumber, - { _, r -> r.isException() }, - coverage = AtLeast(88) - ) - } - } - - @Test - fun testGenerateExample() { - check( - LongStreamExample::generateExample, - ignoreExecutionsNumber, - { r -> r!!.contentEquals(LongArray(10) { 42L }) }, - coverage = Full - ) - } - - @Test - fun testIterateExample() { - check( - LongStreamExample::iterateExample, - ignoreExecutionsNumber, - { r -> r!!.contentEquals(LongArray(10) { i -> 42L + i }) }, - coverage = Full - ) - } - - @Test - fun testConcatExample() { - check( - LongStreamExample::concatExample, - ignoreExecutionsNumber, - { r -> r!!.contentEquals(LongArray(10) { 42L } + LongArray(10) { i -> 42L + i }) }, - coverage = Full - ) - } - - @Test - fun testRangeExample() { - check( - LongStreamExample::rangeExample, - ignoreExecutionsNumber, - { r -> r!!.contentEquals(LongArray(10) { it.toLong() }) }, - coverage = Full - ) - } - - @Test - fun testRangeClosedExample() { - check( - LongStreamExample::rangeClosedExample, - ignoreExecutionsNumber, - { r -> r!!.contentEquals(LongArray(11) { it.toLong() }) }, - coverage = Full - ) - } -} - -private fun List.longs(mapping: (Short?) -> Long = { it?.toLong() ?: 0L }): LongArray = - map { mapping(it) }.toLongArray() diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt deleted file mode 100644 index 30fb1d0553..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt +++ /dev/null @@ -1,69 +0,0 @@ -package org.utbot.examples.stream - -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.framework.plugin.api.visible.UtStreamConsumingException -import org.utbot.testcheckers.eq - - - - -import kotlin.streams.toList - -// TODO 1 instruction is always uncovered https://github.com/UnitTestBot/UTBotJava/issues/193 -// TODO failed Kotlin compilation (generics) JIRA:1332 -class StreamsAsMethodResultExampleTest : UtValueTestCaseChecker( - testClass = StreamsAsMethodResultExample::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ), -) { - @Test - fun testReturningStreamExample() { - check( - StreamsAsMethodResultExample::returningStreamExample, - eq(2), - { c, r -> c.isEmpty() && c == r!!.toList() }, - { c, r -> c.isNotEmpty() && c == r!!.toList() }, - coverage = FullWithAssumptions(assumeCallsNumber = 1) - ) - } - - @Test - fun testReturningIntStreamExample() { - checkWithException( - StreamsAsMethodResultExample::returningIntStreamExample, - eq(3), - { c, r -> c.isEmpty() && c == r.getOrThrow().toList() }, - { c, r -> c.isNotEmpty() && c.none { it == null } && c.toIntArray().contentEquals(r.getOrThrow().toArray()) }, - { c, r -> c.isNotEmpty() && c.any { it == null } && r.isException() }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - - @Test - fun testReturningLongStreamExample() { - checkWithException( - StreamsAsMethodResultExample::returningLongStreamExample, - eq(3), - { c, r -> c.isEmpty() && c == r.getOrThrow().toList() }, - { c, r -> c.isNotEmpty() && c.none { it == null } && c.map { it.toLong() }.toLongArray().contentEquals(r.getOrThrow().toArray()) }, - { c, r -> c.isNotEmpty() && c.any { it == null } && r.isException() }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } - - @Test - fun testReturningDoubleStreamExample() { - checkWithException( - StreamsAsMethodResultExample::returningDoubleStreamExample, - eq(3), - { c, r -> c.isEmpty() && c == r.getOrThrow().toList() }, - { c, r -> c.isNotEmpty() && c.none { it == null } && c.map { it.toDouble() }.toDoubleArray().contentEquals(r.getOrThrow().toArray()) }, - { c, r -> c.isNotEmpty() && c.any { it == null } && r.isException() }, - coverage = FullWithAssumptions(assumeCallsNumber = 2) - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/strings/GenericExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/strings/GenericExamplesTest.kt deleted file mode 100644 index 8548f82b13..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/strings/GenericExamplesTest.kt +++ /dev/null @@ -1,35 +0,0 @@ -package org.utbot.examples.strings - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -@Disabled("TODO: Fails and takes too long") -internal class GenericExamplesTest : UtValueTestCaseChecker( - testClass = GenericExamples::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testContainsOkWithIntegerType() { - checkWithException( - GenericExamples::containsOk, - eq(2), - { obj, result -> obj == null && result.isException() }, - { obj, result -> obj != null && result.isSuccess && result.getOrNull() == false } - ) - } - - @Test - fun testContainsOkExampleTest() { - check( - GenericExamples::containsOkExample, - eq(1), - { result -> result == true } - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/strings/StringExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/strings/StringExamplesTest.kt deleted file mode 100644 index f219660f44..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/strings/StringExamplesTest.kt +++ /dev/null @@ -1,667 +0,0 @@ -package org.utbot.examples.strings - -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.withSolverTimeoutInMillis -import org.utbot.testcheckers.withoutMinimization - -internal class StringExamplesTest : UtValueTestCaseChecker( - testClass = StringExamples::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testByteToString() { - check( - StringExamples::byteToString, - eq(2), - { a, b, r -> a > b && r == a.toString() }, - { a, b, r -> a <= b && r == b.toString() }, - ) - } - - @Test - fun testByteToStringWithConstants() { - val values: Array = arrayOf( - Byte.MIN_VALUE, - (Byte.MIN_VALUE + 100).toByte(), - 0.toByte(), - (Byte.MAX_VALUE - 100).toByte(), - Byte.MAX_VALUE - ) - - val expected = values.map { it.toString() } - - check( - StringExamples::byteToStringWithConstants, - eq(1), - { r -> r != null && r.indices.all { r[it] == expected[it] } } - ) - } - - @Test - fun testReplace() { - check( - StringExamples::replace, - between(3..4), // replace with eq when JIRA:1475 fixed - { fst, _, _ -> fst == null }, - { fst, snd, _ -> fst != null && snd == null }, - { fst, snd, r -> fst != null && snd != null && r != null && (!r.contains("abc") || snd == "abc") }, - coverage = DoNotCalculate - ) - } - - @Test - fun testShortToString() { - check( - StringExamples::shortToString, - ignoreExecutionsNumber, - { a, b, r -> a > b && r == a.toString() }, - { a, b, r -> a <= b && r == b.toString() }, - ) - } - - @Test - fun testShortToStringWithConstants() { - val values: Array = arrayOf( - Short.MIN_VALUE, - (Short.MIN_VALUE + 100).toShort(), - 0.toShort(), - (Short.MAX_VALUE - 100).toShort(), - Short.MAX_VALUE - ) - - val expected = values.map { it.toString() } - - check( - StringExamples::shortToStringWithConstants, - eq(1), - { r -> r != null && r.indices.all { r[it] == expected[it] } } - ) - } - - @Test - fun testIntToString() { - check( - StringExamples::intToString, - ignoreExecutionsNumber, - { a, b, r -> a > b && r == a.toString() }, - { a, b, r -> a <= b && r == b.toString() }, - ) - } - - @Test - fun testIntToStringWithConstants() { - val values: Array = arrayOf( - Integer.MIN_VALUE, - Integer.MIN_VALUE + 100, - 0, - Integer.MAX_VALUE - 100, - Integer.MAX_VALUE - ) - - val expected = values.map { it.toString() } - - check( - StringExamples::intToStringWithConstants, - eq(1), - { r -> r != null && r.indices.all { r[it] == expected[it] } } - ) - } - - @Test - fun testLongToString() { - check( - StringExamples::longToString, - ignoreExecutionsNumber, - { a, b, r -> a > b && r == a.toString() }, - { a, b, r -> a <= b && r == b.toString() }, - ) - } - - @Test - fun testLongToStringWithConstants() { - val values: Array = arrayOf( - Long.MIN_VALUE, - Long.MIN_VALUE + 100L, - 0L, - Long.MAX_VALUE - 100L, - Long.MAX_VALUE - ) - - val expected = values.map { it.toString() } - - check( - StringExamples::longToStringWithConstants, - eq(1), - { r -> r != null && r.indices.all { r[it] == expected[it] } } - ) - } - - @Test - fun testStartsWithLiteral() { - check( - StringExamples::startsWithLiteral, - ge(4), // replace with eq when JIRA:1475 fixed - { v, _ -> v == null }, - { v, r -> v != null && v.startsWith("1234567890") && r!!.startsWith("12a4567890") }, - { v, r -> v != null && v[0] == 'x' && r!![0] == 'x' }, - { v, r -> v != null && v.toLowerCase() == r } - ) - } - - @Test - fun testBooleanToString() { - check( - StringExamples::booleanToString, - eq(2), - { a, b, r -> a == b && r == "false" }, - { a, b, r -> a != b && r == "true" }, - ) - } - - - @Test - fun testCharToString() { - // TODO related to the https://github.com/UnitTestBot/UTBotJava/issues/131 - withSolverTimeoutInMillis(5000) { - check( - StringExamples::charToString, - eq(2), - { a, b, r -> a > b && r == a.toString() }, - { a, b, r -> a <= b && r == b.toString() }, - ) - } - } - - - @Test - @Disabled("TODO:add Byte.valueOf(String) support") - fun testStringToByte() { - check( - StringExamples::stringToByte, - eq(-1), - coverage = DoNotCalculate - ) - } - - @Test - @Disabled("TODO:add Short.valueOf(String) support") - fun testStringToShort() { - check( - StringExamples::stringToShort, - eq(-1), - coverage = DoNotCalculate - ) - } - - @Test - @Disabled("TODO:add Integer.valueOf(String) support") - fun testStringToInt() { - check( - StringExamples::stringToInt, - eq(-1), - coverage = DoNotCalculate - ) - } - - @Test - @Disabled("TODO:add Long.valueOf support") - fun testStringToLong() { - check( - StringExamples::stringToLong, - eq(-1), - coverage = DoNotCalculate - ) - } - - @Test - fun testStringToBoolean() { - check( - StringExamples::stringToBoolean, - ge(2), - { s, r -> (s == null || r == java.lang.Boolean.valueOf(s)) && r == false}, // minimization - { s, r -> s != null && r == true && r == java.lang.Boolean.valueOf(s) }, - ) - } - - @Test - fun testConcat() { - check( - StringExamples::concat, - between(1..2), - { fst, snd, r -> fst == null || snd == null && r == fst + snd }, - { fst, snd, r -> r == fst + snd }, - ) - } - - @Test - @Disabled("Sometimes it freezes the execution for several hours JIRA:1453") - fun testConcatWithObject() { - check( - StringExamples::concatWithObject, - between(2..3), - { pair, r -> pair == null && r == "fst.toString() = $pair" }, - { pair, r -> pair != null && r == "fst.toString() = $pair" } - ) - } - - @Test - fun testStringConstants() { - check( - StringExamples::stringConstants, - between(1..2), - { s, r -> r == "String('$s')" }, - ) - } - - @Test - fun testContainsOnLiterals() { - check( - StringExamples::containsOnLiterals, - eq(1), - ) - } - - @Test - @Disabled("This is a flaky test") - fun testConcatWithInt() { - check( - StringExamples::concatWithInts, - eq(3), - { a, b, r -> a == b && r == null }, // IllegalArgumentException - { a, b, r -> a > b && r == "a > b, a:$a, b:$b" }, - { a, b, r -> a < b && r == "a < b, a:$a, b:$b" }, - ) - } - - @Test - fun testUseStringBuffer() { - check( - StringExamples::useStringBuffer, - between(1..2), - { fst, snd, r -> r == "$fst, $snd" }, - ) - } - - @Test - fun testNullableStringBuffer() { - checkWithException( - StringExamples::nullableStringBuffer, - eq(4), - { _, i, r -> i >= 0 && r.isException() }, - { _, i, r -> i < 0 && r.isException() }, - { buffer, i, r -> i >= 0 && r.getOrNull() == "${buffer}Positive" }, - { buffer, i, r -> i < 0 && r.getOrNull() == "${buffer}Negative" }, - ) - } - - @Test - fun testIsStringBuilderEmpty() { - check( - StringExamples::isStringBuilderEmpty, - eq(2), - { stringBuilder, result -> result == stringBuilder.isEmpty() } - ) - } - - @Test - @Disabled("Flaky on GitHub: https://github.com/UnitTestBot/UTBotJava/issues/1004") - fun testIsValidUuid() { - val pattern = Regex("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}") - check( - StringExamples::isValidUuid, - ignoreExecutionsNumber, - { uuid, r -> uuid == null || uuid.length == 0 && r == false }, - { uuid, r -> uuid.length > 0 && uuid.isBlank() && r == false }, - { uuid, r -> uuid.length > 0 && uuid.isNotBlank() && r == false }, - { uuid, r -> uuid.length > 1 && uuid.isNotBlank() && !uuid.matches(pattern) && r == false }, - { uuid, r -> uuid.length > 1 && uuid.isNotBlank() && uuid.matches(pattern) && r == true }, - ) - } - - @Test - fun testIsValidUuidShortVersion() { - val pattern = Regex("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}") - check( - StringExamples::isValidUuidShortVersion, - eq(3), - { uuid, r -> uuid == null && r == false }, - { uuid, r -> uuid.matches(pattern) && r == true }, - { uuid, r -> !uuid.matches(pattern) && r == false }, - ) - } - - @Test - fun testIsBlank() { - check( - StringExamples::isBlank, - ge(4), - { cs, r -> cs == null && r == true }, - { cs, r -> cs.length == 0 && r == true }, - { cs, r -> cs.length > 0 && cs.isBlank() && r == true }, - { cs, r -> cs.length > 0 && cs.isNotBlank() && r == false }, - summaryNameChecks = listOf( - keyMatch("testIsBlank_StrLenEqualsZero"), - keyMatch("testIsBlank_NotCharacterIsWhitespace"), - keyMatch("testIsBlank_CharacterIsWhitespace") - ) - ) - } - - @Test - fun testLength() { - check( - StringExamples::length, - eq(2), // TODO: that strange, why we haven't 3rd option? - { cs, r -> cs == null && r == 0 }, - { cs, r -> cs != null && r == cs.length }, - ) - } - - @Test - fun testLonger() { - checkWithException( - StringExamples::longer, - ignoreExecutionsNumber, - { _, i, r -> i <= 0 && r.isException() }, - { cs, i, r -> i > 0 && cs == null && !r.getOrThrow() }, - { cs, i, r -> i > 0 && cs != null && cs.length > i && r.getOrThrow() }, - coverage = DoNotCalculate // TODO: Coverage calculation fails in the child process with Illegal Argument Exception - ) - } - - @Test - fun testEqualChar() { - checkWithException( - StringExamples::equalChar, - eq(4), - { cs, r -> cs == null && r.isException() }, - { cs, r -> cs.isEmpty() && r.isException() }, - { cs, r -> cs.isNotEmpty() && cs[0] == 'a' && r.getOrThrow() }, - { cs, r -> cs.isNotEmpty() && cs[0] != 'a' && !r.getOrThrow() }, - ) - } - - @Test - fun testSubstring() { - checkWithException( - StringExamples::substring, - between(5..8), - { s, _, r -> s == null && r.isException() }, - { s, i, r -> s != null && i < 0 || i > s.length && r.isException() }, - { s, i, r -> s != null && i in 0..s.length && r.getOrThrow() == s.substring(i) && s.substring(i) != "password" }, - { s, i, r -> s != null && i == 0 && r.getOrThrow() == s.substring(i) && s.substring(i) == "password" }, - { s, i, r -> s != null && i != 0 && r.getOrThrow() == s.substring(i) && s.substring(i) == "password" }, - ) - } - - @Test - fun testSubstringWithEndIndex() { - checkWithException( - StringExamples::substringWithEndIndex, - ignoreExecutionsNumber, - { s, _, _, r -> s == null && r.isException() }, - { s, b, e, r -> s != null && b < 0 || e > s.length || b > e && r.isException() }, - { s, b, e, r -> r.getOrThrow() == s.substring(b, e) && s.substring(b, e) != "password" }, - { s, b, e, r -> b == 0 && r.getOrThrow() == s.substring(b, e) && s.substring(b, e) == "password" }, - { s, b, e, r -> - b != 0 && e == s.length && r.getOrThrow() == s.substring(b, e) && s.substring(b, e) == "password" - }, - { s, b, e, r -> - b != 0 && e != s.length && r.getOrThrow() == s.substring(b, e) && s.substring(b, e) == "password" - }, - ) - } - - @Test - fun testSubstringWithEndIndexNotEqual() { - checkWithException( - StringExamples::substringWithEndIndexNotEqual, - ignoreExecutionsNumber, - { s, _, r -> s == null && r.isException() }, - { s, e, r -> s != null && e < 1 || e > s.length && r.isException() }, - { s, e, r -> s != null && r.getOrThrow() == s.substring(1, e) }, - ) - } - - @Test - fun testFullSubstringEquality() { - checkWithException( - StringExamples::fullSubstringEquality, - eq(2), - { s, r -> s == null && r.isException() }, - { s, r -> s != null && r.getOrThrow() }, - ) - } - - @Test - @Disabled("TODO: add intern support") - fun testUseIntern() { - checkWithException( - StringExamples::useIntern, - eq(3), - { s, r -> s == null && r.isException() }, - { s, r -> s != null && s != "abc" && r.getOrThrow() == 1 }, - { s, r -> s != null && s == "abc" && r.getOrThrow() == 3 }, - coverage = atLeast(66) - ) - } - - @Test - fun testPrefixAndSuffix() { - check( - StringExamples::prefixAndSuffix, - eq(6), - { s, r -> s == null && r == null }, // NullPointerException - { s, r -> s.length != 5 && r == 0 }, - { s, r -> s.length == 5 && !s.startsWith("ab") && r == 1 }, - { s, r -> s.length == 5 && s.startsWith("ab") && !s.endsWith("de") && r == 2 }, - { s, r -> s.length == 5 && s.startsWith("ab") && s.endsWith("de") && !s.contains("+") && r == 4 }, - { s, r -> s.length == 5 && s == "ab+de" && r == 3 }, - ) - } - - @Test - fun testPrefixWithTwoArgs() { - checkWithException( - StringExamples::prefixWithTwoArgs, - between(3..4), - { s, r -> s == null && r.isException() }, - { s, r -> s != null && s.startsWith("abc", 1) && r.getOrThrow() == 1 }, - { s, r -> s != null && !s.startsWith("abc", 1) && r.getOrThrow() == 2 }, - ) - } - - @Test - fun testPrefixWithOffset() { - withoutMinimization { - check( - StringExamples::prefixWithOffset, - eq(4), // should be 4, but path selector eliminates several results with false - { o, r -> o < 0 && r == 2 }, - { o, r -> o > "babc".length - "abc".length && r == 2 }, - { o, r -> o in 0..1 && !"babc".startsWith("abc", o) && r == 2 }, - { o, r -> "babc".startsWith("abc", o) && r == 1 }, - ) - } - } - - @Test - fun testStartsWith() { - check( - StringExamples::startsWith, - between(5..6), - { _, prefix, _ -> prefix == null }, - { _, prefix, _ -> prefix != null && prefix.length < 2 }, - { s, prefix, _ -> prefix != null && prefix.length >= 2 && s == null }, - { s, prefix, r -> prefix != null && prefix.length >= 2 && s != null && s.startsWith(prefix) && r == true }, - { s, prefix, r -> prefix != null && prefix.length >= 2 && s != null && !s.startsWith(prefix) && r == false } - - ) - } - - @Test - fun testStartsWithOffset() { - check( - StringExamples::startsWithOffset, - between(6..10), - { _, prefix, _, _ -> prefix == null }, - { _, prefix, _, _ -> prefix != null && prefix.length < 2 }, - { s, prefix, _, _ -> prefix != null && prefix.length >= 2 && s == null }, - { s, prefix, o, r -> - prefix != null && prefix.length >= 2 && s != null && s.startsWith(prefix, o) && o > 0 && r == 0 - }, - { s, prefix, o, r -> - prefix != null && prefix.length >= 2 && s != null && s.startsWith(prefix, o) && o == 0 && r == 1 - }, - { s, prefix, o, r -> - prefix != null && prefix.length >= 2 && s != null && !s.startsWith(prefix, o) && r == 2 - } - ) - } - - @Test - fun testEndsWith() { - check( - StringExamples::endsWith, - between(5..6), - { s, suffix, r -> suffix == null }, - { s, suffix, r -> suffix != null && suffix.length < 2 }, - { s, suffix, r -> suffix != null && suffix.length >= 2 && s == null }, - { s, suffix, r -> suffix != null && suffix.length >= 2 && s != null && s.endsWith(suffix) && r == true }, - { s, suffix, r -> suffix != null && suffix.length >= 2 && s != null && !s.endsWith(suffix) && r == false } - ) - } - - @Test - @Disabled("TODO: support replace") - fun testReplaceAll() { - checkWithException( - StringExamples::replaceAll, - eq(4), - { s, _, _, r -> s == null && r.isException() }, - { s, regex, _, r -> s != null && regex == null && r.isException() }, - { s, regex, replacement, r -> s != null && regex != null && replacement == null && r.isException() }, - { s, regex, replacement, r -> - s != null && regex != null && replacement != null && r.getOrThrow() == s.replace(regex, replacement) - }, // one replace only! - ) - } - - @Test - fun testLastIndexOf() { - check( - StringExamples::lastIndexOf, - between(5..7), - { s, _, _ -> s == null }, - { s, find, _ -> s != null && find == null }, - { s, find, r -> r == s.lastIndexOf(find) && r == s.length - find.length }, - { s, find, r -> r == s.lastIndexOf(find) && r < s.length - find.length }, - { s, find, r -> r == s.lastIndexOf(find) && r == -1 }, - ) - } - - @Test - fun testIndexOfWithOffset() { - check( - StringExamples::indexOfWithOffset, - between(5..9), - { s, _, _, _ -> s == null }, - { s, find, _, _ -> s != null && find == null }, - { s, find, offset, r -> r == s.indexOf(find, offset) && r > offset && offset > 0 }, - { s, find, offset, r -> r == s.indexOf(find, offset) && r == offset }, - { s, find, offset, r -> r == s.indexOf(find, offset) && !(r == offset || (offset in 1 until r)) }, - ) - } - - - @Test - fun testLastIndexOfWithOffset() { - check( - StringExamples::lastIndexOfWithOffset, - between(5..9), - { s, _, _, _ -> s == null }, - { s, find, _, _ -> s != null && find == null }, - { s, find, i, r -> r == s.lastIndexOf(find, i) && r >= 0 && r < i - find.length && i < s.length }, - { s, find, i, r -> r == s.lastIndexOf(find, i) && r >= 0 && !(r < i - find.length && i < s.length) }, - { s, find, i, r -> r == s.lastIndexOf(find, i) && r == -1 }, - ) - } - - @Test - fun testCompareCodePoints() { - checkWithException( - StringExamples::compareCodePoints, - between(8..10), - { s, t, i, r -> s == null && r.isException() }, - { s, t, i, r -> s != null && i < 0 || i >= s.length && r.isException() }, - { s, t, i, r -> s != null && t == null && r.isException() }, - { s, t, i, r -> t != null && i < 0 || i >= t.length && r.isException() }, - { s, t, i, r -> s != null && t != null && s.codePointAt(i) < t.codePointAt(i) && i == 0 && r.getOrThrow() == 0 }, - { s, t, i, r -> s != null && t != null && s.codePointAt(i) < t.codePointAt(i) && i != 0 && r.getOrThrow() == 1 }, - { s, t, i, r -> s != null && t != null && s.codePointAt(i) >= t.codePointAt(i) && i == 0 && r.getOrThrow() == 2 }, - { s, t, i, r -> s != null && t != null && s.codePointAt(i) >= t.codePointAt(i) && i != 0 && r.getOrThrow() == 3 }, - ) - } - - @Test - fun testToCharArray() { - check( - StringExamples::toCharArray, - eq(2), - { s, r -> s == null }, - { s, r -> s.toCharArray().contentEquals(r) } - ) - } - - @Test - fun testGetObj() { - check( - StringExamples::getObj, - eq(1), - { obj, r -> obj == r } - ) - } - - @Test - fun testGetObjWithCondition() { - check( - StringExamples::getObjWithCondition, - between(3..4), - { obj, r -> obj == null && r == "null" }, - { obj, r -> obj != null && obj == "BEDA" && r == "48858" }, - { obj, r -> obj != null && obj != "BEDA" && obj == r } - ) - } - - @Test - fun testEqualsIgnoreCase() { - withPushingStateFromPathSelectorForConcrete { - check( - StringExamples::equalsIgnoreCase, - ignoreExecutionsNumber, - { s, r -> "SUCCESS".equals(s, ignoreCase = true) && r == "success" }, - { s, r -> !"SUCCESS".equals(s, ignoreCase = true) && r == "failure" }, - ) - } - } - - // 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 - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/strings11/StringConcatTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/strings11/StringConcatTest.kt deleted file mode 100644 index 090cbb2c7f..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/strings11/StringConcatTest.kt +++ /dev/null @@ -1,113 +0,0 @@ -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 - -class StringConcatTest : UtValueTestCaseChecker( - testClass = StringConcat::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun testConcatArguments() { - withoutConcrete { - 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 }, - ) - } - } - - @Test - fun testConcatWithPrimitives() { - withoutConcrete { - 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 - ) - } - } - - @Test - fun testConcatWithField() { - withoutConcrete { - 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 - ) - } - } - - @Test - fun testSameConcat() { - withoutConcrete { - 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" } - ) - } - } - -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/structures/HeapTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/structures/HeapTest.kt deleted file mode 100644 index 92f87808f8..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/structures/HeapTest.kt +++ /dev/null @@ -1,20 +0,0 @@ -package org.utbot.examples.structures - -import org.junit.jupiter.api.Test - -internal class HeapTest : UtValueTestCaseChecker(testClass = Heap::class) { - @Test - fun testIsHeap() { - val method = Heap::isHeap - checkStaticMethod( - method, - ignoreExecutionsNumber, - { values, _ -> values == null }, - { values, _ -> values.size < 3 }, - { values, r -> values.size >= 3 && r == method(values) }, - { values, r -> values.size >= 3 && values[1] < values[0] && r == method(values) }, - { values, r -> values.size >= 3 && values[1] >= values[0] && values[2] < values[0] && r == method(values) }, - { values, r -> values.size >= 3 && r == method(values) }, - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/structures/MinStackExampleTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/structures/MinStackExampleTest.kt deleted file mode 100644 index 53676ee1d1..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/structures/MinStackExampleTest.kt +++ /dev/null @@ -1,103 +0,0 @@ -package org.utbot.examples.structures - -import kotlin.math.min -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class MinStackExampleTest : UtValueTestCaseChecker(testClass = MinStackExample::class) { - @Test - fun testCreate() { - check( - MinStackExample::create, - eq(3), - { initialValues, _ -> initialValues == null }, - { initialValues, _ -> initialValues != null && initialValues.size < 3 }, - { initialValues, result -> - require(initialValues != null && result != null) - - val stackExample = MinStackExample().create(initialValues) - val initialSize = initialValues.size - - val sizesConstraint = initialSize >= 3 && result.size == 4 - val stacksSize = stackExample.stack.take(initialSize) == result.stack.take(initialSize) - val minStackSize = stackExample.minStack.take(initialSize) == result.minStack.take(initialSize) - - sizesConstraint && stacksSize && minStackSize - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testAddSingleValue() { - check( - MinStackExample::addSingleValue, - eq(3), - { initialValues, _ -> initialValues == null }, - { initialValues, _ -> initialValues != null && initialValues.isEmpty() }, - { initialValues, result -> - require(initialValues != null && result != null) - - val sizeConstraint = initialValues.isNotEmpty() - val firstElementConstraint = result.stack.first() == initialValues.first() - val secondElementConstraint = result.stack[1] == initialValues.first() - 100 - - sizeConstraint && firstElementConstraint && secondElementConstraint - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetMinValue() { - check( - MinStackExample::getMinValue, - eq(3), - { initialValues, _ -> initialValues == null }, - { initialValues, result -> initialValues != null && initialValues.isEmpty() && result == -1L }, - { initialValues, result -> - initialValues != null && initialValues.isNotEmpty() && result == min(-1L, initialValues.minOrNull()!!) - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testRemoveValue() { - check( - MinStackExample::removeValue, - eq(4), - { initialValues, _ -> initialValues == null }, - { initialValues, _ -> initialValues != null && initialValues.isEmpty() }, - { initialValues, result -> - initialValues != null && initialValues.size == 1 && result != null && result.size == initialValues.size - 1 - }, - { initialValues, result -> - initialValues != null && initialValues.size > 1 && result != null && result.size == initialValues.size - 1 - }, - coverage = DoNotCalculate - ) - } - - @Test - fun testConstruct() { - check( - MinStackExample::construct, - between(3..4), - { values, _ -> values == null }, - { values, result -> values != null && values.isEmpty() && result != null && result.size == 0 }, - { values, result -> - require(values != null && result != null) - - val stackExample = MinStackExample().construct(values) - - val sizeConstraint = values.isNotEmpty() && result.size == values.size - val stackSize = stackExample.stack.take(values.size) == result.stack.take(values.size) - val valueConstraint = stackExample.minStack.take(values.size) == result.minStack.take(values.size) - - sizeConstraint && stackSize && valueConstraint - }, - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt deleted file mode 100644 index 5f2c35d34f..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt +++ /dev/null @@ -1,100 +0,0 @@ -package org.utbot.examples.structures - -import org.utbot.framework.plugin.api.DocCodeStmt -import org.utbot.framework.plugin.api.DocPreTagStatement -import org.utbot.framework.plugin.api.DocRegularStmt -import org.utbot.framework.plugin.api.DocStatement -import java.util.LinkedList -import java.util.TreeMap -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.CodegenLanguage -import org.utbot.testcheckers.eq - -internal class StandardStructuresTest : UtValueTestCaseChecker( - testClass = StandardStructures::class, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - @Disabled("TODO down cast for object wrapper JIRA:1480") - fun testGetList() { - check( - StandardStructures::getList, - eq(4), - { l, r -> l is ArrayList && r is ArrayList }, - { l, r -> l is LinkedList && r is LinkedList }, - { l, r -> l == null && r == null }, - { l, r -> - l !is ArrayList && l !is LinkedList && l != null && r !is ArrayList && r !is LinkedList && r != null - }, - coverage = DoNotCalculate - ) - } - - @Test - @Disabled("TODO down cast for object wrapper JIRA:1480") - fun testGetMap() { - check( - StandardStructures::getMap, - eq(3), - { m, r -> m is TreeMap && r is TreeMap }, - { m, r -> m == null && r == null }, - { m, r -> m !is TreeMap && m != null && r !is TreeMap && r != null }, - coverage = DoNotCalculate - ) - } - - @Test - fun testGetDeque() { - val dequeSummary = listOf( - DocPreTagStatement( - listOf( - DocRegularStmt("Test "), - DocRegularStmt("executes conditions:\n"), - DocRegularStmt(" "), - DocCodeStmt("(deque instanceof LinkedList): False"), - DocRegularStmt(",\n"), - DocRegularStmt(" "), - DocCodeStmt("(deque == null): True"), - DocRegularStmt("\n"), - DocRegularStmt("returns from: "), - DocCodeStmt("return null;"), - DocRegularStmt("\n") - ) - ) - ) - - check( - StandardStructures::getDeque, - eq(4), - { d, r -> d is java.util.ArrayDeque && r is java.util.ArrayDeque }, - { d, r -> d is LinkedList && r is LinkedList }, - { d, r -> d == null && r == null }, - { d, r -> - d !is java.util.ArrayDeque<*> && d !is LinkedList && d != null && r !is java.util.ArrayDeque<*> && r !is LinkedList && r != null - }, - coverage = DoNotCalculate, - summaryTextChecks = listOf( - keyContain(DocCodeStmt("(deque instanceof ArrayDeque): True")), - keyContain(DocCodeStmt("(deque instanceof LinkedList): True")), - keyContain(DocCodeStmt("(deque == null): True")), - keyMatch(dequeSummary) - ), - summaryNameChecks = listOf( - keyMatch("testGetDeque_DequeInstanceOfArrayDeque"), - keyMatch("testGetDeque_DequeInstanceOfLinkedList"), - keyMatch("testGetDeque_DequeEqualsNull"), - keyMatch("testGetDeque_DequeNotEqualsNull"), - ), - summaryDisplayNameChecks = listOf( - keyContain("deque", "instance", "ArrayDeque"), - keyContain("deque", "instance", "LinkedList"), - keyContain("deque == null", "True"), - keyContain("deque == null", "False"), - ) - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/thirdparty/numbers/ArithmeticUtilsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/thirdparty/numbers/ArithmeticUtilsTest.kt deleted file mode 100644 index fc7658c50d..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/thirdparty/numbers/ArithmeticUtilsTest.kt +++ /dev/null @@ -1,46 +0,0 @@ -package org.utbot.examples.thirdparty.numbers - -import org.junit.jupiter.api.Tag -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker - -// example from Apache common-numbers -internal class ArithmeticUtilsTest : UtValueTestCaseChecker(testClass = ArithmeticUtils::class) { - @Test - @Tag("slow") - fun testPow() { - check( - ArithmeticUtils::pow, - eq(11), - { _, e, _ -> e < 0 }, // IllegalArgumentException - { k, e, r -> k == 0 && e == 0 && r == 1 }, - { k, e, r -> k == 0 && e != 0 && r == 0 }, - { k, _, r -> k == 1 && r == 1 }, - { k, e, r -> k == -1 && e and 1 == 0 && r == 1 }, - { k, e, r -> k == -1 && e and 1 != 0 && r == -1 }, - { _, e, _ -> e >= 31 }, // ArithmeticException - { k, e, r -> k !in -1..1 && e in 0..30 && r == pow(k, e) }, - - // And 2 additional branches here with ArithmeticException reg integer overflow - { k, e, r -> k !in -1..1 && e in 0..30 && r == null }, - ) - } -} - -fun pow(k: Int, e: Int): Int { - var exp = e - var result = 1 - var k2p = k - while (true) { - if (exp and 0x1 != 0) { - result = Math.multiplyExact(result, k2p) - } - exp = exp shr 1 - if (exp == 0) { - break - } - k2p = Math.multiplyExact(k2p, k2p) - } - return result -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/types/CastExamplesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/types/CastExamplesTest.kt deleted file mode 100644 index 1cc939a373..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/types/CastExamplesTest.kt +++ /dev/null @@ -1,77 +0,0 @@ -package org.utbot.examples.types - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker - -@Suppress("SimplifyNegatedBinaryExpression") -internal class CastExamplesTest : UtValueTestCaseChecker(testClass = CastExamples::class) { - @Test - fun testLongToByte() { - check( - CastExamples::longToByte, - eq(3), - { a, b, r -> (a.toByte() + b.toByte()).toByte() > 10 && r == (a.toByte() + b.toByte()).toByte() }, - { a, b, r -> (a.toByte() + b.toByte()).toByte() <= 10 && a.toByte() > b.toByte() && r == (-1).toByte() }, - { a, b, r -> (a.toByte() + b.toByte()).toByte() <= 10 && a.toByte() <= b.toByte() && r == (0).toByte() }, - ) - } - - @Test - fun testShortToLong() { - check( - CastExamples::shortToLong, - eq(3), - { a, b, r -> a + b > 10 && r == a.toLong() + b.toLong() }, - { a, b, r -> a + b <= 10 && a > b && r == -1L }, - { a, b, r -> a + b <= 10 && a <= b && r == 0L }, - ) - } - - @Test - fun testFloatToDouble() { - check( - CastExamples::floatToDouble, - eq(4), - { a, b, r -> a.toDouble() + b.toDouble() > Float.MAX_VALUE && r == 2.0 }, - { a, b, r -> a.toDouble() + b.toDouble() > 10 && r == 1.0 }, - { a, b, r -> !(a.toDouble() + b.toDouble() > 10) && !(a.toDouble() > b.toDouble()) && r == 0.0 }, - { a, b, r -> !(a.toDouble() + b.toDouble() > 10) && a.toDouble() > b.toDouble() && r == -1.0 }, - ) - } - - @Test - fun testDoubleToFloatArray() { - check( - CastExamples::doubleToFloatArray, - eq(2), - { x, r -> x.toFloat() + 5 > 20 && r == 1.0f }, - { x, r -> !(x.toFloat() + 5 > 20) && r == 0.0f } - ) - } - - @Test - fun testFloatToInt() { - check( - CastExamples::floatToInt, - eq(3), - { x, r -> x < 0 && x.toInt() < 0 && r == 1 }, - { x, r -> x < 0 && x.toInt() >= 0 && r == 2 }, - { x, r -> !(x < 0) && r == 3 }, - ) - } - - @Test - fun testShortToChar() { - check( - CastExamples::shortToChar, - eq(3), - { a, b, r -> (a.charInt() + b.charInt()).charInt() > 10 && r == (a.charInt() + b.charInt()).toChar() }, - { a, b, r -> (a.charInt() + b.charInt()).charInt() <= 10 && a.charInt() <= b.charInt() && r == (0).toChar() }, - { a, b, r -> (a.charInt() + b.charInt()).charInt() <= 10 && a.charInt() > b.charInt() && r == (-1).toChar() }, - ) - } - - // Special cast to emulate Java binary numeric promotion - private fun Number.charInt() = toChar().toInt() -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/types/TypeBordersTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/types/TypeBordersTest.kt deleted file mode 100644 index e1325710de..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/types/TypeBordersTest.kt +++ /dev/null @@ -1,76 +0,0 @@ -package org.utbot.examples.types - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class TypeBordersTest : UtValueTestCaseChecker(testClass = TypeBorders::class) { - @Test - fun testByteBorder() { - check( - TypeBorders::byteBorder, - eq(3), - { x, r -> x == Byte.MIN_VALUE && r == 3 }, - { x, r -> x == Byte.MAX_VALUE && r == 2 }, - { x, r -> x > Byte.MIN_VALUE && x < Byte.MAX_VALUE && r == 4 }, - coverage = atLeast(75) - ) - } - - @Test - fun testShortBorder() { - check( - TypeBorders::shortBorder, - eq(3), - { x, r -> x == Short.MIN_VALUE && r == 3 }, - { x, r -> x == Short.MAX_VALUE && r == 2 }, - { x, r -> x > Short.MIN_VALUE && x < Short.MAX_VALUE && r == 4 }, - coverage = atLeast(75) - ) - } - - @Test - fun testCharBorder() { - check( - TypeBorders::charBorder, - eq(3), - { x, r -> x == Char.MIN_VALUE && r == 3 }, - { x, r -> x == Char.MAX_VALUE && r == 2 }, - { x, r -> x > Char.MIN_VALUE && x < Char.MAX_VALUE && r == 4 }, - coverage = atLeast(75) - ) - } - - @Test - fun testIntBorder() { - check( - TypeBorders::intBorder, - eq(3), - { x, r -> x == Int.MIN_VALUE && r == 3 }, - { x, r -> x == Int.MAX_VALUE && r == 2 }, - { x, r -> x > Int.MIN_VALUE && x < Int.MAX_VALUE && r == 4 }, - coverage = atLeast(75) - ) - } - - @Test - fun testLongBorder() { - check( - TypeBorders::longBorder, - eq(3), - { x, r -> x == Long.MIN_VALUE && r == 3 }, - { x, r -> x == Long.MAX_VALUE && r == 2 }, - { x, r -> x > Long.MIN_VALUE && x < Long.MAX_VALUE && r == 4 }, - coverage = atLeast(75) - ) - } - - @Test - fun testUnreachableByteValue() { - check( - TypeBorders::unreachableByteValue, - eq(1), // should generate one branch with legal byte value - { x, r -> r == 0 && x < 200 }, - coverage = atLeast(50) - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/types/TypeMatchesTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/types/TypeMatchesTest.kt deleted file mode 100644 index 4a3f8d3c76..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/types/TypeMatchesTest.kt +++ /dev/null @@ -1,60 +0,0 @@ -package org.utbot.examples.types - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker - -@Suppress("SimplifyNegatedBinaryExpression") -internal class TypeMatchesTest : UtValueTestCaseChecker(testClass = TypeMatches::class) { - @Test - fun testCompareDoubleByte() { - check( - TypeMatches::compareDoubleByte, - eq(2), - { a, b, r -> a < b && r == 0.0 }, - { a, b, r -> !(a < b) && r == 1.0 } - ) - } - - @Test - fun testCompareShortLong() { - check( - TypeMatches::compareShortLong, - eq(2), - { a, b, r -> a < b && r == 0.toShort() }, - { a, b, r -> a >= b && r == 1.toShort() } - ) - } - - @Test - fun testCompareFloatDouble() { - check( - TypeMatches::compareFloatDouble, - eq(2), - { a, b, r -> a < b && r == 0.0f }, - { a, b, r -> !(a < b) && r == 1.0f } - ) - } - - @Test - fun testSumByteAndShort() { - check( - TypeMatches::sumByteAndShort, - eq(3), - { a, b, r -> a + b > Short.MAX_VALUE && r == 1 }, - { a, b, r -> a + b < Short.MIN_VALUE && r == 2 }, - { a, b, r -> a + b in Short.MIN_VALUE..Short.MAX_VALUE && r == 3 }, - ) - } - - @Test - fun testSumShortAndChar() { - check( - TypeMatches::sumShortAndChar, - eq(3), - { a, b, r -> a + b.toInt() > Char.MAX_VALUE.toInt() && r == 1 }, - { a, b, r -> a + b.toInt() < Char.MIN_VALUE.toInt() && r == 2 }, - { a, b, r -> a + b.toInt() in Char.MIN_VALUE.toInt()..Char.MAX_VALUE.toInt() && r == 3 }, - ) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt deleted file mode 100644 index 03d29c8eab..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/unsafe/UnsafeOperationsTest.kt +++ /dev/null @@ -1,39 +0,0 @@ -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.withoutSandbox -import org.utbot.testing.DoNotCalculate -import org.utbot.testing.UtValueTestCaseChecker - -internal class UnsafeOperationsTest : UtValueTestCaseChecker(testClass = UnsafeOperations::class) { - @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 - ) - } - } - - @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 - ) - } - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/unsafe/UnsafeWithFieldTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/unsafe/UnsafeWithFieldTest.kt deleted file mode 100644 index 4b486a3d23..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/unsafe/UnsafeWithFieldTest.kt +++ /dev/null @@ -1,18 +0,0 @@ -package org.utbot.examples.unsafe - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq -import org.utbot.testing.UtValueTestCaseChecker - -internal class UnsafeWithFieldTest: UtValueTestCaseChecker(UnsafeWithField::class) { - - @Test - fun checkSetField() { - check( - UnsafeWithField::setField, - eq(1) - // TODO JIRA:1579 - // for now we might have any value as a result, so there is no need in the matcher - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/BooleanWrapperTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/BooleanWrapperTest.kt deleted file mode 100644 index aa874a5f3e..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/BooleanWrapperTest.kt +++ /dev/null @@ -1,40 +0,0 @@ -package org.utbot.examples.wrappers - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class BooleanWrapperTest : UtValueTestCaseChecker(testClass = BooleanWrapper::class) { - @Test - fun primitiveToWrapperTest() { - check( - BooleanWrapper::primitiveToWrapper, - eq(2), - { x, r -> x && r == true }, - { x, r -> !x && r == true }, - coverage = DoNotCalculate - ) - } - - @Test - fun wrapperToPrimitiveTest() { - check( - BooleanWrapper::wrapperToPrimitive, - eq(3), - { x, _ -> x == null }, - { x, r -> x && r == true }, - { x, r -> !x && r == true }, - coverage = DoNotCalculate - ) - } - - @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 - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/ByteWrapperTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/ByteWrapperTest.kt deleted file mode 100644 index 51241e7880..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/ByteWrapperTest.kt +++ /dev/null @@ -1,40 +0,0 @@ -package org.utbot.examples.wrappers - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class ByteWrapperTest : UtValueTestCaseChecker(testClass = ByteWrapper::class) { - @Test - fun primitiveToWrapperTest() { - check( - ByteWrapper::primitiveToWrapper, - eq(2), - { x, r -> x >= 0 && r!! <= 0 }, - { x, r -> x < 0 && r!! < 0 }, - coverage = DoNotCalculate - ) - } - - @Test - fun wrapperToPrimitiveTest() { - check( - ByteWrapper::wrapperToPrimitive, - eq(3), - { x, _ -> x == null }, - { x, r -> x >= 0 && r!! <= 0 }, - { x, r -> x < 0 && r!! < 0 }, - coverage = DoNotCalculate - ) - } - - @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 - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/CharacterWrapperTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/CharacterWrapperTest.kt deleted file mode 100644 index bce33bb2f5..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/CharacterWrapperTest.kt +++ /dev/null @@ -1,50 +0,0 @@ -package org.utbot.examples.wrappers - -import org.utbot.framework.plugin.api.CodegenLanguage -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -// TODO failed Kotlin compilation -internal class CharacterWrapperTest : UtValueTestCaseChecker( - testClass = CharacterWrapper::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun primitiveToWrapperTest() { - check( - CharacterWrapper::primitiveToWrapper, - eq(2), - { x, r -> x.toInt() >= 100 && r!!.toInt() >= 100 }, - { x, r -> x.toInt() < 100 && r!!.toInt() == x.toInt() + 100 }, - ) - } - - @Test - fun wrapperToPrimitiveTest() { - check( - CharacterWrapper::wrapperToPrimitive, - eq(3), - { x, _ -> x == null }, - { x, r -> x.toInt() >= 100 && r!!.toInt() >= 100 }, - { x, r -> x.toInt() < 100 && r!!.toInt() == x.toInt() + 100 }, - ) - } - - @Disabled("Caching char values between -128 and 127 isn't supported JIRA:1481") - @Test - fun equalityTest() { - check( - CharacterWrapper::equality, - eq(3), - { a, b, result -> a == b && a.toInt() <= 127 && result == 1 }, - { a, b, result -> a == b && a.toInt() > 127 && result == 2 }, - { a, b, result -> a != b && result == 4 }, - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/DoubleWrapperTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/DoubleWrapperTest.kt deleted file mode 100644 index 049fba0fa5..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/DoubleWrapperTest.kt +++ /dev/null @@ -1,30 +0,0 @@ -package org.utbot.examples.wrappers - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -@Suppress("SimplifyNegatedBinaryExpression") -internal class DoubleWrapperTest : UtValueTestCaseChecker(testClass = DoubleWrapper::class) { - @Test - fun primitiveToWrapperTest() { - check( - DoubleWrapper::primitiveToWrapper, - eq(2), - { x, r -> x >= 0 && r!!.toDouble() >= 0 }, - { x, r -> (x < 0 || x.isNaN()) && (r!!.toDouble() > 0 || r.isNaN()) }, - coverage = DoNotCalculate - ) - } - - @Test - fun wrapperToPrimitiveTest() { - check( - DoubleWrapper::wrapperToPrimitive, - eq(3), - { x, _ -> x == null }, - { x, r -> x >= 0 && r!! >= 0 }, - { x, r -> (x < 0 || x.isNaN()) && (r!! > 0 || r.isNaN()) }, - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/FloatWrapperTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/FloatWrapperTest.kt deleted file mode 100644 index 2142305a1d..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/FloatWrapperTest.kt +++ /dev/null @@ -1,30 +0,0 @@ -package org.utbot.examples.wrappers - -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -@Suppress("SimplifyNegatedBinaryExpression") -internal class FloatWrapperTest : UtValueTestCaseChecker(testClass = FloatWrapper::class) { - @Test - fun primitiveToWrapperTest() { - check( - FloatWrapper::primitiveToWrapper, - eq(2), - { x, r -> x >= 0 && r!! >= 0 }, - { x, r -> (x < 0 || x.isNaN()) && (r!! > 0 || r.isNaN()) }, - coverage = DoNotCalculate - ) - } - - @Test - fun wrapperToPrimitiveTest() { - check( - FloatWrapper::wrapperToPrimitive, - eq(3), - { x, _ -> x == null }, - { x, r -> x >= 0 && r!! >= 0 }, - { x, r -> (x < 0 || x.isNaN()) && (r!! > 0 || r.isNaN()) }, - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/IntegerWrapperTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/IntegerWrapperTest.kt deleted file mode 100644 index 27c78191af..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/IntegerWrapperTest.kt +++ /dev/null @@ -1,70 +0,0 @@ -package org.utbot.examples.wrappers - -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class IntegerWrapperTest : UtValueTestCaseChecker(testClass = IntegerWrapper::class) { - @Test - fun primitiveToWrapperTest() { - check( - IntegerWrapper::primitiveToWrapper, - eq(2), - { x, r -> x >= 0 && r!! <= 0 }, - { x, r -> x < 0 && r!! < 0 }, - coverage = DoNotCalculate - ) - } - - @Test - fun wrapperToPrimitiveTest() { - check( - IntegerWrapper::wrapperToPrimitive, - eq(3), - { x, _ -> x == null }, - { x, r -> x >= 0 && r!! <= 0 }, - { x, r -> x < 0 && r!! < 0 }, - coverage = DoNotCalculate - ) - } - - @Test - fun numberOfZerosTest() { - check( - IntegerWrapper::numberOfZeros, - eq(4), - { x, _ -> x == null }, - { x, r -> Integer.numberOfLeadingZeros(x) >= 5 && r == 0 }, - { x, r -> Integer.numberOfLeadingZeros(x) < 5 && Integer.numberOfTrailingZeros(x) >= 5 && r == 0 }, - { x, r -> Integer.numberOfLeadingZeros(x) < 5 && Integer.numberOfTrailingZeros(x) < 5 && r == 1 }, - coverage = DoNotCalculate - ) - } - - @Test - fun bitCountTest() { - check( - IntegerWrapper::bitCount, - eq(3), - { x, _ -> x == null }, - { x, r -> Integer.bitCount(x) != 5 && r == 0 }, - { x, r -> Integer.bitCount(x) == 5 && r == 1 }, - coverage = DoNotCalculate - ) - } - - - @Disabled("Caching integer values between -128 and 127 isn't supported JIRA:1481") - @Test - fun equalityTest() { - check( - IntegerWrapper::equality, - eq(3), - { a, b, result -> a == b && a >= -128 && a <= 127 && result == 1 }, - { a, b, result -> a == b && (a < -128 || a > 127) && result == 2 }, - { a, b, result -> a != b && result == 4 }, - coverage = DoNotCalculate - ) - } - -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/LongWrapperTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/LongWrapperTest.kt deleted file mode 100644 index 78ead57ad4..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/LongWrapperTest.kt +++ /dev/null @@ -1,69 +0,0 @@ -package org.utbot.examples.wrappers - -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.withoutMinimization - -internal class LongWrapperTest : UtValueTestCaseChecker( - testClass = LongWrapper::class, - testCodeGeneration = true, - pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA), - TestLastStage(CodegenLanguage.KOTLIN, CodeGeneration) - ) -) { - @Test - fun primitiveToWrapperTest() { - check( - LongWrapper::primitiveToWrapper, - eq(2), - { x, r -> x >= 0 && r!! <= 0 }, - { x, r -> x < 0 && r!! < 0 }, - coverage = DoNotCalculate - ) - } - - @Test - fun wrapperToPrimitiveTest() { - check( - LongWrapper::wrapperToPrimitive, - eq(3), - { x, _ -> x == null }, - { x, r -> x >= 0 && r!! <= 0 }, - { x, r -> x < 0 && r!! < 0 }, - coverage = DoNotCalculate - ) - } - - @Disabled("Caching long values between -128 and 127 doesn't work JIRA:1481") - @Test - fun equalityTest() { - check( - LongWrapper::equality, - eq(3), - { a, b, result -> a == b && a >= -128 && a <= 127 && result == 1 }, - { a, b, result -> a == b && (a < -128 || a > 127) && result == 2 }, - { a, b, result -> a != b && result == 4 }, - coverage = DoNotCalculate - ) - } - - @Test - fun parseLong() { - withoutMinimization { // TODO: JIRA:1506. These branches will be minimized. - check( - LongWrapper::parseLong, - eq(6), - { line, _ -> line == null }, - { line, _ -> line.isEmpty() }, - { line, _ -> line == "-" }, - { line, _ -> line == "+" }, - { line, _ -> line.startsWith("-") }, - { line, _ -> !line.startsWith("-") }, - coverage = DoNotCalculate - ) - } - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/ShortWrapperTest.kt b/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/ShortWrapperTest.kt deleted file mode 100644 index 9e8281ddfe..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/examples/wrappers/ShortWrapperTest.kt +++ /dev/null @@ -1,43 +0,0 @@ -package org.utbot.examples.wrappers - -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.testcheckers.eq - -internal class ShortWrapperTest : UtValueTestCaseChecker(testClass = ShortWrapper::class) { - @Test - fun primitiveToWrapperTest() { - check( - ShortWrapper::primitiveToWrapper, - eq(2), - { x, r -> x >= 0 && r!! <= 0 }, - { x, r -> x < 0 && r!! < 0 }, - coverage = DoNotCalculate - ) - } - - @Test - fun wrapperToPrimitiveTest() { - check( - ShortWrapper::wrapperToPrimitive, - eq(3), - { x, _ -> x == null }, - { x, r -> x >= 0 && r!! <= 0 }, - { x, r -> x < 0 && r!! < 0 }, - coverage = DoNotCalculate - ) - } - - @Disabled("Caching short values between -128 and 127 isn't supported JIRA:1481") - @Test - fun equalityTest() { - check( - ShortWrapper::equality, - eq(3), - { a, b, result -> a == b && a >= -128 && a <= 127 && result == 1 }, - { a, b, result -> a == b && (a < -128 || a > 127) && result == 2 }, - { a, b, result -> a != b && result == 4 }, - coverage = DoNotCalculate - ) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/JUnitSetup.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/JUnitSetup.kt deleted file mode 100644 index 19a91f0e50..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/framework/JUnitSetup.kt +++ /dev/null @@ -1,38 +0,0 @@ -package org.utbot.framework - -import org.apache.logging.log4j.Level -import org.apache.logging.log4j.LogManager -import org.apache.logging.log4j.core.LogEvent -import org.apache.logging.log4j.core.Logger -import org.apache.logging.log4j.core.appender.AbstractAppender -import org.apache.logging.log4j.core.appender.AppenderLoggingException -import org.junit.jupiter.api.extension.AfterAllCallback -import org.junit.jupiter.api.extension.BeforeAllCallback -import org.junit.jupiter.api.extension.ExtensionContext - -class JUnitSetup : BeforeAllCallback, AfterAllCallback { - - private var appender: ThrowingAppender? = null - private val rootLogger = LogManager.getRootLogger() as Logger - - override fun beforeAll(context: ExtensionContext?) { - appender = ThrowingAppender().apply { start() } - rootLogger.addAppender(appender) - } - - override fun afterAll(context: ExtensionContext?) { - appender?.let { - it.stop() - rootLogger.removeAppender(it) - appender = null - } - } - -} - -class ThrowingAppender : AbstractAppender(ThrowingAppender::class.simpleName, null, null, false, null) { - override fun append(event: LogEvent) { - if (event.level.isMoreSpecificThan(Level.ERROR)) - throw event.thrown ?: AppenderLoggingException(event.message.formattedMessage) - } -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt deleted file mode 100644 index 7a252bb33e..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt +++ /dev/null @@ -1,1503 +0,0 @@ -package org.utbot.framework.assemble - -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.examples.assemble.AssembleTestUtils -import org.utbot.examples.assemble.ComplexField -import org.utbot.examples.assemble.DirectAccess -import org.utbot.examples.assemble.DirectAccessAndSetter -import org.utbot.examples.assemble.DirectAccessFinal -import org.utbot.examples.assemble.InheritedField -import org.utbot.examples.assemble.ListItem -import org.utbot.examples.assemble.NoModifier -import org.utbot.examples.assemble.PackagePrivateFields -import org.utbot.examples.assemble.PrimitiveFields -import org.utbot.examples.assemble.ArrayOfComplexArrays -import org.utbot.examples.assemble.ArrayOfPrimitiveArrays -import org.utbot.examples.assemble.AssignedArray -import org.utbot.examples.assemble.ComplexArray -import org.utbot.examples.assemble.another.MethodUnderTest -import org.utbot.examples.assemble.PrimitiveArray -import org.utbot.examples.assemble.ComplexConstructor -import org.utbot.examples.assemble.ComplexConstructorWithSetter -import org.utbot.examples.assemble.ConstructorModifyingStatic -import org.utbot.examples.assemble.InheritComplexConstructor -import org.utbot.examples.assemble.InheritPrimitiveConstructor -import org.utbot.examples.assemble.PrimitiveConstructor -import org.utbot.examples.assemble.PrimitiveConstructorWithDefaultField -import org.utbot.examples.assemble.PrivateConstructor -import org.utbot.examples.assemble.PseudoComplexConstructor -import org.utbot.examples.assemble.DefaultField -import org.utbot.examples.assemble.DefaultFieldModifiedInConstructor -import org.utbot.examples.assemble.DefaultFieldWithDirectAccessor -import org.utbot.examples.assemble.DefaultFieldWithSetter -import org.utbot.examples.assemble.DefaultPackagePrivateField -import org.utbot.examples.assemble.StaticField -import org.utbot.framework.plugin.api.ClassId -import org.utbot.framework.plugin.api.ExecutableId -import org.utbot.framework.plugin.api.FieldId -import org.utbot.framework.plugin.api.MethodId -import org.utbot.framework.plugin.api.UtArrayModel -import org.utbot.framework.plugin.api.UtAssembleModel -import org.utbot.framework.plugin.api.UtCompositeModel -import org.utbot.framework.plugin.api.UtModel -import org.utbot.framework.plugin.api.UtNullModel -import org.utbot.framework.plugin.api.UtPrimitiveModel -import org.utbot.framework.plugin.api.util.UtContext -import org.utbot.framework.plugin.api.util.UtContext.Companion.setUtContext -import org.utbot.framework.plugin.api.util.executableId -import org.utbot.framework.plugin.api.util.id -import org.utbot.framework.plugin.api.util.intArrayClassId -import org.utbot.framework.plugin.api.util.intClassId -import org.utbot.framework.plugin.services.JdkInfoDefaultProvider -import org.utbot.framework.util.SootUtils -import org.utbot.framework.util.instanceCounter -import org.utbot.framework.util.modelIdCounter -import kotlin.reflect.full.functions -import org.utbot.framework.codegen.model.constructor.util.arrayTypeOf - -/** - * Test classes must be located in the same folder as [AssembleTestUtils] class. - */ -class AssembleModelGeneratorTests { - - private lateinit var context: AutoCloseable - private lateinit var statementsChain: MutableList - - @BeforeEach - fun setUp() { - instanceCounter.set(0) - modelIdCounter.set(0) - statementsChain = mutableListOf() - SootUtils.runSoot(AssembleTestUtils::class.java, forceReload = false, jdkInfo = JdkInfoDefaultProvider().info) - context = setUtContext(UtContext(AssembleTestUtils::class.java.classLoader)) - } - - @AfterEach - fun tearDown() { - context.close() - } - - @Test - fun testOnObjectWithPrimitiveFields() { - val testClassId = PrimitiveFields::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "a" to 5, "b" to 3) - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("a", 5)) - statementsChain.add("$v1." + ("b" `=` 3)) - - val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithDefaultFields() { - val testClassId = PrimitiveFields::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "a" to 5, "b" to 0) - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("a", 5)) - - val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithPackagePrivateFields() { - val testClassId = PackagePrivateFields::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "a" to 5, "b" to 3) - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + ("a" `=` 5)) - statementsChain.add("$v1." + ("b" `=` 3)) - - val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithPackagePrivateFieldsFromAnotherPackage() { - val testClassId = PackagePrivateFields::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "a" to 5, "b" to 3) - ) - - val methodFromAnotherPackage = MethodUnderTest::class.functions.first() - - createModelAndAssert(compositeModel, null, methodFromAnotherPackage.executableId) - } - - @Test - fun testOnObjectWithComplexFields() { - val testClassId = ComplexField::class.id - val innerClassId = PrimitiveFields::class.id - - val innerCompositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - innerClassId, - isMock = false, - fields(innerClassId, "a" to 2, "b" to 4) - ) - - val complexObjectFields = fields( - testClassId, - "i" to 5, - "s" to innerCompositeModel, - ) - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), testClassId, isMock = false, complexObjectFields - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("i", 5)) - val v2 = createExpectedVariableName() - statementsChain.add("$v1." + addExpectedSetter("s", v2)) - val firstExpectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain.toList()) - - statementsChain.clear() - statementsChain.add("${innerClassId.canonicalName}()") - statementsChain.add("$v2." + addExpectedSetter("a", 2)) - statementsChain.add("$v2." + ("b" `=` 4)) - val secondExpectedRepresentation = printExpectedModel(innerClassId.simpleName, v2, statementsChain.toList()) - - createModelsAndAssert( - listOf(compositeModel, innerCompositeModel), - listOf(firstExpectedRepresentation, secondExpectedRepresentation), - ) - } - - @Test - fun testOnObjectWithComplexDefaultFields() { - val testClassId = ComplexField::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "i" to 5), - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("i", 5)) - - val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnListObject() { - val listClassId = ListItem::class.id - - val secondModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - listClassId, - isMock = false, - fields(listClassId, "value" to 2, "next" to UtNullModel(listClassId)) - ) - - val firstModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - listClassId, - isMock = false, - fields(listClassId, "value" to 1, "next" to secondModel) - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("value", 1)) - val v2 = createExpectedVariableName() - statementsChain.add("$v1." + addExpectedSetter("next", v2)) - val firstExpectedRepresentation = printExpectedModel(listClassId.simpleName, v1, statementsChain.toList()) - - statementsChain.clear() - statementsChain.add("${listClassId.canonicalName}()") - statementsChain.add("$v2." + addExpectedSetter("value", 2)) - val secondExpectedRepresentation = printExpectedModel(listClassId.simpleName, v2, statementsChain.toList()) - - createModelsAndAssert( - listOf(firstModel, secondModel), - listOf(firstExpectedRepresentation, secondExpectedRepresentation), - ) - } - - @Test - fun testOnObjectsTriangle() { - val listClassId = ListItem::class.id - - val firstModel = UtCompositeModel(modelIdCounter.incrementAndGet(), listClassId, isMock = false) - val secondModel = UtCompositeModel(modelIdCounter.incrementAndGet(), listClassId, isMock = false) - val thirdModel = UtCompositeModel(modelIdCounter.incrementAndGet(), listClassId, isMock = false) - - firstModel.fields += fields(listClassId, "value" to 1, "next" to secondModel) - secondModel.fields += fields(listClassId, "value" to 2, "next" to thirdModel) - thirdModel.fields += fields(listClassId, "value" to 3, "next" to firstModel) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("value", 1)) - val v2 = createExpectedVariableName() - val v3 = createExpectedVariableName() - statementsChain.add("$v1." + addExpectedSetter("next", v2)) - val firstExpectedRepresentation = printExpectedModel(listClassId.simpleName, v1, statementsChain.toList()) - - statementsChain.clear() - statementsChain.add("${listClassId.canonicalName}()") - statementsChain.add("$v2." + addExpectedSetter("value", 2)) - statementsChain.add("$v2." + addExpectedSetter("next", v3)) - val secondExpectedRepresentation = printExpectedModel(listClassId.simpleName, v2, statementsChain.toList()) - - statementsChain.clear() - statementsChain.add("${listClassId.canonicalName}()") - statementsChain.add("$v3." + addExpectedSetter("value", 3)) - statementsChain.add("$v3." + addExpectedSetter("next", v1)) - val thirdExpectedRepresentation = printExpectedModel(listClassId.simpleName, v3, statementsChain.toList()) - - createModelsAndAssert( - listOf(firstModel, secondModel, thirdModel), - listOf(firstExpectedRepresentation, secondExpectedRepresentation, thirdExpectedRepresentation), - ) - } - - @Test - fun testOnObjectWithPublicFields() { - val testClassId = DirectAccess::class.id - val innerClassId = PrimitiveFields::class.id - - val primitiveFields = fields(innerClassId, "a" to 2, "b" to 4) - - val fields = fields( - testClassId, - "a" to 5, - "b" to 3, - "s" to UtCompositeModel( - modelIdCounter.incrementAndGet(), - innerClassId, - isMock = false, - primitiveFields - ), - ) - val compositeModel = UtCompositeModel(modelIdCounter.incrementAndGet(), testClassId, isMock = false, fields) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("a", 5)) - statementsChain.add("$v1." + ("b" `=` 3)) - val v2 = createExpectedVariableName() - statementsChain.add("$v1." + ("s" `=` v2)) - - val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithPublicFieldAndSetter() { - val testClassId = DirectAccessAndSetter::class.id - val innerClassId = PrimitiveFields::class.id - - val primitiveFields = fields(innerClassId, "a" to 2, "b" to 4) - - val fields = fields( - testClassId, - "a" to 3, - "p" to UtCompositeModel( - modelIdCounter.incrementAndGet(), - innerClassId, - isMock = false, - primitiveFields - ), - ) - val compositeModel = UtCompositeModel(modelIdCounter.incrementAndGet(), testClassId, isMock = false, fields) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + ("a" `=` 3)) - val v2 = createExpectedVariableName() - statementsChain.add("$v1." + ("p" `=` v2)) - - val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithFinalFields() { - val testClassId = DirectAccessFinal::class.id - - val arrayObjectFields = fields( - testClassId, - "array" to UtArrayModel( - modelIdCounter.incrementAndGet(), - intArrayClassId, - length = 2, - UtPrimitiveModel(0), - mutableMapOf(0 to UtPrimitiveModel(1), 1 to UtPrimitiveModel(2)), - ), - ) - val compositeModel = - UtCompositeModel(modelIdCounter.incrementAndGet(), testClassId, isMock = false, arrayObjectFields) - - createModelAndAssert(compositeModel, null) - } - - //region inheritance_tests - - @Test - fun testOnInheritedObjectWithoutBaseFields() { - val testClassId = InheritedField::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "i" to 5, "d" to 3.0) - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + ("i" `=` 5)) - statementsChain.add("$v1." + ("d" `=` 3.0)) - - val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnInheritedObjectWithDefaultBaseFields() { - val inheritedFieldClassId = InheritedField::class.id - val baseClassId = PrimitiveFields::class.id - - val thisFields = fields(inheritedFieldClassId, "i" to 5, "d" to 3.0) - val baseFields = fields(baseClassId, "a" to 0, "b" to 0) - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - inheritedFieldClassId, - isMock = false, - (thisFields + baseFields).toMutableMap(), - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + ("i" `=` 5)) - statementsChain.add("$v1." + ("d" `=` 3.0)) - - val expectedRepresentation = printExpectedModel(inheritedFieldClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnInheritedObjectWithBaseFields() { - val inheritedFieldClassId = InheritedField::class.id - val baseClassId = PrimitiveFields::class.id - - val thisFields = fields(inheritedFieldClassId, "i" to 5, "d" to 3.0) - val baseFields = fields(baseClassId, "b" to 4) - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - inheritedFieldClassId, - isMock = false, - (thisFields + baseFields).toMutableMap(), - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + ("i" `=` 5)) - statementsChain.add("$v1." + ("d" `=` 3.0)) - statementsChain.add("$v1." + ("b" `=` 4)) - - val expectedRepresentation = printExpectedModel(inheritedFieldClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - //endregion - - @Test - fun testOnObjectWithoutSetter() { - val modelClassId = NoModifier::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - modelClassId, - isMock = false, - fields(modelClassId, "a" to 5), - ) - - createModelAndAssert(compositeModel, null) - } - - @Test - fun testOnObjectWithPrimitiveConstructor() { - val modelClassId = PrimitiveConstructor::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - modelClassId, - isMock = false, - fields(modelClassId, "a" to 5, "b" to 3), - ) - - val v1 = statementsChain.addExpectedVariableDecl(5, 3) - - val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithSimpleConstructorAndDefaultField() { - val modelClassId = PrimitiveConstructor::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - modelClassId, - isMock = false, - fields(modelClassId, "a" to 5, "b" to 0), - ) - - val v1 = statementsChain.addExpectedVariableDecl(5, 0) - - val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithPrimitiveConstructorAndStaticFieldNotInModel() { - val modelClassId = StaticField::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - modelClassId, - isMock = false, - fields(modelClassId, "a" to 5, "b" to 3), - ) - - val v1 = statementsChain.addExpectedVariableDecl(5,3) - - val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithPrimitiveConstructorAndStaticFieldInModel() { - val modelClassId = StaticField::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - modelClassId, - isMock = false, - fields(modelClassId, "a" to 5, "b" to 3, "staticField" to 4), - ) - - createModelAndAssert(compositeModel, null) - } - - @Test - fun testOnObjectWithInheritedPrimitiveConstructor() { - val inheritedClassId = InheritPrimitiveConstructor::class.id - val baseClassId = PrimitiveConstructor::class.id - - val thisFields = fields(inheritedClassId, "c" to 1, "d" to 2.0) - val baseFields = fields(baseClassId, "a" to 3, "b" to 4) - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - inheritedClassId, - isMock = false, - (thisFields + baseFields).toMutableMap(), - ) - - val v1 = statementsChain.addExpectedVariableDecl(4, 3, 1, 2.0) - - val expectedRepresentation = printExpectedModel(inheritedClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithInheritedComplexConstructor() { - val inheritedClassId = InheritComplexConstructor::class.id - val baseClassId = ComplexConstructor::class.id - - val thisFields = fields(inheritedClassId, "c" to 1, "d" to 2.0) - val baseFields = fields(baseClassId, "a" to 3, "b" to 4) - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - inheritedClassId, - isMock = false, - (thisFields + baseFields).toMutableMap(), - ) - - createModelAndAssert(compositeModel, null) - } - - @Test - fun testOnObjectWithDefaultConstructorModifyingField() { - val modelClassId = DefaultField::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - modelClassId, - isMock = false, - fields(modelClassId, "z" to 5), - ) - - createModelAndAssert(compositeModel, null) - } - - @Test - fun testOnObjectWithDefaultConstructorModifyingPackagePrivateField() { - val modelClassId = DefaultPackagePrivateField::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - modelClassId, - isMock = false, - fields(modelClassId, "z" to 0), - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + ("z" `=` 0)) - - val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithConstructorModifyingAffectedField() { - val modelClassId = DefaultFieldModifiedInConstructor::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - modelClassId, - isMock = false, - fields(modelClassId, "z" to 5), - ) - - val v1 = statementsChain.addExpectedVariableDecl(5) - statementsChain.add("$v1." + ("z" `=` 5)) - - val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithPublicFieldModifiedByDefaultConstructor() { - val modelClassId = DefaultFieldWithDirectAccessor::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - modelClassId, - isMock = false, - fields(modelClassId, "z" to 5), - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + ("z" `=` 5)) - - val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithFieldWithSetterModifiedByDefaultConstructor() { - val modelClassId = DefaultFieldWithSetter::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - modelClassId, - isMock = false, - fields(modelClassId, "z" to 5), - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("z", 5)) - - val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithFieldWithPrivateSetterModifiedByDefaultConstructor() { - val modelClassId = PrivateConstructor::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - modelClassId, - isMock = false, - fields(modelClassId, "z" to 5), - ) - - val expectedRepresentation = null - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithPrimitiveConstructorModifyingStaticField() { - val modelClassId = ConstructorModifyingStatic::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - modelClassId, - isMock = false, - fields(modelClassId, "x" to 5), - ) - - createModelAndAssert(compositeModel, null) - } - - @Test - fun testOnObjectWithComplexConstructor() { - val modelClassId = ComplexConstructor::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - modelClassId, - isMock = false, - fields(modelClassId, "a" to 5, "b" to 3), - ) - - createModelAndAssert(compositeModel, null) - } - - @Test - fun testOnObjectWithComplexConstructorAndSetter() { - val modelClassId = ComplexConstructorWithSetter::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - modelClassId, - isMock = false, - fields(modelClassId, "a" to 5, "b" to 3), - ) - - val v1 = statementsChain.addExpectedVariableDecl(5, 0) - statementsChain.add("$v1." + addExpectedSetter("b", 3)) - - val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithPseudoComplexConstructor() { - val modelClassId = PseudoComplexConstructor::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - modelClassId, - isMock = false, - fields(modelClassId, "a" to 5), - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + ("a" `=` 5)) - - val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithPrimitiveConstructorHavingDefaultField() { - val modelClassId = PrimitiveConstructorWithDefaultField::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - modelClassId, - isMock = false, - fields(modelClassId, "a" to 5, "b" to 3), - ) - - createModelAndAssert(compositeModel, null) - } - - @Test - fun testOnObjectWithPrimitiveConstructorHavingDefaultFieldNotInModel() { - val modelClassId = PrimitiveConstructorWithDefaultField::class.id - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - modelClassId, - isMock = false, - fields(modelClassId, "a" to 5), - ) - - val v1 = statementsChain.addExpectedVariableDecl(5) - val expectedRepresentation = printExpectedModel(modelClassId.simpleName, v1, statementsChain) - - createModelAndAssert(compositeModel, expectedRepresentation) - } - - //region coupling_models_tests - - @Test - fun testOnTwoDecoupledPrimitiveObjects() { - val testClassId = PrimitiveFields::class.id - - val firstModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "a" to 5, "b" to 3), - ) - val secondModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "a" to 4, "b" to 2), - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("a", 5)) - statementsChain.add("$v1." + ("b" `=` 3)) - val firstExpectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain.toList()) - - statementsChain.clear() - val v2 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v2." + addExpectedSetter("a", 4)) - statementsChain.add("$v2." + ("b" `=` 2)) - val secondExpectedRepresentation = printExpectedModel(testClassId.simpleName, v2, statementsChain.toList()) - - createModelsAndAssert( - listOf(firstModel, secondModel), - listOf(firstExpectedRepresentation, secondExpectedRepresentation) - ) - } - - @Test - fun testOnTwoDecoupledComplexObjects() { - val testClassId = ComplexField::class.id - val innerClassId = PrimitiveFields::class.id - - val firstSimpleObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - innerClassId, - isMock = false, - fields(innerClassId, "a" to 2, "b" to 4), - ) - val secondSimpleObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - innerClassId, - isMock = false, - fields(innerClassId, "a" to 3, "b" to 5), - ) - - val firstComplexObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "i" to 5, "s" to firstSimpleObjectModel), - ) - val secondComplexObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "i" to 6, "s" to secondSimpleObjectModel), - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("i", 5)) - val v2 = createExpectedVariableName() - statementsChain.add( - "$v1." + addExpectedSetter("s", v2) - ) - val firstExpectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain.toList()) - - statementsChain.clear() - val v3 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v3." + addExpectedSetter("i", 6)) - val v4 = createExpectedVariableName() - statementsChain.add("$v3." + addExpectedSetter("s", v4)) - val secondExpectedRepresentation = printExpectedModel(testClassId.simpleName, v3, statementsChain.toList()) - - createModelsAndAssert( - listOf(firstComplexObjectModel, secondComplexObjectModel), - listOf(firstExpectedRepresentation, secondExpectedRepresentation) - ) - } - - @Test - fun testOnTwoCoupledComplexObjects() { - val testClassId = ComplexField::class.id - val innerClassId = PrimitiveFields::class.id - - val primitiveObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - innerClassId, - isMock = false, - fields(innerClassId, "a" to 2, "b" to 4), - ) - - val firstComplexObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "i" to 5, "s" to primitiveObjectModel), - ) - val secondComplexObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "i" to 6, "s" to primitiveObjectModel), - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("i", 5)) - val v2 = createExpectedVariableName() - statementsChain.add( - "$v1." + addExpectedSetter("s", v2) - ) - val firstExpectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain.toList()) - - statementsChain.clear() - val v3 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v3." + addExpectedSetter("i", 6)) - statementsChain.add("$v3." + addExpectedSetter("s", v2)) - val secondExpectedRepresentation = printExpectedModel(testClassId.simpleName, v3, statementsChain.toList()) - - createModelsAndAssert( - listOf(firstComplexObjectModel, secondComplexObjectModel), - listOf(firstExpectedRepresentation, secondExpectedRepresentation) - ) - } - - @Test - fun testOnThreeCoupledComplexObjects() { - val testClassId = ComplexField::class.id - val innerClassId = PrimitiveFields::class.id - - val primitiveObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - innerClassId, - isMock = false, - fields(innerClassId, "a" to 2, "b" to 4), - ) - - val firstComplexObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "i" to 1, "s" to primitiveObjectModel), - ) - val secondComplexObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "i" to 2, "s" to primitiveObjectModel), - ) - val thirdComplexObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "i" to 3, "s" to primitiveObjectModel), - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("i", 1)) - val v2 = createExpectedVariableName() - statementsChain.add("$v1." + addExpectedSetter("s", v2)) - val firstExpectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain.toList()) - - statementsChain.clear() - val v3 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v3." + addExpectedSetter("i", 2)) - statementsChain.add("$v3." + addExpectedSetter("s", v2)) - val secondExpectedRepresentation = printExpectedModel(testClassId.simpleName, v3, statementsChain.toList()) - - statementsChain.clear() - val v4 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v4." + addExpectedSetter("i", 3)) - statementsChain.add("$v4." + addExpectedSetter("s", v2)) - val thirdExpectedRepresentation = printExpectedModel(testClassId.simpleName, v4, statementsChain.toList()) - - createModelsAndAssert( - listOf(firstComplexObjectModel, secondComplexObjectModel, thirdComplexObjectModel), - listOf(firstExpectedRepresentation, secondExpectedRepresentation, thirdExpectedRepresentation) - ) - } - - @Test - fun testOnTwoEqualComplexObjects() { - val testClassId = ComplexField::class.id - val innerClassId = PrimitiveFields::class.id - - val primitiveObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - innerClassId, - isMock = false, - fields(innerClassId, "a" to 2, "b" to 4), - ) - - val complexObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "i" to 5, "s" to primitiveObjectModel), - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("i", 5)) - val v2 = createExpectedVariableName() - statementsChain.add("$v1." + addExpectedSetter("s", v2)) - - val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) - createModelsAndAssert(listOf(complexObjectModel, complexObjectModel), listOf(expectedRepresentation)) - } - - @Test - fun testOnTwoCoupledListObjects() { - val listClassId = ListItem::class.id - - val secondModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - listClassId, - isMock = false, - fields(listClassId, "value" to 2, "next" to UtNullModel(listClassId)), - ) - - val firstModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - listClassId, - isMock = false, - fields(listClassId, "value" to 1, "next" to secondModel), - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("value", 1)) - val v2 = createExpectedVariableName() - statementsChain.add("$v1." + addExpectedSetter("next", v2)) - val firstExpectedRepresentation = printExpectedModel(listClassId.simpleName, v1, statementsChain.toList()) - - statementsChain.clear() - statementsChain.add("${listClassId.canonicalName}()") - statementsChain.add("$v2." + addExpectedSetter("value", 2)) - val secondExpectedRepresentation = printExpectedModel(listClassId.simpleName, v2, statementsChain.toList()) - - createModelsAndAssert( - listOf(firstModel, secondModel), - listOf(firstExpectedRepresentation, secondExpectedRepresentation) - ) - } - - @Test - fun testOnTwoCrossCoupledListObjects() { - val listClassId = ListItem::class.id - - val firstModel = UtCompositeModel(modelIdCounter.incrementAndGet(), listClassId, isMock = false) - val secondModel = UtCompositeModel(modelIdCounter.incrementAndGet(), listClassId, isMock = false) - - firstModel.fields += fields(listClassId, "value" to 1, "next" to secondModel) - secondModel.fields += fields(listClassId, "value" to 2, "next" to firstModel) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("value", 1)) - val v2 = createExpectedVariableName() - statementsChain.add("$v1." + addExpectedSetter("next", v2)) - - val firstExpectedRepresentation = printExpectedModel(listClassId.simpleName, v1, statementsChain.toList()) - - statementsChain.clear() - statementsChain.add("${listClassId.canonicalName}()") - statementsChain.add("$v2." + addExpectedSetter("value", 2)) - statementsChain.add("$v2." + addExpectedSetter("next", v1)) - val secondExpectedRepresentation = printExpectedModel(listClassId.simpleName, v2, statementsChain) - - createModelsAndAssert( - listOf(firstModel, secondModel), - listOf(firstExpectedRepresentation, secondExpectedRepresentation) - ) - } - - @Test - fun testOnPrimitiveObjectAndNonConstructableOne() { - val simpleClassId = PrimitiveFields::class.id - val nonConstructableClassId = ComplexConstructor::class.id - - val simpleModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - simpleClassId, - isMock = false, - fields(simpleClassId, "a" to 5), - ) - - val nonConstructableModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - nonConstructableClassId, - isMock = false, - fields(nonConstructableClassId, "a" to 5, "b" to 3), - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("a", 5)) - - val simpleModelRepresentation = printExpectedModel(simpleClassId.simpleName, v1, statementsChain.toList()) - - createModelsAndAssert( - listOf(simpleModel, nonConstructableModel), - listOf(simpleModelRepresentation, null) - ) - } - - //endregion - - //region array_field_tests - - @Test - fun testOnObjectWithPrimitiveArrayField() { - val testClassId = PrimitiveArray::class.id - - val arrayObjectFields = fields( - testClassId, - "array" to UtArrayModel( - modelIdCounter.incrementAndGet(), - intArrayClassId, - length = 3, - UtPrimitiveModel(0), - mutableMapOf(0 to UtPrimitiveModel(1), 1 to UtPrimitiveModel(2)), - ), - ) - val compositeModel = - UtCompositeModel(modelIdCounter.incrementAndGet(), testClassId, isMock = false, arrayObjectFields) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + ("array" `=` "[1, 2, 0]")) - - val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithAssignedArrayField() { - val testClassId = AssignedArray::class.id - - val arrayObjectFields = fields( - testClassId, - "array" to UtArrayModel( - modelIdCounter.incrementAndGet(), - intArrayClassId, - length = 3, - UtPrimitiveModel(0), - mutableMapOf(0 to UtPrimitiveModel(1), 1 to UtPrimitiveModel(2)), - ), - ) - val compositeModel = - UtCompositeModel(modelIdCounter.incrementAndGet(), testClassId, isMock = false, arrayObjectFields) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + ("array" `=` "[1, 2, 0]")) - - val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithComplexArrayField() { - val testClassId = ComplexArray::class.id - val innerClassId = PrimitiveFields::class.id - - val arrayObjectFields = fields( - testClassId, - "array" to UtArrayModel( - modelIdCounter.incrementAndGet(), - arrayTypeOf(innerClassId), - length = 3, - UtNullModel(innerClassId), - mutableMapOf( - 1 to UtCompositeModel( - modelIdCounter.incrementAndGet(), - innerClassId, - isMock = false, - fields(innerClassId, "a" to 5) - ) - ), - ), - ) - val compositeModel = - UtCompositeModel(modelIdCounter.incrementAndGet(), testClassId, isMock = false, arrayObjectFields) - - val v1 = statementsChain.addExpectedVariableDecl() - val v2 = createExpectedVariableName() - statementsChain.add( - "$v1." + ("array" `=` "[" + - "null, " + - "UtAssembleModel(${innerClassId.simpleName} $v2) ${innerClassId.canonicalName}() $v2.setA(5), " + - "null" + - "]") - ) - - val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Disabled("Ignored due to https:///unittestbot/UnitTestBot/-/merge_requests/1311") - @Test - fun testOnObjectWithArrayOfPrimitiveArrays() { - val testClassId = ArrayOfPrimitiveArrays::class.id - - val innerArrayModel = UtArrayModel( - modelIdCounter.incrementAndGet(), - intArrayClassId, - length = 2, - UtPrimitiveModel(0), - mutableMapOf(0 to UtPrimitiveModel(1)), - ) - - val arrayModel = UtArrayModel( - modelIdCounter.incrementAndGet(), - intArrayClassId, - length = 2, - innerArrayModel, - mutableMapOf(0 to innerArrayModel, 1 to innerArrayModel), - ) - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "array" to arrayModel) - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + ("array" `=` "[[1, 0], [1, 0]]")) - - val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - @Test - fun testOnObjectWithArrayOfComplexArrays() { - val testClassId = ArrayOfComplexArrays::class.id - val innerClassId = PrimitiveFields::class.id - - val innerArrayClassId = arrayTypeOf(innerClassId) - - val arrayOfArraysModel = UtArrayModel( - modelIdCounter.incrementAndGet(), - arrayTypeOf(testClassId), - length = 2, - UtNullModel(innerArrayClassId), - mutableMapOf( - 0 to UtArrayModel( - modelIdCounter.incrementAndGet(), - innerArrayClassId, - length = 2, - UtNullModel(testClassId), - mutableMapOf( - 0 to UtCompositeModel( - modelIdCounter.incrementAndGet(), - innerClassId, - isMock = false, - fields(innerClassId, "a" to 5) - ) - ) - ), - 1 to UtArrayModel( - modelIdCounter.incrementAndGet(), - innerArrayClassId, - length = 2, - UtNullModel(testClassId), - mutableMapOf( - 0 to UtCompositeModel( - modelIdCounter.incrementAndGet(), - innerClassId, - isMock = false, - fields(innerClassId, "b" to 4) - ) - ), - ) - ), - ) - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = false, - fields(testClassId, "array" to arrayOfArraysModel) - ) - - val v1 = statementsChain.addExpectedVariableDecl() - val v2 = createExpectedVariableName() - val v3 = createExpectedVariableName() - statementsChain.add( - "$v1." + ("array" `=` "[" + - "[UtAssembleModel(${innerClassId.simpleName} $v2) ${innerClassId.canonicalName}() $v2.setA(5), ${null}], " + - "[UtAssembleModel(${innerClassId.simpleName} $v3) ${innerClassId.canonicalName}() $v3.b = 4, ${null}]" + - "]") - ) - - - val expectedRepresentation = printExpectedModel(testClassId.simpleName, v1, statementsChain) - createModelAndAssert(compositeModel, expectedRepresentation) - } - - - //endregion - - //region mocks_tests - - @Test - fun testOnObjectWithPrimitiveModelInMock() { - val testClassId = ComplexField::class.id - - val executableId = MethodId(testClassId, "fake_method_name", intClassId, listOf()) - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = true, - mocks = mutableMapOf( - executableId to listOf(UtPrimitiveModel(5), UtPrimitiveModel(3)) - ) - ) - - createModelWithMockAndAssert(compositeModel, listOf(null, null)) - } - - @Test - fun testOnObjectWithCompositeModelInMock() { - val testClassId = ComplexField::class.id - val innerClassId = PrimitiveFields::class.id - - val executableId = MethodId(testClassId, "fake_method_name", innerClassId, listOf()) - - val mockObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - innerClassId, - isMock = false, - fields(innerClassId, "a" to 2, "b" to 3), - ) - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = true, - mocks = mutableMapOf(executableId to listOf(mockObjectModel)) - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("a", 2)) - statementsChain.add("$v1." + ("b" `=` 3)) - - val expectedModelRepresentation = printExpectedModel(innerClassId.simpleName, v1, statementsChain.toList()) - createModelWithMockAndAssert(compositeModel, listOf(expectedModelRepresentation)) - } - - @Test - fun testOnObjectWithCompositeModelInFieldsInMocks() { - val testClassId = ComplexField::class.id - val innerClassId = PrimitiveFields::class.id - - val executableId = MethodId(testClassId, "fake_method_name", innerClassId, listOf()) - - val mockObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - innerClassId, - isMock = false, - fields(innerClassId, "a" to 2), - ) - - val fieldObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - innerClassId, - isMock = false, - fields(innerClassId, "b" to 3), - ) - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = true, - fields = fields(testClassId, "field" to fieldObjectModel), - mocks = mutableMapOf(executableId to listOf(mockObjectModel)), - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + ("b" `=` 3)) - val firstModelRepresentation = printExpectedModel(innerClassId.simpleName, v1, statementsChain.toList()) - - statementsChain.clear() - val v2 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v2." + addExpectedSetter("a", 2)) - val secondModelRepresentation = printExpectedModel(innerClassId.simpleName, v2, statementsChain.toList()) - - createModelWithMockAndAssert( - compositeModel, - listOf(firstModelRepresentation, secondModelRepresentation) - ) - } - - @Test - fun testOnObjectWithCoupledCompositeModelsInMock() { - val testClassId = ComplexField::class.id - val mockObjectClassId = ComplexField::class.id - val innerClassId = PrimitiveFields::class.id - - val executableId = MethodId(testClassId, "fake_method_name", innerClassId, listOf()) - - val innerObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - innerClassId, - isMock = false, - fields(innerClassId, "a" to 2, "b" to 4), - ) - - val firstMockObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - mockObjectClassId, - isMock = false, - fields(mockObjectClassId, "i" to 1, "s" to innerObjectModel), - ) - - val secondMockObjectModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - mockObjectClassId, - isMock = false, - fields(mockObjectClassId, "i" to 2, "s" to innerObjectModel), - ) - - val compositeModel = UtCompositeModel( - modelIdCounter.incrementAndGet(), - testClassId, - isMock = true, - mocks = mutableMapOf(executableId to listOf(firstMockObjectModel, secondMockObjectModel)) - ) - - val v1 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v1." + addExpectedSetter("i", 1)) - val v2 = createExpectedVariableName() - statementsChain.add("$v1." + addExpectedSetter("s", v2)) - val firstExpectedRepresentation = printExpectedModel(mockObjectClassId.simpleName, v1, statementsChain.toList()) - - statementsChain.clear() - val v3 = statementsChain.addExpectedVariableDecl() - statementsChain.add("$v3." + addExpectedSetter("i", 2)) - statementsChain.add("$v3." + addExpectedSetter("s", v2)) - val secondExpectedRepresentation = - printExpectedModel(mockObjectClassId.simpleName, v3, statementsChain.toList()) - - createModelWithMockAndAssert( - compositeModel, - listOf(firstExpectedRepresentation, secondExpectedRepresentation) - ) - } - - //endregion - - /** - * Represents fields of class [classId] as [UtCompositeModel] parameter. - */ - private fun fields( - classId: ClassId, - vararg fields: Pair - ): MutableMap { - return fields - .associate { - val fieldId = FieldId(classId, it.first) - val fieldValue = when (val value = it.second) { - is UtModel -> value - else -> UtPrimitiveModel(value) - } - fieldId to fieldValue - } - .toMutableMap() - } - - /** - * Calls [createModelsAndAssert] for one model. - */ - private fun createModelAndAssert( - model: UtModel, - expectedModelRepresentation: String?, - methodUnderTest: ExecutableId = AssembleTestUtils::class.id.allMethods.first(), - ) = createModelsAndAssert(listOf(model), listOf(expectedModelRepresentation), methodUnderTest) - - /** - * Assembles a model with mock and asserts that it is same as expected. - */ - private fun createModelWithMockAndAssert( - mockModel: UtCompositeModel, - expectedModelRepresentations: List, - ) { - val innerModels = mockModel.fields.values + mockModel.mocks.values.flatten() - createModelsAndAssert(innerModels, expectedModelRepresentations) - } - - /** - * Creates assemble models and asserts that it is same as expected. - */ - private fun createModelsAndAssert( - models: List, - expectedModelRepresentations: List, - assembleTestDummyMethod: ExecutableId = AssembleTestUtils::class.id.allMethods.first(), - ) { - val modelsMap = AssembleModelGenerator(assembleTestDummyMethod.classId.packageName).createAssembleModels(models) - //we sort values to fix order of models somehow (IdentityHashMap does not guarantee the order) - val assembleModels = modelsMap.values - .filterIsInstance() - .sortedBy { it.modelName } - - val assembledModelsCount = assembleModels.count() - val expectedAssembledModelsCount = expectedModelRepresentations.filterNotNull().count() - assertTrue( - assembledModelsCount == expectedAssembledModelsCount, - "Expected $expectedAssembledModelsCount assembled models, but found $assembledModelsCount" - ) - - expectedModelRepresentations.forEachIndexed { i, expectedModelRepresentation -> - if (expectedModelRepresentation != null) { - assertEquals(expectedModelRepresentation, "${assembleModels[i]}") - } - } - } - - private var expectedVariableCounter = 0 - - /** - * Adds declaration of instantiated variable into expected statements chain. - */ - private inline fun MutableList.addExpectedVariableDecl(vararg params: Any): String { - val fqn = T::class.qualifiedName - val varName = createExpectedVariableName() - - val paramString = if (params.any()) params.joinToString(", ") else "" - this.add("$fqn($paramString)") - - return varName - } - - /** - * Creates the name of the variable in expected statements chain. - */ - private inline fun createExpectedVariableName(): String { - return T::class.simpleName!!.decapitalize() + (++expectedVariableCounter) - } - - /** - * Adds setter of variable named [fName] with value [fValue] into expected statements chain. - */ - private fun addExpectedSetter(fName: String, fValue: Any): String = "set${fName.capitalize()}($fValue)" - private infix fun String.`=`(fValue: Any): String = "$this = $fValue" - - /** - * Prints expected assemble model representation. - */ - private fun printExpectedModel(className: String, instanceName: String, statementsChain: List): String = - "UtAssembleModel(${className} $instanceName) ${statementsChain.joinToString(" ")}" -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/BaseConstructorTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/BaseConstructorTest.kt deleted file mode 100644 index 71c63531fa..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/BaseConstructorTest.kt +++ /dev/null @@ -1,34 +0,0 @@ -package org.utbot.framework.concrete.constructors - -import org.utbot.engine.ValueConstructor -import org.utbot.framework.concrete.UtModelConstructor -import org.utbot.framework.plugin.api.UtAssembleModel -import org.utbot.framework.plugin.api.util.UtContext -import org.utbot.framework.plugin.api.util.id -import java.util.IdentityHashMap -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.BeforeEach - -abstract class BaseConstructorTest { - private lateinit var cookie: AutoCloseable - - @BeforeEach - fun setup() { - cookie = UtContext.setUtContext(UtContext(ClassLoader.getSystemClassLoader())) - } - - @AfterEach - fun tearDown() { - cookie.close() - } - - protected fun computeReconstructed(value: T): T { - val model = UtModelConstructor(IdentityHashMap()).construct(value, value::class.java.id) - - Assertions.assertTrue(model is UtAssembleModel) - - @Suppress("UNCHECKED_CAST") - return ValueConstructor().construct(listOf(model)).single().value as T - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/ListConstructorTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/ListConstructorTest.kt deleted file mode 100644 index e3ef59049e..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/ListConstructorTest.kt +++ /dev/null @@ -1,38 +0,0 @@ -package org.utbot.framework.concrete.constructors - -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test - -class ListConstructorTest : BaseConstructorTest() { - @Test - fun testEmptyList() { - val arrayList = java.util.LinkedList() - - val reconstructed = computeReconstructed(arrayList) - assertEquals(arrayList, reconstructed) - } - - @Test - fun testList() { - val arrayList = java.util.ArrayList() - arrayList.addAll(listOf(1, 2, 3, 4)) - - val reconstructed = computeReconstructed(arrayList) - assertEquals(arrayList, reconstructed) - } - - @Test - fun testListOfLists() { - val arrayList = java.util.ArrayList?>() - val arrayList1 = java.util.ArrayList() - val arrayList2 = java.util.ArrayList() - val arrayList3 = null - arrayList1.addAll(listOf(1, 2, 3)) - arrayList2.addAll(listOf(10, 20, 30)) - arrayList.addAll(listOf(arrayList1, arrayList2, arrayList3)) - - val reconstructed = computeReconstructed(arrayList) - assertEquals(arrayList, reconstructed) - } - -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/MapConstructorTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/MapConstructorTest.kt deleted file mode 100644 index e756e02942..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/MapConstructorTest.kt +++ /dev/null @@ -1,36 +0,0 @@ -package org.utbot.framework.concrete.constructors - -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test - -class MapConstructorTest : BaseConstructorTest() { - @Test - fun testEmptyLinkedHashMap() { - val map = java.util.LinkedHashMap() - - val reconstructed = computeReconstructed(map) - - assertEquals(map, reconstructed) - } - - @Test - fun testMapOfIntegersToStrings() { - val map = java.util.LinkedHashMap() - map.putAll(listOf(1 to "1", 2 to "2", 3 to "3", 1 to "4", 1 to "5", 2 to "6")) - - val reconstructed = computeReconstructed(map) - - assertEquals(map, reconstructed) - } - - - @Test - fun testMapOfStringsToStrings() { - val map = java.util.TreeMap() - map.putAll(listOf("1" to "!", "2" to "?", "3" to "#", "3" to "@", "1" to "*")) - - val reconstructed = computeReconstructed(map) - - assertEquals(map, reconstructed) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/OptionalConstructorTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/OptionalConstructorTest.kt deleted file mode 100644 index 7c515f9d55..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/OptionalConstructorTest.kt +++ /dev/null @@ -1,65 +0,0 @@ -package org.utbot.framework.concrete.constructors - -import java.util.Optional -import java.util.OptionalDouble -import java.util.OptionalInt -import java.util.OptionalLong -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test - -class OptionalConstructorTest : BaseConstructorTest() { - @Test - fun testOptionalInt() { - val optionalInt = OptionalInt.of(42) - - val reconstructed = computeReconstructed(optionalInt) - - assertEquals(optionalInt, reconstructed) - } - - @Test - fun testOptionalDouble() { - val optionalDouble = OptionalDouble.of(42.0) - - val reconstructed = computeReconstructed(optionalDouble) - - assertEquals(optionalDouble, reconstructed) - } - - @Test - fun testOptionalLong() { - val optionalLong = OptionalLong.of(42L) - - val reconstructed = computeReconstructed(optionalLong) - - assertEquals(optionalLong, reconstructed) - } - - @Test - fun testOptional() { - val optional = Optional.of("42") - - val reconstructed = computeReconstructed(optional) - - assertEquals(optional, reconstructed) - } - - @Test - fun testRecursiveOptional() { - val optional = Optional.of("42") - val recursiveOptional = optional.map { optional } - - val reconstructed = computeReconstructed(recursiveOptional) - - assertEquals(reconstructed.get().get(), "42") - } - - @Test - fun testEmptyOptional() { - val emptyOptional = Optional.empty() - - val reconstructed = computeReconstructed(emptyOptional) - - assertEquals(emptyOptional, reconstructed) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/SetConstructorTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/SetConstructorTest.kt deleted file mode 100644 index 56cfe25ff9..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/framework/concrete/constructors/SetConstructorTest.kt +++ /dev/null @@ -1,36 +0,0 @@ -package org.utbot.framework.concrete.constructors - -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Test - -class SetConstructorTest : BaseConstructorTest() { - @Test - fun testEmptyLinkedHashSet() { - val set = java.util.LinkedHashSet() - - val reconstructed = computeReconstructed(set) - - assertEquals(set, reconstructed) - } - - @Test - fun testSetOfIntegers() { - val set = java.util.LinkedHashSet() - set.addAll(listOf(1, 2, 3, 1, 1, 2)) - - val reconstructed = computeReconstructed(set) - - assertEquals(set, reconstructed) - } - - - @Test - fun testSetOfStrings() { - val set = java.util.LinkedHashSet() - set.addAll(listOf("1", "2", "3", "3", "1")) - - val reconstructed = computeReconstructed(set) - - assertEquals(set, reconstructed) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/minimization/MinimizationGreedyEssentialTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/minimization/MinimizationGreedyEssentialTest.kt deleted file mode 100644 index 993f23059a..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/framework/minimization/MinimizationGreedyEssentialTest.kt +++ /dev/null @@ -1,71 +0,0 @@ -package org.utbot.framework.minimization - -import kotlin.math.min -import kotlin.ranges.IntProgression.Companion.fromClosedRange -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.Test - -class MinimizationGreedyEssentialTest { - @Test - fun testEmpty() { - val executions = emptyMap>() - val minimizedExecutions = GreedyEssential.minimize(executions) - assertTrue(minimizedExecutions.isEmpty()) - } - - @Test - fun testCustom1() { - val executions = mapOf( - 1 to listOf(1, 2, 3, 4, 5), - 2 to listOf(2, 3, 4, 5, 6, 7), - 3 to listOf(1, 7), - 4 to listOf(8), - 5 to listOf(1, 8) - ) - val minimizedExecutions = GreedyEssential.minimize(executions) - assertEquals(listOf(2, 5), minimizedExecutions) - } - - @Test - fun testCustom2() { - val executions = mapOf( - 10 to listOf(1, 2, 3, 4, 5), - 20 to listOf(2, 3, 4, 5, 6, 7), - 21 to listOf(1, 7, 2, 3, 5), - 24 to listOf(8, 5, 6, 7), - 50 to listOf(1, 8) - ) - val minimizedExecutions = GreedyEssential.minimize(executions) - assertEquals(listOf(20, 50), minimizedExecutions) - } - - @Test - fun testBigExecutionAndSmallExecutions() { - val size = 10000 - val executions = (1..size) - .associateWith { listOf(it, it + size, it + 2 * size) } - .toMutableMap().apply { - put(0, (1..3 * size).toList()) - } - val minimizedExecutions = GreedyEssential.minimize(executions) - assertEquals(listOf(0), minimizedExecutions.sorted()) - } - - @Test - fun testSameSizeExecutions() { - val size = 2000 - val executionSize = 100 - val executions = (0 until size).associateWith { (it until min(size, it + executionSize)).toList() } - val minimizedExecutions = GreedyEssential.minimize(executions) - assertEquals(fromClosedRange(0, size - 1, executionSize).toList(), minimizedExecutions.sorted()) - } - - @Test - fun testManyExcluding() { - val size = 10000 - val executions = (1..size).associateWith { listOf(it, it + size, it + 2 * size) } - val minimizedExecutions = GreedyEssential.minimize(executions) - assertEquals((1..size).toList(), minimizedExecutions.sorted()) - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt deleted file mode 100644 index 7fd12c48b1..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt +++ /dev/null @@ -1,324 +0,0 @@ -package org.utbot.framework.modificators - -import org.utbot.examples.modificators.ConstructorsAndSetters -import org.utbot.examples.modificators.DefaultField -import org.utbot.examples.modificators.InvokeInAssignment -import org.utbot.examples.modificators.NoFields -import org.utbot.examples.modificators.NoMethods -import org.utbot.examples.modificators.PrimitiveModifications -import org.utbot.examples.modificators.RecursiveAndCrossCalls -import org.utbot.examples.modificators.StronglyConnectedComponent -import org.utbot.examples.modificators.StronglyConnectedComponents -import org.utbot.examples.modificators.coupling.ClassA -import org.utbot.examples.modificators.coupling.ClassB -import org.utbot.examples.modificators.hierarchy.InheritedModifications -import org.utbot.framework.modifications.AnalysisMode -import org.utbot.framework.modifications.AnalysisMode.AllModificators -import org.utbot.framework.modifications.AnalysisMode.SettersAndDirectAccessors -import org.utbot.framework.modifications.UtBotFieldsModificatorsSearcher -import org.utbot.framework.plugin.api.util.UtContext -import org.utbot.framework.plugin.api.util.id -import kotlin.reflect.KClass -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.utbot.common.nameOfPackage -import org.utbot.framework.plugin.services.JdkInfoDefaultProvider -import org.utbot.framework.util.SootUtils - -internal class UtBotFieldModificatorsTest { - private lateinit var fieldsModificatorsSearcher: UtBotFieldsModificatorsSearcher - private lateinit var context: AutoCloseable - - @BeforeEach - fun setUp() { - context = UtContext.setUtContext(UtContext(PrimitiveModifications::class.java.classLoader)) - } - - @AfterEach - fun tearDown() { - context.close() - } - - //region EdgeCases - - @Test - fun testOnClassesWithoutFields() { - val actualResponse = runFullAnalysis(setOf(NoFields::class)) - - assertTrue(actualResponse.isEmpty()) - } - - @Test - fun testOnClassesWithoutMethods() { - val actualResponse = runFullAnalysis(setOf(NoMethods::class)) - - assertTrue(actualResponse.isEmpty()) - } - - //endregion - - @Test - fun testOnClassHierarchy() { - val actualResponse = runFullAnalysis(setOf(ClassA::class, ClassB::class)) - - assertEquals(expectedForHierarchy, actualResponse) - } - - @Test - fun testClassUpdates() { - val actualResponse = runFullAnalysis( - setOf(ClassA::class), - setOf(ClassA::class, ClassB::class) - ) - - assertEquals(expectedForHierarchy, actualResponse) - } - - @Test - fun testClassDeletion() { - setOf(ClassA::class, ClassB::class).also { - initAnalysis() - runUpdate(it) - } - - runDelete(setOf(ClassB::class)) - runUpdate(setOf(ClassB::class)) - - val actualResponse = runFieldModificatorsSearch(analysisMode = AllModificators) - - assertEquals(expectedForHierarchy, actualResponse) - } - - @Test - fun testOnSimpleClass() { - val actualResponse = runFullAnalysis(setOf(PrimitiveModifications::class)) - - assertEquals(expectedForSimpleClass, actualResponse) - } - - @Test - fun testInSettersMode() { - val actualResponse = runFullAnalysis( - setOf(ConstructorsAndSetters::class), - analysisMode = SettersAndDirectAccessors, - ) - - assertEquals(expectedForClassWithSetters, actualResponse) - } - - @Test - fun testOnRecursiveClass() { - val actualResponse = runFullAnalysis(setOf(RecursiveAndCrossCalls::class)) - - assertEquals(expectedForRecursiveClass, actualResponse) - } - - @Test - fun testOnInheritedClass() { - val actualResponse = runFullAnalysis(setOf(InheritedModifications::class)) - - assertEquals(expectedForInheritedClass, actualResponse) - } - - @Test - fun testOnClassWithOneComponent() { - val actualResponse = runFullAnalysis(setOf(StronglyConnectedComponent::class)) - - assertEquals(expectedForClassWithOneComponent, actualResponse) - } - - @Test - fun testOnClassWithComponents() { - val actualResponse = runFullAnalysis(setOf(StronglyConnectedComponents::class)) - - assertEquals(expectedForClassWithComponents, actualResponse) - } - - @Test - fun testOnClassWithInvokeInAssignment() { - val actualResponse = runFullAnalysis(setOf(InvokeInAssignment::class)) - - assertEquals(expectedForClassWithInvokeInAssignment, actualResponse) - } - - @Test - fun testOnClassWithDefaultField() { - val actualResponse = runFullAnalysis(setOf(DefaultField::class)) - - assertEquals(expectedForClassWithDefaultField, actualResponse) - } - - @Test - fun testRunRequestTwice() { - runFullAnalysis(setOf(PrimitiveModifications::class)) - - val actualResponse = runFieldModificatorsSearch(analysisMode = AllModificators) - - assertEquals(expectedForSimpleClass, actualResponse) - } - - private fun runFullAnalysis( - vararg classSets: Set>, - analysisMode: AnalysisMode = AllModificators, - ): Map> { - initAnalysis() - classSets.forEach { runUpdate(it) } - - return runFieldModificatorsSearch(analysisMode) - } - - private fun initAnalysis() { - SootUtils.runSoot( - PrimitiveModifications::class.java, - forceReload = false, - jdkInfo = JdkInfoDefaultProvider().info - ) - fieldsModificatorsSearcher = UtBotFieldsModificatorsSearcher() - } - - private fun runUpdate(classes: Set>) { - val classIds = classes.map { it.id }.toSet() - - fieldsModificatorsSearcher.update(classIds) - } - - private fun runDelete(classes: Set>) { - val classIds = classes.map { it.id }.toSet() - - fieldsModificatorsSearcher.delete(classIds) - } - - //We use sorting here to make comparing with sorted in advance expected collections easier - private fun runFieldModificatorsSearch(analysisMode: AnalysisMode) = - fieldsModificatorsSearcher.findModificators(analysisMode) - .map { (key, value) -> - val modificatorNames = value.filterNot { it.name.startsWith("direct_set_") }.map { it.name } - key.name to modificatorNames.toSortedSet() - } - .toMap() - .filterNot { it.value.isEmpty() } - .toSortedMap() - - private val expectedForHierarchy = sortedMapOf( - "v1" to setOf("a1Pub"), - "v2" to setOf("a2Pub"), - "v3" to setOf("a1Pub"), - "v4" to setOf("a1Pub"), - "v5" to setOf("a2Pub"), - "v6" to setOf("a1Pub", "a2Pub", "b1Pub"), - "w1" to setOf("a1Pub", "b1Pub"), - "w2" to setOf("b2Pub"), - "w3" to setOf("a1Pub", "b1Pub"), - "w4" to setOf("a1Pub", "b1Pub"), - ) - - private val expectedForSimpleClass = sortedMapOf( - "x" to setOf( - "", - "setCallResult", - "setSeveral", - "setStaticCallResult", - "setWithPrivateCall", - "setWithPrivateCallsHierarchy", - "setWithStdCall", - ), - "y" to setOf( - "", - "setStaticCallResult", - ), - "z" to setOf( - "", - "setAndThrow", - "setOne", - "setSeveral", - "setWithPrivateCallsHierarchy", - ), - "t" to setOf( - "setWithPrivateCall", - "setWithPrivateCallsHierarchy", - ), - ) - - private val expectedForClassWithSetters = sortedMapOf( - "d1" to setOf("setWithInternalCall"), - "i" to setOf("setI"), - ) - - private val expectedForRecursiveClass = sortedMapOf( - "x" to setOf( - "setRecursively", - "setWithReverseCalls", - ), - "z" to setOf( - "setRecursively", - "setWithReverseCalls", - ), - "t" to setOf( - "setWithReverseCalls", - ), - "y" to setOf( - "setRecursively", - "setWithReverseCalls", - ) - ) - - private val expectedForInheritedClass = sortedMapOf( - "x" to setOf( - "setInInterfaceMethod", - "setInStaticInterfaceMethodCall", - "setWithModifyingBaseCall", - "setWithOverrideCall", - "writeAndModify" - ), - "y" to setOf( - "", - "setBaseField", - "setBaseFieldInChild", - "setFieldHereAndInChild", - "setInClassAndBaseClassMethods", - "setInInterfaceMethod", - "setInStaticInterfaceMethodCall", - "setWithModifyingBaseCall", - "setWithOverrideCall", - ), - "baseField" to setOf( - "", - "setBaseField", - "setBaseFieldInChild", - "setInChildAbstract", - "setInClassAndBaseClassMethods", - "setWithModifyingBaseCall", - "setWithOverrideCall", - "write", - "writeAndModify", - ), - ) - - private val expectedForClassWithOneComponent = sortedMapOf( - "x0" to setOf("f0"), - "x1" to setOf("f0", "f1"), - "x2" to setOf("f0", "f1"), - "x3" to setOf("f0", "f1"), - "x4" to setOf("f0", "f1", "f4"), - ) - - private val expectedForClassWithComponents = sortedMapOf( - "x0" to setOf("f0", "f1"), - "x1" to setOf("f0", "f1"), - "x2" to setOf("f0", "f1"), - "x3" to setOf("f0", "f1", "f3", "f4"), - "x4" to setOf("f0", "f1", "f3", "f4"), - ) - - private val expectedForClassWithInvokeInAssignment = sortedMapOf( - "x" to setOf("fun"), - "y" to setOf("fun"), - ) - - private val expectedForClassWithDefaultField = sortedMapOf( - "z" to setOf("", "foo"), - ) -} diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/plugin/api/MockStrategyApiTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/plugin/api/MockStrategyApiTest.kt deleted file mode 100644 index 4ce43e1a95..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/framework/plugin/api/MockStrategyApiTest.kt +++ /dev/null @@ -1,48 +0,0 @@ -package org.utbot.framework.plugin.api - -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertFalse -import org.junit.jupiter.api.Test -import org.utbot.engine.MockStrategy -import org.utbot.framework.util.toModel - -internal class MockStrategyApiTest { - - @Test - fun testApiToModel() { - assertEquals( - MockStrategyApi.values().size, MockStrategy.values().size, - "The number of strategies in the contract and engine model should match" - ) - - assertEquals(3, MockStrategyApi.values().size, "Three options only (so far)") - assertEquals(MockStrategy.NO_MOCKS, MockStrategyApi.NO_MOCKS.toModel()) - assertEquals(MockStrategy.OTHER_PACKAGES, MockStrategyApi.OTHER_PACKAGES.toModel()) - assertEquals(MockStrategy.OTHER_CLASSES, MockStrategyApi.OTHER_CLASSES.toModel()) - } - - @Test - fun ensureDefaultStrategyIsOtherPackages() { - assertEquals( - MockStrategyApi.OTHER_PACKAGES, - MockStrategyApi.defaultItem, - "Expecting that ${MockStrategyApi.OTHER_PACKAGES} is the default policy for Mocks " + - "but ${MockStrategyApi.defaultItem} found" - ) - } - - @Test - fun testLabelToEnum() { - assertEquals( - MockStrategyApi.values().size, - MockStrategyApi.labels().toSet().size, - "Expecting all labels are unique" - ) - - assertFalse( - MockStrategyApi.labels().any { it.isBlank() }, - "Expecting all labels are not empty" - ) - } - -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/z3/extension/Z3ExtensionForTests.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/z3/extension/Z3ExtensionForTests.kt deleted file mode 100644 index fdc65fd713..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/framework/z3/extension/Z3ExtensionForTests.kt +++ /dev/null @@ -1,60 +0,0 @@ -@file:Suppress("PackageDirectoryMismatch", "unused", "NonAsciiCharacters") - -package com.microsoft.z3 - -import kotlin.reflect.KProperty - - -operator fun ArithExpr.plus(other: ArithExpr): ArithExpr = context.mkAdd(this, other) -operator fun ArithExpr.plus(other: Int): ArithExpr = this + context.mkInt(other) - -operator fun ArithExpr.minus(other: ArithExpr): ArithExpr = context.mkSub(this, other) -operator fun ArithExpr.minus(other: Int): ArithExpr = this - context.mkInt(other) - -operator fun ArithExpr.times(other: ArithExpr): ArithExpr = context.mkMul(this, other) -operator fun ArithExpr.times(other: Int): ArithExpr = this * context.mkInt(other) - -infix fun Expr.`=`(other: Int): BoolExpr = this eq context.mkInt(other) -infix fun Expr.`=`(other: Expr): BoolExpr = this eq other -infix fun Expr.eq(other: Expr): BoolExpr = context.mkEq(this, other) -infix fun Expr.`!=`(other: Expr): BoolExpr = context.mkNot(this `=` other) -operator fun BoolExpr.not(): BoolExpr = context.mkNot(this) - -infix fun BoolExpr.`⇒`(other: BoolExpr): BoolExpr = this implies other -infix fun BoolExpr.`⇒`(other: Boolean): BoolExpr = this implies other -infix fun BoolExpr.implies(other: Boolean): BoolExpr = this implies context.mkBool(other) -infix fun BoolExpr.implies(other: BoolExpr): BoolExpr = context.mkImplies(this, other) -infix fun BoolExpr.and(other: BoolExpr): BoolExpr = context.mkAnd(this, other) -infix fun BoolExpr.or(other: BoolExpr): BoolExpr = context.mkOr(this, other) - -infix fun ArithExpr.gt(other: ArithExpr): BoolExpr = context.mkGt(this, other) -infix fun ArithExpr.gt(other: Int): BoolExpr = context.mkGt(this, context.mkInt(other)) - -infix fun ArithExpr.`=`(other: Int): BoolExpr = context.mkEq(this, context.mkInt(other)) - -operator fun ArrayExpr.get(index: IntExpr): Expr = context.mkSelect(this, index) -operator fun ArrayExpr.get(index: Int): Expr = this[context.mkInt(index)] -fun ArrayExpr.set(index: IntExpr, value: Expr): ArrayExpr = context.mkStore(this, index, value) -fun ArrayExpr.set(index: Int, value: Expr): ArrayExpr = set(context.mkInt(index), value) - -operator fun SeqExpr.plus(other: SeqExpr): SeqExpr = context.mkConcat(this, other) -operator fun SeqExpr.plus(other: String): SeqExpr = context.mkConcat(context.mkString(other)) - -infix fun SeqExpr.`=`(other: String): BoolExpr = context.mkEq(this, context.mkString(other)) - -class Const(private val ctx: Context, val produce: (Context, name: String) -> T) { - operator fun getValue(thisRef: Nothing?, property: KProperty<*>): T = produce(ctx, property.name) -} - -fun Context.declareInt() = Const(this) { ctx, name -> ctx.mkIntConst(name) } -fun Context.declareBool() = Const(this) { ctx, name -> ctx.mkBoolConst(name) } -fun Context.declareReal() = Const(this) { ctx, name -> ctx.mkRealConst(name) } -fun Context.declareString() = Const(this) { ctx, name -> ctx.mkConst(name, stringSort) as SeqExpr } -fun Context.declareList(sort: ListSort) = Const(this) { ctx, name -> ctx.mkConst(name, sort) } -fun Context.declareIntArray() = Const(this) { ctx, name -> ctx.mkArrayConst(name, intSort, intSort) } - - -operator fun FuncDecl.invoke(vararg expr: Expr): Expr = context.mkApp(this, *expr) - -fun Model.eval(expr: Expr): Expr = this.eval(expr, true) -fun Model.eval(vararg exprs: Expr): List = exprs.map { this.eval(it, true) } \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/framework/z3/extension/Z3ExtensionTest.kt b/utbot-testing/src/test/kotlin/org/utbot/framework/z3/extension/Z3ExtensionTest.kt deleted file mode 100644 index c31298bac8..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/framework/z3/extension/Z3ExtensionTest.kt +++ /dev/null @@ -1,155 +0,0 @@ -package org.utbot.framework.z3.extension - -import org.utbot.engine.z3.Z3Initializer -import com.microsoft.z3.ArrayExpr -import com.microsoft.z3.Context -import com.microsoft.z3.IntNum -import com.microsoft.z3.RatNum -import com.microsoft.z3.SeqExpr -import com.microsoft.z3.Status -import com.microsoft.z3.`=` -import com.microsoft.z3.and -import com.microsoft.z3.declareInt -import com.microsoft.z3.declareIntArray -import com.microsoft.z3.declareList -import com.microsoft.z3.declareReal -import com.microsoft.z3.declareString -import com.microsoft.z3.eval -import com.microsoft.z3.get -import com.microsoft.z3.invoke -import com.microsoft.z3.minus -import com.microsoft.z3.not -import com.microsoft.z3.plus -import com.microsoft.z3.set -import com.microsoft.z3.times -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.Test - -class Z3ExtensionTest : Z3Initializer() { - - @Test - fun testArrayDefault() { - Context().use { ctx -> - val arraySort = ctx.mkArraySort(arrayOf(ctx.mkIntSort(), ctx.mkIntSort()), ctx.mkIntSort()) - val ourArray = ctx.mkConst("a", arraySort) as ArrayExpr - - val solver = ctx.mkSolver() - - solver.add(ctx.mkEq(ctx.mkInt(42), ctx.mkTermArray(ourArray))) //mkTermArray function! - solver.check() - val evalArray = solver.model.eval(ourArray) - assertEquals("((as const (Array Int Int Int)) 42)", evalArray.toString()) - } - } - - @Test - fun testInt() { - Context().use { ctx -> - val a by ctx.declareInt() - val b by ctx.declareInt() - - val solver = ctx.mkSolver().apply { add(a * a + b * b `=` 8) } - - assertEquals(Status.SATISFIABLE, solver.check()) - - val (aVal, bVal) = solver.model - .eval(a, b) - .filterIsInstance() - .map(IntNum::getInt) - .also { list -> assertEquals(2, list.size) } - - assertEquals(8, aVal * aVal + bVal * bVal) - } - } - - @Test - fun testReal() { - Context().use { ctx -> - val x by ctx.declareReal() - - val solver = ctx.mkSolver().apply { - add((x * x - x * 4 + 3 `=` 0) and !(x `=` 3)) - } - - assertEquals(Status.SATISFIABLE, solver.check()) - - val xVal = (solver.model.eval(x) as RatNum).let { - it.bigIntNumerator.divide(it.bigIntDenominator).toDouble() - } - - assertEquals(1.0, xVal, 1E-8) - } - } - - @Test - fun testStrings() { - Context().use { ctx -> - val a by ctx.declareString() - val b by ctx.declareString() - val c by ctx.declareString() - - val solver = ctx.mkSolver().apply { - add(a + b `=` "abcd") - add(b + c `=` "cdef") - add(!(b `=` "")) - } - - assertEquals(Status.SATISFIABLE, solver.check()) - - val (aVal, bVal, cVal) = solver.model - .eval(a, b, c) - .filterIsInstance() - .map(SeqExpr::getString) - .also { list -> assertEquals(3, list.size) } - - assertEquals("abcd", "$aVal$bVal") - assertEquals("cdef", "$bVal$cVal") - assertTrue(bVal.isNotBlank()) - } - } - - @Test - fun testArrays() { - Context().use { ctx -> - val x by ctx.declareInt() - val y by ctx.declareInt() - val a1 by ctx.declareIntArray() - - val solver = ctx.mkSolver().apply { - add(a1[x] `=` x) - add(a1.set(x, y) `=` a1) - } - - assertEquals(Status.SATISFIABLE, solver.check()) - - val (xVal, yVal) = solver.model - .eval(x, y) - .filterIsInstance() - .map(IntNum::getInt) - .also { list -> assertEquals(2, list.size) } - - assertTrue(xVal == yVal) - } - } - - @Test - fun testList() { - Context().use { ctx -> - val type = ctx.mkListSort("intList", ctx.intSort) - val l by ctx.declareList(type) - - val solver = ctx.mkSolver().apply { - add(!(l `=` type.nil)) - add(type.headDecl(l) `=` 1) - add(type.tailDecl(l) `=` type.consDecl(type.headDecl(l), type.nil)) - } - - assertEquals(Status.SATISFIABLE, solver.check()) - - val lVal = solver.model.eval(l) - - assertEquals("(cons 1 (cons 1 nil))", "$lVal") - } - } -} \ No newline at end of file diff --git a/utbot-testing/src/test/kotlin/org/utbot/sarif/SarifReportTest.kt b/utbot-testing/src/test/kotlin/org/utbot/sarif/SarifReportTest.kt deleted file mode 100644 index 44aa51e5f3..0000000000 --- a/utbot-testing/src/test/kotlin/org/utbot/sarif/SarifReportTest.kt +++ /dev/null @@ -1,351 +0,0 @@ -package org.utbot.sarif - -import org.junit.Test -import org.mockito.Mockito -import org.utbot.framework.plugin.api.ExecutableId -import org.utbot.framework.plugin.api.UtExecution -import org.utbot.framework.plugin.api.UtImplicitlyThrownException -import org.utbot.framework.plugin.api.UtPrimitiveModel -import org.utbot.framework.plugin.api.UtMethodTestSet -import org.utbot.framework.plugin.api.UtSymbolicExecution - -class SarifReportTest { - - @Test - fun testNonEmptyReport() { - val actualReport = SarifReport( - testSets = listOf(), - generatedTestsCode = "", - sourceFindingEmpty - ).createReport().toJson() - - assert(actualReport.isNotEmpty()) - } - - @Test - fun testNoUncheckedExceptions() { - val sarif = SarifReport( - testSets = listOf(testSet), - generatedTestsCode = "", - sourceFindingEmpty - ).createReport() - - assert(sarif.runs.first().results.isEmpty()) - } - - @Test - fun testDetectAllUncheckedExceptions() { - mockUtMethodNames() - - val mockUtExecutionNPE = Mockito.mock(UtExecution::class.java, Mockito.RETURNS_DEEP_STUBS) - Mockito.`when`(mockUtExecutionNPE.result).thenReturn( - UtImplicitlyThrownException(NullPointerException(), false), - ) - Mockito.`when`(mockUtExecutionNPE.stateBefore.parameters).thenReturn(listOf()) - - val mockUtExecutionAIOBE = Mockito.mock(UtExecution::class.java, Mockito.RETURNS_DEEP_STUBS) - Mockito.`when`(mockUtExecutionAIOBE.result).thenReturn( - UtImplicitlyThrownException(ArrayIndexOutOfBoundsException(), false), - ) - Mockito.`when`(mockUtExecutionAIOBE.stateBefore.parameters).thenReturn(listOf()) - - val testSets = listOf( - UtMethodTestSet(mockExecutableId, listOf(mockUtExecutionNPE)), - UtMethodTestSet(mockExecutableId, listOf(mockUtExecutionAIOBE)) - ) - - val report = SarifReport( - testSets = testSets, - generatedTestsCode = "", - sourceFindingEmpty - ).createReport() - - assert(report.runs.first().results[0].message.text.contains("NullPointerException")) - assert(report.runs.first().results[1].message.text.contains("ArrayIndexOutOfBoundsException")) - } - - @Test - fun testCorrectResultLocations() { - mockUtMethodNames() - - Mockito.`when`(mockUtExecution.result).thenReturn( - UtImplicitlyThrownException(NullPointerException(), false) - ) - Mockito.`when`(mockUtExecution.stateBefore.parameters).thenReturn(listOf()) - Mockito.`when`(mockUtExecution.path.lastOrNull()?.stmt?.javaSourceStartLineNumber).thenReturn(1337) - Mockito.`when`(mockUtExecution.testMethodName).thenReturn("testMain_ThrowArithmeticException") - - val report = sarifReportMain.createReport() - - val result = report.runs.first().results.first() - val location = result.locations.first().physicalLocation - val relatedLocation = result.relatedLocations.first().physicalLocation - - assert(location.artifactLocation.uri.contains("Main.java")) - assert(location.region.startLine == 1337) - assert(relatedLocation.artifactLocation.uri.contains("MainTest.java")) - assert(relatedLocation.region.startLine == 1) - assert(relatedLocation.region.startColumn == 1) - } - - @Test - fun testCorrectMethodParameters() { - mockUtMethodNames() - - Mockito.`when`(mockUtExecution.result).thenReturn( - UtImplicitlyThrownException(NullPointerException(), false) - ) - Mockito.`when`(mockUtExecution.stateBefore.parameters).thenReturn( - listOf( - UtPrimitiveModel(227), - UtPrimitiveModel(3.14), - UtPrimitiveModel(false) - ) - ) - - val report = sarifReportMain.createReport() - - val result = report.runs.first().results.first() - assert(result.message.text.contains("227")) - assert(result.message.text.contains("3.14")) - assert(result.message.text.contains("false")) - } - - @Test - fun testCorrectCodeFlows() { - mockUtMethodNames() - - val uncheckedException = Mockito.mock(NullPointerException::class.java) - val stackTraceElement = StackTraceElement("Main", "main", "Main.java", 17) - Mockito.`when`(uncheckedException.stackTrace).thenReturn( - Array(2) { stackTraceElement } - ) - - Mockito.`when`(mockUtExecution.result).thenReturn( - UtImplicitlyThrownException(uncheckedException, false) - ) - Mockito.`when`(mockUtExecution.stateBefore.parameters).thenReturn(listOf()) - - val report = sarifReportMain.createReport() - - val result = report.runs.first().results.first().codeFlows.first().threadFlows.first().locations.map { - it.location.physicalLocation - } - for (index in 0..1) { - assert(result[index].artifactLocation.uri.contains("Main.java")) - assert(result[index].region.startLine == 17) - } - } - - @Test - fun testCodeFlowsStartsWithMethodCall() { - mockUtMethodNames() - - val uncheckedException = Mockito.mock(NullPointerException::class.java) - val stackTraceElement = StackTraceElement("Main", "main", "Main.java", 3) - Mockito.`when`(uncheckedException.stackTrace).thenReturn(arrayOf(stackTraceElement)) - - Mockito.`when`(mockUtExecution.result).thenReturn( - UtImplicitlyThrownException(uncheckedException, false) - ) - Mockito.`when`(mockUtExecution.stateBefore.parameters).thenReturn(listOf()) - Mockito.`when`(mockUtExecution.testMethodName).thenReturn("testMain_ThrowArithmeticException") - - val report = sarifReportMain.createReport() - - val codeFlowPhysicalLocations = report.runs[0].results[0].codeFlows[0].threadFlows[0].locations.map { - it.location.physicalLocation - } - assert(codeFlowPhysicalLocations[0].artifactLocation.uri.contains("MainTest.java")) - assert(codeFlowPhysicalLocations[0].region.startLine == 5) - assert(codeFlowPhysicalLocations[0].region.startColumn == 7) - } - - @Test - fun testCodeFlowsStartsWithPrivateMethodCall() { - mockUtMethodNames() - - val uncheckedException = Mockito.mock(NullPointerException::class.java) - val stackTraceElement = StackTraceElement("Main", "main", "Main.java", 3) - Mockito.`when`(uncheckedException.stackTrace).thenReturn(arrayOf(stackTraceElement)) - - Mockito.`when`(mockUtExecution.result).thenReturn( - UtImplicitlyThrownException(uncheckedException, false) - ) - Mockito.`when`(mockUtExecution.stateBefore.parameters).thenReturn(listOf()) - Mockito.`when`(mockUtExecution.testMethodName).thenReturn("testMain_ThrowArithmeticException") - - val report = sarifReportPrivateMain.createReport() - - val codeFlowPhysicalLocations = report.runs[0].results[0].codeFlows[0].threadFlows[0].locations.map { - it.location.physicalLocation - } - assert(codeFlowPhysicalLocations[0].artifactLocation.uri.contains("MainTest.java")) - assert(codeFlowPhysicalLocations[0].region.startLine == 6) - assert(codeFlowPhysicalLocations[0].region.startColumn == 5) - } - - @Test - fun testMinimizationRemovesDuplicates() { - mockUtMethodNames() - - val mockUtExecution = Mockito.mock(UtExecution::class.java, Mockito.RETURNS_DEEP_STUBS) - Mockito.`when`(mockUtExecution.result).thenReturn(UtImplicitlyThrownException(NullPointerException(), false)) - - val testSets = listOf( - UtMethodTestSet(mockExecutableId, listOf(mockUtExecution)), - UtMethodTestSet(mockExecutableId, listOf(mockUtExecution)) // duplicate - ) - - val report = SarifReport( - testSets = testSets, - generatedTestsCode = "", - sourceFindingMain - ).createReport() - - assert(report.runs.first().results.size == 1) // no duplicates - } - - @Test - fun testMinimizationDoesNotRemoveResultsWithDifferentRuleId() { - mockUtMethodNames() - - val mockUtExecution1 = Mockito.mock(UtExecution::class.java, Mockito.RETURNS_DEEP_STUBS) - val mockUtExecution2 = Mockito.mock(UtExecution::class.java, Mockito.RETURNS_DEEP_STUBS) - - // different ruleId's - Mockito.`when`(mockUtExecution1.result).thenReturn(UtImplicitlyThrownException(NullPointerException(), false)) - Mockito.`when`(mockUtExecution2.result).thenReturn(UtImplicitlyThrownException(ArithmeticException(), false)) - - val testSets = listOf( - UtMethodTestSet(mockExecutableId, listOf(mockUtExecution1)), - UtMethodTestSet(mockExecutableId, listOf(mockUtExecution2)) // not a duplicate - ) - - val report = SarifReport( - testSets = testSets, - generatedTestsCode = "", - sourceFindingMain - ).createReport() - - assert(report.runs.first().results.size == 2) // no results have been removed - } - - @Test - fun testMinimizationDoesNotRemoveResultsWithDifferentLocations() { - mockUtMethodNames() - - val mockUtExecution1 = Mockito.mock(UtSymbolicExecution::class.java, Mockito.RETURNS_DEEP_STUBS) - val mockUtExecution2 = Mockito.mock(UtSymbolicExecution::class.java, Mockito.RETURNS_DEEP_STUBS) - - // the same ruleId's - Mockito.`when`(mockUtExecution1.result).thenReturn(UtImplicitlyThrownException(NullPointerException(), false)) - Mockito.`when`(mockUtExecution2.result).thenReturn(UtImplicitlyThrownException(NullPointerException(), false)) - - // different locations - Mockito.`when`(mockUtExecution1.path.lastOrNull()?.stmt?.javaSourceStartLineNumber).thenReturn(11) - Mockito.`when`(mockUtExecution2.path.lastOrNull()?.stmt?.javaSourceStartLineNumber).thenReturn(22) - - val testSets = listOf( - UtMethodTestSet(mockExecutableId, listOf(mockUtExecution1)), - UtMethodTestSet(mockExecutableId, listOf(mockUtExecution2)) // not a duplicate - ) - - val report = SarifReport( - testSets = testSets, - generatedTestsCode = "", - sourceFindingMain - ).createReport() - - assert(report.runs.first().results.size == 2) // no results have been removed - } - - @Test - fun testMinimizationChoosesShortestCodeFlow() { - mockUtMethodNames() - - val mockNPE1 = Mockito.mock(NullPointerException::class.java) - val mockNPE2 = Mockito.mock(NullPointerException::class.java) - - val mockUtExecution1 = Mockito.mock(UtExecution::class.java, Mockito.RETURNS_DEEP_STUBS) - val mockUtExecution2 = Mockito.mock(UtExecution::class.java, Mockito.RETURNS_DEEP_STUBS) - - // the same ruleId's - Mockito.`when`(mockUtExecution1.result).thenReturn(UtImplicitlyThrownException(mockNPE1, false)) - Mockito.`when`(mockUtExecution2.result).thenReturn(UtImplicitlyThrownException(mockNPE2, false)) - - // but different stack traces - val stackTraceElement1 = StackTraceElement("Main", "main", "Main.java", 3) - val stackTraceElement2 = StackTraceElement("Main", "main", "Main.java", 7) - Mockito.`when`(mockNPE1.stackTrace).thenReturn(arrayOf(stackTraceElement1)) - Mockito.`when`(mockNPE2.stackTrace).thenReturn(arrayOf(stackTraceElement1, stackTraceElement2)) - - val testSets = listOf( - UtMethodTestSet(mockExecutableId, listOf(mockUtExecution1)), - UtMethodTestSet(mockExecutableId, listOf(mockUtExecution2)) // duplicate with a longer stack trace - ) - - val report = SarifReport( - testSets = testSets, - generatedTestsCode = "", - sourceFindingMain - ).createReport() - - assert(report.runs.first().results.size == 1) // no duplicates - assert(report.runs.first().results.first().totalCodeFlowLocations() == 1) // with a shorter stack trace - } - - // internal - - private val mockExecutableId = Mockito.mock(ExecutableId::class.java, Mockito.RETURNS_DEEP_STUBS) - - private val mockUtExecution = Mockito.mock(UtSymbolicExecution::class.java, Mockito.RETURNS_DEEP_STUBS) - - private val testSet = UtMethodTestSet(mockExecutableId, listOf(mockUtExecution)) - - private fun mockUtMethodNames() { - Mockito.`when`(mockExecutableId.name).thenReturn("main") - Mockito.`when`(mockExecutableId.classId.name).thenReturn("Main") - } - - // constants - - private val sourceFindingEmpty = SourceFindingStrategyDefault( - sourceClassFqn = "", - sourceFilePath = "", - testsFilePath = "", - projectRootPath = "" - ) - - private val sourceFindingMain = SourceFindingStrategyDefault( - sourceClassFqn = "Main", - sourceFilePath = "src/Main.java", - testsFilePath = "test/MainTest.java", - projectRootPath = "." - ) - - private val generatedTestsCodeMain = """ - public void testMain_ThrowArithmeticException() { - /* This test fails because method [Main.main] produces [java.lang.ArithmeticException: / by zero] - Main.main(Main.java:15) */ - Main main = new Main(); - main.main(0); // shift for `startColumn` == 7 - } - """.trimIndent() - - private val generatedTestsCodePrivateMain = """ - public void testMain_ThrowArithmeticException() { - /* This test fails because method [Main.main] produces [java.lang.ArithmeticException: / by zero] - Main.main(Main.java:15) */ - Main main = new Main(); - // ... - mainMethod.invoke(main, mainMethodArguments); - } - """.trimIndent() - - private val sarifReportMain = - SarifReport(listOf(testSet), generatedTestsCodeMain, sourceFindingMain) - - private val sarifReportPrivateMain = - SarifReport(listOf(testSet), generatedTestsCodePrivateMain, sourceFindingMain) -} \ No newline at end of file diff --git a/utbot-testing/src/test/resources/junit-platform.properties b/utbot-testing/src/test/resources/junit-platform.properties deleted file mode 100644 index b059a65dc4..0000000000 --- a/utbot-testing/src/test/resources/junit-platform.properties +++ /dev/null @@ -1 +0,0 @@ -junit.jupiter.extensions.autodetection.enabled=true \ No newline at end of file diff --git a/utbot-testing/src/test/resources/log4j2.xml b/utbot-testing/src/test/resources/log4j2.xml deleted file mode 100644 index 11a2d0701c..0000000000 --- a/utbot-testing/src/test/resources/log4j2.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/utbot-testing/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/utbot-testing/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index ca6ee9cea8..0000000000 --- a/utbot-testing/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline \ No newline at end of file diff --git a/utbot-testing/src/test/resources/services/org.junit.jupiter.api.extension.Extension b/utbot-testing/src/test/resources/services/org.junit.jupiter.api.extension.Extension deleted file mode 100644 index 3885d45734..0000000000 --- a/utbot-testing/src/test/resources/services/org.junit.jupiter.api.extension.Extension +++ /dev/null @@ -1 +0,0 @@ -org.utbot.framework.JUnitSetup \ No newline at end of file From 0cf62383d1020363c1f3b7d50e9898799c0626f7 Mon Sep 17 00:00:00 2001 From: Denis Fokin Date: Thu, 10 Nov 2022 17:21:15 +0300 Subject: [PATCH 08/12] Enable testing module --- settings.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/settings.gradle.kts b/settings.gradle.kts index 4e30ca7d33..d892bb19e3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -36,6 +36,7 @@ include("utbot-gradle") include("utbot-maven") include("utbot-summary-tests") include("utbot-framework-test") +include("utbot-testing") include("utbot-rd") include("utbot-android-studio") From c1e524adc9f4040622c500b54b08cc5e75c5188f Mon Sep 17 00:00:00 2001 From: Denis Fokin Date: Fri, 11 Nov 2022 16:13:26 +0300 Subject: [PATCH 09/12] Redundant changes and Build Gradle --- gradle.properties | 8 ++-- utbot-framework-test/build.gradle | 4 +- .../examples/arrays/ArrayOfObjectsTest.kt | 8 +++- .../collections/CustomerExamplesTest.kt | 6 ++- .../examples/collections/ListsPart3Test.kt | 6 ++- .../examples/collections/MapEntrySetTest.kt | 7 +++- .../examples/collections/MapKeySetTest.kt | 8 +++- .../examples/collections/MapValuesTest.kt | 8 +++- .../examples/collections/MapsPart1Test.kt | 7 +++- .../examples/collections/OptionalsTest.kt | 7 +++- .../examples/collections/SetIteratorsTest.kt | 6 ++- .../utbot/examples/collections/SetsTest.kt | 7 +++- .../utbot/examples/controlflow/CyclesTest.kt | 8 +++- .../exceptions/ExceptionExamplesTest.kt | 6 ++- .../examples/math/OverflowAsErrorTest.kt | 6 ++- .../mixed/PrivateConstructorExampleTest.kt | 1 - .../utbot/examples/mixed/SimplifierTest.kt | 2 - .../mixed/StaticInitializerExampleTest.kt | 1 - .../mixed/StaticMethodExamplesTest.kt | 1 - .../utbot/examples/mock/ArgumentsMockTest.kt | 13 +++---- .../examples/mock/CommonMocksExampleTest.kt | 2 - .../org/utbot/examples/mock/FieldMockTest.kt | 6 ++- .../utbot/examples/mock/MockFinalClassTest.kt | 5 ++- .../org/utbot/examples/mock/MockRandomTest.kt | 10 ++++- .../mock/MockStaticFieldExampleTest.kt | 6 ++- .../mock/MockStaticMethodExampleTest.kt | 6 ++- .../examples/mock/StaticFieldMockTest.kt | 2 - .../examples/mock/model/FieldMockChecker.kt | 2 - .../mock/model/UseNetworkModelBasedTest.kt | 1 - .../objects/AnonymousClassesExampleTest.kt | 6 ++- .../examples/objects/ClassWithClassRefTest.kt | 6 ++- .../ObjectWithPrimitivesExampleTest.kt | 6 ++- .../objects/ObjectWithRefFieldsExampleTest.kt | 6 ++- .../ObjectWithStaticFieldsExampleTest.kt | 6 ++- .../examples/objects/PrivateFieldsTest.kt | 2 - .../objects/SimpleClassExampleTest.kt | 7 +++- .../SimpleClassMultiInstanceExampleTest.kt | 1 - .../examples/primitives/IntExamplesTest.kt | 1 - .../utbot/examples/stdlib/DateExampleTest.kt | 2 - .../examples/stream/BaseStreamExampleTest.kt | 19 +++++---- .../stream/DoubleStreamExampleTest.kt | 9 ++++- .../examples/stream/IntStreamExampleTest.kt | 9 ++++- .../examples/stream/LongStreamExampleTest.kt | 9 ++++- .../StreamsAsMethodResultExampleTest.kt | 2 - .../examples/strings/StringExamplesTest.kt | 9 ++++- .../examples/strings11/StringConcatTest.kt | 6 ++- .../structures/StandardStructuresTest.kt | 6 ++- .../SummaryArrayQuickSortExampleTest.kt | 1 - .../algorithms/SummaryReturnExampleTest.kt | 1 - .../SummaryListWrapperReturnsVoidTest.kt | 1 - .../controlflow/SummaryConditionsTest.kt | 1 - .../examples/controlflow/SummaryCycleTest.kt | 1 - .../examples/enums/ComplexEnumExampleTest.kt | 1 - .../SummaryExceptionClusteringExamplesTest.kt | 1 - .../exceptions/SummaryExceptionExampleTest.kt | 1 - .../examples/inner/SummaryInnerCallsTest.kt | 1 - .../examples/inner/SummaryNestedCallsTest.kt | 1 - .../structures/SummaryMinStackTest.kt | 1 - .../examples/ternary/SummaryTernaryTest.kt | 1 - .../test/kotlin/math/SummaryIntMathTest.kt | 1 - .../src/test/kotlin/math/SummaryOfMathTest.kt | 1 - utbot-testing/build.gradle | 39 +------------------ .../testing/TestCodeGeneratorPipeline.kt | 1 - 63 files changed, 197 insertions(+), 129 deletions(-) diff --git a/gradle.properties b/gradle.properties index 202ade54a2..dea2a357ce 100644 --- a/gradle.properties +++ b/gradle.properties @@ -64,9 +64,9 @@ shadowJarVersion=7.1.2 openblasVersion=0.3.10-1.5.4 arpackNgVersion=3.7.0-1.5.4 -org.gradle.daemon=false -org.gradle.parallel=false -org.gradle.jvmargs="-XX:MaxHeapSize=6144m" -kotlin.compiler.execution.strategy=in-process +#org.gradle.daemon=false +#org.gradle.parallel=false +#org.gradle.jvmargs="-XX:MaxHeapSize=6144m" +#kotlin.compiler.execution.strategy=in-process org.gradle.caching=false \ No newline at end of file diff --git a/utbot-framework-test/build.gradle b/utbot-framework-test/build.gradle index 00590c6dde..b42815c1a7 100644 --- a/utbot-framework-test/build.gradle +++ b/utbot-framework-test/build.gradle @@ -49,8 +49,8 @@ dependencies { // To use JUnit4, comment out JUnit5 and uncomment JUnit4 dependencies here. Please also check "test" section // testImplementation group: 'junit', name: 'junit', version: '4.13.1' - implementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.8.1' - implementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.1' + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.8.1' + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.1' // used for testing code generation testImplementation group: 'commons-io', name: 'commons-io', version: commonsIoVersion diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt index d82da01587..a24d85220f 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/arrays/ArrayOfObjectsTest.kt @@ -4,7 +4,13 @@ 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.testing.* +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast +import org.utbot.testing.between +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException // TODO failed Kotlin compilation SAT-1332 internal class ArrayOfObjectsTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt index ffbed5d177..0ad601e153 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt @@ -5,7 +5,11 @@ import org.utbot.framework.plugin.api.FieldId import org.utbot.framework.plugin.api.UtConcreteValue import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.testing.* +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.TestExecution +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber internal class CustomerExamplesTest: UtValueTestCaseChecker( testClass = CustomerExamples::class, 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 54d6fa13b8..dc0fda4984 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,7 +5,11 @@ 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.testing.* +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.between +import org.utbot.testing.isException // TODO failed Kotlin compilation SAT-1332 internal class ListsPart3Test : UtValueTestCaseChecker( 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 7cf2352a81..4c2bd5556d 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 @@ -5,7 +5,12 @@ 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.testing.* +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.between +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException // TODO failed Kotlin compilation SAT-1332 class MapEntrySetTest : UtValueTestCaseChecker( 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 64ea3ec835..5ca5900240 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 @@ -6,7 +6,13 @@ import org.utbot.testcheckers.eq import org.utbot.testcheckers.ge import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete import org.utbot.testcheckers.withoutMinimization -import org.utbot.testing.* +import org.utbot.testing.AtLeast +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.between +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException // TODO failed Kotlin compilation SAT-1332 class MapKeySetTest : UtValueTestCaseChecker( 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 935b2e0fe1..69b05b5740 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 @@ -4,7 +4,13 @@ import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.ge import org.utbot.testcheckers.withoutMinimization -import org.utbot.testing.* +import org.utbot.testing.AtLeast +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.between +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException // TODO failed Kotlin compilation SAT-1332 class MapValuesTest : UtValueTestCaseChecker( 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 a228364a3d..7dd3191123 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 @@ -9,7 +9,12 @@ import org.utbot.testcheckers.ge import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete import org.utbot.testcheckers.withoutConcrete import org.utbot.testcheckers.withoutMinimization -import org.utbot.testing.* +import org.utbot.testing.AtLeast +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.between +import org.utbot.testing.ignoreExecutionsNumber // TODO failed Kotlin compilation ($ in names, generics) SAT-1220 SAT-1332 internal class MapsPart1Test : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt index 47834d270c..e998fd27ad 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/OptionalsTest.kt @@ -3,7 +3,12 @@ package org.utbot.examples.collections import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.testing.* +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.between +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException import java.util.* class OptionalsTest : UtValueTestCaseChecker( 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 2d741c6158..4d7d7f40e0 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 @@ -3,7 +3,11 @@ package org.utbot.examples.collections import org.utbot.framework.plugin.api.CodegenLanguage import org.junit.jupiter.api.Test import org.utbot.testcheckers.ge -import org.utbot.testing.* +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.between +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException // TODO failed Kotlin compilation SAT-1332 class SetIteratorsTest : UtValueTestCaseChecker( 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 831d0fe064..335c0088e7 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 @@ -7,7 +7,12 @@ import org.utbot.testcheckers.eq import org.utbot.testcheckers.ge import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete import org.utbot.testcheckers.withoutMinimization -import org.utbot.testing.* +import org.utbot.testing.AtLeast +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.between +import org.utbot.testing.ignoreExecutionsNumber // TODO failed Kotlin compilation SAT-1332 internal class SetsTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt index 6ba747d945..1ec3c1ed73 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/controlflow/CyclesTest.kt @@ -6,7 +6,13 @@ import org.utbot.framework.plugin.api.DocRegularStmt import org.utbot.framework.plugin.api.DocStatement import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.testing.* +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast +import org.utbot.testing.between +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException +import org.utbot.testing.keyContain +import org.utbot.testing.keyMatch internal class CyclesTest : UtValueTestCaseChecker(testClass = Cycles::class) { @Test 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 44bc2c47e6..3895c2eafc 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 @@ -4,7 +4,11 @@ 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.testing.* +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException internal class ExceptionExamplesTest : UtValueTestCaseChecker( testClass = ExceptionExamples::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt index 09b547714c..ad99f2e501 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/math/OverflowAsErrorTest.kt @@ -7,7 +7,11 @@ import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq import org.utbot.testcheckers.withSolverTimeoutInMillis import org.utbot.testcheckers.withTreatingOverflowAsError -import org.utbot.testing.* +import org.utbot.testing.AtLeast +import org.utbot.testing.Compilation +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException import kotlin.math.floor import kotlin.math.sqrt diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt index 26e091ff64..bb074326cb 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt @@ -3,7 +3,6 @@ package org.utbot.examples.mixed import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.testing.Compilation import org.utbot.testing.DoNotCalculate import org.utbot.testing.UtValueTestCaseChecker diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/SimplifierTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/SimplifierTest.kt index 0092e68eab..0c6b13aacd 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/SimplifierTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/SimplifierTest.kt @@ -1,7 +1,5 @@ package org.utbot.examples.mixed - - import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq import org.utbot.testing.DoNotCalculate diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticInitializerExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticInitializerExampleTest.kt index e5b15f10fa..fd31bb20fe 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticInitializerExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticInitializerExampleTest.kt @@ -3,7 +3,6 @@ package org.utbot.examples.mixed import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.examples.StaticInitializerExample - import org.utbot.testcheckers.eq import org.utbot.testing.UtValueTestCaseChecker diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt index baab044c23..7e71562964 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/StaticMethodExamplesTest.kt @@ -1,6 +1,5 @@ package org.utbot.examples.mixed - import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq import org.utbot.testing.UtValueTestCaseChecker diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt index 74663fca45..00c1bcfd13 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/ArgumentsMockTest.kt @@ -1,18 +1,17 @@ package org.utbot.examples.mock - - - - import org.utbot.examples.mock.provider.Provider import org.utbot.examples.mock.service.impl.ExampleClass import org.utbot.examples.mock.service.impl.ServiceWithArguments - - import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.testing.* +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.between +import org.utbot.testing.isParameter +import org.utbot.testing.mocksMethod +import org.utbot.testing.value internal class ArgumentsMockTest : UtValueTestCaseChecker(testClass = ServiceWithArguments::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt index 4d2f841b25..74054cfe05 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/CommonMocksExampleTest.kt @@ -1,7 +1,5 @@ package org.utbot.examples.mock - - import org.utbot.framework.plugin.api.MockStrategyApi import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt index 4ce60d4a49..f7c8a16741 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/FieldMockTest.kt @@ -7,7 +7,11 @@ import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.testing.* +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.between +import org.utbot.testing.mocksMethod +import org.utbot.testing.value internal class FieldMockTest : UtValueTestCaseChecker( testClass = ServiceWithField::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockFinalClassTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockFinalClassTest.kt index e3a8707bb7..9513d520d7 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockFinalClassTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockFinalClassTest.kt @@ -5,7 +5,10 @@ import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_CLASSES import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.ge -import org.utbot.testing.* +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.singleMock +import org.utbot.testing.value internal class MockFinalClassTest : UtValueTestCaseChecker( testClass = MockFinalClassExample::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt index 5e80898dac..15f2fbd08c 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockRandomTest.kt @@ -6,7 +6,15 @@ import java.util.Random import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.testing.* +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.TestExecution +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isParameter +import org.utbot.testing.mockValues +import org.utbot.testing.mocksMethod +import org.utbot.testing.singleMock +import org.utbot.testing.value // TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 internal class MockRandomTest : UtValueTestCaseChecker( 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 2c1188af36..18bdabb472 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 @@ -8,7 +8,11 @@ import kotlin.reflect.KClass import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq import org.utbot.testcheckers.withoutConcrete -import org.utbot.testing.* +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.singleMock +import org.utbot.testing.singleMockOrNull +import org.utbot.testing.value internal class MockStaticFieldExampleTest : UtValueTestCaseChecker(testClass = MockStaticFieldExample::class) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt index 59a4e58e79..0d1ee02a73 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockStaticMethodExampleTest.kt @@ -8,7 +8,11 @@ import org.utbot.framework.util.singleValue import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.testing.* +import org.utbot.testing.CodeGeneration +import org.utbot.testing.Compilation +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.TestExecution +import org.utbot.testing.UtValueTestCaseChecker // TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 internal class MockStaticMethodExampleTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt index db1b4e8ee9..17a43e6c88 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt @@ -3,8 +3,6 @@ package org.utbot.examples.mock import org.utbot.examples.mock.provider.Provider import org.utbot.examples.mock.service.impl.ExampleClass import org.utbot.examples.mock.service.impl.ServiceWithStaticField - - import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt index 39dbef6ef2..07fb1ae337 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/FieldMockChecker.kt @@ -2,13 +2,11 @@ package org.utbot.examples.mock.model import org.utbot.examples.mock.provider.impl.ProviderImpl import org.utbot.examples.mock.service.impl.ServiceWithField - import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.isNotNull import org.utbot.framework.plugin.api.isNull import org.junit.jupiter.api.Test - import org.utbot.testcheckers.eq import org.utbot.testing.UtModelTestCaseChecker import org.utbot.testing.primitiveValue diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/UseNetworkModelBasedTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/UseNetworkModelBasedTest.kt index dcdd58e4d0..b405533f6c 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/UseNetworkModelBasedTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/model/UseNetworkModelBasedTest.kt @@ -1,6 +1,5 @@ package org.utbot.examples.mock.model - import org.utbot.examples.mock.UseNetwork import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtCompositeModel diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt index 4aa14e715c..de11689275 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/AnonymousClassesExampleTest.kt @@ -3,7 +3,11 @@ package org.utbot.examples.objects import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.testing.* +import org.utbot.testing.Compilation +import org.utbot.testing.Full +import org.utbot.testing.TestExecution +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException class AnonymousClassesExampleTest : UtValueTestCaseChecker( testClass = AnonymousClassesExample::class, 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 87fd61f6cc..9b6bb39343 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 @@ -4,7 +4,11 @@ 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.testing.* +import org.utbot.testing.CodeGeneration +import org.utbot.testing.Compilation +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.isException // TODO Kotlin compilation SAT-1332 // Code generation executions fail due we cannot analyze strings properly for now diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt index f8f3d3ff3a..c712d08715 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithPrimitivesExampleTest.kt @@ -3,7 +3,11 @@ package org.utbot.examples.objects import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.testing.* +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException internal class ObjectWithPrimitivesExampleTest : UtValueTestCaseChecker(testClass = ObjectWithPrimitivesExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt index 2f745fbe64..af99f58ec1 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithRefFieldsExampleTest.kt @@ -2,7 +2,11 @@ package org.utbot.examples.objects import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.testing.* +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException internal class ObjectWithRefFieldsExampleTest : UtValueTestCaseChecker(testClass = ObjectWithRefFieldExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt index 79d00425b1..dcd1e9955a 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/ObjectWithStaticFieldsExampleTest.kt @@ -2,7 +2,11 @@ package org.utbot.examples.objects import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.testing.* +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.findByName +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.singleValue internal class ObjectWithStaticFieldsExampleTest : UtValueTestCaseChecker(testClass = ObjectWithStaticFieldsExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt index 985bc1ee4e..3f6c4f7f18 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt @@ -1,7 +1,5 @@ package org.utbot.examples.objects - - import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq import org.utbot.testing.UtValueTestCaseChecker diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt index 7008599b8b..c74f263988 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassExampleTest.kt @@ -6,7 +6,12 @@ import org.utbot.framework.plugin.api.DocRegularStmt import org.utbot.framework.plugin.api.DocStatement import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.testing.* +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.between +import org.utbot.testing.isException +import org.utbot.testing.keyContain +import org.utbot.testing.keyMatch internal class SimpleClassExampleTest : UtValueTestCaseChecker(testClass = SimpleClassExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassMultiInstanceExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassMultiInstanceExampleTest.kt index d7d427cd5e..7ba04d569a 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassMultiInstanceExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/SimpleClassMultiInstanceExampleTest.kt @@ -1,7 +1,6 @@ package org.utbot.examples.objects import org.junit.Test -import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq import org.utbot.testing.DoNotCalculate import org.utbot.testing.UtValueTestCaseChecker diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt index bded155112..baa6ded345 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/primitives/IntExamplesTest.kt @@ -2,7 +2,6 @@ package org.utbot.examples.primitives import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test - import org.utbot.testcheckers.eq import org.utbot.testing.UtValueTestCaseChecker diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt index 9b62b55953..af887d6c4c 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stdlib/DateExampleTest.kt @@ -3,8 +3,6 @@ package org.utbot.examples.stdlib import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test - - import org.utbot.testcheckers.eq import org.utbot.testcheckers.withUsingReflectionForMaximizingCoverage import org.utbot.testing.UtValueTestCaseChecker 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 a34e0d7f5a..700f39ff83 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 @@ -3,19 +3,18 @@ package org.utbot.examples.stream import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Tag 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.testing.* - - +import org.utbot.testing.AtLeast +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.Full +import org.utbot.testing.FullWithAssumptions +import org.utbot.testing.StaticsType +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException import java.util.Optional import java.util.stream.Stream import kotlin.streams.toList 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 65a158ff43..505238faa5 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 @@ -6,8 +6,13 @@ 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.testing.* - +import org.utbot.testing.AtLeast +import org.utbot.testing.CodeGeneration +import org.utbot.testing.Full +import org.utbot.testing.FullWithAssumptions +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException import java.util.OptionalDouble import java.util.stream.DoubleStream import kotlin.streams.toList 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 5549d81214..55cb1ff1f4 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 @@ -6,8 +6,13 @@ 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.testing.* - +import org.utbot.testing.AtLeast +import org.utbot.testing.CodeGeneration +import org.utbot.testing.Full +import org.utbot.testing.FullWithAssumptions +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException import java.util.OptionalDouble import java.util.OptionalInt import java.util.stream.IntStream 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 522c0bca7f..9f41fe552d 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 @@ -6,8 +6,13 @@ 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.testing.* - +import org.utbot.testing.AtLeast +import org.utbot.testing.CodeGeneration +import org.utbot.testing.Full +import org.utbot.testing.FullWithAssumptions +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException import java.util.OptionalDouble import java.util.OptionalLong import java.util.stream.LongStream diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt index 5273c8321f..a6ca53482e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt @@ -8,8 +8,6 @@ import org.utbot.testing.CodeGeneration import org.utbot.testing.FullWithAssumptions import org.utbot.testing.UtValueTestCaseChecker import org.utbot.testing.isException - - import kotlin.streams.toList // TODO 1 instruction is always uncovered https://github.com/UnitTestBot/UTBotJava/issues/193 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 35d029142c..75f58922ce 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 @@ -8,7 +8,14 @@ import org.utbot.testcheckers.ge import org.utbot.testcheckers.withPushingStateFromPathSelectorForConcrete import org.utbot.testcheckers.withSolverTimeoutInMillis import org.utbot.testcheckers.withoutMinimization -import org.utbot.testing.* +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast +import org.utbot.testing.between +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException +import org.utbot.testing.keyMatch internal class StringExamplesTest : UtValueTestCaseChecker( testClass = StringExamples::class, 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 e1bf478b25..ec0fe35670 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 @@ -4,7 +4,11 @@ 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.testing.* +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException class StringConcatTest : UtValueTestCaseChecker( testClass = StringConcat::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt index 14be6af6d6..1a600e0c13 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/structures/StandardStructuresTest.kt @@ -10,7 +10,11 @@ import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq -import org.utbot.testing.* +import org.utbot.testing.CodeGeneration +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.keyContain +import org.utbot.testing.keyMatch internal class StandardStructuresTest : UtValueTestCaseChecker( testClass = StandardStructures::class, diff --git a/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryArrayQuickSortExampleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryArrayQuickSortExampleTest.kt index 4a235f7680..45c4717763 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryArrayQuickSortExampleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryArrayQuickSortExampleTest.kt @@ -4,7 +4,6 @@ import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test import org.utbot.examples.algorithms.ArraysQuickSort - import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtClusterInfo import org.utbot.testing.DoNotCalculate diff --git a/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt index fe7db953eb..ac60b7d8ea 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt @@ -3,7 +3,6 @@ package examples.algorithms import examples.SummaryTestCaseGeneratorTest import org.utbot.examples.algorithms.ReturnExample import org.junit.jupiter.api.Test - import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.testing.DoNotCalculate diff --git a/utbot-summary-tests/src/test/kotlin/examples/collections/SummaryListWrapperReturnsVoidTest.kt b/utbot-summary-tests/src/test/kotlin/examples/collections/SummaryListWrapperReturnsVoidTest.kt index c487269439..bfcd70b2d7 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/collections/SummaryListWrapperReturnsVoidTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/collections/SummaryListWrapperReturnsVoidTest.kt @@ -2,7 +2,6 @@ package examples.collections import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test - import org.utbot.examples.collections.ListWrapperReturnsVoidExample import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.testing.DoNotCalculate diff --git a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryConditionsTest.kt b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryConditionsTest.kt index ab0c150599..8cc88851c3 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryConditionsTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryConditionsTest.kt @@ -5,7 +5,6 @@ import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.utbot.testing.DoNotCalculate - import org.utbot.examples.controlflow.Conditions import org.utbot.framework.plugin.api.MockStrategyApi diff --git a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt index a736946fbd..63c2b84457 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt @@ -2,7 +2,6 @@ package examples.controlflow import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test - import org.utbot.examples.controlflow.Cycles import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.testing.DoNotCalculate diff --git a/utbot-summary-tests/src/test/kotlin/examples/enums/ComplexEnumExampleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/enums/ComplexEnumExampleTest.kt index a7730d6f97..5d737b81c5 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/enums/ComplexEnumExampleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/enums/ComplexEnumExampleTest.kt @@ -8,7 +8,6 @@ import org.utbot.examples.enums.ComplexEnumExamples import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.testing.DoNotCalculate - @ExtendWith(CustomJavaDocTagsEnabler::class) class ComplexEnumExampleTest : SummaryTestCaseGeneratorTest( ComplexEnumExamples::class diff --git a/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt b/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt index ed045c9c6e..4ad6bfc6ff 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionClusteringExamplesTest.kt @@ -5,7 +5,6 @@ import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.utbot.testing.DoNotCalculate - import org.utbot.examples.exceptions.ExceptionClusteringExamples import org.utbot.framework.plugin.api.MockStrategyApi diff --git a/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionExampleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionExampleTest.kt index 77293a24c7..79d815a72d 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionExampleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/exceptions/SummaryExceptionExampleTest.kt @@ -8,7 +8,6 @@ import org.utbot.examples.exceptions.ExceptionExamples import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.testing.DoNotCalculate - @ExtendWith(CustomJavaDocTagsEnabler::class) class SummaryExceptionExampleTest : SummaryTestCaseGeneratorTest( ExceptionExamples::class diff --git a/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt index a40490a429..f992dd73b1 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt @@ -2,7 +2,6 @@ package examples.inner import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test - import org.utbot.examples.inner.InnerCalls import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.testing.DoNotCalculate diff --git a/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt index ed7edf7ca2..93216593e4 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt @@ -2,7 +2,6 @@ package examples.inner import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test - import org.utbot.examples.inner.NestedCalls import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.testing.DoNotCalculate diff --git a/utbot-summary-tests/src/test/kotlin/examples/structures/SummaryMinStackTest.kt b/utbot-summary-tests/src/test/kotlin/examples/structures/SummaryMinStackTest.kt index 12031c45cb..82d06160ef 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/structures/SummaryMinStackTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/structures/SummaryMinStackTest.kt @@ -4,7 +4,6 @@ import examples.CustomJavaDocTagsEnabler import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith - import org.utbot.examples.structures.MinStack import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.testing.DoNotCalculate diff --git a/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernaryTest.kt b/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernaryTest.kt index 817f14a782..f6ff7f93da 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernaryTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernaryTest.kt @@ -2,7 +2,6 @@ package examples.ternary import examples.SummaryTestCaseGeneratorTest import org.junit.jupiter.api.Test - import org.utbot.examples.ternary.Ternary import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.testing.DoNotCalculate diff --git a/utbot-summary-tests/src/test/kotlin/math/SummaryIntMathTest.kt b/utbot-summary-tests/src/test/kotlin/math/SummaryIntMathTest.kt index 14dd5cac5f..f7685e4285 100644 --- a/utbot-summary-tests/src/test/kotlin/math/SummaryIntMathTest.kt +++ b/utbot-summary-tests/src/test/kotlin/math/SummaryIntMathTest.kt @@ -3,7 +3,6 @@ package math import examples.SummaryTestCaseGeneratorTest import guava.examples.math.IntMath import org.junit.jupiter.api.Test - import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtClusterInfo import org.utbot.testing.DoNotCalculate diff --git a/utbot-summary-tests/src/test/kotlin/math/SummaryOfMathTest.kt b/utbot-summary-tests/src/test/kotlin/math/SummaryOfMathTest.kt index c4f0eccc08..ca96cad820 100644 --- a/utbot-summary-tests/src/test/kotlin/math/SummaryOfMathTest.kt +++ b/utbot-summary-tests/src/test/kotlin/math/SummaryOfMathTest.kt @@ -4,7 +4,6 @@ import examples.SummaryTestCaseGeneratorTest import guava.examples.math.Stats import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test - import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtClusterInfo import org.utbot.testing.DoNotCalculate diff --git a/utbot-testing/build.gradle b/utbot-testing/build.gradle index dbc4955144..50c4a6f432 100644 --- a/utbot-testing/build.gradle +++ b/utbot-testing/build.gradle @@ -5,21 +5,6 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { } } -tasks.withType(JavaCompile) { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -} - -repositories { - flatDir { - dirs 'dist' - } -} - -configurations { - z3native -} - dependencies { api project(':utbot-framework-api') @@ -63,26 +48,4 @@ dependencies { testImplementation group: 'org.mockito', name: 'mockito-inline', version: mockitoInlineVersion testImplementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: log4j2Version - - z3native group: 'com.microsoft.z3', name: 'z3-native-win64', version: z3Version, ext: 'zip' - z3native group: 'com.microsoft.z3', name: 'z3-native-linux64', version: z3Version, ext: 'zip' - z3native group: 'com.microsoft.z3', name: 'z3-native-osx', version: z3Version, ext: 'zip' -} - - -test { - - minHeapSize = "128m" - maxHeapSize = "2048m" - - jvmArgs '-XX:MaxHeapSize=2048m' - - // To use JUnit4, comment out useJUnitPlatform and uncomment useJUnit. Please also check "dependencies" section - //useJUnit() - useJUnitPlatform() { - excludeTags 'slow', 'IntegrationTest' - } - if (System.getProperty('DEBUG', 'false') == 'true') { - jvmArgs '-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9009' - } -} +} \ No newline at end of file diff --git a/utbot-testing/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt b/utbot-testing/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt index 0596f092ad..4da5ba2975 100644 --- a/utbot-testing/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt +++ b/utbot-testing/src/main/kotlin/org/utbot/testing/TestCodeGeneratorPipeline.kt @@ -22,7 +22,6 @@ import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.description import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.withUtContext -import org.utbot.testing.TestFrameworkConfiguration import java.io.File import java.nio.file.Path import kotlin.reflect.KClass From d5e67a87e835c89a9596fe67a640012fa4fef574 Mon Sep 17 00:00:00 2001 From: Denis Fokin Date: Fri, 11 Nov 2022 16:49:53 +0300 Subject: [PATCH 10/12] Bring back server settings --- gradle.properties | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index dea2a357ce..202ade54a2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -64,9 +64,9 @@ shadowJarVersion=7.1.2 openblasVersion=0.3.10-1.5.4 arpackNgVersion=3.7.0-1.5.4 -#org.gradle.daemon=false -#org.gradle.parallel=false -#org.gradle.jvmargs="-XX:MaxHeapSize=6144m" -#kotlin.compiler.execution.strategy=in-process +org.gradle.daemon=false +org.gradle.parallel=false +org.gradle.jvmargs="-XX:MaxHeapSize=6144m" +kotlin.compiler.execution.strategy=in-process org.gradle.caching=false \ No newline at end of file From d1415775c3e757c3244401b316ad9321cea31d27 Mon Sep 17 00:00:00 2001 From: Denis Fokin Date: Fri, 11 Nov 2022 17:07:41 +0300 Subject: [PATCH 11/12] Even more exports --- .../examples/algorithms/CorrectBracketSequencesTest.kt | 6 +++++- .../test/kotlin/org/utbot/examples/algorithms/SortTest.kt | 6 +++++- .../utbot/examples/mock/MockReturnObjectExampleTest.kt | 7 ++++++- .../kotlin/org/utbot/examples/recursion/RecursionTest.kt | 8 +++++++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt index 1326ce4d05..30214225cd 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/CorrectBracketSequencesTest.kt @@ -8,7 +8,11 @@ import org.junit.jupiter.api.Test import org.utbot.examples.algorithms.CorrectBracketSequences.isBracket import org.utbot.examples.algorithms.CorrectBracketSequences.isOpen import org.utbot.testcheckers.eq -import org.utbot.testing.* +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException +import org.utbot.testing.keyMatch internal class CorrectBracketSequencesTest : UtValueTestCaseChecker( testClass = CorrectBracketSequences::class, diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt index b999cddae3..4d5a8fb2ba 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/algorithms/SortTest.kt @@ -8,7 +8,11 @@ import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq import org.utbot.testcheckers.ge -import org.utbot.testing.* +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.ignoreExecutionsNumber +import org.utbot.testing.isException +import org.utbot.testing.keyMatch // TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 internal class SortTest : UtValueTestCaseChecker( diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockReturnObjectExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockReturnObjectExampleTest.kt index 3120626749..51cd5f279b 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockReturnObjectExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/MockReturnObjectExampleTest.kt @@ -6,7 +6,12 @@ import org.utbot.examples.mock.others.Locator import org.utbot.framework.plugin.api.MockStrategyApi.OTHER_PACKAGES import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq -import org.utbot.testing.* +import org.utbot.testing.DoNotCalculate +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.mockValue +import org.utbot.testing.singleMock +import org.utbot.testing.singleMockOrNull +import org.utbot.testing.value internal class MockReturnObjectExampleTest : UtValueTestCaseChecker(testClass = MockReturnObjectExample::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt index cb5c500528..1bcc154443 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/recursion/RecursionTest.kt @@ -10,7 +10,13 @@ import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq import org.utbot.testcheckers.ge -import org.utbot.testing.* +import org.utbot.testing.CodeGeneration +import org.utbot.testing.UtValueTestCaseChecker +import org.utbot.testing.atLeast +import org.utbot.testing.between +import org.utbot.testing.isException +import org.utbot.testing.keyContain +import org.utbot.testing.keyMatch // TODO Kotlin mocks generics https://github.com/UnitTestBot/UTBotJava/issues/88 internal class RecursionTest : UtValueTestCaseChecker( From 5c17cd0bbd890ecaf05027418164c77f2ac4abf3 Mon Sep 17 00:00:00 2001 From: Denis Fokin Date: Fri, 11 Nov 2022 18:14:54 +0300 Subject: [PATCH 12/12] Double empty lines and gradle deps --- .../test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt | 1 - .../test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt | 1 - .../src/test/kotlin/examples/structures/SummaryMinStackTest.kt | 1 - .../src/test/kotlin/examples/ternary/SummaryTernaryTest.kt | 1 - utbot-summary-tests/src/test/kotlin/math/SummaryIntMathTest.kt | 1 - utbot-summary/build.gradle.kts | 1 - 6 files changed, 6 deletions(-) diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt index 17a43e6c88..e963a1e6b6 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mock/StaticFieldMockTest.kt @@ -10,7 +10,6 @@ import org.utbot.testing.DoNotCalculate import org.utbot.testing.UtValueTestCaseChecker import org.utbot.testing.mocksMethod import org.utbot.testing.value - internal class StaticFieldMockTest : UtValueTestCaseChecker(testClass = ServiceWithStaticField::class) { @Test diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt index 3f6c4f7f18..a32d8036cb 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/objects/PrivateFieldsTest.kt @@ -4,7 +4,6 @@ import org.junit.jupiter.api.Test import org.utbot.testcheckers.eq import org.utbot.testing.UtValueTestCaseChecker import org.utbot.testing.isException - internal class PrivateFieldsTest : UtValueTestCaseChecker(testClass = PrivateFields::class) { @Test fun testAccessWithGetter() { diff --git a/utbot-summary-tests/src/test/kotlin/examples/structures/SummaryMinStackTest.kt b/utbot-summary-tests/src/test/kotlin/examples/structures/SummaryMinStackTest.kt index 82d06160ef..e5061bc8e8 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/structures/SummaryMinStackTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/structures/SummaryMinStackTest.kt @@ -7,7 +7,6 @@ import org.junit.jupiter.api.extension.ExtendWith import org.utbot.examples.structures.MinStack import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.testing.DoNotCalculate - @ExtendWith(CustomJavaDocTagsEnabler::class) class SummaryMinStackTest : SummaryTestCaseGeneratorTest( MinStack::class diff --git a/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernaryTest.kt b/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernaryTest.kt index f6ff7f93da..03e11cdf83 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernaryTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernaryTest.kt @@ -5,7 +5,6 @@ import org.junit.jupiter.api.Test import org.utbot.examples.ternary.Ternary import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.testing.DoNotCalculate - class SummaryTernaryTest : SummaryTestCaseGeneratorTest( Ternary::class, ) { diff --git a/utbot-summary-tests/src/test/kotlin/math/SummaryIntMathTest.kt b/utbot-summary-tests/src/test/kotlin/math/SummaryIntMathTest.kt index f7685e4285..a5e4319e12 100644 --- a/utbot-summary-tests/src/test/kotlin/math/SummaryIntMathTest.kt +++ b/utbot-summary-tests/src/test/kotlin/math/SummaryIntMathTest.kt @@ -6,7 +6,6 @@ import org.junit.jupiter.api.Test import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtClusterInfo import org.utbot.testing.DoNotCalculate - class SummaryIntMathTest : SummaryTestCaseGeneratorTest( IntMath::class, ) { diff --git a/utbot-summary/build.gradle.kts b/utbot-summary/build.gradle.kts index 736c4e7fb8..e087927bbb 100644 --- a/utbot-summary/build.gradle.kts +++ b/utbot-summary/build.gradle.kts @@ -17,5 +17,4 @@ dependencies { implementation("com.github.javaparser:javaparser-core:3.22.1") testImplementation("org.mockito:mockito-core:4.2.0") testImplementation("org.junit.jupiter:junit-jupiter:$junit5Version") - testImplementation(project(":utbot-testing")) }