Skip to content
Merged
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
Next Next commit
Fix bug in FeatureProcessor
  • Loading branch information
Victor Samoilov committed Jun 22, 2022
commit 80fc26227790fe89bbe569270e10719e22892e91
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class FeatureProcessorWithStatesRepetition(
val states = mutableListOf<Pair<Int, Long>>()
var newCoverage = 0

generateSequence(executionState) { currentState ->
generateSequence(executionState) { it.parent }.forEach { currentState ->
Comment thread
Atos1337 marked this conversation as resolved.
val stateHashCode = currentState.hashCode()

if (currentState.features.isEmpty()) {
Expand All @@ -68,8 +68,6 @@ class FeatureProcessorWithStatesRepetition(
newCoverage++
}
}

currentState.parent
}

generatedTestCases++
Expand Down
7 changes: 7 additions & 0 deletions utbot-analytics/src/test/java/org/utbot/features/OnePath.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.utbot.features;

public class OnePath {
Comment thread
Atos1337 marked this conversation as resolved.
int onePath() {
return 1;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
package org.utbot.features

import org.junit.jupiter.api.AfterAll
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.examples.AbstractTestCaseGeneratorTest
import org.utbot.examples.eq
import org.utbot.examples.withFeaturePath
import java.io.File
import java.io.FileInputStream

class FeatureProcessorWithRepetitionTest {
class FeatureProcessorWithRepetitionTest : AbstractTestCaseGeneratorTest(OnePath::class) {
companion object {
const val featureDir = "src/test/resources/features"
fun reward(coverage: Double, time: Double) = RewardEstimator.reward(coverage, time)

@JvmStatic
@BeforeAll
fun beforeAll() {
File(featureDir).mkdir()
EngineAnalyticsContext.featureProcessorFactory = FeatureProcessorWithStatesRepetitionFactory()
EngineAnalyticsContext.featureExtractorFactory = FeatureExtractorFactoryImpl()
}

@JvmStatic
@AfterAll
fun afterAll() {
File(featureDir).deleteRecursively()
}
}

@Test
fun testDumpFeatures() {
fun testCalculateRewards() {
val statesToInt = mapOf(
"a0" to 1,
"c0" to 2,
Expand Down Expand Up @@ -70,4 +93,16 @@ class FeatureProcessorWithRepetitionTest {
Assertions.assertEquals(it.value, rewards[statesToInt[it.key]])
}
}

@Test
fun addTestCaseTest() {
withFeaturePath(featureDir) {
check(
OnePath::onePath,
eq(1)
)

Assertions.assertTrue(FileInputStream("$featureDir/0.csv").bufferedReader().readLines().size > 1)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2811,3 +2811,18 @@ inline fun <reified T> withPathSelectorType(pathSelectorType: PathSelectorType,
UtSettings.pathSelectorType = prev
}
}

inline fun <reified T> withFeaturePath(featurePath: String, block: () -> T): T {
val prevFeaturePath = UtSettings.featurePath
val prevEnableFeatureProcess = UtSettings.enableFeatureProcess

UtSettings.featurePath = featurePath
UtSettings.enableFeatureProcess = true

try {
return block()
} finally {
UtSettings.featurePath = prevFeaturePath
UtSettings.enableFeatureProcess = prevEnableFeatureProcess
}
}