Чертане на морски шах

Краен срок
18.10.2014 12:00

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

Всеки е играл морски шах.

Нека имаме списъчно представяне на дъска за морски шах, за което е вярно:

  • Съставена е от списък с точно девет елемента.
  • Възможните елементи са или nil за празно поле, или символът :x за поле, в което има "x", или :o за поле, в което има o.
  • Първите три елемента съответстват на първия ред от дъската, вторите три – на втория ред и последните три на третия ред.

От вас ще искаме да напишете код, който да обръща това списъчно представяне на дъската към текстова рисунка. Най-лесно ще е да илюстрираме с пример.

Ако имаме следната дъска:

tic_tac_toe_board = [
  nil, nil, :x,
  :o,  nil, :x,
  :o,  :x,  :o,
]

То ще искаме от вас да дефинирате метода render_tic_tac_toe_board_to_ascii(board), който да върне следният текстов низ:

"|   |   | x |
| o |   | x |
| o | x | o |"

Ако изведем на екрана така получения низ, ще видим следната близка до реалността рисунка:

|   |   | x |
| o |   | x |
| o | x | o |

Бележки

  • Не извеждайте нищо на екрана.
  • Използвайте само \n за разделяне на редовете. Можете да го направите, като сложите \n в низ с двойни кавички: "\n".
  • Няма да ви подаваме некоректни данни. Списъците, с които ще тестваме, винаги ще имат точно девет елемента и елементите винаги ще са един от трите изброени.

С това предизвикателство ще трябва да упражните обхождане и манипулация на списъци и операции с низове. Нашето решение се побира в 270 символа и е сравнително описателно.

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

Примерните тестове се намират в GitHub хранилището с домашните. За информация как да ги изпълните, погледнете README-то на хранилището.

Решения

Константин Тодоров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Константин Тодоров
def render_tic_tac_toe_board_to_ascii(board)
str = "|"
board.each do |item|
if str.count("|") % 4 == 0 then
str += "\n| "
else
str += " "
end
str += render_board_item(item) + " |"
end
str
end
def render_board_item(item)
return " " if item == nil
item.to_s
end
....

Finished in 0.00577 seconds
4 examples, 0 failures
Деян Боиклиев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Деян Боиклиев
def render_tic_tac_toe_board_to_ascii(board)
board.map! { |sign| sign == nil ? " " : sign }
"| #{board[0]} | #{board[1]} | #{board[2]} |\n| #{board[3]} | #{board[4]} | #{board[5]} |\n| #{board[6]} | #{board[7]} | #{board[8]} |"
end
....

Finished in 0.00556 seconds
4 examples, 0 failures
Веселин Русинов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Веселин Русинов
def render_tic_tac_toe_board_to_ascii(board)
"|#{board.map { |e| (e || ' ').to_s.center(3, ' ') }.insert(3, "\n").insert(7, "\n").join("|")}|"
end
....

Finished in 0.00546 seconds
4 examples, 0 failures
Ивайло Георгиев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Ивайло Георгиев
def render_tic_tac_toe_board_to_ascii(board)
return "|" if board == []
new_line = "|\n" if board.length == 7 or board.length == 4
if board.first.nil?
element = " "
else
element = board.first
end
"#{"|"} #{element} #{new_line}#{render_tic_tac_toe_board_to_ascii(board.drop 1)}"
end
....

Finished in 0.00455 seconds
4 examples, 0 failures
Камен Станев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Камен Станев
def render_tic_tac_toe_board_to_ascii(board)
board.each_slice(3).inject("") do |row, (a, b, c)|
row << "| #{a || ' '} | #{b || ' '} | #{c || ' '} |\n"
end.chop
end
....

Finished in 0.00444 seconds
4 examples, 0 failures
Георги Костов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Костов
def render_tic_tac_toe_board_to_ascii(board)
board.map! do |element|
if element == nil
element = " "
elsif element == :x
element = "x"
elsif element == :o
element = "o"
end
end
result = board.to_s
.gsub("nil", " ").gsub(":x", " x ").gsub(":o"," o ")
.gsub(", ", "|").gsub("[", "|").gsub("]", "|").gsub("\"", " ")
result[0...13] + "\n" + result[12...25] + "\n" + result[24...37]
end
....

Finished in 0.0053 seconds
4 examples, 0 failures
Мартин Христов
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Мартин Христов
def render_tic_tac_toe_board_to_ascii board
rendered_board = ''
counter = 0
board.each do |symbol|
counter%3 == 0 && counter!=0 ? rendered_board+= "\n" : rendered_board
symbol.class == Symbol ? symbol = symbol.to_s : symbol
if (symbol.class == NilClass)
rendered_board += '| |'
else
rendered_board += '|' + symbol + '|'
end
counter+=1
end
rendered_board.gsub(/\|{2,}/, '|')
end
FFFF

Failures:

  1) tic_tac_toe_board_from renders a blank board for an array with nils
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "|   |   |   |\n|   |   |   |\n|   |   |   |"
            got: "| | | |\n| | | |\n| | | |"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -|   |   |   |
       -|   |   |   |
       -|   |   |   |
       +| | | |
       +| | | |
       +| | | |
     # /tmp/d20141018-2426-1ffi78s/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) tic_tac_toe_board_from renders boards with x and o markers
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x |   |   |\n| o | x |   |\n| x | o | o |"
            got: "|x| | |\n|o|x| |\n|x|o|o|"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| x |   |   |
       -| o | x |   |
       -| x | o | o |
       +|x| | |
       +|o|x| |
       +|x|o|o|
     # /tmp/d20141018-2426-1ffi78s/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)>'

  3) tic_tac_toe_board_from renders boards with all x-es
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x | x | x |\n| x | x | x |\n| x | x | x |"
            got: "|x|x|x|\n|x|x|x|\n|x|x|x|"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| x | x | x |
       -| x | x | x |
       -| x | x | x |
       +|x|x|x|
       +|x|x|x|
       +|x|x|x|
     # /tmp/d20141018-2426-1ffi78s/spec.rb:27: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) tic_tac_toe_board_from renders boards with all o-s
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| o | o | o |\n| o | o | o |\n| o | o | o |"
            got: "|o|o|o|\n|o|o|o|\n|o|o|o|"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| o | o | o |
       -| o | o | o |
       -| o | o | o |
       +|o|o|o|
       +|o|o|o|
       +|o|o|o|
     # /tmp/d20141018-2426-1ffi78s/spec.rb:39: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.00681 seconds
4 examples, 4 failures

Failed examples:

rspec /tmp/d20141018-2426-1ffi78s/spec.rb:2 # tic_tac_toe_board_from renders a blank board for an array with nils
rspec /tmp/d20141018-2426-1ffi78s/spec.rb:14 # tic_tac_toe_board_from renders boards with x and o markers
rspec /tmp/d20141018-2426-1ffi78s/spec.rb:26 # tic_tac_toe_board_from renders boards with all x-es
rspec /tmp/d20141018-2426-1ffi78s/spec.rb:38 # tic_tac_toe_board_from renders boards with all o-s
Александър Александров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Александров
def render_tic_tac_toe_board_to_ascii(board)
string = board[0..2].to_s + "\n" + board[3..5].to_s + "\n" + board[6..8].to_s
string.gsub("[","| ").gsub("]"," |").gsub(","," |").gsub("nil"," ").gsub(":","")
end
....

Finished in 0.00507 seconds
4 examples, 0 failures
Иван Кавалджиев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Кавалджиев
def render_tic_tac_toe_board_to_ascii(board)
result = [""]
board.each do |element|
case element
when nil then result << " "
when :x then result << " x "
when :o then result << " o "
end
end
result.insert(4, "\n")
result.insert(8, "\n")
result << ""
result * "|"
end
....

Finished in 0.00443 seconds
4 examples, 0 failures
Любомир Папазов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Любомир Папазов
def expected_output(board_as_array_of_rows)
result = ""
board_as_array_of_rows.each do |row|
row.each {|element| result += "|#{element}"}
result += "|\n"
end
result.chomp
end
def render_tic_tac_toe_board_to_ascii(board)
actual_symbols = {nil => ' ', :x => ' x ' , :o => ' o '}
board.map! { |key| actual_symbols[key]}
board_rows = board.each_slice(3).to_a
expected_output(board_rows)
end
....

Finished in 0.00458 seconds
4 examples, 0 failures
Дамян Димитров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Дамян Димитров
def render_tic_tac_toe_board_to_ascii(board)
result = ""
(board.map { |b| b == nil ? ' ' : b.to_s}).each_with_index do |item, index|
if index == 2 or index == 5
result += "| #{item} |\n"
elsif index == 8
result += "| #{item} |"
else
result += "| #{item} "
end
end
result
end
....

Finished in 0.00463 seconds
4 examples, 0 failures
Александър Попов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Попов
def render_tic_tac_toe_board_to_ascii(board)
board.map { |e| "| #{e || ' '} " }.join.scan(/.{12}/).join("|\n") << '|'
end
....

Finished in 0.00475 seconds
4 examples, 0 failures
Иван Станков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Станков
def render_tic_tac_toe_board_to_ascii(board)
count = 0
board_blueprint = "|"
board.each do |cell|
if cell == nil
cell = " "
end
if count %3 == 0 and count != 0
board_blueprint << "\n| #{cell.to_s} |"
else
board_blueprint <<" #{cell.to_s} |"
end
count += 1
end
board_blueprint
end
....

Finished in 0.00593 seconds
4 examples, 0 failures
Герасим Станчев
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Герасим Станчев
def render_tic_tac_toe_board_to_ascii(board)
table = '|'
chess_hash = { nil => ' |', :x => ' x |', :o => ' o |', "\n" => "\n|" }
(3..board.length - 1).step(4) { |index| board.insert(index, "\n") }
board.each { |element| table << chess_hash[element] }
table
end
FF..

Failures:

  1) tic_tac_toe_board_from renders a blank board for an array with nils
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "|   |   |   |\n|   |   |   |\n|   |   |   |"
            got: "| | | |\n| | | |\n| | | |"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -|   |   |   |
       -|   |   |   |
       -|   |   |   |
       +| | | |
       +| | | |
       +| | | |
     # /tmp/d20141018-2426-dnazbd/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) tic_tac_toe_board_from renders boards with x and o markers
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x |   |   |\n| o | x |   |\n| x | o | o |"
            got: "| x | | |\n| o | x | |\n| x | o | o |"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| x |   |   |
       -| o | x |   |
       +| x | | |
       +| o | x | |
        | x | o | o |
     # /tmp/d20141018-2426-dnazbd/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.00656 seconds
4 examples, 2 failures

Failed examples:

rspec /tmp/d20141018-2426-dnazbd/spec.rb:2 # tic_tac_toe_board_from renders a blank board for an array with nils
rspec /tmp/d20141018-2426-dnazbd/spec.rb:14 # tic_tac_toe_board_from renders boards with x and o markers
Диана Генева
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Диана Генева
def render_tic_tac_toe_board_to_ascii(board)
ascii_board = board.map { |mark| ' ' + (!mark ? ' ' : mark.to_s) + ' '}
[3, 7].each { |iter| ascii_board.insert(iter, "\n") }
'|' + ascii_board.join('|') + '|'
end
....

Finished in 0.00458 seconds
4 examples, 0 failures
Емилиан Станков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Емилиан Станков
def render_tic_tac_toe_board_to_ascii(board)
ascii_board = ""
board.each_with_index do |element, index|
case element
when nil then ascii_board << "| "
when :x then ascii_board << "| x "
when :o then ascii_board << "| o "
end
ascii_board << "|\n" if index % 3 == 2
end
ascii_board.chomp
end
....

Finished in 0.00456 seconds
4 examples, 0 failures
Ангел Ангелов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Ангел Ангелов
RENDER = { nil => ' ', :x => 'x', :o => 'o' }
def render_row(row)
'| ' + row.map { |mark| RENDER[mark] }.join(' | ') + ' |'
end
def render_tic_tac_toe_board_to_ascii(board)
board.each_slice(3).to_a.map { |row| render_row(row) }.join("\n")
end
....

Finished in 0.0045 seconds
4 examples, 0 failures
Любомир Петков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Любомир Петков
def to_ascii(element)
case element
when :x then "| x "
when :o then "| o "
else "| "
end
end
def render_tic_tac_toe_board_to_ascii(board)
ascii_board = ""
board.each_slice(3) do |row|
row.each {|element| ascii_board.concat(to_ascii(element))}
ascii_board.concat("|\n")
end
ascii_board.chop
end
....

Finished in 0.00555 seconds
4 examples, 0 failures
Людмил Делчев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Людмил Делчев
def element_to_symbol(element)
case(element)
when nil then return " "
when :x then return " x "
when :o then return " o "
end
end
def render_tic_tac_toe_board_to_ascii(board)
index = 0
rendered_board = "|"
begin
rendered_board = rendered_board + element_to_symbol(board[index]) + "|"
if ((index+1)%3 == 0 and index<8)
rendered_board = rendered_board + "\n" + "|"
end
index = index + 1
end while (index<=8)
return rendered_board
end
....

Finished in 0.00466 seconds
4 examples, 0 failures
Димитър Мутаров
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Димитър Мутаров
def render_tic_tac_toe_board_to_ascii(board)
result,position = '',1
board.each do |item|
item ||= ' '
result += "| #{item} "
if position == 3
result += "|\n"
position = 1
next
end
position += 1
end
result
end
FFFF

Failures:

  1) tic_tac_toe_board_from renders a blank board for an array with nils
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "|   |   |   |\n|   |   |   |\n|   |   |   |"
            got: "|   |   |   |\n|   |   |   |\n|   |   |   |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-1mhkrlk/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) tic_tac_toe_board_from renders boards with x and o markers
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x |   |   |\n| o | x |   |\n| x | o | o |"
            got: "| x |   |   |\n| o | x |   |\n| x | o | o |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-1mhkrlk/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)>'

  3) tic_tac_toe_board_from renders boards with all x-es
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x | x | x |\n| x | x | x |\n| x | x | x |"
            got: "| x | x | x |\n| x | x | x |\n| x | x | x |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-1mhkrlk/spec.rb:27: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) tic_tac_toe_board_from renders boards with all o-s
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| o | o | o |\n| o | o | o |\n| o | o | o |"
            got: "| o | o | o |\n| o | o | o |\n| o | o | o |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-1mhkrlk/spec.rb:39: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.00555 seconds
4 examples, 4 failures

Failed examples:

rspec /tmp/d20141018-2426-1mhkrlk/spec.rb:2 # tic_tac_toe_board_from renders a blank board for an array with nils
rspec /tmp/d20141018-2426-1mhkrlk/spec.rb:14 # tic_tac_toe_board_from renders boards with x and o markers
rspec /tmp/d20141018-2426-1mhkrlk/spec.rb:26 # tic_tac_toe_board_from renders boards with all x-es
rspec /tmp/d20141018-2426-1mhkrlk/spec.rb:38 # tic_tac_toe_board_from renders boards with all o-s
Атанас Димитров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Атанас Димитров
def render_tic_tac_toe_board_to_ascii(board)
substitute = {nil => " ", x: " x ", o: " o "}
board.collect { |element| substitute[element] }.insert(3,"\n").
insert(7, "\n").join("|").insert(0, "|").insert(-1, "|")
end
....

Finished in 0.00443 seconds
4 examples, 0 failures
Снежана Спасова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Снежана Спасова
def render_tic_tac_toe_board_to_ascii(board)
board.map{ |element| element.nil? ? " " : element.to_s}.each_slice(3).to_a.
map{ |element| element.join(" | ").insert(0,"| ") + " |\n"}.join.strip
end
....

Finished in 0.00456 seconds
4 examples, 0 failures
Людмила Савова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Людмила Савова
def render_tic_tac_toe_board_to_ascii(board)
display=""
board.each_with_index do |cell, index|
case cell
when :x then display += "| x |"
when :o then display += "| o |"
when nil then display += "| |"
end
if (index + 1) % 3 == 0 then display += "\n" end
end
display.squeeze('|').chop
end
....

Finished in 0.00457 seconds
4 examples, 0 failures
Веселин Добрев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Веселин Добрев
def render_tic_tac_toe_board_to_ascii(board)
ascii_representation = "| "
3.times do |i|
ascii_representation += "#{board[i*3, 3].join(" | ")} |"
ascii_representation += "\n| " if i < 2
end
ascii_representation.gsub(" ", " ")
end
....

Finished in 0.00467 seconds
4 examples, 0 failures
Светлозар Тодоров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Светлозар Тодоров
def render_tic_tac_toe_board_to_ascii(board)
drawing = "|"
board.each { |mark| drawing << (mark ? " #{mark} |" : " |") }
drawing.insert(13, "\n|").insert(27, "\n|")
end
....

Finished in 0.00561 seconds
4 examples, 0 failures
Никола Ненков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Ненков
def render_tic_tac_toe_board_to_ascii(board)
board.map { |square| "|#{square.to_s.center(3)}" }.each_slice(3).map(&:join).join("|\n") + '|'
end
....

Finished in 0.00581 seconds
4 examples, 0 failures
Ясен Трифонов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Ясен Трифонов
def render_tic_tac_toe_board_to_ascii(board)
board.map { |el| el ? el.to_s : ' ' }
.each_slice(3)
.map { |row| "| %s | %s | %s |" % row }
.join "\n"
end
....

Finished in 0.0045 seconds
4 examples, 0 failures
Екатерина Горанова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Екатерина Горанова
def render_tic_tac_toe_board_to_ascii(board)
symbol_map = {nil => " ", :o => " o ", :x => " x "}
board.each_slice(3).inject("") do |output, row|
output += "|" + row.map { |symbol| symbol_map[symbol] } * "|" + "|\n"
end.rstrip
end
....

Finished in 0.00568 seconds
4 examples, 0 failures
Любомир Иванов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Любомир Иванов
def render_tic_tac_toe_board_to_ascii(board)
result = "| 0 | 1 | 2 |\n| 3 | 4 | 5 |\n| 6 | 7 | 8 |"
board.each_with_index do |board_var, board_index|
if board_var.nil?
result[result.index(board_index.to_s)] = " "
else
result[result.index(board_index.to_s)] = board_var.to_s
end
end
result
end
....

Finished in 0.00444 seconds
4 examples, 0 failures
Гюлджан Купен
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Гюлджан Купен
def render_tic_tac_toe_board_to_ascii(board)
answer=""
board.each do |symbol|
symbol == nil ? answer += "| |" : answer += "| #{symbol} |"
end
answer.insert(15, "\n").insert(31, "\n").insert(47, "\n").squeeze("|")
end
FFFF

Failures:

  1) tic_tac_toe_board_from renders a blank board for an array with nils
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "|   |   |   |\n|   |   |   |\n|   |   |   |"
            got: "|   |   |   |\n|   |   |   |\n|   |   |   |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-1ke2iuc/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) tic_tac_toe_board_from renders boards with x and o markers
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x |   |   |\n| o | x |   |\n| x | o | o |"
            got: "| x |   |   |\n| o | x |   |\n| x | o | o |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-1ke2iuc/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)>'

  3) tic_tac_toe_board_from renders boards with all x-es
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x | x | x |\n| x | x | x |\n| x | x | x |"
            got: "| x | x | x |\n| x | x | x |\n| x | x | x |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-1ke2iuc/spec.rb:27: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) tic_tac_toe_board_from renders boards with all o-s
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| o | o | o |\n| o | o | o |\n| o | o | o |"
            got: "| o | o | o |\n| o | o | o |\n| o | o | o |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-1ke2iuc/spec.rb:39: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.0055 seconds
4 examples, 4 failures

Failed examples:

rspec /tmp/d20141018-2426-1ke2iuc/spec.rb:2 # tic_tac_toe_board_from renders a blank board for an array with nils
rspec /tmp/d20141018-2426-1ke2iuc/spec.rb:14 # tic_tac_toe_board_from renders boards with x and o markers
rspec /tmp/d20141018-2426-1ke2iuc/spec.rb:26 # tic_tac_toe_board_from renders boards with all x-es
rspec /tmp/d20141018-2426-1ke2iuc/spec.rb:38 # tic_tac_toe_board_from renders boards with all o-s
Константин Димитров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Константин Димитров
def render_tic_tac_toe_board_to_ascii(board)
symbol_to_string_map = {:o => 'o', :x => 'x', nil=>' '}
mapped_board = board.map { |i| symbol_to_string_map[ i ] }
mapped_board.each_slice(3).map { |i| '| ' + (i * ' | ') + ' |' } * "\n"
end
....

Finished in 0.00468 seconds
4 examples, 0 failures
Кристиан Цветков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Кристиан Цветков
def render_tic_tac_toe_board_to_ascii(board)
board_to_ascii = board.each_slice(3).map do |line|
"|#{line.map { |field| "#{field.to_s.center(3)}|" }.join}\n"
end
board_to_ascii.join.chomp
end
....

Finished in 0.00468 seconds
4 examples, 0 failures
Мартина Радева
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Мартина Радева
def render_tic_tac_toe_board_to_ascii(board)
board.map{|e| e ? e : " "}.each_slice(3).to_a.map! {|i| "| " + i.join(" | ") + " |\n"}.join.chomp
end
# def render_tic_tac_toe_board_to_ascii(board)
# board_zero = board.map {|e| e ? e : " "}
# exit_string = "| " + board_zero[0..2].join(" | ") + " |\n| " \
# + board_zero[3..5].join(" | ") + " |\n| " \
# + board_zero[6..8].join(" | ") + " |"
# end
....

Finished in 0.00463 seconds
4 examples, 0 failures
Нели Василева
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Нели Василева
def render_tic_tac_toe_board_to_ascii(board)
result = ''
board.each_with_index do |element, index|
result = "#{result}|#{get_ascii(element)}"
(result = "#{result}|\n") if index % 3 == 2
end
result.chomp
end
def get_ascii(element)
case element
when :x then ' x '
when :o then ' o '
else ' '
end
end
....

Finished in 0.00455 seconds
4 examples, 0 failures
Мария Дулева
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Дулева
def render_tic_tac_toe_board_to_ascii(board)
new_board = ""
0.upto(8) do |i|
if i % 3 == 0
new_board = new_board + "|"
end
case board[i]
when nil then new_board = new_board + " |"
when :o , :x then new_board = new_board + " " + board[i].to_s + " |"
end
if i == 2 or i == 5
new_board = new_board + "\n"
end
end
return new_board
end
....

Finished in 0.00478 seconds
4 examples, 0 failures
Александър Иванов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Иванов
def render_tic_tac_toe_board_to_ascii(puzzle)
("|%2s |%2s |%2s |\n" * 3).chomp % puzzle
end
....

Finished in 0.00557 seconds
4 examples, 0 failures
Николина Гюрова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Николина Гюрова
def render_tic_tac_toe_board_to_ascii (board)
string_board = board.map { |mark| (mark ? mark.to_s : " ").center(3) }
double_join(string_board, 3).chomp("\n|")
end
def double_join (to_join, row_length)
joined = "|"
to_join.each.with_index do |element, index|
joined += element + separator(index, row_length, to_join.length)
end
joined
end
def separator (index, row_length, array_length)
if index % row_length == row_length - 1
"|\n|"
else
"|"
end
end
....

Finished in 0.0171 seconds
4 examples, 0 failures
Явор Михайлов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Явор Михайлов
def render_tic_tac_toe_board_to_ascii(board)
board.map!.with_index do |cell|
cell.to_s.center(3)
end
string_representation_of_rows = []
board.each_slice(3) do |row|
row.first.insert(0, '|').insert(-1, '|')
row.last.insert(0, '|').insert(-1, '|')
string_representation_of_rows << row.join('')
end
string_representation_of_rows.join("\n")
end
....

Finished in 0.00464 seconds
4 examples, 0 failures
Атанас Цанков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Атанас Цанков
def render_tic_tac_toe_board_to_ascii(board)
string = ""
board.each_with_index do
|item, index|
if item == :x
current = "| x "
elsif item == :o
current = "| o "
else
current = "| "
end
if (index + 1) % 3 == 0
current = current + "|\n"
end
string = string + current
end
string.strip
end
....

Finished in 0.00449 seconds
4 examples, 0 failures
Калин Христов
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Калин Христов
def check(something)
return " " if something == nil
return "o" if something == :o
return "x" if something == :x
end
def render_tic_tac_toe_board_to_ascii(board)
return '|' + check(board[0]) + '|' + check(board[1]) + '|' + check(board[2]) + '|' + "\n" +
'|' + check(board[3]) + '|' + check(board[4]) + '|' + check(board[5]) + '|' + "\n" +
'|' + check(board[6]) + '|' + check(board[7]) + '|' + check(board[8]) + '|' + "\n"
end
FFFF

Failures:

  1) tic_tac_toe_board_from renders a blank board for an array with nils
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "|   |   |   |\n|   |   |   |\n|   |   |   |"
            got: "| | | |\n| | | |\n| | | |\n"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -|   |   |   |
       -|   |   |   |
       -|   |   |   |
       +| | | |
       +| | | |
       +| | | |
     # /tmp/d20141018-2426-l3n03q/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) tic_tac_toe_board_from renders boards with x and o markers
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x |   |   |\n| o | x |   |\n| x | o | o |"
            got: "|x| | |\n|o|x| |\n|x|o|o|\n"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| x |   |   |
       -| o | x |   |
       -| x | o | o |
       +|x| | |
       +|o|x| |
       +|x|o|o|
     # /tmp/d20141018-2426-l3n03q/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)>'

  3) tic_tac_toe_board_from renders boards with all x-es
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x | x | x |\n| x | x | x |\n| x | x | x |"
            got: "|x|x|x|\n|x|x|x|\n|x|x|x|\n"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| x | x | x |
       -| x | x | x |
       -| x | x | x |
       +|x|x|x|
       +|x|x|x|
       +|x|x|x|
     # /tmp/d20141018-2426-l3n03q/spec.rb:27: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) tic_tac_toe_board_from renders boards with all o-s
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| o | o | o |\n| o | o | o |\n| o | o | o |"
            got: "|o|o|o|\n|o|o|o|\n|o|o|o|\n"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| o | o | o |
       -| o | o | o |
       -| o | o | o |
       +|o|o|o|
       +|o|o|o|
       +|o|o|o|
     # /tmp/d20141018-2426-l3n03q/spec.rb:39: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.0078 seconds
4 examples, 4 failures

Failed examples:

rspec /tmp/d20141018-2426-l3n03q/spec.rb:2 # tic_tac_toe_board_from renders a blank board for an array with nils
rspec /tmp/d20141018-2426-l3n03q/spec.rb:14 # tic_tac_toe_board_from renders boards with x and o markers
rspec /tmp/d20141018-2426-l3n03q/spec.rb:26 # tic_tac_toe_board_from renders boards with all x-es
rspec /tmp/d20141018-2426-l3n03q/spec.rb:38 # tic_tac_toe_board_from renders boards with all o-s
Йончо Йончев
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Йончо Йончев
def render_tic_tac_toe_board_to_ascii(board)
boardString=String.new("")
i=0
board.each do |w|
if w==nil then boardString+="| "
elsif w==:o then boardString+="|o"
elsif w==:x then boardString+="|x"
end
if i==2 then boardString+="|\n" and i=-1
end
i+=1
end
return boardString
end
FFFF

Failures:

  1) tic_tac_toe_board_from renders a blank board for an array with nils
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "|   |   |   |\n|   |   |   |\n|   |   |   |"
            got: "| | | |\n| | | |\n| | | |\n"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -|   |   |   |
       -|   |   |   |
       -|   |   |   |
       +| | | |
       +| | | |
       +| | | |
     # /tmp/d20141018-2426-15juotz/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) tic_tac_toe_board_from renders boards with x and o markers
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x |   |   |\n| o | x |   |\n| x | o | o |"
            got: "|x| | |\n|o|x| |\n|x|o|o|\n"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| x |   |   |
       -| o | x |   |
       -| x | o | o |
       +|x| | |
       +|o|x| |
       +|x|o|o|
     # /tmp/d20141018-2426-15juotz/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)>'

  3) tic_tac_toe_board_from renders boards with all x-es
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x | x | x |\n| x | x | x |\n| x | x | x |"
            got: "|x|x|x|\n|x|x|x|\n|x|x|x|\n"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| x | x | x |
       -| x | x | x |
       -| x | x | x |
       +|x|x|x|
       +|x|x|x|
       +|x|x|x|
     # /tmp/d20141018-2426-15juotz/spec.rb:27: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) tic_tac_toe_board_from renders boards with all o-s
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| o | o | o |\n| o | o | o |\n| o | o | o |"
            got: "|o|o|o|\n|o|o|o|\n|o|o|o|\n"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| o | o | o |
       -| o | o | o |
       -| o | o | o |
       +|o|o|o|
       +|o|o|o|
       +|o|o|o|
     # /tmp/d20141018-2426-15juotz/spec.rb:39: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.00781 seconds
4 examples, 4 failures

Failed examples:

rspec /tmp/d20141018-2426-15juotz/spec.rb:2 # tic_tac_toe_board_from renders a blank board for an array with nils
rspec /tmp/d20141018-2426-15juotz/spec.rb:14 # tic_tac_toe_board_from renders boards with x and o markers
rspec /tmp/d20141018-2426-15juotz/spec.rb:26 # tic_tac_toe_board_from renders boards with all x-es
rspec /tmp/d20141018-2426-15juotz/spec.rb:38 # tic_tac_toe_board_from renders boards with all o-s
Стефан Чипилов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Стефан Чипилов
BOARD_SIZE = 3
def render_row(board, row)
board[row, BOARD_SIZE].map { |x| x.to_s.center(3) }.
join("|").
prepend("|").
concat("|\n")
end
def render_tic_tac_toe_board_to_ascii(board)
rows = (0..6).step(BOARD_SIZE).collect { |row| render_row(board, row) }
rows.join.rstrip!
end
....

Finished in 0.00465 seconds
4 examples, 0 failures
Любослава Димитрова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Любослава Димитрова
def render_tic_tac_toe_board_to_ascii(board)
board.each_index do |index|
case board[index]
when nil then board[index] = "| |"
when :o then board[index] = "| o |"
when :x then board[index] = "| x |"
end
end
board.join("").insert(15, "\n").insert(31, "\n").squeeze("|")
end
....

Finished in 0.00445 seconds
4 examples, 0 failures
Георги Павлов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Павлов
def render_tic_tac_toe_board_to_ascii(board)
hash_table = {:o => "o", :x => "x", nil => " "}
board.map { |a| hash_table.values_at(a) }
.join(" | ").insert(0, "| ").insert(-1, " |")
.insert(13, "\n|").insert(27, "\n|")
end
....

Finished in 0.00454 seconds
4 examples, 0 failures
Станимир Митев
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Станимир Митев
def render_tic_tac_toe_board_to_ascii(board)
string="|"
board.each_with_index do |element, index|
case element
when 'o' then string << " o |"
when 'x' then string << " x |"
when nil then string << " |"
end
string << "\n|" if index == 2 || index == 5
string << "\n" if index == 8
end
string
end
FFFF

Failures:

  1) tic_tac_toe_board_from renders a blank board for an array with nils
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "|   |   |   |\n|   |   |   |\n|   |   |   |"
            got: "|   |   |   |\n|   |   |   |\n|   |   |   |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-1nn4fao/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) tic_tac_toe_board_from renders boards with x and o markers
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x |   |   |\n| o | x |   |\n| x | o | o |"
            got: "|   |   |\n|   |\n|\n"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| x |   |   |
       -| o | x |   |
       -| x | o | o |
       +|   |   |
       +|   |
       +|
     # /tmp/d20141018-2426-1nn4fao/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)>'

  3) tic_tac_toe_board_from renders boards with all x-es
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x | x | x |\n| x | x | x |\n| x | x | x |"
            got: "|\n|\n|\n"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| x | x | x |
       -| x | x | x |
       -| x | x | x |
       +|
       +|
       +|
     # /tmp/d20141018-2426-1nn4fao/spec.rb:27: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) tic_tac_toe_board_from renders boards with all o-s
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| o | o | o |\n| o | o | o |\n| o | o | o |"
            got: "|\n|\n|\n"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| o | o | o |
       -| o | o | o |
       -| o | o | o |
       +|
       +|
       +|
     # /tmp/d20141018-2426-1nn4fao/spec.rb:39: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.00768 seconds
4 examples, 4 failures

Failed examples:

rspec /tmp/d20141018-2426-1nn4fao/spec.rb:2 # tic_tac_toe_board_from renders a blank board for an array with nils
rspec /tmp/d20141018-2426-1nn4fao/spec.rb:14 # tic_tac_toe_board_from renders boards with x and o markers
rspec /tmp/d20141018-2426-1nn4fao/spec.rb:26 # tic_tac_toe_board_from renders boards with all x-es
rspec /tmp/d20141018-2426-1nn4fao/spec.rb:38 # tic_tac_toe_board_from renders boards with all o-s
Евгений Бояджиев
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Евгений Бояджиев
BOARD_COLUMNS_COUNT = 3
BOARD_COLUMN_SEPARATOR = "|"
def symbol_array_to_char_array(arr, empty_char = "")
arr
.map {|elem| if elem.nil? then empty_char else elem end}
.map {|elem| elem.to_s}
end
def matrix_add_new_lines(matrix_arr, columns, has_last_row_new_line = false)
new_line = "\n"
rows = (matrix_arr.length / columns).floor
#Start adding the new lines char from the back of the matrix
for row in 1..(rows - 1) do
matrix_arr.insert((columns - row) * columns, new_line)
end
if has_last_row_new_line then matrix_arr << new_line else matrix_arr end
end
def array_wrap_and_join(arr, middle_separator = "",
begin_separator = "", end_separator = "")
begin_separator + arr.join(middle_separator) + end_separator
end
def render_tic_tac_toe_board_to_ascii(board)
ascii_board = symbol_array_to_char_array(board, " ")
ascii_board = matrix_add_new_lines(ascii_board, BOARD_COLUMNS_COUNT)
array_wrap_and_join(ascii_board, BOARD_COLUMN_SEPARATOR,
BOARD_COLUMN_SEPARATOR, BOARD_COLUMN_SEPARATOR)
end
FFFF

Failures:

  1) tic_tac_toe_board_from renders a blank board for an array with nils
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "|   |   |   |\n|   |   |   |\n|   |   |   |"
            got: "| | | |\n| | | |\n| | | |"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -|   |   |   |
       -|   |   |   |
       -|   |   |   |
       +| | | |
       +| | | |
       +| | | |
     # /tmp/d20141018-2426-1a6l0sy/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) tic_tac_toe_board_from renders boards with x and o markers
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x |   |   |\n| o | x |   |\n| x | o | o |"
            got: "|x| | |\n|o|x| |\n|x|o|o|"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| x |   |   |
       -| o | x |   |
       -| x | o | o |
       +|x| | |
       +|o|x| |
       +|x|o|o|
     # /tmp/d20141018-2426-1a6l0sy/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)>'

  3) tic_tac_toe_board_from renders boards with all x-es
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x | x | x |\n| x | x | x |\n| x | x | x |"
            got: "|x|x|x|\n|x|x|x|\n|x|x|x|"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| x | x | x |
       -| x | x | x |
       -| x | x | x |
       +|x|x|x|
       +|x|x|x|
       +|x|x|x|
     # /tmp/d20141018-2426-1a6l0sy/spec.rb:27: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) tic_tac_toe_board_from renders boards with all o-s
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| o | o | o |\n| o | o | o |\n| o | o | o |"
            got: "|o|o|o|\n|o|o|o|\n|o|o|o|"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| o | o | o |
       -| o | o | o |
       -| o | o | o |
       +|o|o|o|
       +|o|o|o|
       +|o|o|o|
     # /tmp/d20141018-2426-1a6l0sy/spec.rb:39: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.00685 seconds
4 examples, 4 failures

Failed examples:

rspec /tmp/d20141018-2426-1a6l0sy/spec.rb:2 # tic_tac_toe_board_from renders a blank board for an array with nils
rspec /tmp/d20141018-2426-1a6l0sy/spec.rb:14 # tic_tac_toe_board_from renders boards with x and o markers
rspec /tmp/d20141018-2426-1a6l0sy/spec.rb:26 # tic_tac_toe_board_from renders boards with all x-es
rspec /tmp/d20141018-2426-1a6l0sy/spec.rb:38 # tic_tac_toe_board_from renders boards with all o-s
Цветелина Борисова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Цветелина Борисова
TIC_TAC_TOE_TO_ASCII = { nil => " ", :x => 'x', :o => 'o' }
def render_tic_tac_toe_board_to_ascii(board)
result = ""
board.each_with_index do |field, index|
prefix = [0, 3, 6].include?(index) ? "" : " "
result += "#{prefix}| " + TIC_TAC_TOE_TO_ASCII[field]
result += " |\n" if [2, 5].include? index
result += " |" if index == 8
end
result
end
....

Finished in 0.00472 seconds
4 examples, 0 failures
Деян Гюрджеклиев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Деян Гюрджеклиев
def render_tic_tac_toe_board_to_ascii(board)
board.each_with_index.map do |x, i|
case i
when 2, 5 then ' | ' + get_string_representation(x) + " |\n"
when 0, 3, 6 then '| ' + get_string_representation(x)
else ' | ' + get_string_representation(x)
end
end.join + ' |'
end
def get_string_representation(symbol)
symbol ? symbol.to_s : " "
end
....

Finished in 0.00451 seconds
4 examples, 0 failures
Александър Петков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Петков
def render_tic_tac_toe_board_to_ascii(board)
ascii_mapping = {nil => "| ", :o => "| o ", :x => "| x ", :n => "|\n"}
board.insert(3, :n).insert(-4, :n)
board.map { |field| ascii_mapping[field] }.inject{ |x, y| x + y } + "|"
end
....

Finished in 0.00451 seconds
4 examples, 0 failures
Методи Димитров
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Методи Димитров
def render_tic_tac_toe_board_to_ascii(gameboard_array)
gameboard_string = gameboard_array.map.with_index do |field, index|
"|\s#{ field or ' ' }\s#{ "|\n" if index % 3 == 2 }"
end
gameboard_string.reduce(:+)
end
FFFF

Failures:

  1) tic_tac_toe_board_from renders a blank board for an array with nils
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "|   |   |   |\n|   |   |   |\n|   |   |   |"
            got: "|   |   |   |\n|   |   |   |\n|   |   |   |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-ve8ksa/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) tic_tac_toe_board_from renders boards with x and o markers
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x |   |   |\n| o | x |   |\n| x | o | o |"
            got: "| x |   |   |\n| o | x |   |\n| x | o | o |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-ve8ksa/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)>'

  3) tic_tac_toe_board_from renders boards with all x-es
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x | x | x |\n| x | x | x |\n| x | x | x |"
            got: "| x | x | x |\n| x | x | x |\n| x | x | x |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-ve8ksa/spec.rb:27: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) tic_tac_toe_board_from renders boards with all o-s
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| o | o | o |\n| o | o | o |\n| o | o | o |"
            got: "| o | o | o |\n| o | o | o |\n| o | o | o |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-ve8ksa/spec.rb:39: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.00558 seconds
4 examples, 4 failures

Failed examples:

rspec /tmp/d20141018-2426-ve8ksa/spec.rb:2 # tic_tac_toe_board_from renders a blank board for an array with nils
rspec /tmp/d20141018-2426-ve8ksa/spec.rb:14 # tic_tac_toe_board_from renders boards with x and o markers
rspec /tmp/d20141018-2426-ve8ksa/spec.rb:26 # tic_tac_toe_board_from renders boards with all x-es
rspec /tmp/d20141018-2426-ve8ksa/spec.rb:38 # tic_tac_toe_board_from renders boards with all o-s
Велислав Симеонов
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Велислав Симеонов
def render_tic_tac_toe_board_to_ascii(board)
a1=board[0..2]
a2=board[3..5]
a3=board[6..8]
board_to_text="|"
a1.each { |x| board_to_text += " #{x} |"}
board_to_text+="\n|"
a2.each { |x| board_to_text += " #{x} |"}
board_to_text+="\n|"
a3.each { |x| board_to_text += " #{x} |"}
end
FFFF

Failures:

  1) tic_tac_toe_board_from renders a blank board for an array with nils
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "|   |   |   |\n|   |   |   |\n|   |   |   |"
            got: [nil, nil, nil]
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,2 @@
       -|   |   |   |
       -|   |   |   |
       -|   |   |   |
       +[nil, nil, nil]
     # /tmp/d20141018-2426-oyq9xc/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) tic_tac_toe_board_from renders boards with x and o markers
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x |   |   |\n| o | x |   |\n| x | o | o |"
            got: [:x, :o, :o]
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,2 @@
       -| x |   |   |
       -| o | x |   |
       -| x | o | o |
       +[:x, :o, :o]
     # /tmp/d20141018-2426-oyq9xc/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)>'

  3) tic_tac_toe_board_from renders boards with all x-es
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x | x | x |\n| x | x | x |\n| x | x | x |"
            got: [:x, :x, :x]
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,2 @@
       -| x | x | x |
       -| x | x | x |
       -| x | x | x |
       +[:x, :x, :x]
     # /tmp/d20141018-2426-oyq9xc/spec.rb:27: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) tic_tac_toe_board_from renders boards with all o-s
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| o | o | o |\n| o | o | o |\n| o | o | o |"
            got: [:o, :o, :o]
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,2 @@
       -| o | o | o |
       -| o | o | o |
       -| o | o | o |
       +[:o, :o, :o]
     # /tmp/d20141018-2426-oyq9xc/spec.rb:39: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.00809 seconds
4 examples, 4 failures

Failed examples:

rspec /tmp/d20141018-2426-oyq9xc/spec.rb:2 # tic_tac_toe_board_from renders a blank board for an array with nils
rspec /tmp/d20141018-2426-oyq9xc/spec.rb:14 # tic_tac_toe_board_from renders boards with x and o markers
rspec /tmp/d20141018-2426-oyq9xc/spec.rb:26 # tic_tac_toe_board_from renders boards with all x-es
rspec /tmp/d20141018-2426-oyq9xc/spec.rb:38 # tic_tac_toe_board_from renders boards with all o-s
Бетина Иванова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Бетина Иванова
def render_tic_tac_toe_board_to_ascii(board)
new_board = board.map { |element|
element == nil ? element.to_s + " " : " " + element.to_s + " " }
manipulate_board(new_board)
end
def add_newline_character(new_board)
new_board[2] = new_board[2] + "|\n"
new_board[5] = new_board[5] + "|\n"
end
def manipulate_board(new_board)
new_board[8] = new_board[8] + "|"
add_newline_character(new_board)
new_board.unshift("")
new_board.join("|")
end
....

Finished in 0.00463 seconds
4 examples, 0 failures
Симеон Мартев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Симеон Мартев
def render_tic_tac_toe_board_to_ascii(board)
board.map!{ |item| item.nil? ? ' ' : " #{item} " }
board.each_slice(3).map{ |triad| "|#{triad.join('|')}|"}.join("\n")
end
....

Finished in 0.0046 seconds
4 examples, 0 failures
Яни Малцев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Яни Малцев
def render_tic_tac_toe_board_to_ascii(board)
board.collect{ |x| x == nil ? x=" " : x.to_s }
.join(" | ")
.insert(0, " ").scan(/.{1,12}/).join("\n|")
.insert(0, "|")
.insert(-1, " |")
end
....

Finished in 0.00464 seconds
4 examples, 0 failures
Йоана Тодорова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Йоана Тодорова
def ascii
{
nil => ' ',
:x => 'x',
:o => 'o'
}
end
def to_board_row(row)
row.map{ |symbol| "| #{ascii[symbol]} |" }.join.squeeze('|')
end
def render_tic_tac_toe_board_to_ascii(board)
board.each_slice(3).map { |row| to_board_row(row) }.join("\n")
end
....

Finished in 0.00488 seconds
4 examples, 0 failures
Бисер Кръстев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Бисер Кръстев
def symbol_to_char(s)
if s==:x then return 'x' end
if s==:o then return 'o' end
return ' '
end
def render_tic_tac_toe_board_to_ascii(board)
str = "|";
board.each_with_index do |s, i|
str += " #{symbol_to_char(s)} |"
if (i+1)%3 == 0 and (i+1) < 8 then
str += "\n|"
end
end
return str;
end
....

Finished in 0.00517 seconds
4 examples, 0 failures
Петър Гетов
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Петър Гетов
def render_tic_tac_toe_board_to_ascii(board)
stringBoard = ""
board.each_with_index do |cell, index|
cell = " " if cell == nil
stringBoard << "| #{cell} "
if (index + 1) % 3 == 0
stringBoard << "|\n"
end
end
stringBoard
end
FFFF

Failures:

  1) tic_tac_toe_board_from renders a blank board for an array with nils
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "|   |   |   |\n|   |   |   |\n|   |   |   |"
            got: "|   |   |   |\n|   |   |   |\n|   |   |   |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-10lpeim/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) tic_tac_toe_board_from renders boards with x and o markers
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x |   |   |\n| o | x |   |\n| x | o | o |"
            got: "| x |   |   |\n| o | x |   |\n| x | o | o |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-10lpeim/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)>'

  3) tic_tac_toe_board_from renders boards with all x-es
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x | x | x |\n| x | x | x |\n| x | x | x |"
            got: "| x | x | x |\n| x | x | x |\n| x | x | x |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-10lpeim/spec.rb:27: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) tic_tac_toe_board_from renders boards with all o-s
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| o | o | o |\n| o | o | o |\n| o | o | o |"
            got: "| o | o | o |\n| o | o | o |\n| o | o | o |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-10lpeim/spec.rb:39: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.00601 seconds
4 examples, 4 failures

Failed examples:

rspec /tmp/d20141018-2426-10lpeim/spec.rb:2 # tic_tac_toe_board_from renders a blank board for an array with nils
rspec /tmp/d20141018-2426-10lpeim/spec.rb:14 # tic_tac_toe_board_from renders boards with x and o markers
rspec /tmp/d20141018-2426-10lpeim/spec.rb:26 # tic_tac_toe_board_from renders boards with all x-es
rspec /tmp/d20141018-2426-10lpeim/spec.rb:38 # tic_tac_toe_board_from renders boards with all o-s
Елена Орешарова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Елена Орешарова
def render_tic_tac_toe_board_to_ascii(board)
result = ""
board.map.with_index do |x, i|
if x == nil
result << "| "
else
result << "| " + x.to_s + " "
end
if i == 2 or i == 5
result << "|" + "\n"
elsif i == 8
result << "|"
end
end
result
end
....

Finished in 0.00453 seconds
4 examples, 0 failures
Божидар Горов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Божидар Горов
def render_tic_tac_toe_board_to_ascii(board)
board.each_slice(3).to_a.map { |elem| row_to_string(elem) }.join("\n")
end
def row_to_string(row)
"|" + row.map {|elem| " " + (elem ? elem.to_s : " ") + " "}.join("|") + "|"
end
....

Finished in 0.0047 seconds
4 examples, 0 failures
Симеон Цветков
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Симеон Цветков
def render_tic_tac_toe(array)
string = ""
i = 0
array.each do |n|
if n == nil
string.concat("| |")
elsif n == :o
string.concat("| o |")
elsif n == :x
string.concat("| x |")
end
if i == 2 or i == 5
string.concat("\n")
end
i = i + 1
end
return string
end
FFFF

Failures:

  1) tic_tac_toe_board_from renders a blank board for an array with nils
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
     NoMethodError:
       undefined method `render_tic_tac_toe_board_to_ascii' for #<RSpec::Core::ExampleGroup::Nested_1:0xb87184d8>
     # /tmp/d20141018-2426-1kjyzkq/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) tic_tac_toe_board_from renders boards with x and o markers
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
     NoMethodError:
       undefined method `render_tic_tac_toe_board_to_ascii' for #<RSpec::Core::ExampleGroup::Nested_1:0xb8712ce0>
     # /tmp/d20141018-2426-1kjyzkq/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)>'

  3) tic_tac_toe_board_from renders boards with all x-es
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
     NoMethodError:
       undefined method `render_tic_tac_toe_board_to_ascii' for #<RSpec::Core::ExampleGroup::Nested_1:0xb8710724>
     # /tmp/d20141018-2426-1kjyzkq/spec.rb:27: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) tic_tac_toe_board_from renders boards with all o-s
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
     NoMethodError:
       undefined method `render_tic_tac_toe_board_to_ascii' for #<RSpec::Core::ExampleGroup::Nested_1:0xb870c778>
     # /tmp/d20141018-2426-1kjyzkq/spec.rb:39: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.00344 seconds
4 examples, 4 failures

Failed examples:

rspec /tmp/d20141018-2426-1kjyzkq/spec.rb:2 # tic_tac_toe_board_from renders a blank board for an array with nils
rspec /tmp/d20141018-2426-1kjyzkq/spec.rb:14 # tic_tac_toe_board_from renders boards with x and o markers
rspec /tmp/d20141018-2426-1kjyzkq/spec.rb:26 # tic_tac_toe_board_from renders boards with all x-es
rspec /tmp/d20141018-2426-1kjyzkq/spec.rb:38 # tic_tac_toe_board_from renders boards with all o-s
Стилиян Стоянов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Стилиян Стоянов
def render_tic_tac_toe_board_to_ascii(board)
nil_to_blanc(board)
rendered_board = render_tic_tac_toe_board_row(board[0..2]) + "\n" + render_tic_tac_toe_board_row(board[3..5]) + "\n" + render_tic_tac_toe_board_row(board[6..8]);
end
def render_tic_tac_toe_board_row(row)
row_to_string ="| " + row.join(" | ") + " |"
end
def nil_to_blanc(board)
board.each_index do |i|
board[i] = " " if board[i].nil?
end
end
....

Finished in 0.00491 seconds
4 examples, 0 failures
Георги Кожухаров
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Георги Кожухаров
def stringer(val,index)
if index%3 === 0 and index > 0
"\n" << "| #{val.to_s} |"
else
"| #{val.to_s} |"
end
end
def render_tic_tac_toe_board_to_ascii(board)
result_string = ""
board.each_with_index { |val,index| result_string << stringer(val,index) }
result_string
end
FFFF

Failures:

  1) tic_tac_toe_board_from renders a blank board for an array with nils
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "|   |   |   |\n|   |   |   |\n|   |   |   |"
            got: "|  ||  ||  |\n|  ||  ||  |\n|  ||  ||  |"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -|   |   |   |
       -|   |   |   |
       -|   |   |   |
       +|  ||  ||  |
       +|  ||  ||  |
       +|  ||  ||  |
     # /tmp/d20141018-2426-1jcv080/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) tic_tac_toe_board_from renders boards with x and o markers
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x |   |   |\n| o | x |   |\n| x | o | o |"
            got: "| x ||  ||  |\n| o || x ||  |\n| x || o || o |"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| x |   |   |
       -| o | x |   |
       -| x | o | o |
       +| x ||  ||  |
       +| o || x ||  |
       +| x || o || o |
     # /tmp/d20141018-2426-1jcv080/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)>'

  3) tic_tac_toe_board_from renders boards with all x-es
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x | x | x |\n| x | x | x |\n| x | x | x |"
            got: "| x || x || x |\n| x || x || x |\n| x || x || x |"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| x | x | x |
       -| x | x | x |
       -| x | x | x |
       +| x || x || x |
       +| x || x || x |
       +| x || x || x |
     # /tmp/d20141018-2426-1jcv080/spec.rb:27: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) tic_tac_toe_board_from renders boards with all o-s
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| o | o | o |\n| o | o | o |\n| o | o | o |"
            got: "| o || o || o |\n| o || o || o |\n| o || o || o |"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| o | o | o |
       -| o | o | o |
       -| o | o | o |
       +| o || o || o |
       +| o || o || o |
       +| o || o || o |
     # /tmp/d20141018-2426-1jcv080/spec.rb:39: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.00801 seconds
4 examples, 4 failures

Failed examples:

rspec /tmp/d20141018-2426-1jcv080/spec.rb:2 # tic_tac_toe_board_from renders a blank board for an array with nils
rspec /tmp/d20141018-2426-1jcv080/spec.rb:14 # tic_tac_toe_board_from renders boards with x and o markers
rspec /tmp/d20141018-2426-1jcv080/spec.rb:26 # tic_tac_toe_board_from renders boards with all x-es
rspec /tmp/d20141018-2426-1jcv080/spec.rb:38 # tic_tac_toe_board_from renders boards with all o-s
Димитър Шукерски
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Димитър Шукерски
def render_tic_tac_toe_board_to_ascii(board)
my_string = '| ' + board[0].to_s + ' |' +
'| ' + board[1].to_s + ' |' +
'| ' + board[2].to_s + " |\n" +
'| ' + board[3].to_s + ' |' +
'| ' + board[4].to_s + ' |' +
'| ' + board[5].to_s + " |\n" +
'| ' + board[6].to_s + ' |' +
'| ' + board[7].to_s + ' |' +
'| ' + board[8].to_s + ' |'
return my_string
end
FFFF

Failures:

  1) tic_tac_toe_board_from renders a blank board for an array with nils
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "|   |   |   |\n|   |   |   |\n|   |   |   |"
            got: "|  ||  ||  |\n|  ||  ||  |\n|  ||  ||  |"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -|   |   |   |
       -|   |   |   |
       -|   |   |   |
       +|  ||  ||  |
       +|  ||  ||  |
       +|  ||  ||  |
     # /tmp/d20141018-2426-16tcdg7/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) tic_tac_toe_board_from renders boards with x and o markers
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x |   |   |\n| o | x |   |\n| x | o | o |"
            got: "| x ||  ||  |\n| o || x ||  |\n| x || o || o |"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| x |   |   |
       -| o | x |   |
       -| x | o | o |
       +| x ||  ||  |
       +| o || x ||  |
       +| x || o || o |
     # /tmp/d20141018-2426-16tcdg7/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)>'

  3) tic_tac_toe_board_from renders boards with all x-es
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x | x | x |\n| x | x | x |\n| x | x | x |"
            got: "| x || x || x |\n| x || x || x |\n| x || x || x |"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| x | x | x |
       -| x | x | x |
       -| x | x | x |
       +| x || x || x |
       +| x || x || x |
       +| x || x || x |
     # /tmp/d20141018-2426-16tcdg7/spec.rb:27: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) tic_tac_toe_board_from renders boards with all o-s
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| o | o | o |\n| o | o | o |\n| o | o | o |"
            got: "| o || o || o |\n| o || o || o |\n| o || o || o |"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -| o | o | o |
       -| o | o | o |
       -| o | o | o |
       +| o || o || o |
       +| o || o || o |
       +| o || o || o |
     # /tmp/d20141018-2426-16tcdg7/spec.rb:39: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.00664 seconds
4 examples, 4 failures

Failed examples:

rspec /tmp/d20141018-2426-16tcdg7/spec.rb:2 # tic_tac_toe_board_from renders a blank board for an array with nils
rspec /tmp/d20141018-2426-16tcdg7/spec.rb:14 # tic_tac_toe_board_from renders boards with x and o markers
rspec /tmp/d20141018-2426-16tcdg7/spec.rb:26 # tic_tac_toe_board_from renders boards with all x-es
rspec /tmp/d20141018-2426-16tcdg7/spec.rb:38 # tic_tac_toe_board_from renders boards with all o-s
София Петрова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
София Петрова
def render_tic_tac_toe_board_to_ascii(board)
board.map!{|x|x ?x:" "}
board_to_s = board.map { |char| char.to_s }
new_board_collected = board_to_s.collect { |char| " " + char + " " }
final_board = new_board_collected.unshift("|").insert(2,"|").insert(4,"|").insert(6,"|\n").insert(7,"|").insert(9,"|").insert(11, "|").insert(13,"|\n").insert(14, "|").insert(16,"|").insert(18,"|").insert(20,"|")
final_board.join
end
....

Finished in 0.00566 seconds
4 examples, 0 failures
Антон Димов
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Антон Димов
def render_tic_tac_toe_board_to_ascii(board)
convert(board)
i = 0
while(i<board.size)
if((i % 3)==0)
result="\n"
end
result="| #{board[i]} |"
i = i+1
end
end
def convert(board)
i = 0
while i<board.size
i = i+1
if(board[i]==nil.to_s)
board.delete_at(board[i])
board.insert(board[i]," ")
elsif (board[i]==:x.to_s)
board.delete_at(board[i])
board.insert(board[i],"x")
elsif(board[i]==:o.to_s)
board.delete_at(board[i])
board.insert(board[i],"o")
end
end
end
FFFF

Failures:

  1) tic_tac_toe_board_from renders a blank board for an array with nils
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "|   |   |   |\n|   |   |   |\n|   |   |   |"
            got: nil
       
       (compared using ==)
     # /tmp/d20141018-2426-gfii6v/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) tic_tac_toe_board_from renders boards with x and o markers
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x |   |   |\n| o | x |   |\n| x | o | o |"
            got: nil
       
       (compared using ==)
     # /tmp/d20141018-2426-gfii6v/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)>'

  3) tic_tac_toe_board_from renders boards with all x-es
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x | x | x |\n| x | x | x |\n| x | x | x |"
            got: nil
       
       (compared using ==)
     # /tmp/d20141018-2426-gfii6v/spec.rb:27: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) tic_tac_toe_board_from renders boards with all o-s
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| o | o | o |\n| o | o | o |\n| o | o | o |"
            got: nil
       
       (compared using ==)
     # /tmp/d20141018-2426-gfii6v/spec.rb:39: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.00485 seconds
4 examples, 4 failures

Failed examples:

rspec /tmp/d20141018-2426-gfii6v/spec.rb:2 # tic_tac_toe_board_from renders a blank board for an array with nils
rspec /tmp/d20141018-2426-gfii6v/spec.rb:14 # tic_tac_toe_board_from renders boards with x and o markers
rspec /tmp/d20141018-2426-gfii6v/spec.rb:26 # tic_tac_toe_board_from renders boards with all x-es
rspec /tmp/d20141018-2426-gfii6v/spec.rb:38 # tic_tac_toe_board_from renders boards with all o-s
Георги Димов
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Георги Димов
def render_tic_tac_toe_board_to_ascii(board)
converted_board = add_new_rows_to_board(board)
converted_board = add_dividers_to_board(converted_board)
converted_board = convert_cells_to_string(converted_board)
convert_board_to_string(converted_board)
end
def add_dividers_to_board(board)
board.each_with_index do |element, index|
if index.even? == true
board.insert(index, "|")
end
end
end
def convert_cells_to_string(board)
board.each_with_index do |cell, index|
case cell
when nil then board[index] = " "
when :x then board[index] = " x "
when :o then board[index] = " o "
end
end
end
def convert_board_to_string(board)
converted_board = String.new
board.each_with_index do |element, index|
converted_board.concat(element)
end
converted_board
end
def add_new_rows_to_board(board)
counter = 0
board.each_with_index do |element, index|
if index % 3 == 0 and index != 0
board.insert(index + counter, "\n")
counter += 1
end
end
end
FFFF

Failures:

  1) tic_tac_toe_board_from renders a blank board for an array with nils
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "|   |   |   |\n|   |   |   |\n|   |   |   |"
            got: "|   |   |   |\n|   |   |   |\n|   |   |   |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-e70c5d/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) tic_tac_toe_board_from renders boards with x and o markers
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x |   |   |\n| o | x |   |\n| x | o | o |"
            got: "| x |   |   |\n| o | x |   |\n| x | o | o |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-e70c5d/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)>'

  3) tic_tac_toe_board_from renders boards with all x-es
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x | x | x |\n| x | x | x |\n| x | x | x |"
            got: "| x | x | x |\n| x | x | x |\n| x | x | x |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-e70c5d/spec.rb:27: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) tic_tac_toe_board_from renders boards with all o-s
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| o | o | o |\n| o | o | o |\n| o | o | o |"
            got: "| o | o | o |\n| o | o | o |\n| o | o | o |\n"
       
       (compared using ==)
       
       Diff:
     # /tmp/d20141018-2426-e70c5d/spec.rb:39: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.00578 seconds
4 examples, 4 failures

Failed examples:

rspec /tmp/d20141018-2426-e70c5d/spec.rb:2 # tic_tac_toe_board_from renders a blank board for an array with nils
rspec /tmp/d20141018-2426-e70c5d/spec.rb:14 # tic_tac_toe_board_from renders boards with x and o markers
rspec /tmp/d20141018-2426-e70c5d/spec.rb:26 # tic_tac_toe_board_from renders boards with all x-es
rspec /tmp/d20141018-2426-e70c5d/spec.rb:38 # tic_tac_toe_board_from renders boards with all o-s
Вера Бойчева
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Вера Бойчева
def helper(board)
board.each { |n|
if n==":x"
puts"|X"
elsif n==":o"
puts"|O"
else
puts"| "
end
}
end
def render_tic_tac_toe_board_to_ascii(board)
helper(board[0..2])
puts"|\n"
helper(board[3..5])
puts"|\n"
helper(board[6..8])
puts"|\n"
end
| 
| 
| 
|
| 
| 
| 
|
| 
| 
| 
|
F| 
| 
| 
|
| 
| 
| 
|
| 
| 
| 
|
F| 
| 
| 
|
| 
| 
| 
|
| 
| 
| 
|
F| 
| 
| 
|
| 
| 
| 
|
| 
| 
| 
|
F

Failures:

  1) tic_tac_toe_board_from renders a blank board for an array with nils
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "|   |   |   |\n|   |   |   |\n|   |   |   |"
            got: nil
       
       (compared using ==)
     # /tmp/d20141018-2426-ttaln5/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) tic_tac_toe_board_from renders boards with x and o markers
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x |   |   |\n| o | x |   |\n| x | o | o |"
            got: nil
       
       (compared using ==)
     # /tmp/d20141018-2426-ttaln5/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)>'

  3) tic_tac_toe_board_from renders boards with all x-es
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| x | x | x |\n| x | x | x |\n| x | x | x |"
            got: nil
       
       (compared using ==)
     # /tmp/d20141018-2426-ttaln5/spec.rb:27: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) tic_tac_toe_board_from renders boards with all o-s
     Failure/Error: expect(render_tic_tac_toe_board_to_ascii([
       
       expected: "| o | o | o |\n| o | o | o |\n| o | o | o |"
            got: nil
       
       (compared using ==)
     # /tmp/d20141018-2426-ttaln5/spec.rb:39: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.00554 seconds
4 examples, 4 failures

Failed examples:

rspec /tmp/d20141018-2426-ttaln5/spec.rb:2 # tic_tac_toe_board_from renders a blank board for an array with nils
rspec /tmp/d20141018-2426-ttaln5/spec.rb:14 # tic_tac_toe_board_from renders boards with x and o markers
rspec /tmp/d20141018-2426-ttaln5/spec.rb:26 # tic_tac_toe_board_from renders boards with all x-es
rspec /tmp/d20141018-2426-ttaln5/spec.rb:38 # tic_tac_toe_board_from renders boards with all o-s
Мая Терзиева
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Мая Терзиева
def render_tic_tac_toe_board_to_ascii(board)
board_to_ascii = ""
board.each_with_index do |mark, position|
board_to_ascii << "| %s " % (mark or " ").to_s if position % 3 != 2
board_to_ascii << "| %s |\n" % (mark or " ").to_s if position % 3 == 2
end
board_to_ascii.chomp
end
....

Finished in 0.00553 seconds
4 examples, 0 failures