Решение на Трета задача от Ивайло Таушанов

Обратно към всички решения

Към профила на Ивайло Таушанов

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 20 неуспешни тест(а)

Код

class FibonacciSequence
include Enumerable
def initialize(limit, first:, second:)
@limit = limit
@first = first
@second = second
end
def each
while @first < @limit
yield @first
@first, @second = @first + @second, @first
end
end
end

Лог от изпълнението

FFFFFFFFFFFFFFFFFFFF

Failures:

  1) Fifth task RationalSequence can calculate the first four rational numbers
     Failure/Error: expect(RationalSequence.new(4).to_a).to eq %w(1/1 2/1 1/2 1/3).map(&:to_r)
     NameError:
       uninitialized constant RationalSequence
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:4:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) Fifth task RationalSequence returns an empty array when count is 0
     Failure/Error: expect(RationalSequence.new(0).to_a).to eq []
     NameError:
       uninitialized constant RationalSequence
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:8:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) Fifth task RationalSequence can calculate the first 28 rational numbers
     Failure/Error: expect(RationalSequence.new(28).to_a).to eq %w(
     NameError:
       uninitialized constant RationalSequence
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:12:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) Fifth task RationalSequence is properly enumerable
     Failure/Error: ones = RationalSequence.new(28).select { |r| r.numerator == 1 }
     NameError:
       uninitialized constant RationalSequence
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:19:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) Fifth task FibonacciSequence can return the first two Fibonacci numbers
     Failure/Error: expect(FibonacciSequence.new(2).to_a).to eq [1, 1]
     ArgumentError:
       missing keywords: first, second
     # /tmp/d20151111-27349-1q0h3pb/solution.rb:4:in `initialize'
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:26:in `new'
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:26:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) Fifth task FibonacciSequence can return the first 20 Fibonacci numbers
     Failure/Error: expect(FibonacciSequence.new(20).to_a).to eq [
     ArgumentError:
       missing keywords: first, second
     # /tmp/d20151111-27349-1q0h3pb/solution.rb:4:in `initialize'
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:30:in `new'
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:30:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) Fifth task FibonacciSequence can be used to calculate the Lucas numbers
     Failure/Error: expect(FibonacciSequence.new(31, first: 2, second: 1).to_a).to eq [
       
       expected: [2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199, 322, 521, 843, 1364, 2207, 3571, 5778, 9349, 15127, 24476, 39603, 64079, 103682, 167761, 271443, 439204, 710647, 1149851, 1860498]
            got: [2, 3, 5, 8, 13, 21]
       
       (compared using ==)
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:37:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) Fifth task FibonacciSequence is properly enumerable
     Failure/Error: expect(FibonacciSequence.new(20).select { |x| x.even? }).to eq [
     ArgumentError:
       missing keywords: first, second
     # /tmp/d20151111-27349-1q0h3pb/solution.rb:4:in `initialize'
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:45:in `new'
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:45:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  9) Fifth task PrimeSequence returns an empty array for 0 primes
     Failure/Error: expect(PrimeSequence.new(0).to_a).to eq []
     NameError:
       uninitialized constant PrimeSequence
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:53:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  10) Fifth task PrimeSequence can tell which the first two primes are
     Failure/Error: expect(PrimeSequence.new(2).to_a).to eq [2, 3]
     NameError:
       uninitialized constant PrimeSequence
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:57:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  11) Fifth task PrimeSequence can tell the first 58 primes
     Failure/Error: expect(PrimeSequence.new(58).to_a).to eq [
     NameError:
       uninitialized constant PrimeSequence
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:61:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  12) Fifth task DrunkenMathematician #meaningless can calculate for 0 and 1
     Failure/Error: expect(DrunkenMathematician.meaningless(0)).to eq 1
     NameError:
       uninitialized constant DrunkenMathematician
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:73:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  13) Fifth task DrunkenMathematician #meaningless can calculate for 3
     Failure/Error: expect(DrunkenMathematician.meaningless(4)).to eq Rational(1, 3)
     NameError:
       uninitialized constant DrunkenMathematician
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:78:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  14) Fifth task DrunkenMathematician #meaningless can calculate for 42
     Failure/Error: expect(DrunkenMathematician.meaningless(42)).to eq Rational(1, 11)
     NameError:
       uninitialized constant DrunkenMathematician
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:82:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  15) Fifth task DrunkenMathematician #aimless can calculate for 3
     Failure/Error: expect(DrunkenMathematician.aimless(3)).to eq(Rational(2, 3) + Rational(5, 1))
     NameError:
       uninitialized constant DrunkenMathematician
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:88:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  16) Fifth task DrunkenMathematician #aimless can calculate for 4
     Failure/Error: expect(DrunkenMathematician.aimless(4)).to eq(Rational(2, 3) + Rational(5, 7))
     NameError:
       uninitialized constant DrunkenMathematician
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:92:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  17) Fifth task DrunkenMathematician #aimless can calculate for 42
     Failure/Error: expect(DrunkenMathematician.aimless(42)).to eq expected
     NameError:
       uninitialized constant DrunkenMathematician
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:97:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  18) Fifth task DrunkenMathematician #worthless can calculate for 2
     Failure/Error: expect(DrunkenMathematician.worthless(2)).to eq %w(1/1).map(&:to_r)
     NameError:
       uninitialized constant DrunkenMathematician
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:103:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  19) Fifth task DrunkenMathematician #worthless can calculate for 8
     Failure/Error: expect(DrunkenMathematician.worthless(8)).to eq expected
     NameError:
       uninitialized constant DrunkenMathematician
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:108:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  20) Fifth task DrunkenMathematician #worthless can calculate for 15
     Failure/Error: expect(DrunkenMathematician.worthless(15)).to eq %w(
     NameError:
       uninitialized constant DrunkenMathematician
     # /tmp/d20151111-27349-1q0h3pb/spec.rb:112:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.03048 seconds
20 examples, 20 failures

Failed examples:

rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:3 # Fifth task RationalSequence can calculate the first four rational numbers
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:7 # Fifth task RationalSequence returns an empty array when count is 0
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:11 # Fifth task RationalSequence can calculate the first 28 rational numbers
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:18 # Fifth task RationalSequence is properly enumerable
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:25 # Fifth task FibonacciSequence can return the first two Fibonacci numbers
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:29 # Fifth task FibonacciSequence can return the first 20 Fibonacci numbers
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:36 # Fifth task FibonacciSequence can be used to calculate the Lucas numbers
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:44 # Fifth task FibonacciSequence is properly enumerable
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:52 # Fifth task PrimeSequence returns an empty array for 0 primes
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:56 # Fifth task PrimeSequence can tell which the first two primes are
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:60 # Fifth task PrimeSequence can tell the first 58 primes
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:72 # Fifth task DrunkenMathematician #meaningless can calculate for 0 and 1
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:77 # Fifth task DrunkenMathematician #meaningless can calculate for 3
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:81 # Fifth task DrunkenMathematician #meaningless can calculate for 42
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:87 # Fifth task DrunkenMathematician #aimless can calculate for 3
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:91 # Fifth task DrunkenMathematician #aimless can calculate for 4
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:95 # Fifth task DrunkenMathematician #aimless can calculate for 42
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:102 # Fifth task DrunkenMathematician #worthless can calculate for 2
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:106 # Fifth task DrunkenMathematician #worthless can calculate for 8
rspec /tmp/d20151111-27349-1q0h3pb/spec.rb:111 # Fifth task DrunkenMathematician #worthless can calculate for 15

История (1 версия и 0 коментара)

Ивайло обнови решението на 26.10.2015 17:18 (преди над 8 години)

+class FibonacciSequence
+ include Enumerable
+
+ def initialize(limit, first:, second:)
+ @limit = limit
+ @first = first
+ @second = second
+ end
+
+ def each
+ while @first < @limit
+ yield @first
+ @first, @second = @first + @second, @first
+ end
+ end
+end