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

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

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

Резултати

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

Код

def convert_to_bgn(n, currency)
if currency === :usd
"%g" % ( '%.2f ' % ( n * 1.7408))
elsif currency === :gbr
"%g" % ( '%.2f ' % (n * 2.6415))
else
"%g" % ( '%.2f ' % (n * 1.9557))
end
end
a = convert_to_bgn(1000, :gbr)
puts a

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

2641.5
FFFFFFFF

Failures:

  1) #convert_to_bgn converts usd
     Failure/Error: expect(convert_to_bgn(1000, :usd)).to eq 1740.8
       
       expected: 1740.8
            got: "1740.8"
       
       (compared using ==)
     # /tmp/d20151012-23382-vz1npl/spec.rb:3: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 eur
     Failure/Error: expect(convert_to_bgn(1000, :eur)).to eq 1955.7
       
       expected: 1955.7
            got: "1955.7"
       
       (compared using ==)
     # /tmp/d20151012-23382-vz1npl/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)>'

  3) #convert_to_bgn converts gbp
     Failure/Error: expect(convert_to_bgn(1000, :gbp)).to eq 2641.5
       
       expected: 2641.5
            got: "1955.7"
       
       (compared using ==)
     # /tmp/d20151012-23382-vz1npl/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)>'

  4) #convert_to_bgn converts bgn
     Failure/Error: expect(convert_to_bgn(333, :bgn)).to eq 333
       
       expected: 333
            got: "651.25"
       
       (compared using ==)
     # /tmp/d20151012-23382-vz1npl/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)>'

  5) #convert_to_bgn rounds to 2 digits after the point
     Failure/Error: expect(convert_to_bgn(123, :usd)).to eq 214.12
       
       expected: 214.12
            got: "214.12"
       
       (compared using ==)
     # /tmp/d20151012-23382-vz1npl/spec.rb:19: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)>'

  6) #compare_prices compares prices of the same currency
     Failure/Error: expect(compare_prices(10, :usd, 13, :usd)).to be < 0
     NoMethodError:
       undefined method `compare_prices' for #<RSpec::Core::ExampleGroup::Nested_2:0x007f4063b48e30>
     # /tmp/d20151012-23382-vz1npl/spec.rb:25: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)>'

  7) #compare_prices compares usd and bgn
     Failure/Error: expect(compare_prices(5, :usd, 10, :bgn)).to be < 0
     NoMethodError:
       undefined method `compare_prices' for #<RSpec::Core::ExampleGroup::Nested_2:0x007f4063b2e760>
     # /tmp/d20151012-23382-vz1npl/spec.rb:32: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)>'

  8) #compare_prices compares eur and gbp
     Failure/Error: expect(compare_prices(5, :usd, 10, :gbp)).to be < 0
     NoMethodError:
       undefined method `compare_prices' for #<RSpec::Core::ExampleGroup::Nested_2:0x007f4063b27640>
     # /tmp/d20151012-23382-vz1npl/spec.rb:38: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.00424 seconds
8 examples, 8 failures

Failed examples:

rspec /tmp/d20151012-23382-vz1npl/spec.rb:2 # #convert_to_bgn converts usd
rspec /tmp/d20151012-23382-vz1npl/spec.rb:6 # #convert_to_bgn converts eur
rspec /tmp/d20151012-23382-vz1npl/spec.rb:10 # #convert_to_bgn converts gbp
rspec /tmp/d20151012-23382-vz1npl/spec.rb:14 # #convert_to_bgn converts bgn
rspec /tmp/d20151012-23382-vz1npl/spec.rb:18 # #convert_to_bgn rounds to 2 digits after the point
rspec /tmp/d20151012-23382-vz1npl/spec.rb:24 # #compare_prices compares prices of the same currency
rspec /tmp/d20151012-23382-vz1npl/spec.rb:31 # #compare_prices compares usd and bgn
rspec /tmp/d20151012-23382-vz1npl/spec.rb:37 # #compare_prices compares eur and gbp

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

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

+def convert_to_bgn(n, currency)
+ if currency === :usd
+ "%g" % ( '%.2f ' % ( n * 1.7408))
+ elsif currency === :gbr
+ "%g" % ( '%.2f ' % (n * 2.6415))
+ else
+ "%g" % ( '%.2f ' % (n * 1.9557))
+ end
+end
+
+
+a = convert_to_bgn(1000, :gbr)
+puts a