Code Smell: Long Parameter List.

Changed code: …

  1 class DoubleSeries
  2 
  3 def self.generate_sequences(sequence_1, sequence_2, iterations)
  4     item_1, item_2 = sequence_1.start, sequence_2.start
  5     result=[]
  6     (1..iterations).each do
  7       result << item_1 << item_2
  8       item_1 += sequence_1.step
  9       item_2 += sequence_2.step
 10     end
 11     result
 12   end
 13 end

  1 require_relative 'DoubleSeries'
  2 require_relative 'Sequence'
  3 
  4 describe "Generation of two interleaved sequences" do
  5   it "" do
  6     sequence_1 = Sequence.new(1,1)
  7     sequence_2 = Sequence.new(10,5)
  8     DoubleSeries.generate_sequences(sequence_1,sequence_2,3).should == [1,10,2,15,3,20]
  9   end
 10   it "" do
 11     sequence_1 = Sequence.new(1,1)
 12     sequence_2 = Sequence.new(4,2)
 13     DoubleSeries.generate_sequences(sequence_1,sequence_2,2).should == [1,4,2,6]
 14   end
 15 end

  1 class Sequence
  2   attr_reader :start, :step
  3 
  4   def initialize(start, step)
  5     @start = start
  6     @step = step
  7   end

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s