Sha256: daf0e14849fc8cd4810430e3d82087ecb36364df6071455c7bdb81905c3a496b

Contents?: true

Size: 1.58 KB

Versions: 48

Compression:

Stored size: 1.58 KB

Contents

require('cucumber/cucumber_expressions/generated_expression')

module Cucumber
  module CucumberExpressions

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

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

      # 256 generated expressions ought to be enough for anybody
      MAX_EXPRESSIONS = 256

      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
    end

  end
end

Version data entries

48 entries across 48 versions & 5 rubygems

Version Path
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/cucumber-cucumber-expressions-16.1.2/lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb
rubypitaya-3.12.5 ./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
rubypitaya-3.12.4 ./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
rubypitaya-3.12.3 ./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
cucumber-cucumber-expressions-16.1.2 lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb
rubypitaya-3.12.2 ./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
cucumber-cucumber-expressions-16.1.1 lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb
cucumber-cucumber-expressions-16.1.0 lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb
cucumber-cucumber-expressions-16.0.1 lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb
cucumber-cucumber-expressions-16.0.0 lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb
cucumber-cucumber-expressions-15.2.0 lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb
cucumber-cucumber-expressions-15.1.1 lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb
cucumber-cucumber-expressions-15.1.0 lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb
cucumber-cucumber-expressions-15.0.2 lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/cucumber-cucumber-expressions-14.0.0/lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb
cucumber-cucumber-expressions-15.0.1 lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb
cucumber-cucumber-expressions-14.0.0 lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb
cucumber-cucumber-expressions-13.1.3 lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb
cucumber-cucumber-expressions-13.1.2 lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb
cucumber-cucumber-expressions-13.1.1 lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb