Skip to content

Commit 630142e

Browse files
authored
Fuzzer should create object without any modifications (#2319)
When fuzzer mutates objects, it should try to create an object without any modifications
1 parent 9d5a403 commit 630142e

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

utbot-fuzzing/src/main/kotlin/org/utbot/fuzzing/Mutations.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ sealed interface RecursiveMutations<TYPE, RESULT> : Mutation<Pair<Result.Recursi
303303
): Result.Recursive<TYPE, RESULT> {
304304
return Result.Recursive(
305305
construct = source.construct,
306-
modify = source.modify.shuffled(random).take(random.nextInt(source.modify.size + 1).coerceAtLeast(1))
306+
modify = source.modify.shuffled(random).take(random.nextInt(source.modify.size + 1))
307307
)
308308
}
309309
}

utbot-fuzzing/src/test/kotlin/org/utbot/fuzzing/FuzzerSmokeTest.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.utbot.fuzzing
33
import kotlinx.coroutines.*
44
import kotlinx.coroutines.flow.flow
55
import org.junit.jupiter.api.Assertions
6+
import org.junit.jupiter.api.Assertions.fail
67
import org.junit.jupiter.api.Test
78
import org.junit.jupiter.api.assertThrows
89
import org.utbot.fuzzing.seeds.BitVectorValue
@@ -258,4 +259,27 @@ class FuzzerSmokeTest {
258259
deferred.cancel()
259260
}
260261
}
262+
263+
@Test
264+
fun `fuzzer can generate value without mutations`() {
265+
runBlocking {
266+
var seenEmpty = false
267+
withTimeout(1000) {
268+
runFuzzing(
269+
{ _, _ -> sequenceOf(Seed.Recursive<Unit, StringBuilder>(
270+
construct = Routine.Create(emptyList()) { StringBuilder("") },
271+
modify = sequenceOf(Routine.Call(emptyList()) { s, _ -> s.append("1") }),
272+
empty = Routine.Empty { fail("Empty is called despite construct requiring no args") }
273+
)) },
274+
Description(listOf(Unit))
275+
) { _, (s) ->
276+
if (s.isEmpty()) {
277+
seenEmpty = true
278+
BaseFeedback(Unit, Control.STOP)
279+
} else BaseFeedback(Unit, Control.CONTINUE)
280+
}
281+
}
282+
Assertions.assertTrue(seenEmpty) { "Unmodified empty string wasn't generated" }
283+
}
284+
}
261285
}

0 commit comments

Comments
 (0)