Word wrap

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

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

Едно от нещата, които се използват навсякъде в софтуера, е разделянето на дълъг едноредов текст на множество редове. Виждате го във всеки сайт, в любимия си текстов редактор, IM и т.н. Разбира се, обикновено не ви се налага да си го пишете сами.

Проблемът е доста стар и доста труден, защото зависи от шрифта, големината на всяка от буквите, разстоянията между тях, символите, по които могат да се разделят редове, и езика на текста.

В това предизвикателство ще направите подобна функция. Целта е да упражните някои от методите на Enumerable, в комбинация с такива от String и с наученото за Ruby до момента.

След като пробвате да напишете един прост алгоритъм за word wrap, ще оцените какво правят програмите, които рендерират текст за нас и какво и получаваме наготово, приемайки го за даденост.

Условието

Добавете функция word_wrap към класа String (чрез monkey-patching). Като единствен аргумент на функцията се подава цяло число (по-голямо от нула), което задава максималния брой символи на един ред. Няма ограничение за броя редове, които могат да се получат. Възможно е някои от редовете да са по-къси от ограничението. Възможно е в резултата да има и редове, надвишаващи ограничението, ако в тях не е имало къде да се направи line break.

Резултатът от функцията трябва да е масив от низове, всеки елемент на който представлява отделен ред. Ако в текста няма символи, различни от празно място и нов ред, да се върне празен масив.

Разбира се, за опростение на задачата, ще наложим следните ограничения върху текста:

  • Текстът може да съдържа само букви (от всякакви азбуки, не само латиница), цифри, символите .,!?, празни места и нови редове.
  • В резултатния низ не трябва да има whitespace в началото или в края, както и всички последователности от един или повече whitespace символа трябва да бъдат заменени с един-единствен интервал. Функцията трябва да връща един и същ резултат за word wrap, и word \n wrap.
  • Разделяне на текста на два нови реда може да става само на места, където има поне един интервал или символ за нов ред.

Пример

"  \nHow much wood would\na woodchuck chuck if a woodchuck could chuck wood?\n   As much as a woodchuck would chuck if a woodchuck could chuck wood.\n\n ".word_wrap(20)`

Резултат:

[
  "How much wood would",
  "a woodchuck chuck if",
  "a woodchuck could",
  "chuck wood? As much",
  "as a woodchuck would",
  "chuck if a woodchuck",
  "could chuck wood."
]

Както и в предните предизвикателства - няма да получавате невалидни входни данни.

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

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

Решения

Георги Ангелов
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Ангелов
class String
def word_wrap(max_line_length)
split(' ').slice_before(current_line_length: -1) do |word, state|
state[:current_line_length] += word.length + 1
if state[:current_line_length] > max_line_length
state[:current_line_length] = word.length
true
else
false
end
end.map { |words| words.join(' ') }
end
end
...............

Finished in 0.01294 seconds
15 examples, 0 failures
Емилиан Станков
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Емилиан Станков
class String
def word_wrap(max_row_length)
words = self.split
return words if words == []
row = ""
result = []
words.each do |word|
if row.length < max_row_length - word.length + 1
row << word << " "
else
result << row.chop unless row == ""
row = word << " "
end
end
result << row.chop unless row == ""
result
end
end
...............

Finished in 0.0126 seconds
15 examples, 0 failures
Яни Малцев
  • Некоректно
  • 12 успешни тест(а)
  • 3 неуспешни тест(а)
Яни Малцев
class String
def word_wrap(length)
strip.gsub(/\s+/,' ').gsub("\n", "").scan(/\S.{1,#{length-1}}(?!\S)/)
end
end
...........F.FF

Failures:

  1) String#word_wrap keeps longer lines if it is a single word
     Failure/Error: expect("one more string".word_wrap(2)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["ne", "re", "ng"]
       
       (compared using ==)
     # /tmp/d20141030-18133-10w273/spec.rb:47: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) String#word_wrap splits text with hiragana letters correctly
     Failure/Error: expect("まつもとさんは Rubyのおとうさん. ".word_wrap(10)).to eq ['まつもとさんは', 'Rubyのおとうさん.']
       
       expected: ["まつもとさんは", "Rubyのおとうさん."]
            got: ["まつもとさんは", "ubyのおとうさん."]
       
       (compared using ==)
     # /tmp/d20141030-18133-10w273/spec.rb:55: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) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
       
       expected: ["justonelongline", "here"]
            got: ["gline", "here"]
       
       (compared using ==)
     # /tmp/d20141030-18133-10w273/spec.rb:59: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.01858 seconds
15 examples, 3 failures

Failed examples:

rspec /tmp/d20141030-18133-10w273/spec.rb:46 # String#word_wrap keeps longer lines if it is a single word
rspec /tmp/d20141030-18133-10w273/spec.rb:54 # String#word_wrap splits text with hiragana letters correctly
rspec /tmp/d20141030-18133-10w273/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line
Ангел Ангелов
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Ангел Ангелов
class String
def word_wrap(chars_per_row)
row = ''
wrapped = []
split.each do |word|
if (row + word).length + 1 > chars_per_row
wrapped << row unless row.empty?
row = word
else
row += ' ' unless row.empty?
row += word
end
end
wrapped << row unless row.empty?
wrapped
end
end
...............

Finished in 0.01615 seconds
15 examples, 0 failures
Димитър Мутаров
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Мутаров
class Object
def blank?
respond_to?(:empty?) ? empty? : !self
end
end
class String
def word_wrap width
if blank?
Array.new
else
gsub(/[\n]+|[\\\n]+/, ' ').gsub(/\s+/, ' ').strip.scan(/\S.{0,#{width-1}}(?=\s|$)|\S+/)
end
end
end
...............

Finished in 0.01709 seconds
15 examples, 0 failures
Мартин Христов
  • Некоректно
  • 12 успешни тест(а)
  • 3 неуспешни тест(а)
Мартин Христов
class String
def word_wrap line_length
words = self.split(' ')
counter = 0
final_string = ''
reminder = 0
words.each do |item|
counter+= item.length
if (counter <= line_length)
final_string+=item + ' '
counter+=1
else
reminder = counter - line_length
final_string+="\n" + item + ' '
counter = reminder + 1
end
end
final_string.split("\n").each do |item|
item.chop!
end
end
end
......F....F..F

Failures:

  1) String#word_wrap can split more than once
     Failure/Error: expect('point line parallelogram cube'.word_wrap(15)).to eq ['point line', 'parallelogram', 'cube']
       
       expected: ["point line", "parallelogram", "cube"]
            got: ["point line", "parallelogram cube"]
       
       (compared using ==)
     # /tmp/d20141030-18133-12b2mrv/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)>'

  2) String#word_wrap keeps longer lines if it is a single word
     Failure/Error: expect("one more string".word_wrap(2)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["", "one", "more", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-12b2mrv/spec.rb:47: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) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
       
       expected: ["justonelongline", "here"]
            got: ["", "justonelongline", "here"]
       
       (compared using ==)
     # /tmp/d20141030-18133-12b2mrv/spec.rb:59: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.01755 seconds
15 examples, 3 failures

Failed examples:

rspec /tmp/d20141030-18133-12b2mrv/spec.rb:26 # String#word_wrap can split more than once
rspec /tmp/d20141030-18133-12b2mrv/spec.rb:46 # String#word_wrap keeps longer lines if it is a single word
rspec /tmp/d20141030-18133-12b2mrv/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line
Ясен Трифонов
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Ясен Трифонов
class String
def word_wrap(max_line_size)
wrapped = []
line = ""
split(/\s+/).reject(&:empty?).each do |word|
if line.empty? then line = word
elsif line.size + word.size + 1 <= max_line_size then line = line + " " + word
else
wrapped << line
line = word
end
end
wrapped << line unless line.empty?
wrapped
end
end
...............

Finished in 0.01243 seconds
15 examples, 0 failures
Александър Александров
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Александров
class String
def word_wrap (width)
new_str = String.new(self)
arr = []
line = ""
return arr if new_str.size == 0
new_str=new_str.gsub("\n", ' ').squeeze(' ')
return arr if new_str == ' '
new_str.split(/\s+/).each do |word|
if line.size + word.size >= width
arr << line if line.size != 0
line = word
elsif line.empty?
line = word
else
line << " " << word
end
end
arr << line if line
end
end
...............

Finished in 0.01478 seconds
15 examples, 0 failures
Герасим Станчев
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Герасим Станчев
class String
def word_wrap(max_size)
wrapped = strip.gsub(/\s{2,}/, ' ').split(/\s/)
i, j = wrapped.size, 0
while j < i
if wrapped[j].length < max_size and not wrapped[j + 1].nil? and
(wrapped[j] + ' ' + wrapped[j + 1]).length <= max_size
wrapped[j] += ' ' + wrapped[j + 1]
wrapped.delete_at(j + 1)
else
j += 1
i = wrapped.size
end
end
wrapped
end
end
...............

Finished in 0.01623 seconds
15 examples, 0 failures
Веселин Добрев
  • Некоректно
  • 13 успешни тест(а)
  • 2 неуспешни тест(а)
Веселин Добрев
class String
def word_wrap(max_width)
scan(/\S.{0,#{max_width - 2}}\S(?=\s|$)|\S+/)
end
end
..........F.F..

Failures:

  1) String#word_wrap compacts whitespace inside lines
     Failure/Error: expect("one   more        string".word_wrap(12)).to eq ['one more', 'string']
       
       expected: ["one more", "string"]
            got: ["one   more", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1ibpedt/spec.rb:43: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) String#word_wrap splits text with cyrillic correctly
     Failure/Error: expect("  Мерси   за търпението   и\nура за живота! ".word_wrap(20)).to eq ['Мерси за търпението', 'и ура за живота!']
       
       expected: ["Мерси за търпението", "и ура за живота!"]
            got: ["Мерси   за", "търпението   и", "ура за живота!"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1ibpedt/spec.rb:51: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.01498 seconds
15 examples, 2 failures

Failed examples:

rspec /tmp/d20141030-18133-1ibpedt/spec.rb:42 # String#word_wrap compacts whitespace inside lines
rspec /tmp/d20141030-18133-1ibpedt/spec.rb:50 # String#word_wrap splits text with cyrillic correctly
Георги Костов
  • Некоректно
  • 9 успешни тест(а)
  • 6 неуспешни тест(а)
Георги Костов
class String
def word_wrap(integer)
result = []
word_split = strip.gsub(/\s+/, " ").gsub("\n", "").split
row = ""
word_split.each do |word|
if word.length + row.length <= integer - 1
row = row.strip + " " + word.strip
else
result << row
row = ""
row = row + word
end
end
result << row
result.select { |element| element != "" }
end
end
....FF.FFF...F.

Failures:

  1) String#word_wrap can split words given more length
     Failure/Error: expect('one two'.word_wrap(6)).to eq ['one', 'two']
       
       expected: ["one", "two"]
            got: [" one", "two"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1u73ebs/spec.rb:19: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) String#word_wrap splits on the nearest left whitespace
     Failure/Error: expect('point one two'.word_wrap(8)).to eq ['point', 'one two']
       
       expected: ["point", "one two"]
            got: [" point", "one two"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1u73ebs/spec.rb:23: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) String#word_wrap is not influenced by leading whitespace
     Failure/Error: expect("  \n one\nmore string".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: [" one", "more", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1u73ebs/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)>'

  4) String#word_wrap is not influenced by trailing whitespace
     Failure/Error: expect("one more string \n   ".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: [" one", "more", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1u73ebs/spec.rb:35: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)>'

  5) String#word_wrap ignores more than one whitespace between lines
     Failure/Error: expect("one    more   \n        string".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: [" one", "more", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1u73ebs/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)>'

  6) String#word_wrap splits text with hiragana letters correctly
     Failure/Error: expect("まつもとさんは Rubyのおとうさん. ".word_wrap(10)).to eq ['まつもとさんは', 'Rubyのおとうさん.']
       
       expected: ["まつもとさんは", "Rubyのおとうさん."]
            got: [" まつもとさんは", "Rubyのおとうさん."]
       
       (compared using ==)
     # /tmp/d20141030-18133-1u73ebs/spec.rb:55: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.01729 seconds
15 examples, 6 failures

Failed examples:

rspec /tmp/d20141030-18133-1u73ebs/spec.rb:18 # String#word_wrap can split words given more length
rspec /tmp/d20141030-18133-1u73ebs/spec.rb:22 # String#word_wrap splits on the nearest left whitespace
rspec /tmp/d20141030-18133-1u73ebs/spec.rb:30 # String#word_wrap is not influenced by leading whitespace
rspec /tmp/d20141030-18133-1u73ebs/spec.rb:34 # String#word_wrap is not influenced by trailing whitespace
rspec /tmp/d20141030-18133-1u73ebs/spec.rb:38 # String#word_wrap ignores more than one whitespace between lines
rspec /tmp/d20141030-18133-1u73ebs/spec.rb:54 # String#word_wrap splits text with hiragana letters correctly
Йоан Динков
  • Некоректно
  • 13 успешни тест(а)
  • 2 неуспешни тест(а)
Йоан Динков
class String
def word_wrap(line_size)
words = self.strip.squeeze(' ').split(' ')
result, line = [], ''
words.each do |word|
if ((line.length + word.strip.length) <= line_size)
line << word << ' '
else
result << line.strip
line = '' << word << ' '
end
end
if (line.empty?)
result
else
result << line.strip
end
end
end
...........F..F

Failures:

  1) String#word_wrap keeps longer lines if it is a single word
     Failure/Error: expect("one more string".word_wrap(2)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["", "one", "more", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-d2tqmp/spec.rb:47: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) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
       
       expected: ["justonelongline", "here"]
            got: ["", "justonelongline", "here"]
       
       (compared using ==)
     # /tmp/d20141030-18133-d2tqmp/spec.rb:59: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.01288 seconds
15 examples, 2 failures

Failed examples:

rspec /tmp/d20141030-18133-d2tqmp/spec.rb:46 # String#word_wrap keeps longer lines if it is a single word
rspec /tmp/d20141030-18133-d2tqmp/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line
Екатерина Горанова
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Екатерина Горанова
class String
def word_wrap(max_per_row)
gsub(/\s+/,' ').split(' ').inject([]) do |output, word|
if output.last and "#{output.last} #{word}".length <= max_per_row
output << "#{output.pop} #{word}"
else
output << word
end
end
end
end
...............

Finished in 0.01294 seconds
15 examples, 0 failures
Дамян Димитров
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Дамян Димитров
class String
def word_wrap(max_rows_per_line)
return [] unless include? ' ' or include? "\n"
scan_regexp = /\p{Word}+[\,\.\!\?]*|[\,\.\!\?]+/
words = gsub("\n", ' ').strip.squeeze(' ').scan(scan_regexp)
result = ['']
words.each do |word|
if result.last.length + ' '.length + word.length > max_rows_per_line
result << word
else
result[result.size - 1] += " #{word}"
end
end
result.map(&:lstrip).select { |line| line != '' }
end
end
...............

Finished in 0.01366 seconds
15 examples, 0 failures
Калин Христов
  • Некоректно
  • 14 успешни тест(а)
  • 1 неуспешни тест(а)
Калин Христов
class String
def word_wrap(width)
text = gsub(/\s+/, " ")
text.insert(-1, " ")
paragraph = []
if text.strip.length != 0
i = 0
while i < text.length
j = i + width
j -= 1 until text[j] == " " or j == i
if j == i
j = i + width
j += 1 while text[j] != " "
end
paragraph << text[i ... j].strip
i = j + 1
end
end
return paragraph
end
end
.............F.

Failures:

  1) String#word_wrap splits text with hiragana letters correctly
     Failure/Error: expect("まつもとさんは Rubyのおとうさん. ".word_wrap(10)).to eq ['まつもとさんは', 'Rubyのおとうさん.']
     Timeout::Error:
       execution expired
     # /tmp/d20141030-18133-n0aycz/solution.rb:13:in `word_wrap'
     # /tmp/d20141030-18133-n0aycz/spec.rb:55: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 1.11 seconds
15 examples, 1 failure

Failed examples:

rspec /tmp/d20141030-18133-n0aycz/spec.rb:54 # String#word_wrap splits text with hiragana letters correctly
Камен Станев
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Камен Станев
class String
def word_wrap(line_length)
self.gsub(/\s+/, ' ').strip.split.slice_before(length: 0) do |word, state|
if state[:length] + 1 + word.size > line_length
state[:length] = word.size
true
else
state[:length] += 1 + word.size
false
end
end.map { |x| x.join ' ' }
end
end
...............

Finished in 0.0133 seconds
15 examples, 0 failures
Николина Гюрова
  • Некоректно
  • 14 успешни тест(а)
  • 1 неуспешни тест(а)
Николина Гюрова
class String
def word_wrap(line_width)
source = self.dup.strip.squeeze(" ").squeeze("\r\n")
end_of_line, space_or_end_of_line = /[\r\n]+/x, /\s|[\r\n]+/x
result = []
while source.length > line_width
last_space = source.rindex(space_or_end_of_line, line_width) ||
source.index(space_or_end_of_line) ||
source.length
line = source[0...last_space].strip.gsub(end_of_line, '')
result.push(line) if line != ""
source = source[last_space...source.length].strip
end
line = source.strip.gsub(end_of_line, '')
result.push(line) if line != ""
result
end
end
............F..

Failures:

  1) String#word_wrap splits text with cyrillic correctly
     Failure/Error: expect("  Мерси   за търпението   и\nура за живота! ".word_wrap(20)).to eq ['Мерси за търпението', 'и ура за живота!']
       
       expected: ["Мерси за търпението", "и ура за живота!"]
            got: ["Мерси за търпението", "иура за живота!"]
       
       (compared using ==)
     # /tmp/d20141030-18133-rcsq30/spec.rb:51: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.01367 seconds
15 examples, 1 failure

Failed examples:

rspec /tmp/d20141030-18133-rcsq30/spec.rb:50 # String#word_wrap splits text with cyrillic correctly
Теодор Драганов
  • Некоректно
  • 4 успешни тест(а)
  • 11 неуспешни тест(а)
Теодор Драганов
class String
def word_wrap(width)
self.gsub("\n", " ")
.squeeze(" ")
.strip.+(" ")
.scan(/.{#{width},}? /)
.collect {|line| line.strip}
end
end
...FFFFFFFF.FFF

Failures:

  1) String#word_wrap correctly counts the whitespace between words
     Failure/Error: expect('one word n two words'.word_wrap(9)).to eq ['one word', 'n two', 'words']
       
       expected: ["one word", "n two", "words"]
            got: ["one word n", "two words"]
       
       (compared using ==)
     # /tmp/d20141030-18133-96yial/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)>'

  2) String#word_wrap can split words given more length
     Failure/Error: expect('one two'.word_wrap(6)).to eq ['one', 'two']
       
       expected: ["one", "two"]
            got: ["one two"]
       
       (compared using ==)
     # /tmp/d20141030-18133-96yial/spec.rb:19: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) String#word_wrap splits on the nearest left whitespace
     Failure/Error: expect('point one two'.word_wrap(8)).to eq ['point', 'one two']
       
       expected: ["point", "one two"]
            got: ["point one"]
       
       (compared using ==)
     # /tmp/d20141030-18133-96yial/spec.rb:23: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) String#word_wrap can split more than once
     Failure/Error: expect('point line parallelogram cube'.word_wrap(15)).to eq ['point line', 'parallelogram', 'cube']
       
       expected: ["point line", "parallelogram", "cube"]
            got: ["point line parallelogram"]
       
       (compared using ==)
     # /tmp/d20141030-18133-96yial/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)>'

  5) String#word_wrap is not influenced by leading whitespace
     Failure/Error: expect("  \n one\nmore string".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["one more"]
       
       (compared using ==)
     # /tmp/d20141030-18133-96yial/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)>'

  6) String#word_wrap is not influenced by trailing whitespace
     Failure/Error: expect("one more string \n   ".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["one more"]
       
       (compared using ==)
     # /tmp/d20141030-18133-96yial/spec.rb:35: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)>'

  7) String#word_wrap ignores more than one whitespace between lines
     Failure/Error: expect("one    more   \n        string".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["one more"]
       
       (compared using ==)
     # /tmp/d20141030-18133-96yial/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)>'

  8) String#word_wrap compacts whitespace inside lines
     Failure/Error: expect("one   more        string".word_wrap(12)).to eq ['one more', 'string']
       
       expected: ["one more", "string"]
            got: ["one more string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-96yial/spec.rb:43: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)>'

  9) String#word_wrap splits text with cyrillic correctly
     Failure/Error: expect("  Мерси   за търпението   и\nура за живота! ".word_wrap(20)).to eq ['Мерси за търпението', 'и ура за живота!']
       
       expected: ["Мерси за търпението", "и ура за живота!"]
            got: ["Мерси за търпението и"]
       
       (compared using ==)
     # /tmp/d20141030-18133-96yial/spec.rb:51: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)>'

  10) String#word_wrap splits text with hiragana letters correctly
     Failure/Error: expect("まつもとさんは Rubyのおとうさん. ".word_wrap(10)).to eq ['まつもとさんは', 'Rubyのおとうさん.']
       
       expected: ["まつもとさんは", "Rubyのおとうさん."]
            got: ["まつもとさんは Rubyのおとうさん."]
       
       (compared using ==)
     # /tmp/d20141030-18133-96yial/spec.rb:55: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)>'

  11) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
       
       expected: ["justonelongline", "here"]
            got: ["justonelongline"]
       
       (compared using ==)
     # /tmp/d20141030-18133-96yial/spec.rb:59: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.01954 seconds
15 examples, 11 failures

Failed examples:

rspec /tmp/d20141030-18133-96yial/spec.rb:14 # String#word_wrap correctly counts the whitespace between words
rspec /tmp/d20141030-18133-96yial/spec.rb:18 # String#word_wrap can split words given more length
rspec /tmp/d20141030-18133-96yial/spec.rb:22 # String#word_wrap splits on the nearest left whitespace
rspec /tmp/d20141030-18133-96yial/spec.rb:26 # String#word_wrap can split more than once
rspec /tmp/d20141030-18133-96yial/spec.rb:30 # String#word_wrap is not influenced by leading whitespace
rspec /tmp/d20141030-18133-96yial/spec.rb:34 # String#word_wrap is not influenced by trailing whitespace
rspec /tmp/d20141030-18133-96yial/spec.rb:38 # String#word_wrap ignores more than one whitespace between lines
rspec /tmp/d20141030-18133-96yial/spec.rb:42 # String#word_wrap compacts whitespace inside lines
rspec /tmp/d20141030-18133-96yial/spec.rb:50 # String#word_wrap splits text with cyrillic correctly
rspec /tmp/d20141030-18133-96yial/spec.rb:54 # String#word_wrap splits text with hiragana letters correctly
rspec /tmp/d20141030-18133-96yial/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line
Бисер Кръстев
  • Некоректно
  • 13 успешни тест(а)
  • 2 неуспешни тест(а)
Бисер Кръстев
class String
def word_wrap(line_length)
return Array.new if strip == ''
array = strip.squeeze("\s").split
result = [""]
length = 0
array.each do |word|
if length + word.length <= line_length
length += word.length + 1
result[-1] += "#{word} "
else
result[-1].strip!
length = word.length + 1
result << "#{word} "
end
end
result[-1].strip!
result
end
end
...........F..F

Failures:

  1) String#word_wrap keeps longer lines if it is a single word
     Failure/Error: expect("one more string".word_wrap(2)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["", "one", "more", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-aocvzd/spec.rb:47: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) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
       
       expected: ["justonelongline", "here"]
            got: ["", "justonelongline", "here"]
       
       (compared using ==)
     # /tmp/d20141030-18133-aocvzd/spec.rb:59: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.01603 seconds
15 examples, 2 failures

Failed examples:

rspec /tmp/d20141030-18133-aocvzd/spec.rb:46 # String#word_wrap keeps longer lines if it is a single word
rspec /tmp/d20141030-18133-aocvzd/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line
Мартина Радева
  • Некоректно
  • 5 успешни тест(а)
  • 10 неуспешни тест(а)
Мартина Радева
class String
def word_wrap(row_length)
@result = []
if self.length > row_length
self.gsub("\n", ' ').squeeze(" ").strip.each_line(' '){|line| @result << line.strip}
end
i = 0
while i < @result.length
if @result[i..i+1].join(' ').length < row_length
long_row = @result.delete_at(i..i+1).join(' ')
@result.insert(long_row, i)
else i = i+1
end
end
@result
end
end
...FFFFFFFF.F.F

Failures:

  1) String#word_wrap correctly counts the whitespace between words
     Failure/Error: expect('one word n two words'.word_wrap(9)).to eq ['one word', 'n two', 'words']
     TypeError:
       no implicit conversion of Range into Integer
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `delete_at'
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `word_wrap'
     # /tmp/d20141030-18133-j8bdt3/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)>'

  2) String#word_wrap can split words given more length
     Failure/Error: expect('one two'.word_wrap(6)).to eq ['one', 'two']
     TypeError:
       no implicit conversion of Range into Integer
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `delete_at'
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `word_wrap'
     # /tmp/d20141030-18133-j8bdt3/spec.rb:19: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) String#word_wrap splits on the nearest left whitespace
     Failure/Error: expect('point one two'.word_wrap(8)).to eq ['point', 'one two']
     TypeError:
       no implicit conversion of Range into Integer
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `delete_at'
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `word_wrap'
     # /tmp/d20141030-18133-j8bdt3/spec.rb:23: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) String#word_wrap can split more than once
     Failure/Error: expect('point line parallelogram cube'.word_wrap(15)).to eq ['point line', 'parallelogram', 'cube']
     TypeError:
       no implicit conversion of Range into Integer
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `delete_at'
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `word_wrap'
     # /tmp/d20141030-18133-j8bdt3/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)>'

  5) String#word_wrap is not influenced by leading whitespace
     Failure/Error: expect("  \n one\nmore string".word_wrap(7)).to eq ['one', 'more', 'string']
     TypeError:
       no implicit conversion of Range into Integer
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `delete_at'
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `word_wrap'
     # /tmp/d20141030-18133-j8bdt3/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)>'

  6) String#word_wrap is not influenced by trailing whitespace
     Failure/Error: expect("one more string \n   ".word_wrap(7)).to eq ['one', 'more', 'string']
     TypeError:
       no implicit conversion of Range into Integer
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `delete_at'
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `word_wrap'
     # /tmp/d20141030-18133-j8bdt3/spec.rb:35: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)>'

  7) String#word_wrap ignores more than one whitespace between lines
     Failure/Error: expect("one    more   \n        string".word_wrap(7)).to eq ['one', 'more', 'string']
     TypeError:
       no implicit conversion of Range into Integer
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `delete_at'
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `word_wrap'
     # /tmp/d20141030-18133-j8bdt3/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)>'

  8) String#word_wrap compacts whitespace inside lines
     Failure/Error: expect("one   more        string".word_wrap(12)).to eq ['one more', 'string']
     TypeError:
       no implicit conversion of Range into Integer
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `delete_at'
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `word_wrap'
     # /tmp/d20141030-18133-j8bdt3/spec.rb:43: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)>'

  9) String#word_wrap splits text with cyrillic correctly
     Failure/Error: expect("  Мерси   за търпението   и\nура за живота! ".word_wrap(20)).to eq ['Мерси за търпението', 'и ура за живота!']
     TypeError:
       no implicit conversion of Range into Integer
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `delete_at'
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `word_wrap'
     # /tmp/d20141030-18133-j8bdt3/spec.rb:51: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)>'

  10) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
     TypeError:
       no implicit conversion of Range into Integer
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `delete_at'
     # /tmp/d20141030-18133-j8bdt3/solution.rb:11:in `word_wrap'
     # /tmp/d20141030-18133-j8bdt3/spec.rb:59: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.01355 seconds
15 examples, 10 failures

Failed examples:

rspec /tmp/d20141030-18133-j8bdt3/spec.rb:14 # String#word_wrap correctly counts the whitespace between words
rspec /tmp/d20141030-18133-j8bdt3/spec.rb:18 # String#word_wrap can split words given more length
rspec /tmp/d20141030-18133-j8bdt3/spec.rb:22 # String#word_wrap splits on the nearest left whitespace
rspec /tmp/d20141030-18133-j8bdt3/spec.rb:26 # String#word_wrap can split more than once
rspec /tmp/d20141030-18133-j8bdt3/spec.rb:30 # String#word_wrap is not influenced by leading whitespace
rspec /tmp/d20141030-18133-j8bdt3/spec.rb:34 # String#word_wrap is not influenced by trailing whitespace
rspec /tmp/d20141030-18133-j8bdt3/spec.rb:38 # String#word_wrap ignores more than one whitespace between lines
rspec /tmp/d20141030-18133-j8bdt3/spec.rb:42 # String#word_wrap compacts whitespace inside lines
rspec /tmp/d20141030-18133-j8bdt3/spec.rb:50 # String#word_wrap splits text with cyrillic correctly
rspec /tmp/d20141030-18133-j8bdt3/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line
Делян Димитров
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Делян Димитров
class String
def word_wrap(line_size)
result = []
current_line = ""
squish.split(" ").each do |word|
if current_line.size + word.size + 1 > line_size
add_word current_line, result
current_line = word
else
current_line += " " + word
end
end
add_word current_line, result
result
end
private
def add_word(word, array)
if word.size > 0
array << word.strip
end
end
def squish
self.strip.gsub(/\s+/, " ")
end
end
...............

Finished in 0.01277 seconds
15 examples, 0 failures
Атанас Димитров
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Атанас Димитров
class String
def word_wrap(line_length)
wrapped = []
strip.split(/\s+/).each do |word|
if wrapped.empty?
wrapped << word
elsif wrapped.last.length + word.length < line_length
wrapped.last.concat(' ').concat(word)
else
wrapped << word
end
end
wrapped
end
end
...............

Finished in 0.01268 seconds
15 examples, 0 failures
Станислав Венков
  • Некоректно
  • 5 успешни тест(а)
  • 10 неуспешни тест(а)
Станислав Венков
class String
def word_wrap (number_chars)
word_wrap_array = Array.new
if self.size == 0
return word_wrap_array
end
wrapped_phrase = nil
wors_array = self.strip.gsub("\n", " ").split(' ')
wors_array.each_with_index {|word, index|
word.strip
wrapped_phrase = recursive_concat(wrapped_phrase, word, number_chars)
next_word_size = wors_array[index + 1] ? wors_array[index + 1].size : 0
if wrapped_phrase.size + 1 + next_word_size > number_chars ||
wors_array.size == index + 1
word_wrap_array << wrapped_phrase
wrapped_phrase = ''
end
}
word_wrap_array
end
def recursive_concat (first_word, second_word, number_chars)
if second_word && first_word && first_word.size + second_word.size + 1 <= number_chars
first_word << " " << second_word
else
second_word
end
end
end
...FFFFFFFF.F.F

Failures:

  1) String#word_wrap correctly counts the whitespace between words
     Failure/Error: expect('one word n two words'.word_wrap(9)).to eq ['one word', 'n two', 'words']
       
       expected: ["one word", "n two", "words"]
            got: ["one word", " n two", " words"]
       
       (compared using ==)
     # /tmp/d20141030-18133-lbflim/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)>'

  2) String#word_wrap can split words given more length
     Failure/Error: expect('one two'.word_wrap(6)).to eq ['one', 'two']
       
       expected: ["one", "two"]
            got: ["one", " two"]
       
       (compared using ==)
     # /tmp/d20141030-18133-lbflim/spec.rb:19: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) String#word_wrap splits on the nearest left whitespace
     Failure/Error: expect('point one two'.word_wrap(8)).to eq ['point', 'one two']
       
       expected: ["point", "one two"]
            got: ["point", " one two"]
       
       (compared using ==)
     # /tmp/d20141030-18133-lbflim/spec.rb:23: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) String#word_wrap can split more than once
     Failure/Error: expect('point line parallelogram cube'.word_wrap(15)).to eq ['point line', 'parallelogram', 'cube']
       
       expected: ["point line", "parallelogram", "cube"]
            got: ["point line", " parallelogram", " cube"]
       
       (compared using ==)
     # /tmp/d20141030-18133-lbflim/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)>'

  5) String#word_wrap is not influenced by leading whitespace
     Failure/Error: expect("  \n one\nmore string".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["one", " more", " string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-lbflim/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)>'

  6) String#word_wrap is not influenced by trailing whitespace
     Failure/Error: expect("one more string \n   ".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["one", " more", " string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-lbflim/spec.rb:35: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)>'

  7) String#word_wrap ignores more than one whitespace between lines
     Failure/Error: expect("one    more   \n        string".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["one", " more", " string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-lbflim/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)>'

  8) String#word_wrap compacts whitespace inside lines
     Failure/Error: expect("one   more        string".word_wrap(12)).to eq ['one more', 'string']
       
       expected: ["one more", "string"]
            got: ["one more", " string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-lbflim/spec.rb:43: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)>'

  9) String#word_wrap splits text with cyrillic correctly
     Failure/Error: expect("  Мерси   за търпението   и\nура за живота! ".word_wrap(20)).to eq ['Мерси за търпението', 'и ура за живота!']
       
       expected: ["Мерси за търпението", "и ура за живота!"]
            got: ["Мерси за търпението", " и ура за живота!"]
       
       (compared using ==)
     # /tmp/d20141030-18133-lbflim/spec.rb:51: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)>'

  10) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
       
       expected: ["justonelongline", "here"]
            got: ["justonelongline", " here"]
       
       (compared using ==)
     # /tmp/d20141030-18133-lbflim/spec.rb:59: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.01774 seconds
15 examples, 10 failures

Failed examples:

rspec /tmp/d20141030-18133-lbflim/spec.rb:14 # String#word_wrap correctly counts the whitespace between words
rspec /tmp/d20141030-18133-lbflim/spec.rb:18 # String#word_wrap can split words given more length
rspec /tmp/d20141030-18133-lbflim/spec.rb:22 # String#word_wrap splits on the nearest left whitespace
rspec /tmp/d20141030-18133-lbflim/spec.rb:26 # String#word_wrap can split more than once
rspec /tmp/d20141030-18133-lbflim/spec.rb:30 # String#word_wrap is not influenced by leading whitespace
rspec /tmp/d20141030-18133-lbflim/spec.rb:34 # String#word_wrap is not influenced by trailing whitespace
rspec /tmp/d20141030-18133-lbflim/spec.rb:38 # String#word_wrap ignores more than one whitespace between lines
rspec /tmp/d20141030-18133-lbflim/spec.rb:42 # String#word_wrap compacts whitespace inside lines
rspec /tmp/d20141030-18133-lbflim/spec.rb:50 # String#word_wrap splits text with cyrillic correctly
rspec /tmp/d20141030-18133-lbflim/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line
Нели Василева
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Нели Василева
class String
def word_wrap(line_length)
text = strip.gsub(/\r\n|\n/, ' ').squeeze(' ')
return [] if text == ' '
string_array = []
array_index = 0
text.each_line(' ') do |word|
word.strip!
if string_array[array_index].nil?
then
string_array[array_index] = word
elsif string_array[array_index].size + 1 + word.size <= line_length
string_array[array_index].concat(' ').concat(word)
else
array_index = array_index + 1
string_array[array_index] = word
end
end
string_array
end
end
...............

Finished in 0.01314 seconds
15 examples, 0 failures
Деян Боиклиев
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Деян Боиклиев
class String
def word_wrap(symbols_per_row)
rows = []
row = ''
self.strip.gsub(/\s+/, ' ').split(/\s+/).each do |word|
if row.strip.length + word.length >= symbols_per_row
rows << row.strip unless row == ''
row = ''
end
row << word << ' ' unless word == ''
end
rows << row.strip unless row == ''
rows
end
end
...............

Finished in 0.0132 seconds
15 examples, 0 failures
Диана Генева
  • Некоректно
  • 13 успешни тест(а)
  • 2 неуспешни тест(а)
Диана Генева
class String
def word_wrap(line)
changed = []
current_string = ""
self.split(" ").each do |word|
if (current_string.length - 1 <= line)
if (current_string + word).length > line
changed << current_string
current_string = word + " "
else
current_string += word + " "
end
end
end
changed << current_string unless current_string.empty?
changed.map(&:strip)
end
end
...........F..F

Failures:

  1) String#word_wrap keeps longer lines if it is a single word
     Failure/Error: expect("one more string".word_wrap(2)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["", "one"]
       
       (compared using ==)
     # /tmp/d20141030-18133-13ti53q/spec.rb:47: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) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
       
       expected: ["justonelongline", "here"]
            got: ["", "justonelongline"]
       
       (compared using ==)
     # /tmp/d20141030-18133-13ti53q/spec.rb:59: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.01822 seconds
15 examples, 2 failures

Failed examples:

rspec /tmp/d20141030-18133-13ti53q/spec.rb:46 # String#word_wrap keeps longer lines if it is a single word
rspec /tmp/d20141030-18133-13ti53q/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line
Божидар Горов
  • Некоректно
  • 13 успешни тест(а)
  • 2 неуспешни тест(а)
Божидар Горов
class String
def word_wrap(lenght)
text = self.gsub("\\n", " ").split.join(" ")
working_lenght = lenght
while working_lenght < self.size
if text.rindex(' ', working_lenght)
space_index = text.rindex(' ', working_lenght)
elsif text.index(' ', working_lenght)
space_index = text.index(' ', working_lenght)
else
break
end
text[space_index] = '\n'
working_lenght = space_index + lenght + 1
end
text.split('\n')
end
end
..........F.F..

Failures:

  1) String#word_wrap compacts whitespace inside lines
     Failure/Error: expect("one   more        string".word_wrap(12)).to eq ['one more', 'string']
       
       expected: ["one more", "string"]
            got: ["one", "more", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1k45v59/spec.rb:43: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) String#word_wrap splits text with cyrillic correctly
     Failure/Error: expect("  Мерси   за търпението   и\nура за живота! ".word_wrap(20)).to eq ['Мерси за търпението', 'и ура за живота!']
       
       expected: ["Мерси за търпението", "и ура за живота!"]
            got: ["Мерси за търпението", "и ура за", "живота!"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1k45v59/spec.rb:51: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.01711 seconds
15 examples, 2 failures

Failed examples:

rspec /tmp/d20141030-18133-1k45v59/spec.rb:42 # String#word_wrap compacts whitespace inside lines
rspec /tmp/d20141030-18133-1k45v59/spec.rb:50 # String#word_wrap splits text with cyrillic correctly
Бетина Иванова
  • Некоректно
  • 11 успешни тест(а)
  • 4 неуспешни тест(а)
Бетина Иванова
class String
def word_wrap(number)
result = []
if self.chars.any? { |char| char != ' ' or char != '\n' }
array, string = [], self
array = convert_to_array(string)
get_result(array, result, number)
end
result
end
def get_result(array, result, number)
size, index = 0, 0
until array.empty?
help = array.take_while { |word| (size += word.length + 1) <= number + 1 }
size, array, result[index] = 0, array - help, help.join(" ")
index = index + 1
end
end
def convert_to_array(string)
array = []
string.squeeze(' ').squeeze('\n').split('\n').each do |item|
array << item.strip
end
array = array.join(" ").split.delete_if { |word| word.empty? }
array
end
end
...........FFFF

Failures:

  1) String#word_wrap keeps longer lines if it is a single word
     Failure/Error: expect("one more string".word_wrap(2)).to eq ['one', 'more', 'string']
     Timeout::Error:
       execution expired
     # /tmp/d20141030-18133-b7jus5/solution.rb:20:in `get_result'
     # /tmp/d20141030-18133-b7jus5/solution.rb:10:in `word_wrap'
     # /tmp/d20141030-18133-b7jus5/spec.rb:47: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) String#word_wrap splits text with cyrillic correctly
     Failure/Error: expect("  Мерси   за търпението   и\nура за живота! ".word_wrap(20)).to eq ['Мерси за търпението', 'и ура за живота!']
       
       expected: ["Мерси за търпението", "и ура за живота!"]
            got: ["Мерси за търпението", "и ура живота!"]
       
       (compared using ==)
     # /tmp/d20141030-18133-b7jus5/spec.rb:51: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) String#word_wrap splits text with hiragana letters correctly
     Failure/Error: expect("まつもとさんは Rubyのおとうさん. ".word_wrap(10)).to eq ['まつもとさんは', 'Rubyのおとうさん.']
     Timeout::Error:
       execution expired
     # /tmp/d20141030-18133-b7jus5/solution.rb:20:in `get_result'
     # /tmp/d20141030-18133-b7jus5/solution.rb:10:in `word_wrap'
     # /tmp/d20141030-18133-b7jus5/spec.rb:55: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) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
     Timeout::Error:
       execution expired
     # /tmp/d20141030-18133-b7jus5/solution.rb:21:in `block in get_result'
     # /tmp/d20141030-18133-b7jus5/solution.rb:21:in `take_while'
     # /tmp/d20141030-18133-b7jus5/solution.rb:21:in `get_result'
     # /tmp/d20141030-18133-b7jus5/solution.rb:10:in `word_wrap'
     # /tmp/d20141030-18133-b7jus5/spec.rb:59: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 3.31 seconds
15 examples, 4 failures

Failed examples:

rspec /tmp/d20141030-18133-b7jus5/spec.rb:46 # String#word_wrap keeps longer lines if it is a single word
rspec /tmp/d20141030-18133-b7jus5/spec.rb:50 # String#word_wrap splits text with cyrillic correctly
rspec /tmp/d20141030-18133-b7jus5/spec.rb:54 # String#word_wrap splits text with hiragana letters correctly
rspec /tmp/d20141030-18133-b7jus5/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line
Светослав Кръстев
  • Некоректно
  • 5 успешни тест(а)
  • 10 неуспешни тест(а)
Светослав Кръстев
class String
def word_wrap(max_symbols)
new_string = self.sub('\n' , " ").gsub(/\s+/m , " ").scan(/.{1,#{max_symbols}}\W/)
new_string.each { |line| line.strip! }
end
end
..FFFFFF.FFF..F

Failures:

  1) String#word_wrap can split words given exact length
     Failure/Error: expect('one two'.word_wrap(3)).to eq ['one', 'two']
       
       expected: ["one", "two"]
            got: ["one"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmyl89/spec.rb:11: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) String#word_wrap correctly counts the whitespace between words
     Failure/Error: expect('one word n two words'.word_wrap(9)).to eq ['one word', 'n two', 'words']
       
       expected: ["one word", "n two", "words"]
            got: ["one word", "n two"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmyl89/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) String#word_wrap can split words given more length
     Failure/Error: expect('one two'.word_wrap(6)).to eq ['one', 'two']
       
       expected: ["one", "two"]
            got: ["one"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmyl89/spec.rb:19: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) String#word_wrap splits on the nearest left whitespace
     Failure/Error: expect('point one two'.word_wrap(8)).to eq ['point', 'one two']
       
       expected: ["point", "one two"]
            got: ["point", "one"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmyl89/spec.rb:23: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)>'

  5) String#word_wrap can split more than once
     Failure/Error: expect('point line parallelogram cube'.word_wrap(15)).to eq ['point line', 'parallelogram', 'cube']
       
       expected: ["point line", "parallelogram", "cube"]
            got: ["point line", "parallelogram"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmyl89/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)>'

  6) String#word_wrap is not influenced by leading whitespace
     Failure/Error: expect("  \n one\nmore string".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["one", "more"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmyl89/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)>'

  7) String#word_wrap ignores more than one whitespace between lines
     Failure/Error: expect("one    more   \n        string".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["one", "more"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmyl89/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)>'

  8) String#word_wrap compacts whitespace inside lines
     Failure/Error: expect("one   more        string".word_wrap(12)).to eq ['one more', 'string']
       
       expected: ["one more", "string"]
            got: ["one more"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmyl89/spec.rb:43: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)>'

  9) String#word_wrap keeps longer lines if it is a single word
     Failure/Error: expect("one more string".word_wrap(2)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["ne", "re"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmyl89/spec.rb:47: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)>'

  10) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
       
       expected: ["justonelongline", "here"]
            got: ["gline"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmyl89/spec.rb:59: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.01523 seconds
15 examples, 10 failures

Failed examples:

rspec /tmp/d20141030-18133-1bmyl89/spec.rb:10 # String#word_wrap can split words given exact length
rspec /tmp/d20141030-18133-1bmyl89/spec.rb:14 # String#word_wrap correctly counts the whitespace between words
rspec /tmp/d20141030-18133-1bmyl89/spec.rb:18 # String#word_wrap can split words given more length
rspec /tmp/d20141030-18133-1bmyl89/spec.rb:22 # String#word_wrap splits on the nearest left whitespace
rspec /tmp/d20141030-18133-1bmyl89/spec.rb:26 # String#word_wrap can split more than once
rspec /tmp/d20141030-18133-1bmyl89/spec.rb:30 # String#word_wrap is not influenced by leading whitespace
rspec /tmp/d20141030-18133-1bmyl89/spec.rb:38 # String#word_wrap ignores more than one whitespace between lines
rspec /tmp/d20141030-18133-1bmyl89/spec.rb:42 # String#word_wrap compacts whitespace inside lines
rspec /tmp/d20141030-18133-1bmyl89/spec.rb:46 # String#word_wrap keeps longer lines if it is a single word
rspec /tmp/d20141030-18133-1bmyl89/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line
Стилиян Стоянов
  • Некоректно
  • 13 успешни тест(а)
  • 2 неуспешни тест(а)
Стилиян Стоянов
class String
def word_wrap row_length
mutable_string = self
mutable_string.gsub!(/\n/,' ')
mutable_string.strip!
mutable_string.gsub!(/\s+/," ")
text_size = mutable_string.length
return [] if text_size == 0
if text_size < row_length
one_row = []
one << mutable_string
else
word_wrapper( mutable_string, text_size, row_length )
end
end
def word_wrapper mutable_string, string_length, row_length
list_of_formatted_rows = []
index = 0
while( index < string_length )
new_index = mutable_string.index( ' ', index )
if new_index == nil
unless index == 0
list_of_formatted_rows << mutable_string.slice!(0, index).chop
end
list_of_formatted_rows << mutable_string
return list_of_formatted_rows
end
if new_index <= row_length
index = new_index + 1
else
list_of_formatted_rows << mutable_string.slice!(0, index).chop
string_length -= index
if string_length < row_length
return list_of_formatted_rows << mutable_string
end
index = 0
end
end
return list_of_formatted_rows
end
end
...........F..F

Failures:

  1) String#word_wrap keeps longer lines if it is a single word
     Failure/Error: expect("one more string".word_wrap(2)).to eq ['one', 'more', 'string']
     Timeout::Error:
       execution expired
     # /tmp/d20141030-18133-1nd9gev/solution.rb:35:in `word_wrapper'
     # /tmp/d20141030-18133-1nd9gev/solution.rb:14:in `word_wrap'
     # /tmp/d20141030-18133-1nd9gev/spec.rb:47: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) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
     Timeout::Error:
       execution expired
     # /tmp/d20141030-18133-1nd9gev/solution.rb:23:in `=='
     # /tmp/d20141030-18133-1nd9gev/solution.rb:23:in `word_wrapper'
     # /tmp/d20141030-18133-1nd9gev/solution.rb:14:in `word_wrap'
     # /tmp/d20141030-18133-1nd9gev/spec.rb:59: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 2.22 seconds
15 examples, 2 failures

Failed examples:

rspec /tmp/d20141030-18133-1nd9gev/spec.rb:46 # String#word_wrap keeps longer lines if it is a single word
rspec /tmp/d20141030-18133-1nd9gev/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line
Любомир Папазов
  • Некоректно
  • 8 успешни тест(а)
  • 7 неуспешни тест(а)
Любомир Папазов
class String
def word_wrap(max_chars)
if self.squeeze(' ').delete("\n") == "" then []
else squeeze(' ').delete("\n").scan(/.{1,#{max_chars}}\s|.{1,#{max_chars}}/).map(&:strip)
end
end
end
.F...F.F...FFFF

Failures:

  1) String#word_wrap reduces whitespace-only strings to an empty array
     Failure/Error: expect("    \n      ".word_wrap(3)).to eq []
       
       expected: []
            got: [""]
       
       (compared using ==)
     # /tmp/d20141030-18133-16yeg6o/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) String#word_wrap splits on the nearest left whitespace
     Failure/Error: expect('point one two'.word_wrap(8)).to eq ['point', 'one two']
       
       expected: ["point", "one two"]
            got: ["point", "one", "two"]
       
       (compared using ==)
     # /tmp/d20141030-18133-16yeg6o/spec.rb:23: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) String#word_wrap is not influenced by leading whitespace
     Failure/Error: expect("  \n one\nmore string".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["", "onemore", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-16yeg6o/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)>'

  4) String#word_wrap keeps longer lines if it is a single word
     Failure/Error: expect("one more string".word_wrap(2)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["on", "e", "mo", "re", "st", "ri", "ng"]
       
       (compared using ==)
     # /tmp/d20141030-18133-16yeg6o/spec.rb:47: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)>'

  5) String#word_wrap splits text with cyrillic correctly
     Failure/Error: expect("  Мерси   за търпението   и\nура за живота! ".word_wrap(20)).to eq ['Мерси за търпението', 'и ура за живота!']
       
       expected: ["Мерси за търпението", "и ура за живота!"]
            got: ["Мерси за търпението", "иура за живота!"]
       
       (compared using ==)
     # /tmp/d20141030-18133-16yeg6o/spec.rb:51: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)>'

  6) String#word_wrap splits text with hiragana letters correctly
     Failure/Error: expect("まつもとさんは Rubyのおとうさん. ".word_wrap(10)).to eq ['まつもとさんは', 'Rubyのおとうさん.']
       
       expected: ["まつもとさんは", "Rubyのおとうさん."]
            got: ["まつもとさんは", "Rubyのおとうさん", "."]
       
       (compared using ==)
     # /tmp/d20141030-18133-16yeg6o/spec.rb:55: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)>'

  7) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
       
       expected: ["justonelongline", "here"]
            got: ["justo", "nelon", "gline", "here"]
       
       (compared using ==)
     # /tmp/d20141030-18133-16yeg6o/spec.rb:59: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.01795 seconds
15 examples, 7 failures

Failed examples:

rspec /tmp/d20141030-18133-16yeg6o/spec.rb:6 # String#word_wrap reduces whitespace-only strings to an empty array
rspec /tmp/d20141030-18133-16yeg6o/spec.rb:22 # String#word_wrap splits on the nearest left whitespace
rspec /tmp/d20141030-18133-16yeg6o/spec.rb:30 # String#word_wrap is not influenced by leading whitespace
rspec /tmp/d20141030-18133-16yeg6o/spec.rb:46 # String#word_wrap keeps longer lines if it is a single word
rspec /tmp/d20141030-18133-16yeg6o/spec.rb:50 # String#word_wrap splits text with cyrillic correctly
rspec /tmp/d20141030-18133-16yeg6o/spec.rb:54 # String#word_wrap splits text with hiragana letters correctly
rspec /tmp/d20141030-18133-16yeg6o/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line
Георги Димов
  • Некоректно
  • 9 успешни тест(а)
  • 6 неуспешни тест(а)
Георги Димов
class String
def word_wrap(line_length)
return [] unless self.include? '\n' or self.include? ' '
self.gsub(/\n\s+/, " ").strip
.gsub(/(.{1,#{line_length}})(?: +|$)\n?|(.{#{line_length}})/, "\\1\\2\n")
.split("\n")
end
end
.........FFFFFF

Failures:

  1) String#word_wrap ignores more than one whitespace between lines
     Failure/Error: expect("one    more   \n        string".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["one   ", "more   ", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-w8ksi2/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)>'

  2) String#word_wrap compacts whitespace inside lines
     Failure/Error: expect("one   more        string".word_wrap(12)).to eq ['one more', 'string']
       
       expected: ["one more", "string"]
            got: ["one   more  ", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-w8ksi2/spec.rb:43: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) String#word_wrap keeps longer lines if it is a single word
     Failure/Error: expect("one more string".word_wrap(2)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["on", "e", "mo", "re", "st", "ri", "ng"]
       
       (compared using ==)
     # /tmp/d20141030-18133-w8ksi2/spec.rb:47: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) String#word_wrap splits text with cyrillic correctly
     Failure/Error: expect("  Мерси   за търпението   и\nура за живота! ".word_wrap(20)).to eq ['Мерси за търпението', 'и ура за живота!']
       
       expected: ["Мерси за търпението", "и ура за живота!"]
            got: ["Мерси   за", "търпението   и", "ура за живота!"]
       
       (compared using ==)
     # /tmp/d20141030-18133-w8ksi2/spec.rb:51: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)>'

  5) String#word_wrap splits text with hiragana letters correctly
     Failure/Error: expect("まつもとさんは Rubyのおとうさん. ".word_wrap(10)).to eq ['まつもとさんは', 'Rubyのおとうさん.']
       
       expected: ["まつもとさんは", "Rubyのおとうさん."]
            got: ["まつもとさんは", "Rubyのおとうさん", "."]
       
       (compared using ==)
     # /tmp/d20141030-18133-w8ksi2/spec.rb:55: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)>'

  6) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
       
       expected: ["justonelongline", "here"]
            got: ["justo", "nelon", "gline", "here"]
       
       (compared using ==)
     # /tmp/d20141030-18133-w8ksi2/spec.rb:59: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.0155 seconds
15 examples, 6 failures

Failed examples:

rspec /tmp/d20141030-18133-w8ksi2/spec.rb:38 # String#word_wrap ignores more than one whitespace between lines
rspec /tmp/d20141030-18133-w8ksi2/spec.rb:42 # String#word_wrap compacts whitespace inside lines
rspec /tmp/d20141030-18133-w8ksi2/spec.rb:46 # String#word_wrap keeps longer lines if it is a single word
rspec /tmp/d20141030-18133-w8ksi2/spec.rb:50 # String#word_wrap splits text with cyrillic correctly
rspec /tmp/d20141030-18133-w8ksi2/spec.rb:54 # String#word_wrap splits text with hiragana letters correctly
rspec /tmp/d20141030-18133-w8ksi2/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line
Евгений Янев
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Евгений Янев
class String
def word_wrap width
self.strip.gsub(/\s+/, " ").scan(/\S.{0,#{width-2}}\S(?=\s|$)|\S+/)
end
end
...............

Finished in 0.01441 seconds
15 examples, 0 failures
Константин Тодоров
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Константин Тодоров
class String
def word_wrap(maxSymbols)
words_array = self.strip.gsub("\n", " ").squeeze(" ").split(" ")
return [] if words_array.empty?
result_array = []
current_element = 0
words_array.each do |word|
result_array[current_element] = "" if result_array[current_element] == nil
if result_array[current_element].size + 1 + word.size <= maxSymbols + 1 and result_array[current_element].size != 0
result_array[current_element] += word + " "
else
current_element += 1
result_array[current_element] = word + " "
end
end
result_array.reject! { |item| item.empty? }.collect! { |item| item.strip.squeeze(" ") }
result_array
end
end
...............

Finished in 0.01216 seconds
15 examples, 0 failures
Петя Петрова
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Петя Петрова
class String
def word_wrap count
words = self.strip.gsub(/\s+/, " ").scan(/\S.{0,#{ count - 2 }}\S(?=\s|$)|\S+/)
end
end
...............

Finished in 0.01832 seconds
15 examples, 0 failures
Атанас Цанков
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Атанас Цанков
class String
def word_wrap(n)
perform_wrap(gsub(/\s+/, "\n").strip.lines.map{|i| i.chomp}, n)
end
def perform_wrap(array, n)
newarr = []
if array.size == 0
return newarr
elsif array[0].size >= n || array.size == 1 || ((array[0].size + array[1].size + 1) > n)
newarr.push(array[0])
array.delete_at(0)
return newarr.concat(perform_wrap(array, n))
else
newarr.push(array[0] + " " + array[1])
array.slice!(0,2)
array.insert(0, newarr[0])
return perform_wrap(array, n)
end
end
end
...............

Finished in 0.01748 seconds
15 examples, 0 failures
Йоана Тодорова
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Йоана Тодорова
class String
def word_wrap(symbols_count)
gsub(/[\s\n]+/, ' ')
.strip
.gsub(/(?<line>.{1,#{symbols_count}})(\s+|$)/, "\\k<line>\n")
.split("\n")
end
end
...............

Finished in 0.03359 seconds
15 examples, 0 failures
Венцислав Димитров
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Венцислав Димитров
class String
def word_wrap(length)
strip.gsub(/\s+/," ").scan(/\S.{0,#{length-2}}\S(?=\s|$)|\S+/).map { |x| x.strip }
end
end
...............

Finished in 0.01447 seconds
15 examples, 0 failures
Евгений Бояджиев
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Евгений Бояджиев
class String
def word_wrap(max_line_length)
result_lines = []
words = self.dup.strip.gsub("\n", "\n ").squeeze(" ").split(" ")
line = ""
words.each do |word|
word = word.slice 0..-1 if word[-1] == "\n"
if line.empty?
line = word
elsif line.size + " ".size + word.size <= max_line_length
line += " " + word
else
result_lines << line
line = word
end
end
result_lines << line if line.size > 0
return result_lines
end
end
...............

Finished in 0.01329 seconds
15 examples, 0 failures
Георги Железов
  • Некоректно
  • 0 успешни тест(а)
  • 15 неуспешни тест(а)
Георги Железов
class String
include Enumerable
def word_wrap(length)
@length = length
result = []
word = self.word_wrap_strip
end
def word_wrap_strip
self.lstrip.rstrip.gsub(/\s+/, " ")
end
def each(&block)
@numbers.each { |number| block.call number } if block_given?
@numbers.to_enum unless block_given?
end
end
" f fe F \nfef E ".word_wrap(3)
FFFFFFFFFFFFFFF

Failures:

  1) String#word_wrap reduces the empty string to an empty array
     Failure/Error: expect(''.word_wrap(2)).to eq []
       
       expected: []
            got: ""
       
       (compared using ==)
     # /tmp/d20141030-18133-iyjmnj/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) String#word_wrap reduces whitespace-only strings to an empty array
     Failure/Error: expect("    \n      ".word_wrap(3)).to eq []
       
       expected: []
            got: ""
       
       (compared using ==)
     # /tmp/d20141030-18133-iyjmnj/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)>'

  3) String#word_wrap can split words given exact length
     Failure/Error: expect('one two'.word_wrap(3)).to eq ['one', 'two']
       
       expected: ["one", "two"]
            got: "one two"
       
       (compared using ==)
     # /tmp/d20141030-18133-iyjmnj/spec.rb:11: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) String#word_wrap correctly counts the whitespace between words
     Failure/Error: expect('one word n two words'.word_wrap(9)).to eq ['one word', 'n two', 'words']
       
       expected: ["one word", "n two", "words"]
            got: "one word n two words"
       
       (compared using ==)
     # /tmp/d20141030-18133-iyjmnj/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)>'

  5) String#word_wrap can split words given more length
     Failure/Error: expect('one two'.word_wrap(6)).to eq ['one', 'two']
       
       expected: ["one", "two"]
            got: "one two"
       
       (compared using ==)
     # /tmp/d20141030-18133-iyjmnj/spec.rb:19: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)>'

  6) String#word_wrap splits on the nearest left whitespace
     Failure/Error: expect('point one two'.word_wrap(8)).to eq ['point', 'one two']
       
       expected: ["point", "one two"]
            got: "point one two"
       
       (compared using ==)
     # /tmp/d20141030-18133-iyjmnj/spec.rb:23: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)>'

  7) String#word_wrap can split more than once
     Failure/Error: expect('point line parallelogram cube'.word_wrap(15)).to eq ['point line', 'parallelogram', 'cube']
       
       expected: ["point line", "parallelogram", "cube"]
            got: "point line parallelogram cube"
       
       (compared using ==)
     # /tmp/d20141030-18133-iyjmnj/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)>'

  8) String#word_wrap is not influenced by leading whitespace
     Failure/Error: expect("  \n one\nmore string".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: "one more string"
       
       (compared using ==)
     # /tmp/d20141030-18133-iyjmnj/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)>'

  9) String#word_wrap is not influenced by trailing whitespace
     Failure/Error: expect("one more string \n   ".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: "one more string"
       
       (compared using ==)
     # /tmp/d20141030-18133-iyjmnj/spec.rb:35: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)>'

  10) String#word_wrap ignores more than one whitespace between lines
     Failure/Error: expect("one    more   \n        string".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: "one more string"
       
       (compared using ==)
     # /tmp/d20141030-18133-iyjmnj/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)>'

  11) String#word_wrap compacts whitespace inside lines
     Failure/Error: expect("one   more        string".word_wrap(12)).to eq ['one more', 'string']
       
       expected: ["one more", "string"]
            got: "one more string"
       
       (compared using ==)
     # /tmp/d20141030-18133-iyjmnj/spec.rb:43: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)>'

  12) String#word_wrap keeps longer lines if it is a single word
     Failure/Error: expect("one more string".word_wrap(2)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: "one more string"
       
       (compared using ==)
     # /tmp/d20141030-18133-iyjmnj/spec.rb:47: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)>'

  13) String#word_wrap splits text with cyrillic correctly
     Failure/Error: expect("  Мерси   за търпението   и\nура за живота! ".word_wrap(20)).to eq ['Мерси за търпението', 'и ура за живота!']
       
       expected: ["Мерси за търпението", "и ура за живота!"]
            got: "Мерси за търпението и ура за живота!"
       
       (compared using ==)
     # /tmp/d20141030-18133-iyjmnj/spec.rb:51: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)>'

  14) String#word_wrap splits text with hiragana letters correctly
     Failure/Error: expect("まつもとさんは Rubyのおとうさん. ".word_wrap(10)).to eq ['まつもとさんは', 'Rubyのおとうさん.']
       
       expected: ["まつもとさんは", "Rubyのおとうさん."]
            got: "まつもとさんは Rubyのおとうさん."
       
       (compared using ==)
     # /tmp/d20141030-18133-iyjmnj/spec.rb:55: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)>'

  15) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
       
       expected: ["justonelongline", "here"]
            got: "justonelongline here"
       
       (compared using ==)
     # /tmp/d20141030-18133-iyjmnj/spec.rb:59: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.01383 seconds
15 examples, 15 failures

Failed examples:

rspec /tmp/d20141030-18133-iyjmnj/spec.rb:2 # String#word_wrap reduces the empty string to an empty array
rspec /tmp/d20141030-18133-iyjmnj/spec.rb:6 # String#word_wrap reduces whitespace-only strings to an empty array
rspec /tmp/d20141030-18133-iyjmnj/spec.rb:10 # String#word_wrap can split words given exact length
rspec /tmp/d20141030-18133-iyjmnj/spec.rb:14 # String#word_wrap correctly counts the whitespace between words
rspec /tmp/d20141030-18133-iyjmnj/spec.rb:18 # String#word_wrap can split words given more length
rspec /tmp/d20141030-18133-iyjmnj/spec.rb:22 # String#word_wrap splits on the nearest left whitespace
rspec /tmp/d20141030-18133-iyjmnj/spec.rb:26 # String#word_wrap can split more than once
rspec /tmp/d20141030-18133-iyjmnj/spec.rb:30 # String#word_wrap is not influenced by leading whitespace
rspec /tmp/d20141030-18133-iyjmnj/spec.rb:34 # String#word_wrap is not influenced by trailing whitespace
rspec /tmp/d20141030-18133-iyjmnj/spec.rb:38 # String#word_wrap ignores more than one whitespace between lines
rspec /tmp/d20141030-18133-iyjmnj/spec.rb:42 # String#word_wrap compacts whitespace inside lines
rspec /tmp/d20141030-18133-iyjmnj/spec.rb:46 # String#word_wrap keeps longer lines if it is a single word
rspec /tmp/d20141030-18133-iyjmnj/spec.rb:50 # String#word_wrap splits text with cyrillic correctly
rspec /tmp/d20141030-18133-iyjmnj/spec.rb:54 # String#word_wrap splits text with hiragana letters correctly
rspec /tmp/d20141030-18133-iyjmnj/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line
Любомир Иванов
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Любомир Иванов
class String
def word_wrap(sentence_length)
sentences = []
sentence = ""
words = self.strip.split(' ')
words.each do |word|
if word.length > sentence_length && sentence != ""
sentences << sentence
sentences << word
sentence = ""
elsif word.length > sentence_length
sentences << word
elsif word.length <= sentence_length
if sentence == ""
sentence += word
elsif (sentence + ' ' + word).length <= sentence_length
sentence += " " + word
else
sentences << sentence
sentence = word
end
end
end
sentences << sentence if sentence != ""
sentences
end
end
...............

Finished in 0.0122 seconds
15 examples, 0 failures
Велислав Симеонов
  • Коректно
  • 15 успешни тест(а)
  • 0 неуспешни тест(а)
Велислав Симеонов
class String
def word_wrap wrap_size
temp= self.dup
.split
array = ""
array_size = 0
temp.each do |item|
if array_size + item.size <= wrap_size
array << " " + item
array_size += item.size + 1
else
array << "\n" + item
array_size = 0
array_size += item.size + 1
end
end
array.lstrip
.split("\n")
end
end
...............

Finished in 0.01529 seconds
15 examples, 0 failures
Явор Михайлов
  • Некоректно
  • 12 успешни тест(а)
  • 3 неуспешни тест(а)
Явор Михайлов
class String
def word_wrap(symbols_per_row)
formatted_text = gsub("\n", ' ').delete("\n").strip.squeeze(' ')
rows = []
formatted_text.gsub(/(.{1,#{symbols_per_row}})(\s+|\Z)/).each do |word|
rows << word.strip
end
rows
end
end
...........F.FF

Failures:

  1) String#word_wrap keeps longer lines if it is a single word
     Failure/Error: expect("one more string".word_wrap(2)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["ne", "re", "ng"]
       
       (compared using ==)
     # /tmp/d20141030-18133-9f99fx/spec.rb:47: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) String#word_wrap splits text with hiragana letters correctly
     Failure/Error: expect("まつもとさんは Rubyのおとうさん. ".word_wrap(10)).to eq ['まつもとさんは', 'Rubyのおとうさん.']
       
       expected: ["まつもとさんは", "Rubyのおとうさん."]
            got: ["まつもとさんは", "ubyのおとうさん."]
       
       (compared using ==)
     # /tmp/d20141030-18133-9f99fx/spec.rb:55: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) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
       
       expected: ["justonelongline", "here"]
            got: ["gline", "here"]
       
       (compared using ==)
     # /tmp/d20141030-18133-9f99fx/spec.rb:59: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.01541 seconds
15 examples, 3 failures

Failed examples:

rspec /tmp/d20141030-18133-9f99fx/spec.rb:46 # String#word_wrap keeps longer lines if it is a single word
rspec /tmp/d20141030-18133-9f99fx/spec.rb:54 # String#word_wrap splits text with hiragana letters correctly
rspec /tmp/d20141030-18133-9f99fx/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line
София Петрова
  • Некоректно
  • 10 успешни тест(а)
  • 5 неуспешни тест(а)
София Петрова
class String
def word_wrap(max)
self.strip.squeeze(" ").split(" " || "\n").compact
end
end
...F.FF...F.F..

Failures:

  1) String#word_wrap correctly counts the whitespace between words
     Failure/Error: expect('one word n two words'.word_wrap(9)).to eq ['one word', 'n two', 'words']
       
       expected: ["one word", "n two", "words"]
            got: ["one", "word", "n", "two", "words"]
       
       (compared using ==)
     # /tmp/d20141030-18133-3kbx0u/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)>'

  2) String#word_wrap splits on the nearest left whitespace
     Failure/Error: expect('point one two'.word_wrap(8)).to eq ['point', 'one two']
       
       expected: ["point", "one two"]
            got: ["point", "one", "two"]
       
       (compared using ==)
     # /tmp/d20141030-18133-3kbx0u/spec.rb:23: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) String#word_wrap can split more than once
     Failure/Error: expect('point line parallelogram cube'.word_wrap(15)).to eq ['point line', 'parallelogram', 'cube']
       
       expected: ["point line", "parallelogram", "cube"]
            got: ["point", "line", "parallelogram", "cube"]
       
       (compared using ==)
     # /tmp/d20141030-18133-3kbx0u/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) String#word_wrap compacts whitespace inside lines
     Failure/Error: expect("one   more        string".word_wrap(12)).to eq ['one more', 'string']
       
       expected: ["one more", "string"]
            got: ["one", "more", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-3kbx0u/spec.rb:43: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)>'

  5) String#word_wrap splits text with cyrillic correctly
     Failure/Error: expect("  Мерси   за търпението   и\nура за живота! ".word_wrap(20)).to eq ['Мерси за търпението', 'и ура за живота!']
       
       expected: ["Мерси за търпението", "и ура за живота!"]
            got: ["Мерси", "за", "търпението", "и", "ура", "за", "живота!"]
       
       (compared using ==)
     # /tmp/d20141030-18133-3kbx0u/spec.rb:51: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.01338 seconds
15 examples, 5 failures

Failed examples:

rspec /tmp/d20141030-18133-3kbx0u/spec.rb:14 # String#word_wrap correctly counts the whitespace between words
rspec /tmp/d20141030-18133-3kbx0u/spec.rb:22 # String#word_wrap splits on the nearest left whitespace
rspec /tmp/d20141030-18133-3kbx0u/spec.rb:26 # String#word_wrap can split more than once
rspec /tmp/d20141030-18133-3kbx0u/spec.rb:42 # String#word_wrap compacts whitespace inside lines
rspec /tmp/d20141030-18133-3kbx0u/spec.rb:50 # String#word_wrap splits text with cyrillic correctly
Пламен Каращранов
  • Некоректно
  • 12 успешни тест(а)
  • 3 неуспешни тест(а)
Пламен Каращранов
class String
def word_wrap(wrap_size)
source= self.dup
source=source.split()
temp=""
temp_size=0
source.each do |item|
if temp_size + item.size + 1 <= wrap_size
temp<<item+" "
temp_size=temp_size+item.size
temp_size=temp_size+1
else
temp = temp.rstrip
temp_size = temp_size - 1
if temp_size + item.size + 1 <= wrap_size
temp<<" " + item
temp_size=temp_size+item.size
temp_size=temp_size+1
else
temp<<"\n"<<item+" "
temp_size=0
temp_size=item.size
temp_size=temp_size+1
end
end
end
temp =temp.rstrip
temp.split("\n" )
end
end
..F........F..F

Failures:

  1) String#word_wrap can split words given exact length
     Failure/Error: expect('one two'.word_wrap(3)).to eq ['one', 'two']
       
       expected: ["one", "two"]
            got: [" one", "two"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1q51rol/spec.rb:11: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) String#word_wrap keeps longer lines if it is a single word
     Failure/Error: expect("one more string".word_wrap(2)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["", "one", "more", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1q51rol/spec.rb:47: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) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
       
       expected: ["justonelongline", "here"]
            got: ["", "justonelongline", "here"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1q51rol/spec.rb:59: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.01604 seconds
15 examples, 3 failures

Failed examples:

rspec /tmp/d20141030-18133-1q51rol/spec.rb:10 # String#word_wrap can split words given exact length
rspec /tmp/d20141030-18133-1q51rol/spec.rb:46 # String#word_wrap keeps longer lines if it is a single word
rspec /tmp/d20141030-18133-1q51rol/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line
Светлозар Стефанов
  • Некоректно
  • 2 успешни тест(а)
  • 13 неуспешни тест(а)
Светлозар Стефанов
class String
def word_wrap(number_size)
source = self.dup.strip.gsub("\n", ' ').squeeze(' ').split(' ')
temp_array = []
current_pos = 0
source.each do |word|
temp_array[current_pos] = "" if temp_array[current_pos] == nil
if (temp_array[current_pos].length + word.length + 1) <= number_size
temp_array[current_pos] << ' ' + word
else
current_pos += 1
temp_array[current_pos] = word
end
end
temp_array.reject { |c| c.empty? }
temp_array
end
end
..FFFFFFFFFFFFF

Failures:

  1) String#word_wrap can split words given exact length
     Failure/Error: expect('one two'.word_wrap(3)).to eq ['one', 'two']
       
       expected: ["one", "two"]
            got: ["", "one", "two"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmjijc/spec.rb:11: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) String#word_wrap correctly counts the whitespace between words
     Failure/Error: expect('one word n two words'.word_wrap(9)).to eq ['one word', 'n two', 'words']
       
       expected: ["one word", "n two", "words"]
            got: [" one word", "n two", "words"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmjijc/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) String#word_wrap can split words given more length
     Failure/Error: expect('one two'.word_wrap(6)).to eq ['one', 'two']
       
       expected: ["one", "two"]
            got: [" one", "two"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmjijc/spec.rb:19: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) String#word_wrap splits on the nearest left whitespace
     Failure/Error: expect('point one two'.word_wrap(8)).to eq ['point', 'one two']
       
       expected: ["point", "one two"]
            got: [" point", "one two"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmjijc/spec.rb:23: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)>'

  5) String#word_wrap can split more than once
     Failure/Error: expect('point line parallelogram cube'.word_wrap(15)).to eq ['point line', 'parallelogram', 'cube']
       
       expected: ["point line", "parallelogram", "cube"]
            got: [" point line", "parallelogram", "cube"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmjijc/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)>'

  6) String#word_wrap is not influenced by leading whitespace
     Failure/Error: expect("  \n one\nmore string".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: [" one", "more", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmjijc/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)>'

  7) String#word_wrap is not influenced by trailing whitespace
     Failure/Error: expect("one more string \n   ".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: [" one", "more", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmjijc/spec.rb:35: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)>'

  8) String#word_wrap ignores more than one whitespace between lines
     Failure/Error: expect("one    more   \n        string".word_wrap(7)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: [" one", "more", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmjijc/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)>'

  9) String#word_wrap compacts whitespace inside lines
     Failure/Error: expect("one   more        string".word_wrap(12)).to eq ['one more', 'string']
       
       expected: ["one more", "string"]
            got: [" one more", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmjijc/spec.rb:43: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)>'

  10) String#word_wrap keeps longer lines if it is a single word
     Failure/Error: expect("one more string".word_wrap(2)).to eq ['one', 'more', 'string']
       
       expected: ["one", "more", "string"]
            got: ["", "one", "more", "string"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmjijc/spec.rb:47: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)>'

  11) String#word_wrap splits text with cyrillic correctly
     Failure/Error: expect("  Мерси   за търпението   и\nура за живота! ".word_wrap(20)).to eq ['Мерси за търпението', 'и ура за живота!']
       
       expected: ["Мерси за търпението", "и ура за живота!"]
            got: [" Мерси за търпението", "и ура за живота!"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmjijc/spec.rb:51: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)>'

  12) String#word_wrap splits text with hiragana letters correctly
     Failure/Error: expect("まつもとさんは Rubyのおとうさん. ".word_wrap(10)).to eq ['まつもとさんは', 'Rubyのおとうさん.']
       
       expected: ["まつもとさんは", "Rubyのおとうさん."]
            got: [" まつもとさんは", "Rubyのおとうさん."]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmjijc/spec.rb:55: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)>'

  13) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
       
       expected: ["justonelongline", "here"]
            got: ["", "justonelongline", "here"]
       
       (compared using ==)
     # /tmp/d20141030-18133-1bmjijc/spec.rb:59: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.01515 seconds
15 examples, 13 failures

Failed examples:

rspec /tmp/d20141030-18133-1bmjijc/spec.rb:10 # String#word_wrap can split words given exact length
rspec /tmp/d20141030-18133-1bmjijc/spec.rb:14 # String#word_wrap correctly counts the whitespace between words
rspec /tmp/d20141030-18133-1bmjijc/spec.rb:18 # String#word_wrap can split words given more length
rspec /tmp/d20141030-18133-1bmjijc/spec.rb:22 # String#word_wrap splits on the nearest left whitespace
rspec /tmp/d20141030-18133-1bmjijc/spec.rb:26 # String#word_wrap can split more than once
rspec /tmp/d20141030-18133-1bmjijc/spec.rb:30 # String#word_wrap is not influenced by leading whitespace
rspec /tmp/d20141030-18133-1bmjijc/spec.rb:34 # String#word_wrap is not influenced by trailing whitespace
rspec /tmp/d20141030-18133-1bmjijc/spec.rb:38 # String#word_wrap ignores more than one whitespace between lines
rspec /tmp/d20141030-18133-1bmjijc/spec.rb:42 # String#word_wrap compacts whitespace inside lines
rspec /tmp/d20141030-18133-1bmjijc/spec.rb:46 # String#word_wrap keeps longer lines if it is a single word
rspec /tmp/d20141030-18133-1bmjijc/spec.rb:50 # String#word_wrap splits text with cyrillic correctly
rspec /tmp/d20141030-18133-1bmjijc/spec.rb:54 # String#word_wrap splits text with hiragana letters correctly
rspec /tmp/d20141030-18133-1bmjijc/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line
Станимир Митев
  • Некоректно
  • 5 успешни тест(а)
  • 10 неуспешни тест(а)
Станимир Митев
class String
def word_wrap(line_length)
return split(/\n/) if size == 0
strip!.squeeze!(" ")
while index(/\n/) != nil
self[index(/\n/)] = " "
end
position = 0
while position < size - line_length
position += line_length if position + line_length < size
self[rindex(" ",position)] = "\n" if rindex(" ",position) != nil
position = rindex(/\n/) + 1
end
split(/\n/)
end
end
..FFFFF..FFF.FF

Failures:

  1) String#word_wrap can split words given exact length
     Failure/Error: expect('one two'.word_wrap(3)).to eq ['one', 'two']
     NoMethodError:
       undefined method `squeeze!' for nil:NilClass
     # /tmp/d20141030-18133-11hc6ap/solution.rb:5:in `word_wrap'
     # /tmp/d20141030-18133-11hc6ap/spec.rb:11: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) String#word_wrap correctly counts the whitespace between words
     Failure/Error: expect('one word n two words'.word_wrap(9)).to eq ['one word', 'n two', 'words']
     NoMethodError:
       undefined method `squeeze!' for nil:NilClass
     # /tmp/d20141030-18133-11hc6ap/solution.rb:5:in `word_wrap'
     # /tmp/d20141030-18133-11hc6ap/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) String#word_wrap can split words given more length
     Failure/Error: expect('one two'.word_wrap(6)).to eq ['one', 'two']
     NoMethodError:
       undefined method `squeeze!' for nil:NilClass
     # /tmp/d20141030-18133-11hc6ap/solution.rb:5:in `word_wrap'
     # /tmp/d20141030-18133-11hc6ap/spec.rb:19: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) String#word_wrap splits on the nearest left whitespace
     Failure/Error: expect('point one two'.word_wrap(8)).to eq ['point', 'one two']
     NoMethodError:
       undefined method `squeeze!' for nil:NilClass
     # /tmp/d20141030-18133-11hc6ap/solution.rb:5:in `word_wrap'
     # /tmp/d20141030-18133-11hc6ap/spec.rb:23: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)>'

  5) String#word_wrap can split more than once
     Failure/Error: expect('point line parallelogram cube'.word_wrap(15)).to eq ['point line', 'parallelogram', 'cube']
     NoMethodError:
       undefined method `squeeze!' for nil:NilClass
     # /tmp/d20141030-18133-11hc6ap/solution.rb:5:in `word_wrap'
     # /tmp/d20141030-18133-11hc6ap/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)>'

  6) String#word_wrap ignores more than one whitespace between lines
     Failure/Error: expect("one    more   \n        string".word_wrap(7)).to eq ['one', 'more', 'string']
     NoMethodError:
       undefined method `squeeze!' for nil:NilClass
     # /tmp/d20141030-18133-11hc6ap/solution.rb:5:in `word_wrap'
     # /tmp/d20141030-18133-11hc6ap/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)>'

  7) String#word_wrap compacts whitespace inside lines
     Failure/Error: expect("one   more        string".word_wrap(12)).to eq ['one more', 'string']
     NoMethodError:
       undefined method `squeeze!' for nil:NilClass
     # /tmp/d20141030-18133-11hc6ap/solution.rb:5:in `word_wrap'
     # /tmp/d20141030-18133-11hc6ap/spec.rb:43: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)>'

  8) String#word_wrap keeps longer lines if it is a single word
     Failure/Error: expect("one more string".word_wrap(2)).to eq ['one', 'more', 'string']
     NoMethodError:
       undefined method `squeeze!' for nil:NilClass
     # /tmp/d20141030-18133-11hc6ap/solution.rb:5:in `word_wrap'
     # /tmp/d20141030-18133-11hc6ap/spec.rb:47: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)>'

  9) String#word_wrap splits text with hiragana letters correctly
     Failure/Error: expect("まつもとさんは Rubyのおとうさん. ".word_wrap(10)).to eq ['まつもとさんは', 'Rubyのおとうさん.']
     Timeout::Error:
       execution expired
     # /tmp/d20141030-18133-11hc6ap/solution.rb:10:in `word_wrap'
     # /tmp/d20141030-18133-11hc6ap/spec.rb:55: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)>'

  10) String#word_wrap allows lines longer than max line length if there is nowhere to break the line
     Failure/Error: expect('justonelongline here'.word_wrap(5)).to eq ['justonelongline', 'here']
     NoMethodError:
       undefined method `squeeze!' for nil:NilClass
     # /tmp/d20141030-18133-11hc6ap/solution.rb:5:in `word_wrap'
     # /tmp/d20141030-18133-11hc6ap/spec.rb:59: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 1.11 seconds
15 examples, 10 failures

Failed examples:

rspec /tmp/d20141030-18133-11hc6ap/spec.rb:10 # String#word_wrap can split words given exact length
rspec /tmp/d20141030-18133-11hc6ap/spec.rb:14 # String#word_wrap correctly counts the whitespace between words
rspec /tmp/d20141030-18133-11hc6ap/spec.rb:18 # String#word_wrap can split words given more length
rspec /tmp/d20141030-18133-11hc6ap/spec.rb:22 # String#word_wrap splits on the nearest left whitespace
rspec /tmp/d20141030-18133-11hc6ap/spec.rb:26 # String#word_wrap can split more than once
rspec /tmp/d20141030-18133-11hc6ap/spec.rb:38 # String#word_wrap ignores more than one whitespace between lines
rspec /tmp/d20141030-18133-11hc6ap/spec.rb:42 # String#word_wrap compacts whitespace inside lines
rspec /tmp/d20141030-18133-11hc6ap/spec.rb:46 # String#word_wrap keeps longer lines if it is a single word
rspec /tmp/d20141030-18133-11hc6ap/spec.rb:54 # String#word_wrap splits text with hiragana letters correctly
rspec /tmp/d20141030-18133-11hc6ap/spec.rb:58 # String#word_wrap allows lines longer than max line length if there is nowhere to break the line