Решение на Първа задача от Пламен Сухиндолски

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

Към профила на Пламен Сухиндолски

Резултати

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

Код

def convert_to_bgn(price, currency)
if currency = :usd
(price * 1.7408).round(2)
elsif currency = :eur
(price * 1.9557).round(2)
elsif currency = :gbd
(price * 2.6415).round(2)
else
price
end
end
def compare_prices(one,currency_one,two,currency_two)
convert_to_bgn(one,currency_one) - convert_to_bgn(two,currency_two)
end

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

.FFF..F.

Failures:

  1) #convert_to_bgn converts eur
     Failure/Error: expect(convert_to_bgn(1000, :eur)).to eq 1955.7
       
       expected: 1955.7
            got: 1740.8
       
       (compared using ==)
     # /tmp/d20151012-23382-l7y0gz/spec.rb:7:in `block (2 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) #convert_to_bgn converts gbp
     Failure/Error: expect(convert_to_bgn(1000, :gbp)).to eq 2641.5
       
       expected: 2641.5
            got: 1740.8
       
       (compared using ==)
     # /tmp/d20151012-23382-l7y0gz/spec.rb:11:in `block (2 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) #convert_to_bgn converts bgn
     Failure/Error: expect(convert_to_bgn(333, :bgn)).to eq 333
       
       expected: 333
            got: 579.69
       
       (compared using ==)
     # /tmp/d20151012-23382-l7y0gz/spec.rb:15:in `block (2 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) #compare_prices compares usd and bgn
     Failure/Error: expect(compare_prices(1000, :usd, 1740.8, :bgn)).to eq 0
       
       expected: 0
            got: -1289.5800000000002
       
       (compared using ==)
     # /tmp/d20151012-23382-l7y0gz/spec.rb:33:in `block (2 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.00654 seconds
8 examples, 4 failures

Failed examples:

rspec /tmp/d20151012-23382-l7y0gz/spec.rb:6 # #convert_to_bgn converts eur
rspec /tmp/d20151012-23382-l7y0gz/spec.rb:10 # #convert_to_bgn converts gbp
rspec /tmp/d20151012-23382-l7y0gz/spec.rb:14 # #convert_to_bgn converts bgn
rspec /tmp/d20151012-23382-l7y0gz/spec.rb:31 # #compare_prices compares usd and bgn

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

Пламен обнови решението на 12.10.2015 17:27 (преди около 9 години)

+def convert_to_bgn(price, currency)
+ if currency = :usd
+ (price * 1.7408).round(2)
+ elsif currency = :eur
+ (price * 1.9557).round(2)
+ elsif currency = :gbd
+ (price * 2.6415).round(2)
+ else
+ price
+ end
+end
+
+def compare_prices(one,currency_one,two,currency_two)
+ convert_to_bgn(one,currency_one) - convert_to_bgn(two,currency_two)
+end