@@ -6,35 +6,63 @@ import org.utbot.fuzzing.Seed
6
6
import org.utbot.python.framework.api.python.PythonTree
7
7
import org.utbot.python.framework.api.python.util.pythonNdarrayClassId
8
8
import org.utbot.python.fuzzing.FuzzedUtType
9
- import org.utbot.python.fuzzing.FuzzedUtType.Companion.activateAnyIf
10
9
import org.utbot.python.fuzzing.FuzzedUtType.Companion.toFuzzed
11
10
import org.utbot.python.fuzzing.PythonFuzzedValue
12
11
import org.utbot.python.fuzzing.PythonMethodDescription
13
12
import org.utbot.python.fuzzing.PythonValueProvider
14
- import org.utpython.types.pythonAnnotationParameters
13
+ import org.utbot.python.fuzzing.provider.utils.*
14
+ import org.utpython.types.*
15
+ import kotlin.math.abs
15
16
16
17
17
18
private val logger = KotlinLogging .logger {}
18
19
19
- object NDArrayValueProvider : PythonValueProvider {
20
+ class NDArrayValueProvider (
21
+ private val typeStorage : PythonTypeHintsStorage
22
+ ) : PythonValueProvider {
20
23
override fun accept (type : FuzzedUtType ): Boolean {
21
24
return type.pythonTypeName() == pythonNdarrayClassId.canonicalName
22
25
}
23
26
27
+ @Suppress(" UNCHECKED_CAST" )
24
28
override fun generate (
25
29
description : PythonMethodDescription , type : FuzzedUtType
26
30
) = sequence {
27
31
val param = type.utType.pythonAnnotationParameters()
28
- yield (Seed .Collection ( // TODO: Rewrite to construct NDArray objects
29
- construct = Routine .Collection {
32
+ val intType = typeStorage.pythonInt
33
+ val listType = typeStorage.pythonList
34
+
35
+ yield (Seed .Recursive (
36
+ construct = Routine .Create (
37
+ listOf (
38
+ listType
39
+ .pythonDescription()
40
+ .createTypeWithNewAnnotationParameters(listType, listOf (intType)).toFuzzed()
41
+ )
42
+ ) {
30
43
PythonFuzzedValue (
44
+
31
45
PythonTree .NdarrayNode (
32
- emptyMap<Int , PythonTree .PythonTreeNode >().toMutableMap(),
46
+ emptyMap<Int , PythonTree .PythonTreeNode >().toMutableMap(), // Generate new Python IntNode
47
+ ((it.first().tree as PythonTree .ListNode ).items as Map <Int , PythonTree .PrimitiveNode >).values.map { node ->
48
+ abs(node.repr.take(3 ).toInt()) % 10
49
+ }
33
50
), " %var% = ${type.pythonTypeRepresentation()} "
34
51
)
35
52
},
36
- modify = Routine .ForEach (param.toFuzzed().activateAnyIf(type)) { self, i, values ->
37
- (self.tree as PythonTree .NdarrayNode ).items[i] = values.first().tree
38
- }))
53
+ // TODO: Call to modify
54
+ modify = sequence {
55
+ yield (Routine .Call ((0 until 10000 ). map{param[1 ]}.toFuzzed()) { instance, arguments ->
56
+ val obj = instance.tree as PythonTree .NdarrayNode
57
+ (0 until obj.dimention.fold(1 , Int ::times)).map {
58
+ obj.items[it] = arguments.get(it).tree
59
+ }
60
+
61
+ })
62
+ },
63
+ empty = Routine .Empty { PythonFuzzedValue (PythonTree .FakeNode ) }
64
+ )
65
+
66
+ )
39
67
}
40
68
}
0 commit comments