Esempio n. 1
0
    def test_one_node(self):
        dfa = DFAParser.from_dict({
            'accepts': {0},
            'start': 0,
            'transitions': {
                0: {
                    'a': 0
                }
            }
        })

        teacher = csteacher.CharacteristicSetTeacher(dfa)
        result = teacher.construct_char_set()
        self.assertCountEqual(result[0], ['a'])
        self.assertCountEqual(result[1], [])
Esempio n. 2
0
    def test_two_circular(self):
        dfa = DFAParser.from_dict(
            {'accepts': {0, 1},
             'start': 0,
             'transitions': {0: {'a': 1}, 1: {'a': 0}}})

        t = csteacher.CharacteristicSetTeacher(dfa)
        samples = t.construct_char_set()

        l = Learner(drawsteps=False)
        learned_dfa = l.rpni(samples[0], samples[1])
        for pos_sample in samples[0]:
            self.assertTrue(learned_dfa.recognizes(pos_sample))

        for neg_sample in samples[1]:
            self.assertFalse(learned_dfa.recognizes(neg_sample))
Esempio n. 3
0
    def test_big_dfa(self):
        dfa = DFAParser.from_dict(
            {'accepts': {'aa','aaa','aaab','aba','b','babab' },    
             'start': 'start',
             'transitions': {'a': {'a': 'aa', 'b': 'ab'}, 'aa': {'a': 'aaa'}, 'aaa': {'b': 'aaab'}, 'aaab':{}, 'ab':{'a':'aba'}, 'aba': {}, 'b' : {'a': 'ba'}, 'ba': {'b': 'bab'}, 'bab': {'a': 'baba'}, 'baba': {'b': 'babab'}, 'babab': {}, 'sink': {}, 'start': {'a': 'a', 'b': 'b'}}})

        t = csteacher.CharacteristicSetTeacher(dfa)
        samples = t.construct_char_set()

        l = Learner(drawsteps=False)
        learned_dfa = l.rpni(samples[0], samples[1])
        
        for pos_sample in samples[0]:
            self.assertTrue(learned_dfa.recognizes(pos_sample))

        for neg_sample in samples[1]:
            self.assertFalse(learned_dfa.recognizes(neg_sample))
Esempio n. 4
0
    def test_single_path(self):
        dfa = DFAParser.from_dict({
            'accepts': {3},
            'start': 0,
            'transitions': {
                0: {
                    'a': 1
                },
                1: {
                    'a': 2
                },
                2: {
                    'b': 3
                }
            }
        })

        teacher = csteacher.CharacteristicSetTeacher(dfa)
        result = teacher.construct_char_set()
        self.assertCountEqual(result[0], ['aab'])
        self.assertCountEqual(result[1], ['a', 'aa'])