diff --git a/automata/fa/dfa.py b/automata/fa/dfa.py index 448bd20c..f981b078 100644 --- a/automata/fa/dfa.py +++ b/automata/fa/dfa.py @@ -1276,8 +1276,6 @@ def predecessor( *, strict: bool = True, key: Optional[Callable[[Any], Any]] = None, - min_length: int = 0, - max_length: Optional[int] = None, ) -> Optional[str]: """ Returns the first string accepted by the DFA that comes before @@ -1293,10 +1291,6 @@ def predecessor( key : Optional[Callable], default: None Function for defining custom lexicographical ordering. Defaults to using the standard string ordering. - min_length : int, default: 0 - Limits generation to words with at least the given length. - max_length : Optional[int], default: None - Limits generation to words with at most the given length. Returns ------ @@ -1309,13 +1303,7 @@ def predecessor( Raised if the language accepted by self is infinite, as we cannot generate predecessors in this case. """ - for word in self.predecessors( - input_str, - strict=strict, - key=key, - min_length=min_length, - max_length=max_length, - ): + for word in self.predecessors(input_str, strict=strict, key=key): return word return None @@ -1325,8 +1313,6 @@ def predecessors( *, strict: bool = True, key: Optional[Callable[[Any], Any]] = None, - min_length: int = 0, - max_length: Optional[int] = None, ) -> Generator[str, None, None]: """ Generates all strings that come before the input string @@ -1342,10 +1328,6 @@ def predecessors( key : Optional[Callable], default: None Function for defining custom lexicographical ordering. Defaults to using the standard string ordering. - min_length : int, default: 0 - Limits generation to words with at least the given length. - max_length : Optional[int], default: None - Limits generation to words with at most the given length. Returns ------ @@ -1359,14 +1341,7 @@ def predecessors( Raised if the language accepted by self is infinite, as we cannot generate predecessors in this case. """ - yield from self.successors( - input_str, - strict=strict, - reverse=True, - key=key, - min_length=min_length, - max_length=max_length, - ) + yield from self.successors(input_str, strict=strict, reverse=True, key=key) def successor( self, @@ -1374,8 +1349,6 @@ def successor( *, strict: bool = True, key: Optional[Callable[[Any], Any]] = None, - min_length: int = 0, - max_length: Optional[int] = None, ) -> Optional[str]: """ Returns the first string accepted by the DFA that comes after @@ -1391,23 +1364,13 @@ def successor( key : Optional[Callable], default: None Function for defining custom lexicographical ordering. Defaults to using the standard string ordering. - min_length : int, default: 0 - Limits generation to words with at least the given length. - max_length : Optional[int], default: None - Limits generation to words with at most the given length. Returns ------ str The first string accepted by the DFA lexicographically before input_string. """ - for word in self.successors( - input_str, - strict=strict, - key=key, - min_length=min_length, - max_length=max_length, - ): + for word in self.successors(input_str, strict=strict, key=key): return word return None @@ -1418,8 +1381,6 @@ def successors( strict: bool = True, key: Optional[Callable[[Any], Any]] = None, reverse: bool = False, - min_length: int = 0, - max_length: Optional[int] = None, ) -> Generator[str, None, None]: """ Generates all strings that come after the input string @@ -1437,10 +1398,6 @@ def successors( the standard string ordering. reverse : bool, default: False If True, then predecessors will be generated instead of successors. - min_length : int, default: 0 - Limits generation to words with at least the given length. - max_length : Optional[int], default: None - Limits generation to words with at most the given length. Returns ------ @@ -1489,8 +1446,6 @@ def successors( if ( not reverse and should_yield - and min_length <= len(char_stack) - and (max_length is None or len(char_stack) <= max_length) and candidate == first_symbol and state in self.final_states ): @@ -1501,9 +1456,7 @@ def successors( else self._get_next_current_state(state, candidate) ) # Traverse to child if candidate is viable - if candidate_state in coaccessible_nodes and ( - max_length is None or len(char_stack) < max_length - ): + if candidate_state in coaccessible_nodes: state_stack.append(candidate_state) char_stack.append(cast(str, candidate)) candidate = first_symbol @@ -1512,8 +1465,6 @@ def successors( if ( reverse and should_yield - and min_length <= len(char_stack) - and (max_length is None or len(char_stack) <= max_length) and candidate is None and state in self.final_states ): @@ -1529,8 +1480,6 @@ def successors( if ( reverse and should_yield - and min_length <= len(char_stack) - and (max_length is None or len(char_stack) <= max_length) and candidate is None and state in self.final_states ): diff --git a/tests/test_dfa.py b/tests/test_dfa.py index 632b3103..44da097a 100644 --- a/tests/test_dfa.py +++ b/tests/test_dfa.py @@ -1836,9 +1836,6 @@ def test_predecessor(self, as_partial: bool) -> None: actual = list(dfa.predecessors("010", strict=False)) self.assertEqual(dfa.predecessor("000"), "00") - self.assertEqual(dfa.predecessor("000", max_length=1), "0") - self.assertEqual(dfa.predecessor("0", min_length=2), None) - self.assertEqual(dfa.predecessor("0000", min_length=2, max_length=3), "000") self.assertEqual(dfa.predecessor("0100"), "010") self.assertEqual(dfa.predecessor("1"), "010101111111101011010100") self.assertEqual( @@ -1875,10 +1872,6 @@ def test_successor(self, as_partial: bool) -> None: self.assertIsNone(dfa.successor("110")) self.assertIsNone(dfa.successor("111111110101011")) - self.assertEqual(dfa.successor("", min_length=3), "000") - self.assertEqual(dfa.successor("", min_length=4), "010101111111101011010100") - self.assertEqual(dfa.successor("010", max_length=6), "100") - infinite_dfa = DFA.from_nfa(NFA.from_regex("0*1*")) self.assertEqual(infinite_dfa.successor(""), "0") self.assertEqual(infinite_dfa.successor("0"), "00") @@ -1889,10 +1882,6 @@ def test_successor(self, as_partial: bool) -> None: self.assertEqual(infinite_dfa.successor("1"), "11") self.assertEqual(infinite_dfa.successor(100 * "0"), 101 * "0") self.assertEqual(infinite_dfa.successor(100 * "1"), 101 * "1") - self.assertEqual(infinite_dfa.successor("", min_length=5), "00000") - self.assertEqual(infinite_dfa.successor("000", min_length=5), "00000") - self.assertEqual(infinite_dfa.successor("1", min_length=5), "11111") - self.assertEqual(infinite_dfa.successor("1111", max_length=4), None) @params(True, False) def test_successor_and_predecessor(self, as_partial: bool) -> None: