Решение на Шеста задача от Кирил Владимиров
Обратно към всички решения
Към профила на Кирил Владимиров
Резултати
- 5 точки от тестове
- 0 бонус точки
- 5 точки общо
- 36 успешни тест(а)
- 11 неуспешни тест(а)
Код
Лог от изпълнението
...F...FF......F.....FF...F...F.F....FF........
Failures:
1) ExchangeRate#set sets the exchange rate in both directions
Failure/Error: rate.get(:EUR, :BGN).should eq '1.25'.to_d
expected: #<BigDecimal:893a0a0,'0.125E1',18(18)>
got: #<BigDecimal:8b6c83c,'0.2E1',9(36)>
(compared using ==)
# /tmp/d20130203-23049-hwpvx2/spec.rb:25: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
expected: #<BigDecimal:8255a28,'0.1E1',9(36)>
got: nil
(compared using ==)
# /tmp/d20130203-23049-hwpvx2/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#get does not allow changing the exchange rate between two identical currencies
Failure/Error: rate.get(:EUR, :EUR).should eq 1.to_d
expected: #<BigDecimal:8258de0,'0.1E1',9(36)>
got: nil
(compared using ==)
# /tmp/d20130203-23049-hwpvx2/spec.rb:50: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) Money has a custom to_s representation
Failure/Error: Money.new('12.1'.to_d, :USD).to_s.should eq '12.10 USD'
expected: "12.10 USD"
got: "12.1 USD"
(compared using ==)
# /tmp/d20130203-23049-hwpvx2/spec.rb:90:in `block (2 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 arithmetic allows / with a numeric
Failure/Error: result.amount.should eq bucks.amount.public_send(operation, numeric)
expected: #<BigDecimal:863efb8,'0.1190476190 47619048E0',18(36)>
got: 0.11904761904761904
(compared using ==)
# /tmp/d20130203-23049-hwpvx2/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)>'
6) Money arithmetic / with money objects raises an ArgumentError
Failure/Error: expect do
expected ArgumentError, got #<TypeError: Money can't be coerced into Float>
# /tmp/d20130203-23049-hwpvx2/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)>'
7) Money arithmetic - with numeric objects raises an ArgumentError
Failure/Error: expect do
expected ArgumentError, got #<NoMethodError: undefined method `amount' for 42:Fixnum>
# /tmp/d20130203-23049-hwpvx2/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)>'
8) Money arithmetic - with other objects raises an ArgumentError
Failure/Error: expect do
expected ArgumentError, got #<NoMethodError: undefined method `amount' for "foobar":String>
# /tmp/d20130203-23049-hwpvx2/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)>'
9) Money arithmetic / with other objects raises an ArgumentError
Failure/Error: expect do
expected ArgumentError, got #<TypeError: String can't be coerced into Float>
# /tmp/d20130203-23049-hwpvx2/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)>'
10) Money comparison with == raises ArgumentError when comparing with other objects
Failure/Error: expect do
expected ArgumentError but nothing was raised
# /tmp/d20130203-23049-hwpvx2/spec.rb:195: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 comparison with == raises IncompatibleCurrencies when currencies differ
Failure/Error: expect do
expected Money::IncompatibleCurrencies but nothing was raised
# /tmp/d20130203-23049-hwpvx2/spec.rb:201: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)>'
Finished in 0.05874 seconds
47 examples, 11 failures
Failed examples:
rspec /tmp/d20130203-23049-hwpvx2/spec.rb:21 # ExchangeRate#set sets the exchange rate in both directions
rspec /tmp/d20130203-23049-hwpvx2/spec.rb:44 # ExchangeRate#get always returns 1 as the exchange rate between two identical currencies
rspec /tmp/d20130203-23049-hwpvx2/spec.rb:48 # ExchangeRate#get does not allow changing the exchange rate between two identical currencies
rspec /tmp/d20130203-23049-hwpvx2/spec.rb:88 # Money has a custom to_s representation
rspec /tmp/d20130203-23049-hwpvx2/spec.rb:119 # Money arithmetic allows / with a numeric
rspec /tmp/d20130203-23049-hwpvx2/spec.rb:128 # Money arithmetic / with money objects raises an ArgumentError
rspec /tmp/d20130203-23049-hwpvx2/spec.rb:136 # Money arithmetic - with numeric objects raises an ArgumentError
rspec /tmp/d20130203-23049-hwpvx2/spec.rb:159 # Money arithmetic - with other objects raises an ArgumentError
rspec /tmp/d20130203-23049-hwpvx2/spec.rb:159 # Money arithmetic / with other objects raises an ArgumentError
rspec /tmp/d20130203-23049-hwpvx2/spec.rb:194 # Money comparison with == raises ArgumentError when comparing with other objects
rspec /tmp/d20130203-23049-hwpvx2/spec.rb:200 # Money comparison with == raises IncompatibleCurrencies when currencies differ
История (2 версии и 0 коментара)
Кирил обнови решението на 16.01.2013 15:46 (преди почти 12 години)
Кирил обнови решението на 16.01.2013 15:46 (преди почти 12 години)