コード例 #1
0
    def test_not_matchable(self):
        self.nt = Terminal('X', matchable=False)

        path = map_path('X')
        matches = self.nt.match_path(path)
        expected_result = []
        self.assertListEqual(matches, expected_result)
コード例 #2
0
ファイル: apt_diagnoser_test.py プロジェクト: winsena/adapt
    def setUp(self):
        # Graph =
        #     9
        #  /  |  \
        # 6   7   8
        #  \ / \ /
        #   4   5
        #  / \ / \
        # 1   2   3
        self.g1 = InmemoryGraph()
        edges = [(1, 4), (2, 4), (2, 5), (3, 5), (4, 6), (4, 7), (5, 7),
                 (5, 8), (6, 9), (7, 9), (8, 9)]

        for edge in edges:
            self.g1.add_edge(*edge)

        self.g1.add_node_label(1, 'A')
        self.g1.add_node_label(3, 'A')
        self.g1.add_node_label(7, 'B')
        self.g1.add_node_label(9, 'C')

        g1 = Sequence(
            [Terminal('A'), Terminal('B'),
             Terminal('C')], 'sequence')
        self.matcher1 = StatelessMatcher(g1)
        self.apt_diagnoser = APTDiagnoser(self.g1, self.matcher1)
コード例 #3
0
ファイル: sequence_test.py プロジェクト: winsena/adapt
    def test_nested(self):
        s2 = Sequence(
            [Terminal('A'), self.s, Terminal('C')],
            'sequence2',
            matchable='False')

        path = map_path('AABCC')
        matches = s2.match_path(path)
        expected_result = \
            [MatcherResult(path, [(0, 'A'), (1, 'A'), (2, 'B'), (3, 'C'), (4, 'C')], counter=4)]
        self.assertListEqual(matches, expected_result)
コード例 #4
0
class TerminalMatcherTest(unittest.TestCase):
    def setUp(self):
        self.nt = Terminal('X')

    def test_label(self):
        self.assertEqual('X', self.nt.get_label())

    def test_simple_path(self):
        path = map_path('abcXdeX')
        matches = self.nt.match_path(path)
        expected_result = [
            MatcherResult(path, [(3, 'X')], counter=3),
            MatcherResult(path, [(6, 'X')], counter=6)
        ]
        self.assertListEqual(matches, expected_result)

    def test_multiple_symbols(self):
        path = [['a'], ['b', 'X'], ['X', 'c']]
        matches = self.nt.match_path(path)
        expected_result = [
            MatcherResult(path, [(1, 'X')], counter=1),
            MatcherResult(path, [(2, 'X')], counter=2)
        ]
        self.assertListEqual(matches, expected_result)

    def test_empty_path(self):
        path = []
        matches = self.nt.match_path(path)
        expected_result = []
        self.assertListEqual(matches, expected_result)

    def test_mid_match(self):
        path = map_path('wXyXyz')
        matches = self.nt.match(MatcherResult(path, [(1, 'X')], counter=2))
        expected_result = [
            MatcherResult(path, [(1, 'X'), (3, 'X')], counter=3)
        ]

        self.assertListEqual(matches, expected_result)

    def test_not_matchable(self):
        self.nt = Terminal('X', matchable=False)

        path = map_path('X')
        matches = self.nt.match_path(path)
        expected_result = []
        self.assertListEqual(matches, expected_result)

    def test_reverse(self):
        path = map_path('abcXdeX')
        matches = self.nt.match_reverse_path(path)
        expected_result = [
            MatcherResult(path, [(6, 'X')], counter=6, reverse=True),
            MatcherResult(path, [(3, 'X')], counter=3, reverse=True)
        ]
        self.assertListEqual(matches, expected_result)
コード例 #5
0
ファイル: sequence_test.py プロジェクト: winsena/adapt
 def setUp(self):
     self.s = Sequence(
         [Terminal('A'), Terminal('B'),
          Terminal('C')], 'sequence')
コード例 #6
0
ファイル: sequence_test.py プロジェクト: winsena/adapt
    def test_cardinality(self):
        with self.assertRaises(RuleException):
            Sequence('s')

        with self.assertRaises(RuleException):
            Sequence('s', Terminal('A'))
コード例 #7
0
 def setUp(self):
     self.nt = Terminal('X')
コード例 #8
0
ファイル: matcher_test.py プロジェクト: winsena/adapt
 def setUp(self):
     g1 = Sequence(
         [Terminal('A'), Terminal('B'),
          Terminal('C')], 'sequence')
     self.matcher1 = StatelessMatcher(g1, CrispStrategy())
コード例 #9
0
 def setUp(self):
     self.ot = Optional([Terminal('A')])
     self.os = Optional([Sequence([Terminal('B'),
                                   Terminal('C')])])
コード例 #10
0
 def setUp(self):
     self.c = Choice(
         [Terminal('A'), Terminal('B'),
          Terminal('C')], 'choice')
コード例 #11
0
    def test_cardinality(self):
        with self.assertRaises(RuleException):
            Choice([Terminal('A')])

        with self.assertRaises(RuleException):
            Choice([])