Skip to content

Move all summary tests in utbot-summary-tests project #1765

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

Merged
merged 3 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,6 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS
*/
var useExpressionSimplification by getBooleanProperty(true)

/**
* Activate or deactivate tests on comments
*/
var testSummary by getBooleanProperty(true)

/**
* Activate or deactivate tests on names
*/
var testName by getBooleanProperty(true)

/**
* Activate or deactivate tests on displayNames
*/
var testDisplayName by getBooleanProperty(true)

/**
* Enable the Summarization module to generate summaries for methods under test.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
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
Expand All @@ -12,60 +8,14 @@ import org.utbot.testing.isException
class BinarySearchTest : UtValueTestCaseChecker(testClass = BinarySearch::class,) {
@Test
fun testLeftBinarySearch() {
val fullSummary = listOf<DocStatement>(
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<NullPointerException>() },
{ a, _, r -> a.size >= 2 && a[0] > a[1] && r.isException<IllegalArgumentException>() },
{ 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")
)
*/
{ a, key, r -> a.isNotEmpty() && key in a && r.getOrNull() == a.indexOfFirst { it == key } + 1 }
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
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.examples.algorithms.CorrectBracketSequences.isBracket
import org.utbot.examples.algorithms.CorrectBracketSequences.isOpen
Expand All @@ -12,7 +9,6 @@ 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,
Expand All @@ -24,50 +20,18 @@ internal class CorrectBracketSequencesTest : UtValueTestCaseChecker(
) {
@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)
)
{ c, r -> c !in "({[".toList() && r == false }
)
}

@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),
Expand All @@ -77,33 +41,12 @@ internal class CorrectBracketSequencesTest : UtValueTestCaseChecker(
{ 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)
)
{ c, r -> c !in "(){}[]".toList() && r == false }
)
}

@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,
Expand All @@ -113,18 +56,7 @@ internal class CorrectBracketSequencesTest : UtValueTestCaseChecker(
{ 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)
)
{ a, b, r -> (a != '(' || b != ')') && (a != '{' || b != '}') && (a != '[' || b != ']') && r == false }
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
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
Expand All @@ -12,7 +9,6 @@ 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(
Expand Down Expand Up @@ -111,54 +107,12 @@ internal class SortTest : UtValueTestCaseChecker(
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),
Expand All @@ -167,22 +121,7 @@ internal class SortTest : UtValueTestCaseChecker(
{ 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"),
)
}
)
}
}
Original file line number Diff line number Diff line change
@@ -1,51 +1,18 @@
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
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
fun testSimpleCondition() {
val conditionSummary = listOf<DocStatement>(
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"),
)
{ condition, r -> condition && r == 1 }
)
}

Expand Down
Loading