Skip to content
Closed
Show file tree
Hide file tree
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
Added tests for primitive streams
  • Loading branch information
Damtev committed Sep 2, 2022
commit 686ed669f83dd5764bcfd1be3b7309f7cb4cdbd9
6 changes: 3 additions & 3 deletions utbot-core/src/main/kotlin/org/utbot/common/FileUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ object FileUtil {
// https://stackoverflow.com/a/68822715
fun byteCountToDisplaySize(bytes: Long): String =
when {
bytes >= 1 shl 30 -> "%.1f GB".format(bytes / (1 shl 30))
bytes >= 1 shl 20 -> "%.1f MB".format(bytes / (1 shl 20))
bytes >= 1 shl 10 -> "%.0f kB".format(bytes / (1 shl 10))
bytes >= 1 shl 30 -> "%.1f GB".format(bytes.toDouble() / (1 shl 30))
bytes >= 1 shl 20 -> "%.1f MB".format(bytes.toDouble() / (1 shl 20))
bytes >= 1 shl 10 -> "%.0f kB".format(bytes.toDouble() / (1 shl 10))
else -> "$bytes bytes"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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.examples.AtLeast
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
import org.utbot.tests.infrastructure.DoNotCalculate
import org.utbot.tests.infrastructure.Full
Expand Down Expand Up @@ -69,10 +70,43 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
fun testMapExample() {
checkWithException(
BaseStreamExample::mapExample,
eq(2),
ignoreExecutionsNumber,
{ c, r -> null in c && r.isException<NullPointerException>() },
{ c, r -> r.getOrThrow().contentEquals(c.map { it * 2 }.toTypedArray()) },
coverage = DoNotCalculate
coverage = AtLeast(90)
)
}

@Test
fun testMapToIntExample() {
checkWithException(
BaseStreamExample::mapToIntExample,
ignoreExecutionsNumber,
{ c, r -> null in c && r.isException<NullPointerException>() },
{ c, r -> r.getOrThrow().contentEquals(c.map { it.toInt() }.toIntArray()) },
coverage = AtLeast(90)
)
}

@Test
fun testMapToLongExample() {
checkWithException(
BaseStreamExample::mapToLongExample,
ignoreExecutionsNumber,
{ c, r -> null in c && r.isException<NullPointerException>() },
{ c, r -> r.getOrThrow().contentEquals(c.map { it.toLong() }.toLongArray()) },
coverage = AtLeast(90)
)
}

@Test
fun testMapToDoubleExample() {
checkWithException(
BaseStreamExample::mapToDoubleExample,
ignoreExecutionsNumber,
{ c, r -> null in c && r.isException<NullPointerException>() },
{ c, r -> r.getOrThrow().contentEquals(c.map { it.toDouble() }.toDoubleArray()) },
coverage = AtLeast(90)
)
}

Expand All @@ -87,7 +121,36 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
}

@Test
@Disabled("Java 11 transition -- Yura looks at this. We have similar issue with Strings")
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(), it.toDouble()) }.toDoubleArray()) },
coverage = FullWithAssumptions(assumeCallsNumber = 1)
)
}

@Test
fun testDistinctExample() {
check(
BaseStreamExample::distinctExample,
Expand Down Expand Up @@ -146,17 +209,17 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
fun testForEachExample() {
checkThisAndStaticsAfter(
BaseStreamExample::forEachExample,
eq(2),
ignoreExecutionsNumber,
*streamConsumerStaticsMatchers,
coverage = DoNotCalculate
coverage = AtLeast(92)
)
}

@Test
fun testToArrayExample() {
check(
BaseStreamExample::toArrayExample,
ignoreExecutionsNumber,
eq(2),
{ c, r -> c.toTypedArray().contentEquals(r) },
coverage = FullWithAssumptions(assumeCallsNumber = 1)
)
Expand Down Expand Up @@ -311,10 +374,11 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
fun testIteratorExample() {
checkWithException(
BaseStreamExample::iteratorSumExample,
eq(2),
ignoreExecutionsNumber,
{ c, r -> c.isEmpty() && r.getOrThrow() == 0 },
{ c, r -> null in c && r.isException<NullPointerException>() },
{ c, r -> null !in c && r.getOrThrow() == c.sum() },
coverage = DoNotCalculate
{ c, r -> c.isNotEmpty() && null !in c && r.getOrThrow() == c.sum() },
coverage = AtLeast(75)
)
}

Expand Down Expand Up @@ -394,15 +458,15 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
coverage = Full
)
}
}

private val streamConsumerStaticsMatchers = arrayOf(
{ _: BaseStreamExample, c: List<Int?>, _: StaticsType, _: Int? -> null in c },
{ _: BaseStreamExample, c: List<Int?>, statics: StaticsType, r: Int? ->
val x = statics.values.single().value as Int
internal val streamConsumerStaticsMatchers = arrayOf(
{ _: Any, c: List<Int?>, _: StaticsType, _: Int? -> null in c },
{ _: Any, c: List<Int?>, statics: StaticsType, r: Int? ->
val x = statics.values.single().value as Int

r!! + c.sumOf { it ?: 0 } == x
}
)
}
r!! + c.sumOf { it ?: 0 } == x
}
)

private fun <E : Comparable<E>> Sequence<E>.isSorted(): Boolean = zipWithNext { a, b -> a <= b }.all { it }
internal fun <E : Comparable<E>> Sequence<E>.isSorted(): Boolean = zipWithNext { a, b -> a <= b }.all { it }
Loading