Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rick Smetsers
z3gi
Commits
f409167b
Commit
f409167b
authored
Nov 27, 2018
by
Paul Fiterau Brostean
Browse files
Added provisional fix to problem
parent
bc84e65e
Changes
1
Hide whitespace changes
Inline
Side-by-side
z3gi/test/__init__.py
View file @
f409167b
from
abc
import
ABCMeta
,
abstractmethod
from
typing
import
List
,
Generator
,
Iterable
,
Tuple
from
typing
import
List
,
Generator
,
Iterable
,
Tuple
,
Set
import
itertools
from
model
import
Automaton
,
Acceptor
,
Transducer
...
...
@@ -17,6 +17,10 @@ class Test(metaclass=ABCMeta):
def
check
(
self
,
model
:
Automaton
):
"""checks if the hyp passes the test. On failure, it returns a minimal trace to be added by the learner.
On success it return None"""
# TODO this is a quick fix to the problem of not having a predefined alphabet from the very start.
# if the trace contains new labels, then we return whole trace
if
len
(
self
.
input_labels
().
difference
(
model
.
input_labels
()))
!=
0
:
return
self
.
tr
return
self
.
_check_trace
(
model
,
self
.
tr
)
@
abstractmethod
...
...
@@ -36,6 +40,27 @@ class Test(metaclass=ABCMeta):
def
covers
(
self
,
test
)
->
bool
:
pass
@
abstractmethod
def
inputs
(
self
)
->
List
[
object
]:
pass
def
input_labels
(
self
)
->
Set
[
object
]:
"""generates all the input labels in the test trace. Used to verify that model contains all test input labels"""
inputs
=
self
.
inputs
()
input_labels
=
set
()
for
inp
in
inputs
:
# if it's RA stuff
if
isinstance
(
inp
,
Action
):
(
label
,
_
)
=
inp
elif
isinstance
(
inp
,
str
):
label
=
inp
else
:
raise
Exception
(
"Unrecognized type"
)
input_labels
.
add
(
label
)
return
input_labels
class
EqualTestsMixin
(
metaclass
=
ABCMeta
):
"""doesn't work unfortunately"""
def
__eq__
(
self
,
other
):
...
...
@@ -131,6 +156,9 @@ class TransducerTest(Test):
def
size
(
self
):
return
len
(
self
.
tr
)
def
inputs
(
self
):
return
[
inp
for
(
inp
,
_
)
in
self
.
tr
]
def
covers
(
self
,
test
):
if
type
(
test
)
is
type
(
self
)
and
len
(
test
.
trace
())
<=
len
(
self
.
trace
()):
for
((
inp
,
_
),(
inp2
,
_
))
in
zip
(
self
.
trace
(),
test
.
trace
()):
...
...
@@ -186,6 +214,10 @@ class AcceptorTest(Test):
(
seq
,
acc
)
=
self
.
tr
return
len
(
seq
)
def
inputs
(
self
):
(
seq
,
acc
)
=
self
.
tr
return
seq
def
__hash__
(
self
):
(
seq
,
acc
)
=
self
.
tr
return
hash
((
type
(
self
),
frozenset
(
seq
),
acc
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment