test_ralearner.py 1.1 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

class RaTest(unittest.TestCase):

    def setUp(self):
10
        self.ralearner = RALearner(labels, verbose=True)
11

12
13
    def test_sut1(self):
        self.check_scenario(sut_m1)
14
        # pass
15

16
17
18
19
20
21
22
    #def test_sut2(self):
    #    pass
    #    # self.check_scenario(sut_m2)
    #
    #def test_sut3(self):
    #    pass
    ##    self.check_scenario(sut_m3)
23
24
25

    def check_scenario(self, test_scenario : RaTestScenario):
        ra = self.learn_model(test_scenario)
26
        self.assertIsNotNone(ra, "Register Automaton could not be inferred")
27
28
29
30
31
32
33
        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()