@@ -8,7 +8,10 @@ import org.utbot.fuzzing.Description
8
8
import org.utbot.fuzzing.Feedback
9
9
import org.utbot.fuzzing.Fuzzing
10
10
import org.utbot.fuzzing.Seed
11
+ import org.utbot.python.framework.api.python.PythonClassId
12
+ import org.utbot.python.framework.api.python.PythonTree
11
13
import org.utbot.python.framework.api.python.PythonTreeModel
14
+ import org.utbot.python.framework.api.python.util.pythonNoneClassId
12
15
import org.utbot.python.fuzzing.provider.BoolValueProvider
13
16
import org.utbot.python.fuzzing.provider.DictValueProvider
14
17
import org.utbot.python.fuzzing.provider.FloatValueProvider
@@ -21,6 +24,7 @@ import org.utbot.python.fuzzing.provider.StrValueProvider
21
24
import org.utbot.python.fuzzing.provider.TupleFixSizeValueProvider
22
25
import org.utbot.python.fuzzing.provider.TupleValueProvider
23
26
import org.utbot.python.fuzzing.provider.UnionValueProvider
27
+ import org.utbot.python.fuzzing.value.UndefValue
24
28
import org.utbot.python.newtyping.PythonProtocolDescription
25
29
import org.utbot.python.newtyping.PythonSubtypeChecker
26
30
import org.utbot.python.newtyping.PythonTypeStorage
@@ -67,31 +71,47 @@ fun pythonDefaultValueProviders(idGenerator: IdGenerator<Long>) = listOf(
67
71
)
68
72
69
73
class PythonFuzzing (
70
- val pythonTypeStorage : PythonTypeStorage ,
74
+ private val pythonTypeStorage : PythonTypeStorage ,
71
75
val execute : suspend (description: PythonMethodDescription , values: List <PythonTreeModel >) -> PythonFeedback ,
72
76
) : Fuzzing<Type, PythonTreeModel, PythonMethodDescription, PythonFeedback> {
73
- fun generateDefault (description : PythonMethodDescription , type : Type ): Sequence <Seed <Type , PythonTreeModel >> {
74
- val idGenerator = PythonIdGenerator ()
75
- return pythonDefaultValueProviders(idGenerator).asSequence().flatMap { provider ->
77
+ private fun generateDefault (description : PythonMethodDescription , type : Type , idGenerator : IdGenerator < Long > ): Sequence <Seed <Type , PythonTreeModel >> {
78
+ var providers = emptyList< Seed < Type , PythonTreeModel >>().asSequence ()
79
+ pythonDefaultValueProviders(idGenerator).asSequence().forEach { provider ->
76
80
if (provider.accept(type)) {
77
- provider.generate(description, type)
78
- } else {
79
- emptySequence()
81
+ providers + = provider.generate(description, type)
80
82
}
81
83
}
84
+ return providers
82
85
}
83
86
84
- override fun generate (description : PythonMethodDescription , type : Type ): Sequence <Seed <Type , PythonTreeModel >> {
85
- var providers = generateDefault(description, type )
87
+ private fun generateSubtype (description : PythonMethodDescription , type : Type , idGenerator : IdGenerator < Long > ): Sequence <Seed <Type , PythonTreeModel >> {
88
+ var providers = emptyList< Seed < Type , PythonTreeModel >>().asSequence( )
86
89
if (type.meta is PythonProtocolDescription ) {
87
90
val subtypes = pythonTypeStorage.allTypes.filter {
88
91
PythonSubtypeChecker .checkIfRightIsSubtypeOfLeft(type, it, pythonTypeStorage)
89
92
}
90
- subtypes.forEach { providers + = generateDefault(description, it) }
93
+ subtypes.forEach {
94
+ providers + = generateDefault(description, it, idGenerator)
95
+ // providers += generateSubtype(description, it, idGenerator)
96
+ }
91
97
}
92
98
return providers
93
99
}
94
100
101
+ override fun generate (description : PythonMethodDescription , type : Type ): Sequence <Seed <Type , PythonTreeModel >> {
102
+ val idGenerator = PythonIdGenerator ()
103
+ var providers = emptyList<Seed <Type , PythonTreeModel >>().asSequence()
104
+
105
+ providers + = generateDefault(description, type, idGenerator)
106
+ providers + = generateSubtype(description, type, idGenerator)
107
+
108
+ if (providers.toList().isEmpty()) {
109
+ providers + = Seed .Known (UndefValue ()) {PythonTreeModel (PythonTree .fromNone(), PythonClassId (" UNDEF_VALUE" ))}
110
+ }
111
+
112
+ return providers
113
+ }
114
+
95
115
override suspend fun handle (description : PythonMethodDescription , values : List <PythonTreeModel >): PythonFeedback {
96
116
return execute(description, values)
97
117
}
0 commit comments