File tree Expand file tree Collapse file tree 3 files changed +20
-7
lines changed
main/kotlin/org/utbot/fuzzer
test/kotlin/org/utbot/framework/plugin/api Expand file tree Collapse file tree 3 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -74,9 +74,10 @@ class Combinations(vararg elementNumbers: Int): Iterable<IntArray> {
74
74
}
75
75
count = LongArray (elementNumbers.size) { elementNumbers[it].toLong() }
76
76
for (i in count.size - 2 downTo 0 ) {
77
- count[i] = count[i] * count[i + 1 ]
78
- if (count[i] < count[i + 1 ]) {
79
- throw TooManyCombinationsException (" Long overflow or bad sequence: ${count[i]} < ${count[i + 1 ]} " )
77
+ try {
78
+ count[i] = StrictMath .multiplyExact(count[i], count[i + 1 ])
79
+ } catch (e: ArithmeticException ) {
80
+ throw TooManyCombinationsException (" Long overflow: ${count[i]} * ${count[i + 1 ]} " )
80
81
}
81
82
}
82
83
}
Original file line number Diff line number Diff line change @@ -228,12 +228,24 @@ class CombinationsTest {
228
228
assertTrue(expected.isEmpty())
229
229
}
230
230
231
+ @Test
232
+ fun testCartesianProductDoesNotThrowsExceptionBeforeOverflow () {
233
+ // We assume that a standard method has no more than 7 parameters.
234
+ // In this case every parameter can accept up to 511 values without Long overflow.
235
+ // CartesianProduct throws exception
236
+ val values = Array (511 ) { it }.toList()
237
+ val parameters = Array (7 ) { values }.toList()
238
+ assertDoesNotThrow {
239
+ CartesianProduct (parameters, Random (0 )).asSequence()
240
+ }
241
+ }
242
+
231
243
@Test
232
244
fun testCartesianProductThrowsExceptionOnOverflow () {
233
245
// We assume that a standard method has no more than 7 parameters.
234
- // In this case every parameter can accept up to 1700 values without Long overflow.
246
+ // In this case every parameter can accept up to 511 values without Long overflow.
235
247
// CartesianProduct throws exception
236
- val values = Array (1701 ) { it }.toList()
248
+ val values = Array (512 ) { it }.toList()
237
249
val parameters = Array (7 ) { values }.toList()
238
250
assertThrows(TooManyCombinationsException ::class .java) {
239
251
CartesianProduct (parameters, Random (0 )).asSequence()
Original file line number Diff line number Diff line change @@ -115,12 +115,12 @@ class FuzzerTest {
115
115
), fuzz.map { arguments -> arguments.map { fuzzedValue -> fuzzedValue.model } }.toSet())
116
116
}
117
117
118
- // Because of Long limitation fuzzer can process no more than 1700 values for method with 7 parameters
118
+ // Because of Long limitation fuzzer can process no more than 511 values for method with 7 parameters
119
119
@Test
120
120
@Timeout(1 , unit = TimeUnit .SECONDS )
121
121
fun `the worst case works well` () {
122
122
assertDoesNotThrow {
123
- val values = (0 until 1700 ).map { UtPrimitiveModel (it).fuzzed() }.asSequence()
123
+ val values = (0 until 511 ).map { UtPrimitiveModel (it).fuzzed() }.asSequence()
124
124
val provider = ModelProvider { descr ->
125
125
(0 until descr.parameters.size).asSequence()
126
126
.flatMap { index -> values.map { FuzzedParameter (index, it) } }
You can’t perform that action at this time.
0 commit comments