Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Damtev/symbolic tests fixes #1253

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ inline fun <reified T> withSolverTimeoutInMillis(timeoutInMillis: Int, block: ()
}
}

inline fun <reified T> withoutConcrete(block: () -> T): T {
inline fun <reified T> withConcrete(useConcreteExecution: Boolean, block: () -> T): T {
val prev = UtSettings.useConcreteExecution
UtSettings.useConcreteExecution = false
UtSettings.useConcreteExecution = useConcreteExecution
try {
return block()
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test
import org.utbot.tests.infrastructure.DoNotCalculate
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
import org.utbot.testcheckers.eq
import org.utbot.testcheckers.withConcrete

/**
* Tests for Lombok annotations
Expand All @@ -15,11 +16,13 @@ import org.utbot.testcheckers.eq
internal class EnumWithAnnotationsTest : UtValueTestCaseChecker(testClass = EnumWithAnnotations::class) {
@Test
fun testGetterWithAnnotations() {
check(
EnumWithAnnotations::getConstant,
eq(1),
{ r -> r == "Constant_1" },
coverage = DoNotCalculate,
)
withConcrete(useConcreteExecution = true) { // TODO https://github.com/UnitTestBot/UTBotJava/issues/1249
check(
EnumWithAnnotations::getConstant,
eq(1),
{ r -> r == "Constant_1" },
coverage = DoNotCalculate,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ package org.utbot.examples.annotations.lombok
import org.junit.jupiter.api.Test
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
import org.utbot.testcheckers.eq
import org.utbot.testcheckers.withConcrete

internal class EnumWithoutAnnotationsTest : UtValueTestCaseChecker(testClass = EnumWithoutAnnotations::class) {
@Test
fun testGetterWithoutAnnotations() {
check(
EnumWithoutAnnotations::getConstant,
eq(1),
{ r -> r == "Constant_1" },
)
withConcrete(useConcreteExecution = true) { // TODO https://github.com/UnitTestBot/UTBotJava/issues/1249
check(
EnumWithoutAnnotations::getConstant,
eq(1),
{ r -> r == "Constant_1" },
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.utbot.testcheckers.eq
import org.utbot.testcheckers.ge
import org.utbot.testcheckers.withConcrete
import org.utbot.tests.infrastructure.CodeGeneration

// TODO failed Kotlin compilation SAT-1332
Expand Down Expand Up @@ -278,46 +279,48 @@ internal class InstanceOfExampleTest : UtValueTestCaseChecker(
@Test
//TODO: fails without concrete execution
fun testComplicatedInstanceOf() {
check(
InstanceOfExample::complicatedInstanceOf,
eq(8),
{ _, index, _, result -> index < 0 && result == null },
{ _, index, _, result -> index > 2 && result == null },
{ objects, index, _, result -> index in 0..2 && objects == null && result == null },
{ objects, index, _, result -> index in 0..2 && objects != null && objects.size < index + 2 && result == null },
{ objects, index, objectExample, result ->
require(objects != null && result != null && objectExample is CastClassFirstSucc)

val sizeConstraint = index in 0..2 && objects.size >= index + 2
val resultConstraint = result[index].x == objectExample.z

sizeConstraint && resultConstraint
},
{ objects, index, objectExample, _ ->
index in 0..2 && objects != null && objects.size >= index + 2 && objectExample == null
},
{ objects, index, objectExample, result ->
require(objects != null && result != null && result[index] is CastClassSecondSucc)

val sizeConstraint = index in 0..2 && objects.size >= index + 2
val typeConstraint = objectExample !is CastClassFirstSucc && result[index] is CastClassSecondSucc
val resultConstraint = result[index].x == result[index].foo()

sizeConstraint && typeConstraint && resultConstraint
},
{ objects, index, objectExample, result ->
require(objects != null && result != null)

val sizeConstraint = index in 0..2 && objects.size >= index + 2
val objectExampleConstraint = objectExample !is CastClassFirstSucc
val resultTypeConstraint = result[index] !is CastClassFirstSucc && result[index] !is CastClassSecondSucc
val typeConstraint = objectExampleConstraint && resultTypeConstraint
val resultConstraint = result[index].x == result[index].foo()

sizeConstraint && typeConstraint && resultConstraint
},
coverage = DoNotCalculate
)
withConcrete(useConcreteExecution = true) {
check(
InstanceOfExample::complicatedInstanceOf,
eq(8),
{ _, index, _, result -> index < 0 && result == null },
{ _, index, _, result -> index > 2 && result == null },
{ objects, index, _, result -> index in 0..2 && objects == null && result == null },
{ objects, index, _, result -> index in 0..2 && objects != null && objects.size < index + 2 && result == null },
{ objects, index, objectExample, result ->
require(objects != null && result != null && objectExample is CastClassFirstSucc)

val sizeConstraint = index in 0..2 && objects.size >= index + 2
val resultConstraint = result[index].x == objectExample.z

sizeConstraint && resultConstraint
},
{ objects, index, objectExample, _ ->
index in 0..2 && objects != null && objects.size >= index + 2 && objectExample == null
},
{ objects, index, objectExample, result ->
require(objects != null && result != null && result[index] is CastClassSecondSucc)

val sizeConstraint = index in 0..2 && objects.size >= index + 2
val typeConstraint = objectExample !is CastClassFirstSucc && result[index] is CastClassSecondSucc
val resultConstraint = result[index].x == result[index].foo()

sizeConstraint && typeConstraint && resultConstraint
},
{ objects, index, objectExample, result ->
require(objects != null && result != null)

val sizeConstraint = index in 0..2 && objects.size >= index + 2
val objectExampleConstraint = objectExample !is CastClassFirstSucc
val resultTypeConstraint =
result[index] !is CastClassFirstSucc && result[index] !is CastClassSecondSucc
val typeConstraint = objectExampleConstraint && resultTypeConstraint
val resultConstraint = result[index].x == result[index].foo()

sizeConstraint && typeConstraint && resultConstraint
},
)
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import org.utbot.examples.mock.MockRandomExamples
import kotlin.reflect.full.functions
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.utbot.testcheckers.withoutConcrete

internal class CodegenExampleTest : UtValueTestCaseChecker(testClass = CodegenExample::class) {
@Test
fun firstExampleTest() {
withoutConcrete {
checkAllCombinations(
CodegenExample::firstExample,
)
}
checkAllCombinations(
CodegenExample::firstExample,
)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
import org.utbot.tests.infrastructure.DoNotCalculate
import org.utbot.tests.infrastructure.between
import org.utbot.tests.infrastructure.isException
import org.utbot.testcheckers.eq
import org.utbot.testcheckers.ge
import org.utbot.tests.infrastructure.CodeGeneration
import org.utbot.tests.infrastructure.FullWithAssumptions
import org.utbot.tests.infrastructure.ignoreExecutionsNumber

// TODO failed Kotlin compilation SAT-1332
internal class ListsPart3Test : UtValueTestCaseChecker(
Expand All @@ -27,8 +28,7 @@ internal class ListsPart3Test : UtValueTestCaseChecker(
eq(3),
{ a, _ -> a == null },
{ a, r -> a != null && a.isEmpty() && r!!.isEmpty() },
{ a, r -> a != null && a.isNotEmpty() && r != null && r.isNotEmpty() && a.toList() == r.also { println(r) } },
coverage = DoNotCalculate
{ a, r -> a != null && a.isNotEmpty() && !r.isNullOrEmpty() && a.toList() == r.also { println(r) } },
)
}

Expand All @@ -38,19 +38,18 @@ internal class ListsPart3Test : UtValueTestCaseChecker(
Lists::bigListFromParameters,
eq(1),
{ list, r -> list.size == r && list.size == 11 },
coverage = DoNotCalculate
coverage = FullWithAssumptions(assumeCallsNumber = 1)
)
}

@Test
fun testGetNonEmptyCollection() {
check(
Lists::getNonEmptyCollection,
eq(3),
ignoreExecutionsNumber,
{ collection, _ -> collection == null },
{ collection, r -> collection.isEmpty() && r == null },
{ collection, r -> collection.isNotEmpty() && collection == r },
coverage = DoNotCalculate
)
}

Expand All @@ -63,7 +62,6 @@ internal class ListsPart3Test : UtValueTestCaseChecker(
{ l, _ -> l.isEmpty() },
{ l, r -> l[0] == null && r == null },
{ l, r -> l[0] != null && r is Array<*> && r.isArrayOf<Int>() && r.size == 1 && r[0] == l[0] },
coverage = DoNotCalculate
)
}

Expand All @@ -84,15 +82,14 @@ internal class ListsPart3Test : UtValueTestCaseChecker(

sizeConstraint && content
},
coverage = DoNotCalculate
)
}

@Test
fun removeElementsTest() {
checkWithException(
Lists::removeElements,
between(7..8),
ignoreExecutionsNumber,
{ list, _, _, r -> list == null && r.isException<NullPointerException>() },
{ list, i, _, r -> list != null && i < 0 && r.isException<IndexOutOfBoundsException>() },
{ list, i, _, r -> list != null && i >= 0 && list.size > i && list[i] == null && r.isException<NullPointerException>() },
Expand Down Expand Up @@ -134,7 +131,6 @@ internal class ListsPart3Test : UtValueTestCaseChecker(

precondition && postcondition
},
coverage = DoNotCalculate
)
}

Expand All @@ -145,7 +141,6 @@ internal class ListsPart3Test : UtValueTestCaseChecker(
eq(2),
{ x, r -> x % 2 != 0 && r is java.util.LinkedList && r == List(4) { it } },
{ x, r -> x % 2 == 0 && r is java.util.ArrayList && r == List(4) { it } },
coverage = DoNotCalculate
)
}

Expand All @@ -158,7 +153,6 @@ internal class ListsPart3Test : UtValueTestCaseChecker(
{ x, r -> x != null && x.isEmpty() && r!!.isEmpty() },
{ x, _ -> x != null && x.isNotEmpty() && x.any { it == null } },
{ x, r -> x != null && x.isNotEmpty() && x.all { it is Int } && r!!.toList() == x },
coverage = DoNotCalculate
)
}

Expand All @@ -170,7 +164,6 @@ internal class ListsPart3Test : UtValueTestCaseChecker(
{ x, _ -> x == null },
{ x, r -> x != null && x.isEmpty() && r!!.isEmpty() },
{ x, r -> x != null && x.isNotEmpty() && r!!.containsAll(x.toList()) && r.size == x.size },
coverage = DoNotCalculate
)
}

Expand All @@ -182,7 +175,6 @@ internal class ListsPart3Test : UtValueTestCaseChecker(
{ list, _ -> list == null },
{ list, r -> list.size >= 2 && r == emptyList<Int>() },
{ list, r -> list.size < 2 && r == emptyList<Int>() },
coverage = DoNotCalculate
)
}

Expand All @@ -198,7 +190,6 @@ internal class ListsPart3Test : UtValueTestCaseChecker(
{ list, i, r ->
list != null && list.isNotEmpty() && r != null && r.size == 1 + list.size && r == listOf(i) + list
},
coverage = DoNotCalculate
)
}

Expand All @@ -213,7 +204,6 @@ internal class ListsPart3Test : UtValueTestCaseChecker(
{ list, i, r ->
list != null && i in 0..list.lastIndex && r == list.toMutableList().apply { addAll(i, listOf(0, 1)) }
},
coverage = DoNotCalculate
)
}

Expand Down
Loading