test_ralearner.py 1.08 KB
Newer Older
1
2
import unittest

3
from tests.ra_testscenario import *
4
from z3gi.learn.ra import RALearner
5
from z3gi.define.ra import RegisterAutomaton
6
7
8
9
10
11
12
13
14

class RaTest(unittest.TestCase):
    def __init__(self):
        super.__init__()

    def setUp(self):
        self.ralearner = RALearner()


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
    def test_sut1(self):
        self.check_scenario(sut_m1)

    def test_sut2(self):
        self.check_scenario(sut_m2)

    def test_sut3(self):
        self.check_scenario(sut_m3)

    def check_scenario(self, test_scenario : RaTestScenario):
        ra = self.learn_model(test_scenario)
        self.assertIsNotNone(ra, "Register Automaton could not be infferred")
        self.assertEqual(len(ra.locations), test_scenario.nr_locations,
                         "Wrong number of locations")
        self.assertEqual(len(ra.locations), test_scenario.nr_locations,
                         "Wrong number of registers")

    def learn_model(self, test_scenario : RaTestScenario) -> RegisterAutomaton:
        for trace in test_scenario.traces:
34
35
36
37
38
            self.ralearner.add(trace)
        return self.ralearner.model()