Class: Cucumber::CucumberExpressions::CombinatorialGeneratedExpressionFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-cucumber-expressions-15.2.0/lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb

Constant Summary collapse

MAX_EXPRESSIONS =

256 generated expressions ought to be enough for anybody

256

Instance Method Summary collapse

Constructor Details

#initialize(expression_template, parameter_type_combinations) ⇒ CombinatorialGeneratedExpressionFactory

Returns a new instance of CombinatorialGeneratedExpressionFactory.



7
8
9
10
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-cucumber-expressions-15.2.0/lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb', line 7

def initialize(expression_template, parameter_type_combinations)
  @expression_template = expression_template
  @parameter_type_combinations = parameter_type_combinations
end

Instance Method Details

#generate_expressionsObject



12
13
14
15
16
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-cucumber-expressions-15.2.0/lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb', line 12

def generate_expressions
  generated_expressions = []
  generate_permutations(generated_expressions, 0, [])
  generated_expressions
end

#generate_permutations(generated_expressions, depth, current_parameter_types) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-cucumber-expressions-15.2.0/lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb', line 21

def generate_permutations(generated_expressions, depth, current_parameter_types)
  if generated_expressions.length >= MAX_EXPRESSIONS
    return
  end

  if depth == @parameter_type_combinations.length
    generated_expression = GeneratedExpression.new(@expression_template, current_parameter_types)
    generated_expressions.push(generated_expression)
    return
  end

  (0...@parameter_type_combinations[depth].length).each do |i|
    # Avoid recursion if no elements can be added.
    if generated_expressions.length >= MAX_EXPRESSIONS
      return
    end
    new_current_parameter_types = current_parameter_types.dup # clone
    new_current_parameter_types.push(@parameter_type_combinations[depth][i])
    generate_permutations(
        generated_expressions,
        depth + 1,
        new_current_parameter_types
    )
  end
end