def test_node_with_several_remaining_values_is_returned_repeatedly_until_exhausted( self): unexhausted_node_one = new_unexhausted_mock_node( "A", remaining_value_count=2) unexhausted_node_two = new_unexhausted_mock_node( "B", remaining_value_count=3) stack = _SearchGraphNodeStack() stack.push(unexhausted_node_one) stack.push(new_exhausted_mock_node("C")) stack.push(unexhausted_node_two) self.assertIs(stack.backtrack_to_first_unexhausted_node(), unexhausted_node_two) self.assertIs(stack.backtrack_to_first_unexhausted_node(), unexhausted_node_two) self.assertIs(stack.backtrack_to_first_unexhausted_node(), unexhausted_node_two) self.assertIs(stack.backtrack_to_first_unexhausted_node(), unexhausted_node_one) self.assertIs(stack.backtrack_to_first_unexhausted_node(), unexhausted_node_one) self.assertIsNone(stack.backtrack_to_first_unexhausted_node())
def test_backtrack_with_stack_containing_only_exhausted_nodes_returns_none( self): stack = _SearchGraphNodeStack() stack.push(new_exhausted_mock_node()) stack.push(new_exhausted_mock_node()) stack.push(new_exhausted_mock_node()) self.assertIsNone(stack.backtrack_to_first_unexhausted_node())
def test_backtrack_with_stack_containing_two_or_more_unexhausted_nodes_returns_the_topmost_unexhausted_node( self): unexhausted_node_one = new_unexhausted_mock_node() unexhausted_node_two = new_unexhausted_mock_node() stack = _SearchGraphNodeStack() stack.push(new_exhausted_mock_node()) stack.push(new_exhausted_mock_node()) stack.push(unexhausted_node_one) stack.push(unexhausted_node_two) self.assertIs(stack.backtrack_to_first_unexhausted_node(), unexhausted_node_two)
def test_backtracking_preserves_lifo_semantics(self): unexhausted_node_one = new_unexhausted_mock_node("A") unexhausted_node_two = new_unexhausted_mock_node("B") unexhausted_node_three = new_unexhausted_mock_node("C") stack = _SearchGraphNodeStack() stack.push(new_exhausted_mock_node("D")) stack.push(new_exhausted_mock_node("E")) stack.push(unexhausted_node_one) stack.push(unexhausted_node_two) stack.push(new_exhausted_mock_node("F")) stack.push(unexhausted_node_three) self.assertIs(stack.backtrack_to_first_unexhausted_node(), unexhausted_node_three) self.assertIs(stack.backtrack_to_first_unexhausted_node(), unexhausted_node_two) self.assertIs(stack.backtrack_to_first_unexhausted_node(), unexhausted_node_one) self.assertIsNone(stack.backtrack_to_first_unexhausted_node())
def test_backtrack_with_empty_virgin_stack_returns_none(self): stack = _SearchGraphNodeStack() self.assertIsNone(stack.backtrack_to_first_unexhausted_node())