Решение на Шеста задача от Петко Борджуков
Обратно към всички решения
Към профила на Петко Борджуков
Резултати
- 4 точки от тестове
- 0 бонус точки
- 4 точки общо
- 34 успешни тест(а)
- 13 неуспешни тест(а)
Код
Лог от изпълнението
....F..F.F..F....FF..FFF..F...F.FF.............
Failures:
1) ExchangeRate#get returns nil for non-existing rates
Failure/Error: rate.get(:EUR, :BGN).should be_nil
ExchangeRate::ExchangeRateUnknown:
ExchangeRate::ExchangeRateUnknown
# /tmp/d20130203-23049-654za3/solution.rb:18:in `get'
# /tmp/d20130203-23049-654za3/spec.rb:31:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'
2) ExchangeRate#get always returns 1 as the exchange rate between two identical currencies
Failure/Error: rate.get(:JPY, :JPY).should eq 1.to_d
ExchangeRate::ExchangeRateUnknown:
ExchangeRate::ExchangeRateUnknown
# /tmp/d20130203-23049-654za3/solution.rb:18:in `get'
# /tmp/d20130203-23049-654za3/spec.rb:45:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'
3) ExchangeRate#convert raises an ExchangeRate::Unknown exception when the rate is not defined
Failure/Error: end.to raise_error(ExchangeRate::Unknown)
NameError:
uninitialized constant ExchangeRate::Unknown
# /tmp/d20130203-23049-654za3/spec.rb:58:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'
4) ExchangeRate#convert works for identical currencies without defining any rates
Failure/Error: rate.convert(:JPY, :JPY, 123.to_d).should eq 123.to_d
ExchangeRate::ExchangeRateUnknown:
ExchangeRate::ExchangeRateUnknown
# /tmp/d20130203-23049-654za3/solution.rb:18:in `get'
# /tmp/d20130203-23049-654za3/solution.rb:23:in `convert'
# /tmp/d20130203-23049-654za3/spec.rb:72:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'
5) Money convertion does not change the amount if the same currency is passed
Failure/Error: Money.new(5.to_d, :EUR).in(:EUR, ExchangeRate.new).amount.should eq 5.to_d
ExchangeRate::ExchangeRateUnknown:
ExchangeRate::ExchangeRateUnknown
# /tmp/d20130203-23049-654za3/solution.rb:18:in `get'
# /tmp/d20130203-23049-654za3/solution.rb:23:in `convert'
# /tmp/d20130203-23049-654za3/solution.rb:42:in `in'
# /tmp/d20130203-23049-654za3/spec.rb:107:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'
6) Money convertion raises an ExchangeRate::Unknown exception for unknown rates
Failure/Error: end.to raise_error(ExchangeRate::Unknown)
NameError:
uninitialized constant ExchangeRate::Unknown
# /tmp/d20130203-23049-654za3/spec.rb:113:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'
7) Money arithmetic allows / with a numeric
Failure/Error: result.amount.should eq bucks.amount.public_send(operation, numeric)
expected: #<BigDecimal:93a0364,'0.1190476190 47619048E0',18(36)>
got: #<BigDecimal:93a03f0,'0.1190476190 4761905E0',18(45)>
(compared using ==)
# /tmp/d20130203-23049-654za3/spec.rb:125:in `block (4 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'
8) Money arithmetic / with money objects raises an ArgumentError
Failure/Error: expect do
expected ArgumentError, got #<NoMethodError: undefined method `to_d' for 5.00 USD:Money>
# /tmp/d20130203-23049-654za3/spec.rb:129:in `block (4 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'
9) Money arithmetic + with numeric objects raises an ArgumentError
Failure/Error: expect do
expected ArgumentError but nothing was raised
# /tmp/d20130203-23049-654za3/spec.rb:137:in `block (4 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'
10) Money arithmetic - with numeric objects raises an ArgumentError
Failure/Error: expect do
expected ArgumentError but nothing was raised
# /tmp/d20130203-23049-654za3/spec.rb:137:in `block (4 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'
11) Money arithmetic - with other objects raises an ArgumentError
Failure/Error: expect do
expected ArgumentError, got #<NoMethodError: undefined method `-@' for "foobar":String>
# /tmp/d20130203-23049-654za3/spec.rb:160:in `block (4 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'
12) Money arithmetic / with other objects raises an ArgumentError
Failure/Error: expect do
expected ArgumentError but nothing was raised
# /tmp/d20130203-23049-654za3/spec.rb:160:in `block (4 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'
13) Money comparison works when currencies are the same
Failure/Error: (a <=> b).should eq 1
expected: 1
got: nil
(compared using ==)
# /tmp/d20130203-23049-654za3/spec.rb:174:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
# ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'
Finished in 0.07019 seconds
47 examples, 13 failures
Failed examples:
rspec /tmp/d20130203-23049-654za3/spec.rb:30 # ExchangeRate#get returns nil for non-existing rates
rspec /tmp/d20130203-23049-654za3/spec.rb:44 # ExchangeRate#get always returns 1 as the exchange rate between two identical currencies
rspec /tmp/d20130203-23049-654za3/spec.rb:55 # ExchangeRate#convert raises an ExchangeRate::Unknown exception when the rate is not defined
rspec /tmp/d20130203-23049-654za3/spec.rb:71 # ExchangeRate#convert works for identical currencies without defining any rates
rspec /tmp/d20130203-23049-654za3/spec.rb:106 # Money convertion does not change the amount if the same currency is passed
rspec /tmp/d20130203-23049-654za3/spec.rb:110 # Money convertion raises an ExchangeRate::Unknown exception for unknown rates
rspec /tmp/d20130203-23049-654za3/spec.rb:119 # Money arithmetic allows / with a numeric
rspec /tmp/d20130203-23049-654za3/spec.rb:128 # Money arithmetic / with money objects raises an ArgumentError
rspec /tmp/d20130203-23049-654za3/spec.rb:136 # Money arithmetic + with numeric objects raises an ArgumentError
rspec /tmp/d20130203-23049-654za3/spec.rb:136 # Money arithmetic - with numeric objects raises an ArgumentError
rspec /tmp/d20130203-23049-654za3/spec.rb:159 # Money arithmetic - with other objects raises an ArgumentError
rspec /tmp/d20130203-23049-654za3/spec.rb:159 # Money arithmetic / with other objects raises an ArgumentError
rspec /tmp/d20130203-23049-654za3/spec.rb:168 # Money comparison works when currencies are the same
История (3 версии и 2 коментара)
Петко обнови решението на 13.01.2013 14:27 (преди почти 12 години)
Петко обнови решението на 13.01.2013 14:53 (преди почти 12 години)
Петко обнови решението на 13.01.2013 15:51 (преди почти 12 години)