Функции от по-висок ред

Краен срок
19.10.2015 17:30

Срокът за предаване на решения е отминал

Функция от по-висок ред е функция, която изпълнява едно от следните: * Приема една или повече функции като аргументи * Връща функция като резултат

В това предизвикателство искаме от вас да дефинирате две функции: complement и compose.

complement

Дефинирайте функция complement(f), която приема функция и връща друга функция, която приема същите аргументи като f, има същия ефект като f, но връща:

  • true, когато f се оценява на false
  • false, когато f се оценява на true

Пример

is_answer = ->(n) { n == 42 }
not_answer = complement(is_answer)

is_answer.call(42)  # => true
is_answer.call(12)  # => false
not_answer.call(42) # => false
not_answer.call(12) # => true

compose

Дефинирайте функция compose(f, g), която приема две функции и връща тяхната композиция (f ∘ g). Нотацията с кръгчето може да бъде прочетена така: "f след g", "f от g" и други.

Върнатата от compose функция трябва да приема броят аргументи, който приема и функцията, подадена като втори аргумент на compose (в горния пример това е g).

Пример

add_two = ->(n) { n + 2 }
is_answer = ->(n) { n == 42 }

compose(is_answer, add_two).call(40) # => true
compose(is_answer, add_two).call(10) # => false

Примерни тестове

Написали сме примерни тестове, които може да намерите в хранилището с домашните. Как да си ги пуснете може да видите в ръководството. Когато проверяваме предадените решения, ще включим и допълнителни тестове.

Преди да предадете решение се уверете, че тестовете ви се изпълняват без грешки. Това ще ви гарантира, че не сте сбъркали нещо тривиално. Например име на функция, брой приемани аргументи и подобни.

Забележка: Няма да ви бъдат подавани грешни данни. Няма нужда да правите допълнителни проверки за некоректни аргументи или да връщате специални стойности в случай на грешка.

Решения

Ивайло Христов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Ивайло Христов
def complement(f)
->(*args) { not f.call(*args) }
end
def compose(f, g)
->(*args) { f.call(g.call(*args)) }
end
....

Finished in 0.00262 seconds
4 examples, 0 failures
Мирослав Лалев
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Мирослав Лалев
def complement(f)
Proc.new {|answer| !f.call(answer)}
end
def compose(f, g)
Proc.new {|answer| f.call(g.call(answer))}
end
.F.F

Failures:

  1) complement complements a function with arity of two
     Failure/Error: is_sum_four = ->(a, b) { a + b == 4 }
     ArgumentError:
       wrong number of arguments (1 for 2)
     # /tmp/d20151019-15631-1xxie48/spec.rb:11:in `block (3 levels) in <top (required)>'
     # /tmp/d20151019-15631-1xxie48/solution.rb:2:in `call'
     # /tmp/d20151019-15631-1xxie48/solution.rb:2:in `block in complement'
     # /tmp/d20151019-15631-1xxie48/spec.rb:14:in `call'
     # /tmp/d20151019-15631-1xxie48/spec.rb:14: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) compose returns a function composition with arity of two of two functions
     Failure/Error: pow = ->(a, b) { a**b }
     ArgumentError:
       wrong number of arguments (1 for 2)
     # /tmp/d20151019-15631-1xxie48/spec.rb:29:in `block (3 levels) in <top (required)>'
     # /tmp/d20151019-15631-1xxie48/solution.rb:6:in `call'
     # /tmp/d20151019-15631-1xxie48/solution.rb:6:in `block in compose'
     # /tmp/d20151019-15631-1xxie48/spec.rb:31:in `call'
     # /tmp/d20151019-15631-1xxie48/spec.rb:31: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.00288 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20151019-15631-1xxie48/spec.rb:10 # complement complements a function with arity of two
rspec /tmp/d20151019-15631-1xxie48/spec.rb:27 # compose returns a function composition with arity of two of two functions
Денис Михайлов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Денис Михайлов
def complement(f)
-> (*args) { not f.call(*args) }
end
def compose(f, g)
-> (*args) do
args_for_f = g.call(*args)
f.call(*args_for_f)
end
end
....

Finished in 0.00297 seconds
4 examples, 0 failures
Георги Стефанов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Стефанов
def complement(f)
lambda {|*arguments| not f.call(*arguments)}
end
def compose(f, g)
lambda {|*arguments| f.call(g.call(*arguments))}
end
....

Finished in 0.00258 seconds
4 examples, 0 failures
Даниела Иванова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Даниела Иванова
def complement(f)
->(*args) { not f.call(*args) }
end
def compose(f, g)
->(*args) { f.call(g.call(*args)) }
end
....

Finished in 0.0026 seconds
4 examples, 0 failures
Пламен Никифоров
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Пламен Никифоров
def complement(f)
opposite = ->(x) { not f.call(*x) }
end
def compose(f, g)
composed = ->(x) { f.call(g.call(*x)) }
end
.F.F

Failures:

  1) complement complements a function with arity of two
     Failure/Error: expect(sum_not_four.call(2, 2)).to eq false
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-177qo2k/solution.rb:2:in `block in complement'
     # /tmp/d20151019-15631-177qo2k/spec.rb:14:in `call'
     # /tmp/d20151019-15631-177qo2k/spec.rb:14: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) compose returns a function composition with arity of two of two functions
     Failure/Error: expect(compose(add_two, pow).call(2, 3)).to eq 10
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-177qo2k/solution.rb:6:in `block in compose'
     # /tmp/d20151019-15631-177qo2k/spec.rb:31:in `call'
     # /tmp/d20151019-15631-177qo2k/spec.rb:31: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.00285 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20151019-15631-177qo2k/spec.rb:10 # complement complements a function with arity of two
rspec /tmp/d20151019-15631-177qo2k/spec.rb:27 # compose returns a function composition with arity of two of two functions
Димитър Узунов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Узунов
def complement(f)
->(*parameters) { not f.call(*parameters) }
end
def compose(f, g)
->(*parameters) { f.call(g.call(*parameters)) }
end
....

Finished in 0.00262 seconds
4 examples, 0 failures
Мария Рангелова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Рангелова
def complement(f)
lambda { |*x| not f.call(*x) }
end
def compose(f, g)
lambda { |*x| f.call(g.call(*x)) }
end
....

Finished in 0.00263 seconds
4 examples, 0 failures
Владимир Алексиев
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Владимир Алексиев
def complement(f)
->(param) do
!f.call(param)
end
end
def compose(f, g)
->(param) do
f.call(g.call(param))
end
end
.F.F

Failures:

  1) complement complements a function with arity of two
     Failure/Error: expect(sum_not_four.call(2, 2)).to eq false
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-1rlj5xz/solution.rb:2:in `block in complement'
     # /tmp/d20151019-15631-1rlj5xz/spec.rb:14:in `call'
     # /tmp/d20151019-15631-1rlj5xz/spec.rb:14: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) compose returns a function composition with arity of two of two functions
     Failure/Error: expect(compose(add_two, pow).call(2, 3)).to eq 10
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-1rlj5xz/solution.rb:8:in `block in compose'
     # /tmp/d20151019-15631-1rlj5xz/spec.rb:31:in `call'
     # /tmp/d20151019-15631-1rlj5xz/spec.rb:31: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.0028 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20151019-15631-1rlj5xz/spec.rb:10 # complement complements a function with arity of two
rspec /tmp/d20151019-15631-1rlj5xz/spec.rb:27 # compose returns a function composition with arity of two of two functions
Алекс Николов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Алекс Николов
def complement(f)
->(*arguments) { not f.call(*arguments) }
end
def compose(f, g)
->(*g_arguments) { f.call(g.call(*g_arguments)) }
end
....

Finished in 0.01412 seconds
4 examples, 0 failures
Александрина Каракехайова
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Александрина Каракехайова
def complement(f)
lambda{ |x| f.call(x) ? false : true }
end
def compose(f,g)
lambda{ |x| f.call(g.call(x)) }
end
.F.F

Failures:

  1) complement complements a function with arity of two
     Failure/Error: expect(sum_not_four.call(2, 2)).to eq false
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-18eflfw/solution.rb:2:in `block in complement'
     # /tmp/d20151019-15631-18eflfw/spec.rb:14:in `call'
     # /tmp/d20151019-15631-18eflfw/spec.rb:14: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) compose returns a function composition with arity of two of two functions
     Failure/Error: expect(compose(add_two, pow).call(2, 3)).to eq 10
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-18eflfw/solution.rb:6:in `block in compose'
     # /tmp/d20151019-15631-18eflfw/spec.rb:31:in `call'
     # /tmp/d20151019-15631-18eflfw/spec.rb:31: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.00277 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20151019-15631-18eflfw/spec.rb:10 # complement complements a function with arity of two
rspec /tmp/d20151019-15631-18eflfw/spec.rb:27 # compose returns a function composition with arity of two of two functions
Теодор Климентов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Теодор Климентов
def complement(f)
->(*x) { not f.call *x }
end
def compose(f, g)
->(*x) { f.call g.call *x }
end
....

Finished in 0.00258 seconds
4 examples, 0 failures
Иван Стоилов
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Иван Стоилов
def complement(f)
-> (*args) {not f}
end
def compose(f, g)
-> (*args) {f.call(g.call(*args))}
end
FF..

Failures:

  1) complement complements a function
     Failure/Error: expect(not_answer.call(12)).to eq true
       
       expected: true
            got: false
       
       (compared using ==)
     # /tmp/d20151019-15631-a4ojzj/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) complement complements a function with arity of two
     Failure/Error: expect(sum_not_four.call(1, 2)).to eq true
       
       expected: true
            got: false
       
       (compared using ==)
     # /tmp/d20151019-15631-a4ojzj/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)>'

Finished in 0.00286 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20151019-15631-a4ojzj/spec.rb:2 # complement complements a function
rspec /tmp/d20151019-15631-a4ojzj/spec.rb:10 # complement complements a function with arity of two
Адриана Стефанова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Адриана Стефанова
def complement (f)
->(*arguments) { not f.call(*arguments) }
end
def compose (f, g)
->(*arguments) { f.call(g.call(*arguments)) }
end
....

Finished in 0.00269 seconds
4 examples, 0 failures
Петър Нетовски
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Петър Нетовски
def complement(f)
->(x) { !f.call x }
end
def compose(f, g)
->(x) { f.call g.call x }
end
.F.F

Failures:

  1) complement complements a function with arity of two
     Failure/Error: expect(sum_not_four.call(2, 2)).to eq false
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-1dgtml2/solution.rb:2:in `block in complement'
     # /tmp/d20151019-15631-1dgtml2/spec.rb:14:in `call'
     # /tmp/d20151019-15631-1dgtml2/spec.rb:14: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) compose returns a function composition with arity of two of two functions
     Failure/Error: expect(compose(add_two, pow).call(2, 3)).to eq 10
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-1dgtml2/solution.rb:6:in `block in compose'
     # /tmp/d20151019-15631-1dgtml2/spec.rb:31:in `call'
     # /tmp/d20151019-15631-1dgtml2/spec.rb:31: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.00277 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20151019-15631-1dgtml2/spec.rb:10 # complement complements a function with arity of two
rspec /tmp/d20151019-15631-1dgtml2/spec.rb:27 # compose returns a function composition with arity of two of two functions
Николай Коцев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Коцев
def complement(method)
->(* arguments) { not method.call(* arguments) }
end
def compose(function_a, function_b)
->(* arguments) { function_a.call(function_b.call(* arguments)) }
end
....

Finished in 0.00259 seconds
4 examples, 0 failures
Николай Станев
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Николай Станев
def compose(f,g)
lambda{ |x| f.call(g.call(x)) }
end
def complement(f)
lambda{ |x| !(f.call(x)) }
end
.F.F

Failures:

  1) complement complements a function with arity of two
     Failure/Error: expect(sum_not_four.call(2, 2)).to eq false
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-1hc9y2m/solution.rb:6:in `block in complement'
     # /tmp/d20151019-15631-1hc9y2m/spec.rb:14:in `call'
     # /tmp/d20151019-15631-1hc9y2m/spec.rb:14: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) compose returns a function composition with arity of two of two functions
     Failure/Error: expect(compose(add_two, pow).call(2, 3)).to eq 10
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-1hc9y2m/solution.rb:2:in `block in compose'
     # /tmp/d20151019-15631-1hc9y2m/spec.rb:31:in `call'
     # /tmp/d20151019-15631-1hc9y2m/spec.rb:31: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.0028 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20151019-15631-1hc9y2m/spec.rb:10 # complement complements a function with arity of two
rspec /tmp/d20151019-15631-1hc9y2m/spec.rb:27 # compose returns a function composition with arity of two of two functions
Георги Киряков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Киряков
def complement(f)
-> *args { not f.call *args }
end
def compose(f, g)
-> *args { f.call( g.call(*args) ) }
end
....

Finished in 0.00519 seconds
4 examples, 0 failures
Методи Димитров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Методи Димитров
def complement(f)
-> (*args) { not f.call *args }
end
def compose(f, g)
-> (*args) { f.(g.(*args)) }
end
....

Finished in 0.00295 seconds
4 examples, 0 failures
Петър Иванов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Иванов
def complement(f)
->(*args) { not f.call(*args) }
end
def compose(f, g)
->(*args) { f.call(g.call(*args)) }
end
....

Finished in 0.00265 seconds
4 examples, 0 failures
Станимира Влаева
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Станимира Влаева
def complement(f)
->(*args) { !f.call(*args) }
end
def compose(f, g)
->(*args) { f.call(g.call(*args)) }
end
....

Finished in 0.00258 seconds
4 examples, 0 failures
Клара Кайралах
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Клара Кайралах
def complement(f)
lambda { | x |
if f.call(x) == true then false else true end
}
end
def compose(f, g)
lambda{ | x | f.call(g.call(x)) }
end
.F.F

Failures:

  1) complement complements a function with arity of two
     Failure/Error: expect(sum_not_four.call(2, 2)).to eq false
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-1lp9eyu/solution.rb:2:in `block in complement'
     # /tmp/d20151019-15631-1lp9eyu/spec.rb:14:in `call'
     # /tmp/d20151019-15631-1lp9eyu/spec.rb:14: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) compose returns a function composition with arity of two of two functions
     Failure/Error: expect(compose(add_two, pow).call(2, 3)).to eq 10
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-1lp9eyu/solution.rb:8:in `block in compose'
     # /tmp/d20151019-15631-1lp9eyu/spec.rb:31:in `call'
     # /tmp/d20151019-15631-1lp9eyu/spec.rb:31: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.0028 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20151019-15631-1lp9eyu/spec.rb:10 # complement complements a function with arity of two
rspec /tmp/d20151019-15631-1lp9eyu/spec.rb:27 # compose returns a function composition with arity of two of two functions
Божидар Горов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Божидар Горов
def complement(function)
-> (*n) {not function.call(*n)}
end
def compose(first_function, second_function)
-> (*n) {first_function.call(second_function.call(*n))}
end
....

Finished in 0.00266 seconds
4 examples, 0 failures
Георги Стефанов
  • Некоректно
  • 1 успешни тест(а)
  • 3 неуспешни тест(а)
Георги Стефанов
odd = ->(a) { a % 2 == 1}
def compliment(f)
lambda { |x| f.call (x + 1) }
end
even = compliment(odd)
transform = ->(a) {a + 1}
def compose(f, g)
lambda { |x| f.call (g.call x) }
end
FF.F

Failures:

  1) complement complements a function
     Failure/Error: not_answer = complement(is_answer)
     NoMethodError:
       undefined method `complement' for #<RSpec::Core::ExampleGroup::Nested_1:0x007fa2f5fb0258>
     # /tmp/d20151019-15631-k5upjh/spec.rb:4: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) complement complements a function with arity of two
     Failure/Error: sum_not_four = complement(is_sum_four)
     NoMethodError:
       undefined method `complement' for #<RSpec::Core::ExampleGroup::Nested_1:0x007fa2f5fa1d48>
     # /tmp/d20151019-15631-k5upjh/spec.rb:12: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) compose returns a function composition with arity of two of two functions
     Failure/Error: expect(compose(add_two, pow).call(2, 3)).to eq 10
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-k5upjh/solution.rb:12:in `block in compose'
     # /tmp/d20151019-15631-k5upjh/spec.rb:31:in `call'
     # /tmp/d20151019-15631-k5upjh/spec.rb:31: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.00275 seconds
4 examples, 3 failures

Failed examples:

rspec /tmp/d20151019-15631-k5upjh/spec.rb:2 # complement complements a function
rspec /tmp/d20151019-15631-k5upjh/spec.rb:10 # complement complements a function with arity of two
rspec /tmp/d20151019-15631-k5upjh/spec.rb:27 # compose returns a function composition with arity of two of two functions
Мила Русева
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Мила Русева
def move(snake, direction)
snake_new = snake[1..-1]
grow(snake_new, direction)
end
def grow(snake, direction)
snake_new = snake.dup
head = new_head(snake, direction)
snake_new.push(head)
end
def new_head(snake, direction)
old_head = snake[-1]
[old_head[0] + direction[0], old_head[1] + direction[1]]
end
def new_food(food, snake, dimensions)
field = new_field(dimensions)
while snake.include?(field) or food.include?(field) do
field = new_field(dimensions)
end
field
end
def new_field(dimensions)
xs = rand(dimensions[:width])
ys = rand(dimensions[:height])
[xs, ys]
end
def obstacle_ahead?(snake, direction, dimensions)
head = new_head(snake, direction)
snake.include?(head) or wall?(head, dimensions)
end
def wall?(head, dimensions)
return true if head[0] < 0
return true if head[0] >= dimensions[:width]
return true if head[1] < 0
return true if head[1] >= dimensions[:height]
return false
end
def danger?(snake, direction, dimensions)
return true if obstacle_ahead?(snake, direction, dimensions)
next_turn = move(snake, direction)
obstacle_ahead?(next_turn, direction, dimensions)
end
FFFF

Failures:

  1) complement complements a function
     Failure/Error: not_answer = complement(is_answer)
     NoMethodError:
       undefined method `complement' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f6722c98840>
     # /tmp/d20151019-15631-zlymoq/spec.rb:4: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) complement complements a function with arity of two
     Failure/Error: sum_not_four = complement(is_sum_four)
     NoMethodError:
       undefined method `complement' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f6722c8eac0>
     # /tmp/d20151019-15631-zlymoq/spec.rb:12: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) compose returns a function composition of two functions
     Failure/Error: expect(compose(is_answer, add_two).call(40)).to eq true
     NoMethodError:
       undefined method `compose' for #<RSpec::Core::ExampleGroup::Nested_2:0x007f6722c6f4b8>
     # /tmp/d20151019-15631-zlymoq/spec.rb:24: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) compose returns a function composition with arity of two of two functions
     Failure/Error: expect(compose(add_two, pow).call(2, 3)).to eq 10
     NoMethodError:
       undefined method `compose' for #<RSpec::Core::ExampleGroup::Nested_2:0x007f6722c6cf38>
     # /tmp/d20151019-15631-zlymoq/spec.rb:31: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.00199 seconds
4 examples, 4 failures

Failed examples:

rspec /tmp/d20151019-15631-zlymoq/spec.rb:2 # complement complements a function
rspec /tmp/d20151019-15631-zlymoq/spec.rb:10 # complement complements a function with arity of two
rspec /tmp/d20151019-15631-zlymoq/spec.rb:20 # compose returns a function composition of two functions
rspec /tmp/d20151019-15631-zlymoq/spec.rb:27 # compose returns a function composition with arity of two of two functions
Кристиан Цветков
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Кристиан Цветков
def complement(f)
lambda { |*args| !f }
end
def compose(f, g)
lambda { |*args| f.call(g.call(*args)) }
end
FF..

Failures:

  1) complement complements a function
     Failure/Error: expect(not_answer.call(12)).to eq true
       
       expected: true
            got: false
       
       (compared using ==)
     # /tmp/d20151019-15631-991gmf/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) complement complements a function with arity of two
     Failure/Error: expect(sum_not_four.call(1, 2)).to eq true
       
       expected: true
            got: false
       
       (compared using ==)
     # /tmp/d20151019-15631-991gmf/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)>'

Finished in 0.008 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20151019-15631-991gmf/spec.rb:2 # complement complements a function
rspec /tmp/d20151019-15631-991gmf/spec.rb:10 # complement complements a function with arity of two
Бойко Караджов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Бойко Караджов
def complement(f)
-> (*arguments) { not f.call(*arguments) }
end
def compose(f, g)
-> (*arguments) { f.call(g.call(*arguments)) }
end
....

Finished in 0.00263 seconds
4 examples, 0 failures
Здравко Андонов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Здравко Андонов
def complement(f)
->(*arguments) { !f.call(*arguments) }
end
def compose(f, g)
->(*arguments) { f.call(g.call(*arguments)) }
end
....

Finished in 0.00259 seconds
4 examples, 0 failures
Даяна Маринова
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Даяна Маринова
def complement(f)
->(n) { !f.call(n) }
end
def compose(f, g)
->(n) { f.call(g.call(n)) }
end
.F.F

Failures:

  1) complement complements a function with arity of two
     Failure/Error: expect(sum_not_four.call(2, 2)).to eq false
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-xscr0s/solution.rb:2:in `block in complement'
     # /tmp/d20151019-15631-xscr0s/spec.rb:14:in `call'
     # /tmp/d20151019-15631-xscr0s/spec.rb:14: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) compose returns a function composition with arity of two of two functions
     Failure/Error: expect(compose(add_two, pow).call(2, 3)).to eq 10
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-xscr0s/solution.rb:6:in `block in compose'
     # /tmp/d20151019-15631-xscr0s/spec.rb:31:in `call'
     # /tmp/d20151019-15631-xscr0s/spec.rb:31: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.00276 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20151019-15631-xscr0s/spec.rb:10 # complement complements a function with arity of two
rspec /tmp/d20151019-15631-xscr0s/spec.rb:27 # compose returns a function composition with arity of two of two functions
Кристиян Тодоров
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Кристиян Тодоров
def complement(f)
-> (n) { !f.call(n) }
end
def compose(f, g)
-> (n) { f.call(g.call(n)) }
end
.F.F

Failures:

  1) complement complements a function with arity of two
     Failure/Error: expect(sum_not_four.call(2, 2)).to eq false
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-1cwtt9c/solution.rb:2:in `block in complement'
     # /tmp/d20151019-15631-1cwtt9c/spec.rb:14:in `call'
     # /tmp/d20151019-15631-1cwtt9c/spec.rb:14: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) compose returns a function composition with arity of two of two functions
     Failure/Error: expect(compose(add_two, pow).call(2, 3)).to eq 10
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-1cwtt9c/solution.rb:6:in `block in compose'
     # /tmp/d20151019-15631-1cwtt9c/spec.rb:31:in `call'
     # /tmp/d20151019-15631-1cwtt9c/spec.rb:31: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.00284 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20151019-15631-1cwtt9c/spec.rb:10 # complement complements a function with arity of two
rspec /tmp/d20151019-15631-1cwtt9c/spec.rb:27 # compose returns a function composition with arity of two of two functions
Слави Боянов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Слави Боянов
def complement(function)
-> (*arguments) { not function.call(*arguments) }
end
def compose(function_one, function_two)
-> (*arguments) { function_one.call(function_two.call(*arguments)) }
end
....

Finished in 0.00264 seconds
4 examples, 0 failures
Георги Карапетров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Карапетров
def complement(f)
->(*args) { not f.(*args) }
end
def compose(f, g)
->(*args) { f.(g.(*args)) }
end
....

Finished in 0.00264 seconds
4 examples, 0 failures
Ивайло Чернев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Ивайло Чернев
def complement (f)
-> (*args) { !f.call *args }
end
def compose(f, g)
-> (*args) { f.call g.call *args }
end
....

Finished in 0.00259 seconds
4 examples, 0 failures
Александър Дражев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Дражев
def complement(f)
->(*args) { not f.call(*args) }
end
def compose(f, g)
->(*args) { f.call(g.call(*args)) }
end
....

Finished in 0.00273 seconds
4 examples, 0 failures
Анджелин Неделчев
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Анджелин Неделчев
def complement(f)
lambda { |n| not f.call(n) }
end
def compose(f, g)
lambda { |*args| f.call(g.call(*args)) }
end
.F..

Failures:

  1) complement complements a function with arity of two
     Failure/Error: expect(sum_not_four.call(2, 2)).to eq false
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-z5asyj/solution.rb:2:in `block in complement'
     # /tmp/d20151019-15631-z5asyj/spec.rb:14:in `call'
     # /tmp/d20151019-15631-z5asyj/spec.rb:14: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.00273 seconds
4 examples, 1 failure

Failed examples:

rspec /tmp/d20151019-15631-z5asyj/spec.rb:10 # complement complements a function with arity of two
Станимир Богданов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Станимир Богданов
def complement(f)
lambda { |*args| not f.call(*args) }
end
def compose(f, g)
lambda { |*args| f.call(g.call(*args)) }
end
....

Finished in 0.00282 seconds
4 examples, 0 failures
Димитър Терзиев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Терзиев
def complement(f)
->(*args) { !f.call(*args) }
end
def compose(f, g)
->(*args) { f.call(g.call(*args)) }
end
....

Finished in 0.00298 seconds
4 examples, 0 failures
Мариян Борисов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Мариян Борисов
def complement(f)
->(*p) { not f.call(*p) }
end
def compose(f, g)
->(*p) { f.call(g.call(*p)) }
end
....

Finished in 0.00266 seconds
4 examples, 0 failures
Десислава Цветкова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Десислава Цветкова
def complement(function)
lambda {|*args| not function.call(*args)}
end
def compose(f_function, g_function)
lambda do |*args|
f_function.call(g_function.call(*args))
end
end
....

Finished in 0.00264 seconds
4 examples, 0 failures
Стоян Желязков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Стоян Желязков
def complement(f)
-> (*args) { !f.call(*args) }
end
def compose(f, g)
-> (*args) { f.call(g.call(*args)) }
end
....

Finished in 0.00264 seconds
4 examples, 0 failures
Андрея Костов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Андрея Костов
def complement(f)
->(*args) { !f[*args] }
end
def compose(f, g)
->(*args) { f[g[*args]] }
end
....

Finished in 0.00264 seconds
4 examples, 0 failures
Бони Бонев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Бони Бонев
def complement(f)
lambda { |*args| not f.call *args }
end
def compose(f, g)
lambda { |*args| f.call g.call *args }
end
....

Finished in 0.00264 seconds
4 examples, 0 failures
Никола Терзиев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Терзиев
def complement(f)
lambda { |*args| not f[*args] }
end
def compose(f, g)
lambda { |*args| f[g[*args]] }
end
....

Finished in 0.00259 seconds
4 examples, 0 failures
Димитър Ангелов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Ангелов
def complement(function)
return_function = -> (*args) { not function.call(*args) }
end
def compose (function_f, function_g)
return_function = -> (*args) { function_f.call(function_g.call(*args))}
end
....

Finished in 0.00304 seconds
4 examples, 0 failures
Добромир Иванов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Добромир Иванов
def complement(f)
->(*args) { !f.call(*args) }
end
def compose(f, g)
->(*args) { f.call(g.call(*args)) }
end
....

Finished in 0.0026 seconds
4 examples, 0 failures
Милена Дренска
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Милена Дренска
def complement(f)
arguments = f.parameters
return a = -> (*arguments){ !f.call(*arguments) }
end
..FF

Failures:

  1) compose returns a function composition of two functions
     Failure/Error: expect(compose(is_answer, add_two).call(40)).to eq true
     NoMethodError:
       undefined method `compose' for #<RSpec::Core::ExampleGroup::Nested_2:0x007f47344d4e50>
     # /tmp/d20151019-15631-17zed34/spec.rb:24: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) compose returns a function composition with arity of two of two functions
     Failure/Error: expect(compose(add_two, pow).call(2, 3)).to eq 10
     NoMethodError:
       undefined method `compose' for #<RSpec::Core::ExampleGroup::Nested_2:0x007f47344b5ac8>
     # /tmp/d20151019-15631-17zed34/spec.rb:31: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.0027 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20151019-15631-17zed34/spec.rb:20 # compose returns a function composition of two functions
rspec /tmp/d20151019-15631-17zed34/spec.rb:27 # compose returns a function composition with arity of two of two functions
Мартина Тонковска
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Мартина Тонковска
def complement(f)
lambda {|*args| not f.call(*args) }
end
def compose(f, g)
lambda {|*args| f.call(g.call(*args)) }
end
....

Finished in 0.00269 seconds
4 examples, 0 failures
Мартин Симеонов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Мартин Симеонов
def complement(f)
->(*argument) { !f.call *argument }
end
def compose(f, g)
->(*argument) { f.call(g.call *argument) }
end
....

Finished in 0.00256 seconds
4 examples, 0 failures
Марк Андонов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Марк Андонов
def complement(f)
lambda { |*args| f.call(*args) == false }
end
def compose(f, g)
lambda { |*args| f.call(* (g.call(*args))) }
end
....

Finished in 0.00261 seconds
4 examples, 0 failures
София Петрова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
София Петрова
def complement(f)
-> *parameters { !f.call(*parameters) }
end
def compose(f, g)
-> *parameters { f.call(g.call(*parameters)) }
end
....

Finished in 0.00262 seconds
4 examples, 0 failures
Мария Османлиева
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Мария Османлиева
def complement(f)
lambda do |(*arguments)|
not f.(*arguments)
end
end
def compose(f, g)
lambda do |(*arguments)|
f.(g.(*arguments))
end
end
.F.F

Failures:

  1) complement complements a function with arity of two
     Failure/Error: expect(sum_not_four.call(2, 2)).to eq false
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-aoeady/solution.rb:2:in `block in complement'
     # /tmp/d20151019-15631-aoeady/spec.rb:14:in `call'
     # /tmp/d20151019-15631-aoeady/spec.rb:14: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) compose returns a function composition with arity of two of two functions
     Failure/Error: expect(compose(add_two, pow).call(2, 3)).to eq 10
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-aoeady/solution.rb:8:in `block in compose'
     # /tmp/d20151019-15631-aoeady/spec.rb:31:in `call'
     # /tmp/d20151019-15631-aoeady/spec.rb:31: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.00327 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20151019-15631-aoeady/spec.rb:10 # complement complements a function with arity of two
rspec /tmp/d20151019-15631-aoeady/spec.rb:27 # compose returns a function composition with arity of two of two functions
Рали Ралев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Рали Ралев
def complement(f)
->(*a) { !f.call(*a) }
end
def compose(f, g)
->(*a) { f.call(g.call(*a)) }
end
....

Finished in 0.00261 seconds
4 examples, 0 failures
Живка Пейчинова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Живка Пейчинова
def complement(f)
lambda { |*args| f.call(*args) ? false : true }
end
def compose(f, g)
lambda do |*args|
f.call(g.call(*args))
end
end
....

Finished in 0.00259 seconds
4 examples, 0 failures
Кузман Белев
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Кузман Белев
def complement(is_answer)
->(x) { is_answer[x] ? false : true }
end
def compose(f, g)
->(x) { f[g[x]] }
end
.F.F

Failures:

  1) complement complements a function with arity of two
     Failure/Error: expect(sum_not_four.call(2, 2)).to eq false
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-qxy3hm/solution.rb:2:in `block in complement'
     # /tmp/d20151019-15631-qxy3hm/spec.rb:14:in `call'
     # /tmp/d20151019-15631-qxy3hm/spec.rb:14: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) compose returns a function composition with arity of two of two functions
     Failure/Error: expect(compose(add_two, pow).call(2, 3)).to eq 10
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-qxy3hm/solution.rb:6:in `block in compose'
     # /tmp/d20151019-15631-qxy3hm/spec.rb:31:in `call'
     # /tmp/d20151019-15631-qxy3hm/spec.rb:31: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.00277 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20151019-15631-qxy3hm/spec.rb:10 # complement complements a function with arity of two
rspec /tmp/d20151019-15631-qxy3hm/spec.rb:27 # compose returns a function composition with arity of two of two functions
Веселин Русинов
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Веселин Русинов
def complement(f)
->(param) { !f.call(param) }
end
def compose(f, g)
->(param) { f.call(g.call(param)) }
end
.F.F

Failures:

  1) complement complements a function with arity of two
     Failure/Error: expect(sum_not_four.call(2, 2)).to eq false
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-t5a350/solution.rb:2:in `block in complement'
     # /tmp/d20151019-15631-t5a350/spec.rb:14:in `call'
     # /tmp/d20151019-15631-t5a350/spec.rb:14: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) compose returns a function composition with arity of two of two functions
     Failure/Error: expect(compose(add_two, pow).call(2, 3)).to eq 10
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-t5a350/solution.rb:6:in `block in compose'
     # /tmp/d20151019-15631-t5a350/spec.rb:31:in `call'
     # /tmp/d20151019-15631-t5a350/spec.rb:31: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.00287 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20151019-15631-t5a350/spec.rb:10 # complement complements a function with arity of two
rspec /tmp/d20151019-15631-t5a350/spec.rb:27 # compose returns a function composition with arity of two of two functions
Росен Тодоров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Росен Тодоров
def complement(f)
-> (*arguments) { !f.call(*arguments) }
end
def compose(f, g)
-> (*arguments) { f.call( g.call(*arguments)) }
end
....

Finished in 0.00304 seconds
4 examples, 0 failures
Пламена Петрова
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Пламена Петрова
def complement(f)
lambda { |x| not(f.call x)}
end
def compose(f, g)
lambda { |x| f.call(g.call x)}
end
.F.F

Failures:

  1) complement complements a function with arity of two
     Failure/Error: expect(sum_not_four.call(2, 2)).to eq false
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-17zx9uh/solution.rb:2:in `block in complement'
     # /tmp/d20151019-15631-17zx9uh/spec.rb:14:in `call'
     # /tmp/d20151019-15631-17zx9uh/spec.rb:14: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) compose returns a function composition with arity of two of two functions
     Failure/Error: expect(compose(add_two, pow).call(2, 3)).to eq 10
     ArgumentError:
       wrong number of arguments (2 for 1)
     # /tmp/d20151019-15631-17zx9uh/solution.rb:6:in `block in compose'
     # /tmp/d20151019-15631-17zx9uh/spec.rb:31:in `call'
     # /tmp/d20151019-15631-17zx9uh/spec.rb:31: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.00294 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20151019-15631-17zx9uh/spec.rb:10 # complement complements a function with arity of two
rspec /tmp/d20151019-15631-17zx9uh/spec.rb:27 # compose returns a function composition with arity of two of two functions