Exemplo n.º 1
0
    def test_accepts(self, word):
        """Test the behaviour of the method 'accepts'."""
        simulator = AutomatonSimulator(self.dfa)

        assert simulator.accepts(word) == self.dfa.accepts(word)

        for index, symbol in enumerate(word):
            simulator.step(symbol)
            assert simulator.accepts(word[index:]) == self.dfa.accepts(word)
Exemplo n.º 2
0
    def test_reset(self, word):
        """Test the behaviour of the method 'reset'."""
        simulator = AutomatonSimulator(self.dfa)

        assert not simulator.is_started
        assert simulator.cur_state == {self.dfa.initial_state}

        for symbol in word:
            simulator.step(symbol)
            assert simulator.is_started

        initial_state = simulator.reset()
        assert not simulator.is_started
        assert simulator.cur_state == initial_state == {self.dfa.initial_state}
Exemplo n.º 3
0
    def test_is_failed(self):
        """Test the behaviour of the method 'is_failed'."""
        simulator = AutomatonSimulator(self.dfa)

        assert not simulator.is_failed()
        simulator.step("a")
        assert not simulator.is_failed()
        simulator.step("b")
        assert not simulator.is_failed()
        simulator.step("c")
        assert not simulator.is_failed()
        simulator.step("d")
        assert simulator.is_failed()
Exemplo n.º 4
0
    def test_step(self, word):
        """Test the behaviour of the method 'step'."""
        simulator = AutomatonSimulator(self.dfa)

        for symbol in word:
            previous_states = simulator.cur_state
            current_states = simulator.step(symbol)
            expected_current_states = reduce(
                set.union,
                [self.dfa.get_successors(s, symbol) for s in previous_states],
                set(),
            )
            assert simulator.cur_state == current_states == expected_current_states
Exemplo n.º 5
0
    def test_is_true(self):
        """Test the behaviour of the method 'is_true'."""
        simulator = AutomatonSimulator(self.dfa)

        assert not simulator.is_true()
        simulator.step({"a": True})
        assert not simulator.is_true()
        simulator.step({"b": True})
        assert not simulator.is_true()
        simulator.step({"c": True})
        assert simulator.is_true()