Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add tests for recursion tag
  • Loading branch information
onewhl committed Sep 8, 2022
commit a71bfa32fb690775ed97bf98db7eb8bfd2d9978d
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package examples.recursion

import examples.CustomJavaDocTagsEnabler
import examples.SummaryTestCaseGeneratorTest
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(
Recursion::class
) {
@Test
fun testFib() {
val summary1 = "@utbot.classUnderTest {@link Recursion}\n" +
"@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#fib(int)}\n" +
"@utbot.executesCondition {@code (n == 0): False},\n" +
Copy link
Copy Markdown
Collaborator

@amandelpie amandelpie Sep 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thought that in future we could have something like testing dsl

javadoc {
methodUnderTest = "org.utbot.examples.recursion.Recursion#fib(int)"
executesCondition = "(n == 0): False"
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yesss, it would be awesome!

"{@code (n == 1): True}\n" +
"@utbot.returnsFrom {@code return 1;}"
val summary2 = "@utbot.classUnderTest {@link Recursion}\n" +
"@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#fib(int)}\n" +
"@utbot.executesCondition {@code (n == 0): True}\n" +
"@utbot.returnsFrom {@code return 0;}\n"
val summary3 = "@utbot.classUnderTest {@link Recursion}\n" +
"@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#fib(int)}\n" +
"@utbot.executesCondition {@code (n == 1): False}\n" +
"@utbot.returnsFrom {@code return fib(n - 1) + fib(n - 2);}"
val summary4 = "@utbot.classUnderTest {@link Recursion}\n" +
"@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#fib(int)}\n" +
"@utbot.executesCondition {@code (n < 0): True}\n" +
"@utbot.throwsException {@link java.lang.IllegalArgumentException} in: n < 0"

val methodName1 = "testFib_Return1"
val methodName2 = "testFib_ReturnZero"
val methodName3 = "testFib_NNotEquals1"
val methodName4 = "testFib_NLessThanZero"

val displayName1 = "n == 0 : False -> return 1"
val displayName2 = "n == 0 : True -> return 0"
val displayName3 = "return 1 -> return 0" //it looks weird
val displayName4 = "n < 0 -> ThrowIllegalArgumentException"

val summaryKeys = listOf(
summary1,
summary2,
summary3,
summary4
)

val displayNames = listOf(
displayName1,
displayName2,
displayName3,
displayName4
)

val methodNames = listOf(
methodName1,
methodName2,
methodName3,
methodName4
)

val method = Recursion::fib
val mockStrategy = MockStrategyApi.NO_MOCKS
val coverage = DoNotCalculate

summaryCheck(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames)
}

@Test
fun testFactorial() {
val summary1 = "@utbot.classUnderTest {@link Recursion}\n" +
"@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#factorial(int)}\n" +
//TODO: this condition is lost in both SimpleCommentBuilder ans CustomJavaDocCommentBuilder
Comment thread
onewhl marked this conversation as resolved.
Outdated
//"@utbot.executesCondition {@code (n == 0): True}\n"
"@utbot.returnsFrom {@code return 1;}"
val summary2 = "@utbot.classUnderTest {@link Recursion}\n" +
"@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#factorial(int)}\n" +
"@utbot.executesCondition {@code (n == 0): False}\n" +
"@utbot.returnsFrom {@code return n * factorial(n - 1);}"
val summary3 = "@utbot.classUnderTest {@link Recursion}\n" +
"@utbot.methodUnderTest {@link org.utbot.examples.recursion.Recursion#factorial(int)}\n" +
"@utbot.executesCondition {@code (n < 0): True}\n" +
"@utbot.throwsException {@link java.lang.IllegalArgumentException} after condition: n < 0"

val methodName1 = "testFactorial_Return1"
val methodName2 = "testFactorial_NNotEqualsZero"
val methodName3 = "testFactorial_NLessThanZero"

//TODO: display names are not complete,
//they should be equal "n == 0 : True -> return 1" and "n == 0 : False -> return n * factorial(n - 1)" respectively
Comment thread
onewhl marked this conversation as resolved.
val displayName1 = "-> return 1"
val displayName2 = "-> return 1"
val displayName3 = "n < 0 -> ThrowIllegalArgumentException"

val summaryKeys = listOf(
summary1,
summary2,
summary3
)

val displayNames = listOf(
displayName1,
displayName2,
displayName3
)

val methodNames = listOf(
methodName1,
methodName2,
methodName3
)

val method = Recursion::factorial
val mockStrategy = MockStrategyApi.NO_MOCKS
val coverage = DoNotCalculate

summaryCheck(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames)
}
}