Ejemplo n.º 1
0
    def test_map_properties(self):
        dvfa_3pal = dvfa_generator.create_3PAL_DVFA()
        assert len(dvfa_3pal.const_set) is 0
        assert len(dvfa_3pal.var_set) is 1

        dvfa_1_x_plus = dvfa_generator.create_1_x_plus_DVFA()
        assert len(dvfa_1_x_plus.const_set) is 1
        assert len(dvfa_1_x_plus.var_set) is 1
Ejemplo n.º 2
0
    def test_3PAL_dvfa_on_empty_word(self):
        # test that 3pal vdfa not accepting an empty word

        # setup
        word = dvfa_tool.word.Word([])

        dvfa = dvfa_generator.create_3PAL_DVFA()

        # run
        run = dvfa_tool.run.Run(dvfa, word)
        res = run.run()

        # test
        assert res is False  # cant accept empty word
Ejemplo n.º 3
0
    def test_complement_3pal(self):
        dvfa_3pal = dvfa_generator.create_3PAL_DVFA()
        dvfa_3pal_complement = dvfa_3pal.complement()

        word1 = dvfa_tool.word.Word([1, 2, 2])
        word2 = dvfa_tool.word.Word([1, 2, 1])
        word3 = dvfa_tool.word.Word([1, 1, 1])
        word4 = dvfa_tool.word.Word([1, 2])
        word5 = dvfa_tool.word.Word([1, 2, 3, 2, 2, 1])

        word_list = [word1, word2, word3, word4, word5]

        for word in word_list:
            original_run = dvfa_tool.run.Run(dvfa=dvfa_3pal, word=word).run()
            complementing_run = dvfa_tool.run.Run(dvfa=dvfa_3pal_complement,
                                                  word=word).run()
            assert original_run != complementing_run
Ejemplo n.º 4
0
    def test_copy_3pal(self):
        dvfa_3pal = dvfa_generator.create_3PAL_DVFA()
        dvfa_3pal_copy = dvfa_3pal.copy()

        word1 = dvfa_tool.word.Word([1, 2, 2])
        word2 = dvfa_tool.word.Word([1, 2, 1])
        word3 = dvfa_tool.word.Word([1, 1, 1])
        word4 = dvfa_tool.word.Word([1, 2])
        word5 = dvfa_tool.word.Word([1, 2, 3, 2, 2, 1])

        word_list = [word1, word2, word3, word4, word5]

        for word in word_list:
            expected_run = dvfa_tool.run.Run(dvfa=dvfa_3pal, word=word).run()
            actual_run = dvfa_tool.run.Run(dvfa=dvfa_3pal_copy,
                                           word=word).run()
            assert expected_run == actual_run
Ejemplo n.º 5
0
    def test_3PAL_dvfa(self):
        # test if we can properly create and run on a dvfa that accepts ALL 3pal.

        # setup
        word = dvfa_tool.word.Word([1, 1, 1])

        dvfa = dvfa_generator.create_3PAL_DVFA()

        # run
        run = dvfa_tool.run.Run(dvfa, word)

        break_flag = False
        config = None

        while not break_flag:
            config = run.next_state()
            break_flag = config.has_finished()

        # test
        assert config.remaining_word.get_word_length() is 0
        assert config.is_current_state_accepting() is True
Ejemplo n.º 6
0
    def test_3PAL_dvfa_sink_works_for_reading_y_more_than_once(self):
        # test if run can run on longer words that the designated language without crushing.

        # setup
        word = dvfa_tool.word.Word([1, 2, 1, 3, 4, 5])

        dvfa = dvfa_generator.create_3PAL_DVFA()

        # run
        run = dvfa_tool.run.Run(dvfa, word)

        break_flag = False
        config = None

        while not break_flag:
            config = run.next_state()
            break_flag = config.has_finished()

        # test
        assert config.remaining_word.get_word_length() is 0
        assert config.is_current_state_accepting() is False
Ejemplo n.º 7
0
    def test_3PAL_dvfa_using_wildcard(self):
        # test if we can properly create and run on a dvfa that accepts ALL 3pal.

        # setup
        word = dvfa_tool.word.Word([1, 2, 1])  # this is special case - it make our DVFA use the "y" wildcard.

        dvfa = dvfa_generator.create_3PAL_DVFA()

        # run
        run = dvfa_tool.run.Run(dvfa, word)

        break_flag = False
        config = None

        while not break_flag:
            config = run.next_state()
            break_flag = config.has_finished()

        # test
        assert config.remaining_word.get_word_length() is 0
        assert config.is_y_read is True
        assert config.is_current_state_accepting() is True
Ejemplo n.º 8
0
    def test_intersect(self):
        # Setup
        dvfa_1_x_plus = dvfa_generator.create_1_x_plus_DVFA()
        dvfa_3pal = dvfa_generator.create_3PAL_DVFA()

        word1 = dvfa_tool.word.Word([1, 2, 2])
        word2 = dvfa_tool.word.Word([1, 2, 1])
        word3 = dvfa_tool.word.Word([1, 1, 1])
        word4 = dvfa_tool.word.Word([1, 2])
        word5 = dvfa_tool.word.Word([1, 2, 3, 2, 2, 1])

        word_list = [word1, word2, word3, word4, word5]

        # Run
        intersect_dvfa = dvfa_tool.dvfa.DVFA.intersect(dvfa_3pal,
                                                       dvfa_1_x_plus)

        # Test
        for word in word_list:
            a1_run = dvfa_tool.run.Run(dvfa=dvfa_1_x_plus, word=word).run()
            a2_run = dvfa_tool.run.Run(dvfa=dvfa_3pal, word=word).run()
            intersect_run = dvfa_tool.run.Run(dvfa=intersect_dvfa,
                                              word=word).run()
            assert intersect_run == (a1_run and a2_run)
Ejemplo n.º 9
0
    def test_unwind_3PAL(self):
        """Test for unwinding functionality."""
        # setup
        word1 = dvfa_tool.word.Word([1, 2, 2])
        word2 = dvfa_tool.word.Word([1, 2, 1])
        word3 = dvfa_tool.word.Word([1, 1, 1])
        word4 = dvfa_tool.word.Word([1, 2])
        word5 = dvfa_tool.word.Word([1, 2, 3, 2, 2, 1])

        dvfa = dvfa_generator.create_3PAL_DVFA()

        # run
        unwinded_dvfa, unwind_dict = dvfa_tool.dvfa.DVFA.unwind(dvfa)

        # test
        assert len(unwinded_dvfa.var_set) == len(dvfa.var_set)
        assert len(unwinded_dvfa.const_set) == len(dvfa.const_set)

        # Checking language of unwinded vs standard 3PAL against 5 words
        break_flag = False
        run = dvfa_tool.run.Run(unwinded_dvfa, word1)
        while not break_flag:
            config = run.next_state()
            break_flag = config.has_finished()

        # test
        assert config.remaining_word.get_word_length() is 0
        assert config.is_current_state_accepting() is False

        break_flag = False
        run = dvfa_tool.run.Run(unwinded_dvfa, word2)
        while not break_flag:
            config = run.next_state()
            break_flag = config.has_finished()

        # test
        assert config.remaining_word.get_word_length() is 0
        assert config.is_current_state_accepting() is True

        break_flag = False
        run = dvfa_tool.run.Run(unwinded_dvfa, word3)
        while not break_flag:
            config = run.next_state()
            break_flag = config.has_finished()

        # test
        assert config.remaining_word.get_word_length() is 0
        assert config.is_current_state_accepting() is True

        break_flag = False
        run = dvfa_tool.run.Run(unwinded_dvfa, word4)
        while not break_flag:
            config = run.next_state()
            break_flag = config.has_finished()

        # test
        assert config.remaining_word.get_word_length() is 0
        assert config.is_current_state_accepting() is False

        break_flag = False
        run = dvfa_tool.run.Run(unwinded_dvfa, word5)
        while not break_flag:
            config = run.next_state()
            break_flag = config.has_finished()

        # test
        assert config.remaining_word.get_word_length() is 0
        assert config.is_current_state_accepting() is False
Ejemplo n.º 10
0
    def generate_automata_new(self, filewin, generate_3pal):
        """Function for generating VFA. """

        filewin.destroy()
        # todo: add dummy proof - check for integer only
        global_dvfa_1 = dvfa_generator.create_3PAL_DVFA()