Skip to content

Commit 25697d1

Browse files
committed
Try to add complex and refactoring
1 parent 371b013 commit 25697d1

File tree

6 files changed

+59
-9
lines changed

6 files changed

+59
-9
lines changed

utbot-python/src/main/kotlin/org/utbot/python/PythonEngine.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ class PythonEngine(
222222
if (coverageLimit < 0)
223223
return@PythonFuzzing PythonFeedback(control = Control.STOP)
224224

225-
if (parameterValues.all { it.classId.name == "UNDEF_VALUE" }) {
226-
coverageLimit--
227-
return@PythonFuzzing PythonFeedback(control = Control.PASS)
228-
}
225+
// if (parameterValues.all { it.classId.name == "UNDEF_VALUE" }) {
226+
// coverageLimit--
227+
// return@PythonFuzzing PythonFeedback(control = Control.PASS)
228+
// }
229229

230230
val (thisObject, modelList) =
231231
if (methodUnderTest.containingPythonClassId == null)

utbot-python/src/main/kotlin/org/utbot/python/framework/api/python/util/PythonIdUtils.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import org.utbot.python.framework.api.python.PythonSetModel
1010

1111
// none annotation can be used in code only since Python 3.10
1212
val pythonNoneClassId = PythonClassId("types.NoneType")
13+
val pythonObjectClassId = PythonClassId("builtins.object")
1314
val pythonAnyClassId = NormalizedPythonAnnotation("typing.Any")
1415
val pythonIntClassId = PythonClassId("builtins.int")
1516
val pythonFloatClassId = PythonClassId("builtins.float")
17+
val pythonComplexClassId = PythonClassId("builtins.complex")
1618
val pythonStrClassId = PythonClassId("builtins.str")
1719
val pythonBoolClassId = PythonBoolModel.classId
1820
val pythonRangeClassId = PythonClassId("builtins.range")

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/PythonApi.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import org.utbot.python.framework.api.python.PythonClassId
1212
import org.utbot.python.framework.api.python.PythonTree
1313
import org.utbot.python.framework.api.python.PythonTreeModel
1414
import org.utbot.python.framework.api.python.util.pythonNoneClassId
15+
import org.utbot.python.framework.api.python.util.pythonObjectClassId
1516
import org.utbot.python.fuzzing.provider.BoolValueProvider
17+
import org.utbot.python.fuzzing.provider.ComplexValueProvider
1618
import org.utbot.python.fuzzing.provider.DictValueProvider
1719
import org.utbot.python.fuzzing.provider.FloatValueProvider
1820
import org.utbot.python.fuzzing.provider.IntValueProvider
@@ -24,7 +26,7 @@ import org.utbot.python.fuzzing.provider.StrValueProvider
2426
import org.utbot.python.fuzzing.provider.TupleFixSizeValueProvider
2527
import org.utbot.python.fuzzing.provider.TupleValueProvider
2628
import org.utbot.python.fuzzing.provider.UnionValueProvider
27-
import org.utbot.python.fuzzing.value.UndefValue
29+
import org.utbot.python.fuzzing.value.ObjectValue
2830
import org.utbot.python.newtyping.PythonProtocolDescription
2931
import org.utbot.python.newtyping.PythonSubtypeChecker
3032
import org.utbot.python.newtyping.PythonTypeStorage
@@ -60,6 +62,7 @@ fun pythonDefaultValueProviders(idGenerator: IdGenerator<Long>) = listOf(
6062
BoolValueProvider,
6163
IntValueProvider,
6264
FloatValueProvider,
65+
ComplexValueProvider,
6366
StrValueProvider,
6467
ListValueProvider,
6568
SetValueProvider,
@@ -81,6 +84,7 @@ class PythonFuzzing(
8184
providers += provider.generate(description, type)
8285
}
8386
}
87+
logger.info("Default ${type.meta} providers: $providers")
8488
return providers
8589
}
8690

@@ -92,9 +96,9 @@ class PythonFuzzing(
9296
}
9397
subtypes.forEach {
9498
providers += generateDefault(description, it, idGenerator)
95-
// providers += generateSubtype(description, it, idGenerator)
9699
}
97100
}
101+
logger.info("Subtype ${type.meta} providers: $providers")
98102
return providers
99103
}
100104

@@ -106,7 +110,8 @@ class PythonFuzzing(
106110
providers += generateSubtype(description, type, idGenerator)
107111

108112
if (providers.toList().isEmpty()) {
109-
providers += Seed.Known(UndefValue()) {PythonTreeModel(PythonTree.fromNone(), PythonClassId("UNDEF_VALUE"))}
113+
logger.info("Add object provider for ${type.meta}")
114+
providers += Seed.Known(ObjectValue()) {PythonTreeModel(PythonTree.fromNone(), pythonObjectClassId)}
110115
}
111116

112117
return providers
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.utbot.python.fuzzing.provider
2+
3+
import org.utbot.fuzzing.Routine
4+
import org.utbot.fuzzing.Seed
5+
import org.utbot.fuzzing.ValueProvider
6+
import org.utbot.fuzzing.seeds.BitVectorValue
7+
import org.utbot.fuzzing.seeds.Signed
8+
import org.utbot.python.framework.api.python.PythonClassId
9+
import org.utbot.python.framework.api.python.PythonTree
10+
import org.utbot.python.framework.api.python.PythonTreeModel
11+
import org.utbot.python.framework.api.python.util.pythonComplexClassId
12+
import org.utbot.python.framework.api.python.util.pythonFloatClassId
13+
import org.utbot.python.framework.api.python.util.pythonIntClassId
14+
import org.utbot.python.fuzzing.PythonMethodDescription
15+
import org.utbot.python.fuzzing.provider.utils.isAny
16+
import org.utbot.python.newtyping.PythonConcreteCompositeTypeDescription
17+
import org.utbot.python.newtyping.general.Type
18+
19+
object ComplexValueProvider : ValueProvider<Type, PythonTreeModel, PythonMethodDescription> {
20+
override fun accept(type: Type): Boolean {
21+
val meta = type.meta
22+
if (meta is PythonConcreteCompositeTypeDescription) {
23+
return meta.name.toString() == "builtins.complex"
24+
}
25+
return type.isAny()
26+
}
27+
28+
override fun generate(description: PythonMethodDescription, type: Type) = sequence {
29+
val meta = type.meta as PythonConcreteCompositeTypeDescription
30+
yield(Seed.Recursive(
31+
construct = Routine.Create(emptyList<Type>()) { v ->
32+
PythonTreeModel(
33+
PythonTree.PrimitiveNode(
34+
pythonComplexClassId,
35+
"complex('${v[0]}+${v[1]}j')"
36+
),
37+
pythonComplexClassId,
38+
)
39+
},
40+
empty = Routine.Empty { PythonTreeModel(PythonTree.fromObject(), PythonClassId(meta.name.toString())) }
41+
))
42+
}
43+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object UnionValueProvider : ValueProvider<Type, PythonTreeModel, PythonMethodDes
3131
params.forEach { unionParam ->
3232
yield(Seed.Recursive(
3333
construct = Routine.Create(listOf(unionParam)) { v -> v.first() },
34-
empty = Routine.Empty { PythonTreeModel(PythonTree.fromNone(), PythonClassId(meta.name.toString())) }
34+
empty = Routine.Empty { PythonTreeModel(PythonTree.fromObject(), PythonClassId(meta.name.toString())) }
3535
))
3636
}
3737
}

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/value/UndefValue.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package org.utbot.python.fuzzing.value
33
import org.utbot.fuzzing.Mutation
44
import org.utbot.fuzzing.seeds.KnownValue
55

6-
class UndefValue : KnownValue {
6+
class ObjectValue : KnownValue {
77
override fun mutations(): List<Mutation<KnownValue>> {
88
return emptyList()
99
}

0 commit comments

Comments
 (0)