Skip to content

Commit d2754ed

Browse files
committed
fixing test
1 parent 2dda8cb commit d2754ed

5 files changed

Lines changed: 18 additions & 5 deletions

File tree

core/src/main/kotlin/org/evomaster/core/problem/rest/data/RestCallAction.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ class RestCallAction(
457457
fun getNamedExamples() : Map<String, Int> {
458458
return seeAllGenes()
459459
.filterIsInstance<UserExamplesGene>()
460-
.mapNotNull { it.getValueName() }
460+
.filter { it.isUsedForExamples() }
461+
.flatMap { it.getAvailableExampleNames() }
461462
.groupingBy { it }
462463
.eachCount()
463464
}

core/src/main/kotlin/org/evomaster/core/search/gene/collection/EnumGene.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ class EnumGene<T : Comparable<T>>(
202202
return valueNames?.get(index)
203203
}
204204

205+
override fun getAvailableExampleNames() : Set<String> {
206+
return valueNames?.mapNotNull { it }?.toSet() ?: setOf()
207+
}
208+
205209
/**
206210
* [EnumGene] can be used in DTOs when the API spec contains either example values or an enum.
207211
* Since the [EnumGene] uses generics to hold values, this function returns the type to be used

core/src/main/kotlin/org/evomaster/core/search/gene/interfaces/UserExamplesGene.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ interface UserExamplesGene {
3232
*/
3333
fun getValueName(): String?
3434

35+
fun getAvailableExampleNames() : Set<String>
3536
}
3637

core/src/main/kotlin/org/evomaster/core/search/gene/wrapper/ChoiceGene.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ class ChoiceGene<T>(
182182
return valueNames?.get(activeGeneIndex)
183183
}
184184

185+
override fun getAvailableExampleNames() : Set<String> {
186+
return valueNames?.mapNotNull { it }?.toSet() ?: setOf()
187+
}
188+
185189
/**
186190
* Copies the value of the other gene. The other gene
187191
* does not have to be [ChoiceGene].

core/src/test/kotlin/org/evomaster/core/problem/rest/RestActionBuilderV3Test.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,18 +2238,21 @@ class RestActionBuilderV3Test{
22382238
}
22392239

22402240

2241-
@Disabled
22422241
@Test
22432242
fun testMultiParamExamples(){
22442243

2245-
val map = loadAndAssertActions("/swagger/artificial/defaultandexamples/examples_multi_params.yaml", 1, true)
2244+
val map = loadAndAssertActions(
2245+
"/swagger/artificial/defaultandexamples/examples_multi_params.yaml",
2246+
1,
2247+
RestActionBuilderV3.Options(enableConstraintHandling = true, probUseExamples = 0.5)
2248+
)
22462249

22472250
val post = map["POST:/v2/api"] as RestCallAction
22482251

22492252
val examples = post.getNamedExamples()
22502253
assertEquals(3, examples.size)
2251-
assertEquals(3, examples["Foo"])
2252-
assertEquals(2, examples["Bar"])
2254+
assertEquals(2, examples["Foo"])
2255+
assertEquals(3, examples["Bar"])
22532256
assertEquals(1, examples["Hello"])
22542257

22552258

0 commit comments

Comments
 (0)