Skip to content

Commit d9c0d49

Browse files
committed
Update fuzzing strategy for Dict and Set
1 parent 4374a26 commit d9c0d49

File tree

2 files changed

+21
-47
lines changed

2 files changed

+21
-47
lines changed

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/DictValueProvider.kt

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,23 @@ object DictValueProvider : ValueProvider<UtType, PythonFuzzedValue, PythonMethod
2020
override fun generate(description: PythonMethodDescription, type: UtType) = sequence {
2121
val params = type.pythonAnnotationParameters()
2222

23-
val modifications = emptyList<Routine.Call<UtType, PythonFuzzedValue>>().toMutableList()
24-
modifications.add(Routine.Call(params) { instance, arguments ->
25-
val key = arguments[0].tree
26-
val value = arguments[1].tree
27-
val dict = instance.tree as PythonTree.DictNode
28-
if (dict.items.keys.toList().contains(key)) {
29-
dict.items.replace(key, value)
30-
} else {
31-
dict.items[key] = value
32-
}
33-
})
34-
modifications.add(Routine.Call(listOf(params[0])) { instance, arguments ->
35-
val key = arguments[0].tree
36-
val dict = instance.tree as PythonTree.DictNode
37-
if (dict.items.keys.toList().contains(key)) {
38-
dict.items.remove(key)
39-
}
40-
})
41-
yield(Seed.Recursive(
42-
construct = Routine.Create(emptyList()) { v ->
23+
yield(Seed.Collection(
24+
construct = Routine.Collection { _ ->
4325
PythonFuzzedValue(
4426
PythonTree.DictNode(mutableMapOf()),
4527
"%var% = ${type.pythonTypeRepresentation()}"
4628
)
4729
},
48-
modify = modifications.asSequence(),
49-
empty = Routine.Empty { PythonFuzzedValue(
50-
PythonTree.DictNode(emptyMap<PythonTree.PythonTreeNode, PythonTree.PythonTreeNode>().toMutableMap()),
51-
"%var% = ${type.pythonTypeRepresentation()}"
52-
)}
30+
modify = Routine.ForEach(params) { instance, _, arguments ->
31+
val key = arguments[0].tree
32+
val value = arguments[1].tree
33+
val dict = instance.tree as PythonTree.DictNode
34+
if (dict.items.keys.toList().contains(key)) {
35+
dict.items.replace(key, value)
36+
} else {
37+
dict.items[key] = value
38+
}
39+
},
5340
))
5441
}
5542
}

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/SetValueProvider.kt

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,18 @@ object SetValueProvider : ValueProvider<UtType, PythonFuzzedValue, PythonMethodD
2020
override fun generate(description: PythonMethodDescription, type: UtType) = sequence {
2121
val params = type.pythonAnnotationParameters()
2222

23-
val modifications = emptyList<Routine.Call<UtType, PythonFuzzedValue>>().toMutableList()
24-
modifications.add(Routine.Call(params) { instance, arguments ->
25-
val set = instance.tree as PythonTree.SetNode
26-
set.items.add(arguments.first().tree)
27-
})
28-
modifications.add(Routine.Call(params) { instance, arguments ->
29-
val set = instance.tree as PythonTree.SetNode
30-
val value = arguments.first().tree
31-
if (set.items.contains(value)) {
32-
set.items.remove(value)
33-
}
34-
})
35-
yield(Seed.Recursive(
36-
construct = Routine.Create(emptyList()) {
37-
val items = emptySet<PythonTree.PythonTreeNode>().toMutableSet()
23+
yield(Seed.Collection(
24+
construct = Routine.Collection { _ ->
3825
PythonFuzzedValue(
39-
PythonTree.SetNode(items),
40-
"%var% = ${type.pythonTypeRepresentation()}",
26+
PythonTree.SetNode(mutableSetOf()),
27+
"%var% = ${type.pythonTypeRepresentation()}"
4128
)
4229
},
43-
modify = modifications.asSequence(),
44-
empty = Routine.Empty { PythonFuzzedValue(
45-
PythonTree.SetNode(emptySet<PythonTree.PythonTreeNode>().toMutableSet()),
46-
"%var% = ${type.pythonTypeRepresentation()}",
47-
)}
30+
modify = Routine.ForEach(params) { instance, _, arguments ->
31+
val item = arguments[0].tree
32+
val set = instance.tree as PythonTree.SetNode
33+
set.items.add(item)
34+
},
4835
))
4936
}
5037
}

0 commit comments

Comments
 (0)