forked from jon-jacky/PyModel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActionNameCoverage.py
30 lines (25 loc) · 1 KB
/
ActionNameCoverage.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
"""
ActionNameCoverage: choose the action name which has been used least
"""
import sys
import random
# Tester state is a bag of action names: { aname : n of times used }
coverage = dict()
def SelectAction(enabled):
"""
Choose the action symbol which has been used the least number of times.
If more than one action has been used that many times, choose randomly.
"""
if not enabled: # empty
return (None, None)
else:
coverage.update(dict([(aname,0)
for (aname,args,result,next,properties) in enabled
if aname not in coverage])) # multiple occurs OK
least = min([coverage[aname]
for (aname,args,result,next,properties) in enabled])
aleast = [(aname,args) for (aname,args,result,next,properties) in enabled
if coverage[aname] == least]
(aname,args) = random.choice(aleast)
coverage[aname] += 1
return (aname,args)