Drunk Proxy
- Краен срок
- 14.12.2016 23:59
Срокът за предаване на решения е отминал
Drunk Proxy
Дефинирайте клас DrunkProxy
, чийто конструктор приема като единствен аргумент списък от обекти.
Инстанцията на класа трябва да отговаря на всички методи, на които отговарят подадените обекти в конструктора.
Възможно е няколко обекта да могат да отговорят на един метод (например '123'.length
и [1, 2].length
).
Ако проксито може да отговори на даден метод, то връща списък с резултатите от всички обекти, които са
кандидати за отговор (редът в списъка на резултатите трябва да съответства на реда на подаване на обектите
при инициализация).
Примери:
proxy = DrunkProxy.new [-42, 'foo', 'bar baz', [2, 3, 5, 8]]
proxy.reverse # => ["oof", "zab rab", [8, 5, 3, 2]]
proxy.abs # => [42]
proxy.length # => [3, 7, 4]
# ----------------------------------------------------------
proxy = DrunkProxy.new ['foo', [24], {x: 2}]
proxy.class # => [String, Array, Hash]
Бележки:
- Ако няма обект, който да отговори на дадения метод, вдигнете
NoMethodError
изключение.
- Постарайте се да прихванете всички методи, на които подадените обекти могат да отговорят. Изключение правят
!
, ==
, !=
, __send__
, equal?
, instance_veal
, instance_exec
, __id__
и __binding__
- Няма да подаваме блокове на методите в тестовете. Тоест, не се тревожете за
нещо подобно на:
proxy = DrunkProxy.new [[2, 3, 5, 8], {a: 1, b: 2, c: 3}]
proxy.select(&:odd?)
proxy.select { |x| x > 42 }
Примерни тестове
Написали сме примерни тестове, които може да намерите в хранилището с
домашните.
Решения
-
Некоректно
- 3 успешни тест(а)
- 1 неуспешни тест(а)
Здравко Петров
.F..
Failures:
1) DrunkProxy proxies most of the methods
Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
ArgumentError:
wrong number of arguments (given 0, expected 1)
# /tmp/d20161215-15620-sofe0a/solution.rb:25:in `is_a?'
# /tmp/d20161215-15620-sofe0a/solution.rb:25:in `block in has_method'
# /tmp/d20161215-15620-sofe0a/solution.rb:23:in `each'
# /tmp/d20161215-15620-sofe0a/solution.rb:23:in `has_method'
# /tmp/d20161215-15620-sofe0a/solution.rb:17:in `method_missing'
# /tmp/d20161215-15620-sofe0a/spec.rb:20:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.00668 seconds
4 examples, 1 failure
Failed examples:
rspec /tmp/d20161215-15620-sofe0a/spec.rb:14 # DrunkProxy proxies most of the methods
-
Некоректно
- 2 успешни тест(а)
- 2 неуспешни тест(а)
Добрин Цветков
.FF.
Failures:
1) DrunkProxy proxies most of the methods
Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
ArgumentError:
wrong number of arguments (given 1, expected 0)
# /tmp/d20161215-15620-1jbm280/solution.rb:14:in `block (2 levels) in methods_macro'
# /tmp/d20161215-15620-1jbm280/spec.rb:20:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
2) DrunkProxy raises error when calling missing methods
Failure/Error: expect { DrunkProxy.new(['string']).abs }.to raise_error(NoMethodError)
expected NoMethodError but nothing was raised
# /tmp/d20161215-15620-1jbm280/spec.rb:25:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.03813 seconds
4 examples, 2 failures
Failed examples:
rspec /tmp/d20161215-15620-1jbm280/spec.rb:14 # DrunkProxy proxies most of the methods
rspec /tmp/d20161215-15620-1jbm280/spec.rb:23 # DrunkProxy raises error when calling missing methods
-
Некоректно
- 3 успешни тест(а)
- 1 неуспешни тест(а)
Даниела Русева
.F..
Failures:
1) DrunkProxy proxies most of the methods
Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
ArgumentError:
wrong number of arguments (given 1, expected 0)
# /tmp/d20161215-15620-16epimk/solution.rb:14:in `block (2 levels) in define_methods'
# /tmp/d20161215-15620-16epimk/spec.rb:20:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.01327 seconds
4 examples, 1 failure
Failed examples:
rspec /tmp/d20161215-15620-16epimk/spec.rb:14 # DrunkProxy proxies most of the methods
-
Некоректно
- 2 успешни тест(а)
- 2 неуспешни тест(а)
Божидар Михайлов
..FF
Failures:
1) DrunkProxy raises error when calling missing methods
Failure/Error: expect { DrunkProxy.new([]).abs }.to raise_error(NoMethodError)
expected NoMethodError but nothing was raised
# /tmp/d20161215-15620-993714/spec.rb:24:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
2) DrunkProxy raises error when calling private methods
Failure/Error: expect { proxy.private_method }.to raise_error(NoMethodError)
expected NoMethodError but nothing was raised
# /tmp/d20161215-15620-993714/spec.rb:32:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.0042 seconds
4 examples, 2 failures
Failed examples:
rspec /tmp/d20161215-15620-993714/spec.rb:23 # DrunkProxy raises error when calling missing methods
rspec /tmp/d20161215-15620-993714/spec.rb:28 # DrunkProxy raises error when calling private methods
-
Некоректно
- 3 успешни тест(а)
- 1 неуспешни тест(а)
Христина Тодорова
.F..
Failures:
1) DrunkProxy proxies most of the methods
Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
expected: [true, false]
got: false
(compared using ==)
# /tmp/d20161215-15620-nghh0x/spec.rb:20:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.00951 seconds
4 examples, 1 failure
Failed examples:
rspec /tmp/d20161215-15620-nghh0x/spec.rb:14 # DrunkProxy proxies most of the methods
-
Некоректно
- 3 успешни тест(а)
- 1 неуспешни тест(а)
Лазар Дилов
.F..
Failures:
1) DrunkProxy proxies most of the methods
Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
ArgumentError:
wrong number of arguments (given 2, expected 1)
# /tmp/d20161215-15620-btwz4v/solution.rb:7:in `method_missing'
# /tmp/d20161215-15620-btwz4v/spec.rb:20:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.00432 seconds
4 examples, 1 failure
Failed examples:
rspec /tmp/d20161215-15620-btwz4v/spec.rb:14 # DrunkProxy proxies most of the methods
-
Коректно
- 4 успешни тест(а)
- 0 неуспешни тест(а)
Петко Митков
/tmp/d20161215-15620-1tmpzpj/solution.rb:6: warning: undefining `object_id' may cause serious problems
....
Finished in 0.0042 seconds
4 examples, 0 failures
-
Коректно
- 4 успешни тест(а)
- 0 неуспешни тест(а)
Никола Жишев
....
Finished in 0.00427 seconds
4 examples, 0 failures
-
Коректно
- 4 успешни тест(а)
- 0 неуспешни тест(а)
Ралица Дарджонова
....
Finished in 0.01207 seconds
4 examples, 0 failures
-
Некоректно
- 3 успешни тест(а)
- 1 неуспешни тест(а)
Мариян Асенов
.F..
Failures:
1) DrunkProxy proxies most of the methods
Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
ArgumentError:
wrong number of arguments (given 1, expected 0)
# /tmp/d20161215-15620-3za109/solution.rb:7:in `block (2 levels) in <class:DrunkProxy>'
# /tmp/d20161215-15620-3za109/spec.rb:20:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.00626 seconds
4 examples, 1 failure
Failed examples:
rspec /tmp/d20161215-15620-3za109/spec.rb:14 # DrunkProxy proxies most of the methods
-
Коректно
- 4 успешни тест(а)
- 0 неуспешни тест(а)
Георги Иванов
....
Finished in 0.00423 seconds
4 examples, 0 failures
-
Некоректно
- 2 успешни тест(а)
- 2 неуспешни тест(а)
Делян Лафчиев
..FF
Failures:
1) DrunkProxy raises error when calling missing methods
Failure/Error: expect { DrunkProxy.new([]).abs }.to raise_error(NoMethodError)
expected NoMethodError but nothing was raised
# /tmp/d20161215-15620-1xmam7c/spec.rb:24:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
2) DrunkProxy raises error when calling private methods
Failure/Error: expect { proxy.private_method }.to raise_error(NoMethodError)
expected NoMethodError but nothing was raised
# /tmp/d20161215-15620-1xmam7c/spec.rb:32:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.00472 seconds
4 examples, 2 failures
Failed examples:
rspec /tmp/d20161215-15620-1xmam7c/spec.rb:23 # DrunkProxy raises error when calling missing methods
rspec /tmp/d20161215-15620-1xmam7c/spec.rb:28 # DrunkProxy raises error when calling private methods
-
Некоректно
- 3 успешни тест(а)
- 1 неуспешни тест(а)
Георги Карапетров
.F..
Failures:
1) DrunkProxy proxies most of the methods
Failure/Error: expect(proxy.class).to eq [string.class, array.class]
expected: [String, Array]
got: DrunkProxy
(compared using ==)
Diff:
@@ -1,2 +1,2 @@
-[String, Array]
+DrunkProxy
# /tmp/d20161215-15620-xn8amt/spec.rb:19:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.00474 seconds
4 examples, 1 failure
Failed examples:
rspec /tmp/d20161215-15620-xn8amt/spec.rb:14 # DrunkProxy proxies most of the methods
-
Некоректно
- 2 успешни тест(а)
- 2 неуспешни тест(а)
Милен Дончев
.FF.
Failures:
1) DrunkProxy proxies most of the methods
Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
ArgumentError:
wrong number of arguments (given 1, expected 0)
# /tmp/d20161215-15620-nek98a/solution.rb:24:in `block (2 levels) in append_methods'
# /tmp/d20161215-15620-nek98a/spec.rb:20:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
2) DrunkProxy raises error when calling missing methods
Failure/Error: expect { DrunkProxy.new([]).abs }.to raise_error(NoMethodError)
expected NoMethodError but nothing was raised
# /tmp/d20161215-15620-nek98a/spec.rb:24:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.01144 seconds
4 examples, 2 failures
Failed examples:
rspec /tmp/d20161215-15620-nek98a/spec.rb:14 # DrunkProxy proxies most of the methods
rspec /tmp/d20161215-15620-nek98a/spec.rb:23 # DrunkProxy raises error when calling missing methods
-
Коректно
- 4 успешни тест(а)
- 0 неуспешни тест(а)
Виктор Маринов
....
Finished in 0.00418 seconds
4 examples, 0 failures
-
Некоректно
- 1 успешни тест(а)
- 3 неуспешни тест(а)
Исмаил Алиджиков
.FFF
Failures:
1) DrunkProxy proxies most of the methods
Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
ArgumentError:
wrong number of arguments (given 0, expected 1)
# /tmp/d20161215-15620-1thwcgc/solution.rb:10:in `is_a?'
# /tmp/d20161215-15620-1thwcgc/solution.rb:10:in `block in method_missing'
# /tmp/d20161215-15620-1thwcgc/solution.rb:10:in `map'
# /tmp/d20161215-15620-1thwcgc/solution.rb:10:in `method_missing'
# /tmp/d20161215-15620-1thwcgc/spec.rb:20:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
2) DrunkProxy raises error when calling missing methods
Failure/Error: expect { DrunkProxy.new([]).abs }.to raise_error(NoMethodError)
expected NoMethodError but nothing was raised
# /tmp/d20161215-15620-1thwcgc/spec.rb:24:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
3) DrunkProxy raises error when calling private methods
Failure/Error: expect { proxy.private_method }.to raise_error(NoMethodError)
expected NoMethodError but nothing was raised
# /tmp/d20161215-15620-1thwcgc/spec.rb:32:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.00422 seconds
4 examples, 3 failures
Failed examples:
rspec /tmp/d20161215-15620-1thwcgc/spec.rb:14 # DrunkProxy proxies most of the methods
rspec /tmp/d20161215-15620-1thwcgc/spec.rb:23 # DrunkProxy raises error when calling missing methods
rspec /tmp/d20161215-15620-1thwcgc/spec.rb:28 # DrunkProxy raises error when calling private methods
-
Некоректно
- 3 успешни тест(а)
- 1 неуспешни тест(а)
Антон Сотиров
.F..
Failures:
1) DrunkProxy proxies most of the methods
Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
expected: [true, false]
got: false
(compared using ==)
# /tmp/d20161215-15620-uadikd/spec.rb:20:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.00631 seconds
4 examples, 1 failure
Failed examples:
rspec /tmp/d20161215-15620-uadikd/spec.rb:14 # DrunkProxy proxies most of the methods
-
Некоректно
- 2 успешни тест(а)
- 2 неуспешни тест(а)
Йордан Иванов
..FF
Failures:
1) DrunkProxy raises error when calling missing methods
Failure/Error: expect { DrunkProxy.new([]).abs }.to raise_error(NoMethodError)
expected NoMethodError, got #<NameError: uninitialized constant DrunkProxy::NoMethodError> with backtrace:
# /tmp/d20161215-15620-1sr8itn/solution.rb:13:in `method_missing'
# /tmp/d20161215-15620-1sr8itn/spec.rb:24:in `block (3 levels) in <top (required)>'
# /tmp/d20161215-15620-1sr8itn/spec.rb:24:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
# /tmp/d20161215-15620-1sr8itn/spec.rb:24:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
2) DrunkProxy raises error when calling private methods
Failure/Error: expect { proxy.private_method }.to raise_error(NoMethodError)
expected NoMethodError, got #<NameError: uninitialized constant DrunkProxy::NoMethodError> with backtrace:
# /tmp/d20161215-15620-1sr8itn/solution.rb:13:in `method_missing'
# /tmp/d20161215-15620-1sr8itn/spec.rb:32:in `block (3 levels) in <top (required)>'
# /tmp/d20161215-15620-1sr8itn/spec.rb:32:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
# /tmp/d20161215-15620-1sr8itn/spec.rb:32:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.00557 seconds
4 examples, 2 failures
Failed examples:
rspec /tmp/d20161215-15620-1sr8itn/spec.rb:23 # DrunkProxy raises error when calling missing methods
rspec /tmp/d20161215-15620-1sr8itn/spec.rb:28 # DrunkProxy raises error when calling private methods
-
Некоректно
- 3 успешни тест(а)
- 1 неуспешни тест(а)
Христо Кирилов
.F..
Failures:
1) DrunkProxy proxies most of the methods
Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
ArgumentError:
wrong number of arguments (given 0, expected 1)
# /tmp/d20161215-15620-117url6/solution.rb:7:in `is_a?'
# /tmp/d20161215-15620-117url6/solution.rb:7:in `block in method_missing'
# /tmp/d20161215-15620-117url6/solution.rb:7:in `map'
# /tmp/d20161215-15620-117url6/solution.rb:7:in `method_missing'
# /tmp/d20161215-15620-117url6/spec.rb:20:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.00425 seconds
4 examples, 1 failure
Failed examples:
rspec /tmp/d20161215-15620-117url6/spec.rb:14 # DrunkProxy proxies most of the methods
-
Некоректно
- 3 успешни тест(а)
- 1 неуспешни тест(а)
Елеонора Кайкова
.F..
Failures:
1) DrunkProxy proxies most of the methods
Failure/Error: expect(proxy.class).to eq [string.class, array.class]
expected: [String, Array]
got: DrunkProxy
(compared using ==)
Diff:
@@ -1,2 +1,2 @@
-[String, Array]
+DrunkProxy
# /tmp/d20161215-15620-y90szz/spec.rb:19:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.00684 seconds
4 examples, 1 failure
Failed examples:
rspec /tmp/d20161215-15620-y90szz/spec.rb:14 # DrunkProxy proxies most of the methods
-
Некоректно
- 3 успешни тест(а)
- 1 неуспешни тест(а)
Стамен Драгоев
.F..
Failures:
1) DrunkProxy proxies most of the methods
Failure/Error: expect(proxy.is_a?(String)).to eq [true, false]
ArgumentError:
wrong number of arguments (given 0, expected 1)
# /tmp/d20161215-15620-1b2z5yd/solution.rb:56:in `is_a?'
# /tmp/d20161215-15620-1b2z5yd/solution.rb:56:in `block in method_missing'
# /tmp/d20161215-15620-1b2z5yd/solution.rb:56:in `map'
# /tmp/d20161215-15620-1b2z5yd/solution.rb:56:in `method_missing'
# /tmp/d20161215-15620-1b2z5yd/spec.rb:20:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.00897 seconds
4 examples, 1 failure
Failed examples:
rspec /tmp/d20161215-15620-1b2z5yd/spec.rb:14 # DrunkProxy proxies most of the methods
-
Некоректно
- 3 успешни тест(а)
- 1 неуспешни тест(а)
Теодора Петкова
.F..
Failures:
1) DrunkProxy proxies most of the methods
Failure/Error: expect(proxy.class).to eq [string.class, array.class]
expected: [String, Array]
got: DrunkProxy
(compared using ==)
Diff:
@@ -1,2 +1,2 @@
-[String, Array]
+DrunkProxy
# /tmp/d20161215-15620-1ojik3o/spec.rb:19:in `block (2 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
# ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'
Finished in 0.00474 seconds
4 examples, 1 failure
Failed examples:
rspec /tmp/d20161215-15620-1ojik3o/spec.rb:14 # DrunkProxy proxies most of the methods