-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_compact.py
108 lines (85 loc) · 2.18 KB
/
game_compact.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from dataclasses import dataclass
from dataclasses_json import dataclass_json
from typing import List
@dataclass_json
@dataclass
class StateHistoryElem:
GraphVertexId: int
NumOfVisits: int
@dataclass_json
@dataclass
class State:
Id: int
Position: int
PredictedUsefulness: float
PathConditionSize: int
VisitedAgainVertices: int
VisitedNotCoveredVerticesInZone: int
VisitedNotCoveredVerticesOutOfZone: int
History: List[StateHistoryElem]
Children: List[int]
def __hash__(self) -> int:
return self.Id.__hash__()
@dataclass_json
@dataclass
class GameMapVertex:
Uid: int
Id: int
InCoverageZone: bool
BasicBlockSize: int
CoveredByTest: bool
VisitedByState: bool
TouchedByState: bool
States: List[int]
@dataclass_json
@dataclass
class GameEdgeLabel:
Token: int
@dataclass_json
@dataclass
class GameMapEdge:
VertexFrom: int
VertexTo: int
Label: GameEdgeLabel
@dataclass_json
@dataclass
class GameState:
GraphVertices: List[GameMapVertex]
States: List[State]
Map: List[GameMapEdge]
@dataclass_json
@dataclass
class GameMap:
Id: int
MaxSteps: int
CoverageToStart: int
AssemblyFullName: str
CoverageZone: bool
NameOfObjectToCover: str
def __hash__(self) -> int:
return self.Id.__hash__()
@dataclass_json
@dataclass
class MoveReward:
ForCoverage: int
ForVisitedInstructions: int
def __eq__(self, __o) -> bool:
if type(self) != type(__o):
raise RuntimeError(f"Can't compare {type(self)} with {type(__o)}")
return self == __o
def __add__(self, __o: "MoveReward") -> "MoveReward":
if type(self) != type(__o):
raise RuntimeError(f"Can't add {type(__o)} to {type(self)}")
return MoveReward(
self.ForCoverage + __o.ForCoverage,
self.ForVisitedInstructions + __o.ForVisitedInstructions,
)
def printable(self, verbose=False) -> str:
if verbose:
return f"ForVisitedInstructions: {self.ForVisitedInstructions}"
return f"#vi={self.ForVisitedInstructions}"
@dataclass_json
@dataclass
class Reward:
ForMove: MoveReward
MaxPossibleReward: int