Форматиране на низ

Краен срок
07.10.2014 23:59

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

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

Вашето първо предизвикателство е да помогнете на Весела, като напишете функцията format_string(string, width). Все още не сме казали как се дефинира функция в Ruby, но разчитаме на вашите умения да изровите тази информация.

Функцията трябва да приема непразен низ от символи string и естесвено число width, и го обработва по следния начин:

  1. Премахва интервалите в началото и края на низа, ако има такива.
  2. Редуцира всяка последователност от два или повече интервала между думите до един-единствен.
  3. Заменя всяка малка буква с главна.
  4. Центрира текста в поле с ширина width - допълва го поравно и от двете страни с интервали, така че дължината на низа да бъде равна на width. Това допълване се прави само ако дължината на текста след първите три стъпки е по-малка от параметъра width. Допълнително, ако width - дължината_на_низа_преди_центрирането е нечетно число, "нечетният" интервал трябва да се добави в края на низа.

Конвенцията # =>

Текстът след символа # е коментар. С конвенцията # => резултат в края на ред с код ще означаваме резултата, който се очаква след изпълнението на въпросния код.

Примери

format_string("run  FOrest   run!!", 20)            # => "  RUN FOREST RUN!!  "
format_string("  do YouR   homeWork   NoW    ", 10) # => "DO YOUR HOMEWORK NOW"
format_string("bacon", 6)                           # => "BACON "

Няма да ви подаваме некоректни данни за вход.

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

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

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

Решения

Камен Станев
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Камен Станев
def format_string(string, width)
return string
.strip()
.gsub(/ +/, ' ')
.upcase()
.center(width)
end
.......

Finished in 0.00641 seconds
7 examples, 0 failures
Емилиан Станков
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Емилиан Станков
def format_string(string, width)
result = string.split.join(" ").upcase
if result.length < width
result.prepend(" " * ((width - result.length) / 2).floor)
result << " " * ((width - result.length))
end
result
end
.......

Finished in 0.00654 seconds
7 examples, 0 failures
Йоана Тодорова
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Йоана Тодорова
def format_string(string, width)
string.strip.squeeze(" ").upcase.center(width)
end
.......

Finished in 0.00643 seconds
7 examples, 0 failures
Александър Александров
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Александров
def format_string (string,width)
string=string.strip.gsub(/\s+/," ").upcase.center(width)
end
.......

Finished in 0.00864 seconds
7 examples, 0 failures
Екатерина Горанова
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Екатерина Горанова
def format_string(string, width)
string.strip.gsub(/\s+/, " ").upcase.center(width)
end
.......

Finished in 0.00637 seconds
7 examples, 0 failures
Мартин Христов
  • Некоректно
  • 0 успешни тест(а)
  • 7 неуспешни тест(а)
Мартин Христов
def format_string(str, width)
no_spaces = str.gsub(/^\s\s*/, '').gsub(/\s\s*$/, '').gsub(/\s{2,}/, ' ')
upcase_word = no_spaces.upcase
if no_spaces.size < width
spaces = width - no_spaces.size
for i in 0..spaces-1
if i.odd?
upcase_word.insert 0, ' '
else
upcase_word.insert upcase_word.size, ' '
end
end
end
puts upcase_word
end
BACON!!
FBACON!!
FDO YOUR CHALLENGE NOW
FHASTA LA VISTA, BABY!
FODD 
F TRY HARDER! 
F   CHUNKY BACON!!   
F

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-jslqxd/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) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-jslqxd/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
       
       expected: "DO YOUR CHALLENGE NOW"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-jslqxd/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) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
       
       expected: "HASTA LA VISTA, BABY!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-jslqxd/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) format_string appends odd intervals at the end of the string when centering
     Failure/Error: expect(format_string('odd', 4)).to eq 'ODD '
       
       expected: "ODD "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-jslqxd/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) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
       
       expected: " TRY HARDER! "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-jslqxd/spec.rb:25: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) format_string works with already trimmed strings with greater width padding
     Failure/Error: expect(format_string('chunky   bacon!! ', 20)).to eq '   CHUNKY BACON!!   '
       
       expected: "   CHUNKY BACON!!   "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-jslqxd/spec.rb:30: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.00879 seconds
7 examples, 7 failures

Failed examples:

rspec /tmp/d20141008-29654-jslqxd/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-jslqxd/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-jslqxd/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-jslqxd/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-jslqxd/spec.rb:18 # format_string appends odd intervals at the end of the string when centering
rspec /tmp/d20141008-29654-jslqxd/spec.rb:24 # format_string centers strings properly when the length difference is even
rspec /tmp/d20141008-29654-jslqxd/spec.rb:29 # format_string works with already trimmed strings with greater width padding
Йоан Динков
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Йоан Динков
def format_string(input, width)
input = input.strip.squeeze(' ').upcase
if input.size < width
return input.center(width, ' ')
end
return input
end
.......

Finished in 0.00617 seconds
7 examples, 0 failures
Божидар Горов
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Божидар Горов
def format_string (str , width)
str = str.squeeze(" ").strip;
to_add = width - str.length;
if to_add > 0
num = to_add / 2.to_f;
left = num.floor;
right = num.ceil;
str = " " * left + str + " " * right;
end
str.upcase;
end
.......

Finished in 0.00643 seconds
7 examples, 0 failures
Константин Тодоров
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Константин Тодоров
def format_string(string, width)
unless string.nil?
while string[0] == ' ' do #1
string = string[1..-1]
end
while string[-1] == ' ' do
string = string[0..-2]
end
while string.include? ' ' do #2
string = string.sub ' ', ' '
end
string = string.upcase #3
while ((string.length) < width) do #4
string.insert -1, ' '
if ((string.length) < width)
string.insert 0, ' '
end
end
end
return string
end
.......

Finished in 0.00664 seconds
7 examples, 0 failures
Светлозар Тодоров
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Светлозар Тодоров
def format_string(string, width)
string.split.join(" ").upcase().center(width)
end
.......

Finished in 0.00617 seconds
7 examples, 0 failures
Атанас Димитров
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Атанас Димитров
def format_string(string, width)
string.strip.gsub(/\s\s+/, " ").upcase.center(width)
end
.......

Finished in 0.00635 seconds
7 examples, 0 failures
Божидар Григоров
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Божидар Григоров
def format_string(string, width)
string = string.gsub(/\s+/, " ").strip.upcase
whitespace = (width - string.length) / 2.0
puts whitespace
if whitespace > 0
if whitespace % 2 == 0
return((" " * whitespace) + string + (" " * whitespace))
else
return ((" " * whitespace.floor) + string + (" " * whitespace.ceil))
end
end
return string
end
-1.0
.-3.5
.-5.5
.-10.5
.0.5
1.5
2.5
.1.0
2.0
.3.0
.

Finished in 0.00737 seconds
7 examples, 0 failures
Елена Орешарова
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Елена Орешарова
def format_string(string, width)
string = string.strip.gsub(/\s+/, " ").upcase
if string.length < width then string.center(width) else string end
end
.......

Finished in 0.0067 seconds
7 examples, 0 failures
Атанас Цанков
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Атанас Цанков
def format_string(string, width)
string = string.strip.upcase.squeeze(" ")
string_length = string.length
if string_length < width
spaces_to_add_per_side = ((width - string_length) / 2)
space_to_add_at_end = ((width - string_length) % 2)
string.insert(0, " " * spaces_to_add_per_side)
string.insert(-1, " " * (spaces_to_add_per_side + space_to_add_at_end))
else
string
end
end
.......

Finished in 0.00623 seconds
7 examples, 0 failures
Кирил Кабакчиев
  • Некоректно
  • 6 успешни тест(а)
  • 1 неуспешни тест(а)
Кирил Кабакчиев
def format_string(string, width)
fixed_string = string.strip.gsub(/(\s|\u00A0)+/, ' ').upcase
if fixed_string.length < width
temp = fixed_string.length
if temp.odd?
fixed_string = fixed_string + " "
end
fixed_string = fixed_string.center(width)
end
return fixed_string
end
puts format_string("run FOrest run!!", 20) # => " RUN FOREST RUN!! "
puts format_string(" do YouR homeWork NoW ", 10) # => "DO YOUR HOMEWORK NOW"
puts format_string("bacon", 6) # => "BACON "
RUN FOREST RUN!!  
DO YOUR HOMEWORK NOW
BACON 
.....F.

Failures:

  1) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
       
       expected: " TRY HARDER! "
            got: "TRY HARDER!  "
       
       (compared using ==)
     # /tmp/d20141008-29654-z2xty0/spec.rb:25: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.00726 seconds
7 examples, 1 failure

Failed examples:

rspec /tmp/d20141008-29654-z2xty0/spec.rb:24 # format_string centers strings properly when the length difference is even
Снежана Спасова
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Снежана Спасова
def format_string(text, width)
text.strip.gsub(/\s{2,}/, " ").upcase.center width
end
.......

Finished in 0.00677 seconds
7 examples, 0 failures
Бисер Кръстев
  • Некоректно
  • 0 успешни тест(а)
  • 7 неуспешни тест(а)
Бисер Кръстев
def format_string(string, width)
string = string.strip
string = string.upcase
string = string.squeeze ' '
string = string.center width
print "\"#{ string }\"\n"
end
"BACON!!"
F"BACON!!"
F"DO YOUR CHALLENGE NOW"
F"HASTA LA VISTA, BABY!"
F"ODD "
F" TRY HARDER! "
F"   CHUNKY BACON!!   "
F

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-141yxcq/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) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-141yxcq/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
       
       expected: "DO YOUR CHALLENGE NOW"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-141yxcq/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) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
       
       expected: "HASTA LA VISTA, BABY!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-141yxcq/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) format_string appends odd intervals at the end of the string when centering
     Failure/Error: expect(format_string('odd', 4)).to eq 'ODD '
       
       expected: "ODD "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-141yxcq/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) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
       
       expected: " TRY HARDER! "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-141yxcq/spec.rb:25: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) format_string works with already trimmed strings with greater width padding
     Failure/Error: expect(format_string('chunky   bacon!! ', 20)).to eq '   CHUNKY BACON!!   '
       
       expected: "   CHUNKY BACON!!   "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-141yxcq/spec.rb:30: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.00716 seconds
7 examples, 7 failures

Failed examples:

rspec /tmp/d20141008-29654-141yxcq/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-141yxcq/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-141yxcq/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-141yxcq/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-141yxcq/spec.rb:18 # format_string appends odd intervals at the end of the string when centering
rspec /tmp/d20141008-29654-141yxcq/spec.rb:24 # format_string centers strings properly when the length difference is even
rspec /tmp/d20141008-29654-141yxcq/spec.rb:29 # format_string works with already trimmed strings with greater width padding
Георги Буюклиев
  • Некоректно
  • 0 успешни тест(а)
  • 7 неуспешни тест(а)
Георги Буюклиев
def format_string(string, width)
string = string.strip
string = string.gsub(/\s+/, ' ')
string = string.upcase
if (width - string.length)%2 == 0
string = string.center(width)
else
string = string.center(width - 1)
string = string.insert(width - 1, ' ')
end
print string
end
BACON!!FBACON!! FDO YOUR C HALLENGE NOWFHASTA LA VISTA, BABY! FODD F TRY HARDER! F   CHUNKY BACON!!   F

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1gnhddc/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) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1gnhddc/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
       
       expected: "DO YOUR CHALLENGE NOW"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1gnhddc/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) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
       
       expected: "HASTA LA VISTA, BABY!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1gnhddc/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) format_string appends odd intervals at the end of the string when centering
     Failure/Error: expect(format_string('odd', 4)).to eq 'ODD '
       
       expected: "ODD "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1gnhddc/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) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
       
       expected: " TRY HARDER! "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1gnhddc/spec.rb:25: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) format_string works with already trimmed strings with greater width padding
     Failure/Error: expect(format_string('chunky   bacon!! ', 20)).to eq '   CHUNKY BACON!!   '
       
       expected: "   CHUNKY BACON!!   "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1gnhddc/spec.rb:30: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.00706 seconds
7 examples, 7 failures

Failed examples:

rspec /tmp/d20141008-29654-1gnhddc/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-1gnhddc/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-1gnhddc/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-1gnhddc/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-1gnhddc/spec.rb:18 # format_string appends odd intervals at the end of the string when centering
rspec /tmp/d20141008-29654-1gnhddc/spec.rb:24 # format_string centers strings properly when the length difference is even
rspec /tmp/d20141008-29654-1gnhddc/spec.rb:29 # format_string works with already trimmed strings with greater width padding
Методи Димитров
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Методи Димитров
def format_string(string, width)
string.strip
.gsub(/ +/, ' ')
.center(width)
.upcase
end
.......

Finished in 0.00673 seconds
7 examples, 0 failures
Евгений Бояджиев
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Евгений Бояджиев
def format_string(text, width)
# 1) Remove spaces from begining and the end
# and save the text value in a new variable just in case
format_text = text.strip
# 2) Replace the multiple spaces with just one
format_text = format_text.gsub(/\s+/, ' ')
# 3) Make all letters uppercase
format_text.upcase!
# 4) Add spaces in the begining and end if the string is too short.
# The number of space on both sides must be either equal or one more on the right side
text_length = format_text.length
if text_length < width
remaining = width - text_length
left = (remaining / 2).floor
right = remaining - left
format_text = (' ' * left) + format_text + (' ' * right)
end
# 5) We're done. Return the result
return format_text
end
.......

Finished in 0.0077 seconds
7 examples, 0 failures
Явор Михайлов
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Явор Михайлов
def format_string string, width
# Strip
string = string.strip
# Upcase
string = string.upcase
# Remove Intervals
# Solution 1
string = string.split.join ' '
# Solution 2
# string_arr = string.scan(/\w+/)
# string = string_arr.join ' '
# Solution 3
#string = string.squeeze ' '
# Center
string = string.center width
end
.......

Finished in 0.00934 seconds
7 examples, 0 failures
Венцислав Димитров
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Венцислав Димитров
def format_string(str, w)
result = str.strip
result = result.gsub(/ +/, ' ')
result = result.upcase
spaces = (w.to_f - result.length)/2
spaces = 0 if spaces < 0
result = (' ' * spaces.floor) + result + (' ' * spaces.ceil)
end
.......

Finished in 0.00757 seconds
7 examples, 0 failures
Ангел Ангелов
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Ангел Ангелов
def format_string(string, width)
string.strip().squeeze(' ').upcase().center(width)
end
.......

Finished in 0.00621 seconds
7 examples, 0 failures
Яни Малцев
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Яни Малцев
def format_string(string, width)
string1=string.strip.gsub(/\s+/, ' ')
string1=string1.upcase
string1=string1.center(width)
return string1
end
.......

Finished in 0.00635 seconds
7 examples, 0 failures
Мария Дулева
  • Некоректно
  • 4 успешни тест(а)
  • 3 неуспешни тест(а)
Мария Дулева
def format_string(string,width)
string.squeeze!(" ").upcase!
string.slice!(0) if string.start_with?(" ")
string.chop! if string.end_with?(" ")
string=string.center(width)
end
F...FF.

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
     NoMethodError:
       undefined method `upcase!' for nil:NilClass
     # /tmp/d20141008-29654-1w9imw2/solution.rb:2:in `format_string'
     # /tmp/d20141008-29654-1w9imw2/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) format_string appends odd intervals at the end of the string when centering
     Failure/Error: expect(format_string('odd', 4)).to eq 'ODD '
     NoMethodError:
       undefined method `upcase!' for nil:NilClass
     # /tmp/d20141008-29654-1w9imw2/solution.rb:2:in `format_string'
     # /tmp/d20141008-29654-1w9imw2/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) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
     NoMethodError:
       undefined method `upcase!' for nil:NilClass
     # /tmp/d20141008-29654-1w9imw2/solution.rb:2:in `format_string'
     # /tmp/d20141008-29654-1w9imw2/spec.rb:25: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.00625 seconds
7 examples, 3 failures

Failed examples:

rspec /tmp/d20141008-29654-1w9imw2/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-1w9imw2/spec.rb:18 # format_string appends odd intervals at the end of the string when centering
rspec /tmp/d20141008-29654-1w9imw2/spec.rb:24 # format_string centers strings properly when the length difference is even
Иван Станков
  • Некоректно
  • 0 успешни тест(а)
  • 7 неуспешни тест(а)
Иван Станков
def format_string(string, width)
removeBlanksInTheEnds(string)
removeConsecutiveBlanks(string)
insertMoreBlanks(string, width)
string = string.upcase
puts string
end
def removeBlanksInTheEnds(string)
while string[0] == ' ' or string[string.length - 1] == ' '
if string[0] == ' ' then
string[0] = ''
end
if string[string.length-1] == ' ' then
string[string.length-1] = ''
end
end
end
def removeConsecutiveBlanks(string)
for i in 0..string.length
while string[i]==" " and string[i+1]==" "
string[i]=""
end
end
end
def insertMoreBlanks(string, width)
while string.length < width
if string.length % 2 == 1
string.insert (string.length), " "
else
string.insert 0, " "
end
end
end
format_string("bacon", 6)
format_string(" do YouR homeWork NoW ", 10)
format_string(" run FOrest run!!", 20)
format_string(" nqkyv test da vidim ",14)
format_string(" drug test za da sme sigurni ", 30)
BACON 
DO YOUR HOMEWORK NOW
  RUN FOREST RUN!!  
NQKYV TEST DA VIDIM
 DRUG TEST ZA DA SME SIGURNI  
BACON!!
FBACON!!
FDO YOUR CHALLENGE NOW
FHASTA LA VISTA, BABY!
FODD 
F TRY HARDER! 
F   CHUNKY BACON!!   
F

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1nudtum/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) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1nudtum/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
       
       expected: "DO YOUR CHALLENGE NOW"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1nudtum/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) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
       
       expected: "HASTA LA VISTA, BABY!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1nudtum/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) format_string appends odd intervals at the end of the string when centering
     Failure/Error: expect(format_string('odd', 4)).to eq 'ODD '
       
       expected: "ODD "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1nudtum/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) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
       
       expected: " TRY HARDER! "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1nudtum/spec.rb:25: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) format_string works with already trimmed strings with greater width padding
     Failure/Error: expect(format_string('chunky   bacon!! ', 20)).to eq '   CHUNKY BACON!!   '
       
       expected: "   CHUNKY BACON!!   "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1nudtum/spec.rb:30: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.00727 seconds
7 examples, 7 failures

Failed examples:

rspec /tmp/d20141008-29654-1nudtum/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-1nudtum/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-1nudtum/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-1nudtum/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-1nudtum/spec.rb:18 # format_string appends odd intervals at the end of the string when centering
rspec /tmp/d20141008-29654-1nudtum/spec.rb:24 # format_string centers strings properly when the length difference is even
rspec /tmp/d20141008-29654-1nudtum/spec.rb:29 # format_string works with already trimmed strings with greater width padding
Калин Христов
  • Некоректно
  • 0 успешни тест(а)
  • 7 неуспешни тест(а)
Калин Христов
def format_string(string, width)
str = string.upcase()
str = str.gsub(/\s+/, " ").strip
str = str.center(width,' ')
puts str
end
BACON!!
FBACON!!
FDO YOUR CHALLENGE NOW
FHASTA LA VISTA, BABY!
FODD 
F TRY HARDER! 
F   CHUNKY BACON!!   
F

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-11o95z2/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) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-11o95z2/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
       
       expected: "DO YOUR CHALLENGE NOW"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-11o95z2/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) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
       
       expected: "HASTA LA VISTA, BABY!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-11o95z2/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) format_string appends odd intervals at the end of the string when centering
     Failure/Error: expect(format_string('odd', 4)).to eq 'ODD '
       
       expected: "ODD "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-11o95z2/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) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
       
       expected: " TRY HARDER! "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-11o95z2/spec.rb:25: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) format_string works with already trimmed strings with greater width padding
     Failure/Error: expect(format_string('chunky   bacon!! ', 20)).to eq '   CHUNKY BACON!!   '
       
       expected: "   CHUNKY BACON!!   "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-11o95z2/spec.rb:30: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.00724 seconds
7 examples, 7 failures

Failed examples:

rspec /tmp/d20141008-29654-11o95z2/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-11o95z2/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-11o95z2/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-11o95z2/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-11o95z2/spec.rb:18 # format_string appends odd intervals at the end of the string when centering
rspec /tmp/d20141008-29654-11o95z2/spec.rb:24 # format_string centers strings properly when the length difference is even
rspec /tmp/d20141008-29654-11o95z2/spec.rb:29 # format_string works with already trimmed strings with greater width padding
Александър Петков
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Петков
def format_string(string, width)
core_string = string.strip.gsub(/\s+/, ' ').upcase
core_length = core_string.length
if width < core_length
return core_string
else
total_spaces_count = width - core_length
left_spaces = total_spaces_count / 2
right_spaces = total_spaces_count - left_spaces
padded_string = ' ' * left_spaces + core_string + ' ' * right_spaces
return padded_string
end
end
.......

Finished in 0.00639 seconds
7 examples, 0 failures
Дамян Димитров
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Дамян Димитров
def format_string(string, width)
string.squeeze(' ').strip.upcase.center(width, ' ')
end
.......

Finished in 0.0082 seconds
7 examples, 0 failures
Диана Генева
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Диана Генева
def format_string(string, width)
string.strip.squeeze(" ").upcase.center(width," ")
end
.......

Finished in 0.00658 seconds
7 examples, 0 failures
Пламен Каращранов
  • Некоректно
  • 0 успешни тест(а)
  • 0 неуспешни тест(а)
Пламен Каращранов
def format_string (string,width)
text=string.split
my_string=""
text.each {|x| my_string<<x+" "}
retun my_string.rstrip.upcase.center(width)
end
format_string("bacon", 6) # =>"BACON "
/tmp/d20141008-29654-7elqct/solution.rb:5:in `format_string': undefined method `retun' for main:Object (NoMethodError)
	from /tmp/d20141008-29654-7elqct/solution.rb:7:in `<top (required)>'
	from /data/rails/evans-2014/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:867:in `require'
	from /data/rails/evans-2014/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:867:in `block in setup_load_path_and_require'
	from /data/rails/evans-2014/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:867:in `each'
	from /data/rails/evans-2014/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:867:in `setup_load_path_and_require'
	from /data/rails/evans-2014/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration_options.rb:25:in `configure'
	from /data/rails/evans-2014/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:21:in `run'
	from /data/rails/evans-2014/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:80:in `run'
	from /data/rails/evans-2014/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'
Теодор Драганов
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Теодор Драганов
def format_string(string, width)
string = string.split.join(" ")
string = string.upcase
string = string.center(width)
return string
end
.......

Finished in 0.00645 seconds
7 examples, 0 failures
Деян Гюрджеклиев
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Деян Гюрджеклиев
def format_string(string, width)
string.strip.squeeze(" ").upcase.center(width," ")
end
.......

Finished in 0.00639 seconds
7 examples, 0 failures
Симеон Цветков
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Симеон Цветков
def format_string(string, width)
string.strip!
string = string.gsub(/\s+/, " ").strip
string.upcase!
string = string.center(width)
end
.......

Finished in 0.00639 seconds
7 examples, 0 failures
Цветелина Борисова
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Цветелина Борисова
def format_string(string, width)
string.strip.squeeze(' ').upcase.center(width)
end
.......

Finished in 0.00629 seconds
7 examples, 0 failures
София Петрова
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
София Петрова
def format_string(string,width)
return string.strip.squeeze(" ").upcase.center(width)
end
.......

Finished in 0.0063 seconds
7 examples, 0 failures
Веселин Русинов
  • Некоректно
  • 0 успешни тест(а)
  • 7 неуспешни тест(а)
Веселин Русинов
def format_text text, width
text = text.strip! unless text.strip
if (width - text.length) % 2 == 0
multiplier = (width - text.length) / 2
empty_text = " " * multiplier
text = empty_text + text + empty_text
else
multiplier = width - text.length
empty_text = " " * multiplier
text = text + empty_text
end
text.upcase
end
FFFFFFF

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
     NoMethodError:
       undefined method `format_string' for #<RSpec::Core::ExampleGroup::Nested_1:0xb8854d4c>
     # /tmp/d20141008-29654-5a0ic2/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) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
     NoMethodError:
       undefined method `format_string' for #<RSpec::Core::ExampleGroup::Nested_1:0xb884fcc0>
     # /tmp/d20141008-29654-5a0ic2/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
     NoMethodError:
       undefined method `format_string' for #<RSpec::Core::ExampleGroup::Nested_1:0xb884d86c>
     # /tmp/d20141008-29654-5a0ic2/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) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
     NoMethodError:
       undefined method `format_string' for #<RSpec::Core::ExampleGroup::Nested_1:0xb8847e94>
     # /tmp/d20141008-29654-5a0ic2/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) format_string appends odd intervals at the end of the string when centering
     Failure/Error: expect(format_string('odd', 4)).to eq 'ODD '
     NoMethodError:
       undefined method `format_string' for #<RSpec::Core::ExampleGroup::Nested_1:0xb8846d8c>
     # /tmp/d20141008-29654-5a0ic2/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) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
     NoMethodError:
       undefined method `format_string' for #<RSpec::Core::ExampleGroup::Nested_1:0xb8845eb4>
     # /tmp/d20141008-29654-5a0ic2/spec.rb:25: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) format_string works with already trimmed strings with greater width padding
     Failure/Error: expect(format_string('chunky   bacon!! ', 20)).to eq '   CHUNKY BACON!!   '
     NoMethodError:
       undefined method `format_string' for #<RSpec::Core::ExampleGroup::Nested_1:0xb8844f78>
     # /tmp/d20141008-29654-5a0ic2/spec.rb:30: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.00528 seconds
7 examples, 7 failures

Failed examples:

rspec /tmp/d20141008-29654-5a0ic2/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-5a0ic2/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-5a0ic2/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-5a0ic2/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-5a0ic2/spec.rb:18 # format_string appends odd intervals at the end of the string when centering
rspec /tmp/d20141008-29654-5a0ic2/spec.rb:24 # format_string centers strings properly when the length difference is even
rspec /tmp/d20141008-29654-5a0ic2/spec.rb:29 # format_string works with already trimmed strings with greater width padding
Георги Железов
  • Некоректно
  • 0 успешни тест(а)
  • 7 неуспешни тест(а)
Георги Железов
def format_string(string, width)
strings = string.lstrip.rstrip.gsub(/\s+/, " ")
strLen = strings.size
if strLen % 2 == 0
puts strings.center(width).upcase
else
width - strLen
puts strings.ljust(width).upcase
end
end
format_string("run FOrest run!!", 20);
format_string(" do YouR homeWork NoW ", 10);
format_string("bacon", 6);
RUN FOREST RUN!!  
DO YOUR HOMEWORK NOW
BACON 
BACON!!
FBACON!!
FDO YOUR CHALLENGE NOW
FHASTA LA VISTA, BABY!
FODD 
FTRY HARDER!  
F   CHUNKY BACON!!   
F

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-g44qrv/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) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-g44qrv/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
       
       expected: "DO YOUR CHALLENGE NOW"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-g44qrv/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) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
       
       expected: "HASTA LA VISTA, BABY!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-g44qrv/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) format_string appends odd intervals at the end of the string when centering
     Failure/Error: expect(format_string('odd', 4)).to eq 'ODD '
       
       expected: "ODD "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-g44qrv/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) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
       
       expected: " TRY HARDER! "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-g44qrv/spec.rb:25: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) format_string works with already trimmed strings with greater width padding
     Failure/Error: expect(format_string('chunky   bacon!! ', 20)).to eq '   CHUNKY BACON!!   '
       
       expected: "   CHUNKY BACON!!   "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-g44qrv/spec.rb:30: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.00725 seconds
7 examples, 7 failures

Failed examples:

rspec /tmp/d20141008-29654-g44qrv/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-g44qrv/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-g44qrv/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-g44qrv/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-g44qrv/spec.rb:18 # format_string appends odd intervals at the end of the string when centering
rspec /tmp/d20141008-29654-g44qrv/spec.rb:24 # format_string centers strings properly when the length difference is even
rspec /tmp/d20141008-29654-g44qrv/spec.rb:29 # format_string works with already trimmed strings with greater width padding
Георги Костов
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Костов
def format_string_help(string)
if string.empty?
puts "Empty string"
exit -1
end
if string.end_with? ' '
return format_string_help(string.rstrip.upcase)
elsif string.start_with? ' '
return format_string_help(string.lstrip.upcase)
else
return string.upcase
end
end
def magic(string)
if string.include? ' '
return magic(string.gsub(' ', ' '))
else
return string
end
end
def format_string(string, width)
string1=magic(format_string_help(string))
if string1.length < width
division = (width - string1.length).to_f
left = (division/2).floor
right = (division/2).ceil
return (' ' * left) + string1 + (' ' * right)
else
return string1
end
end
.......

Finished in 0.007 seconds
7 examples, 0 failures
Герасим Станчев
  • Некоректно
  • 1 успешни тест(а)
  • 6 неуспешни тест(а)
Герасим Станчев
def format_string(string, width)
string = string.strip.split.join(' ').upcase
spaceCounter = string.length
if spaceCounter < width
((width - spaceCounter) / 2).times { string.insert(0, ' '); string.insert(string.length, ' ')}
end
if string.length % 2 == 1
string.insert(string.length, ' ')
end
return string
end
FFFFFF.

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: "BACON!! "
       
       (compared using ==)
     # /tmp/d20141008-29654-1kfj62a/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) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: "BACON!! "
       
       (compared using ==)
     # /tmp/d20141008-29654-1kfj62a/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
       
       expected: "DO YOUR CHALLENGE NOW"
            got: "DO YOUR CHALLENGE NOW "
       
       (compared using ==)
     # /tmp/d20141008-29654-1kfj62a/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) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
       
       expected: "HASTA LA VISTA, BABY!"
            got: "HASTA LA VISTA, BABY! "
       
       (compared using ==)
     # /tmp/d20141008-29654-1kfj62a/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) format_string appends odd intervals at the end of the string when centering
     Failure/Error: expect(format_string('odds', 7)).to eq ' ODDS  '
       
       expected: " ODDS  "
            got: " ODDS "
       
       (compared using ==)
     # /tmp/d20141008-29654-1kfj62a/spec.rb:20: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) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
       
       expected: " TRY HARDER! "
            got: " TRY HARDER!  "
       
       (compared using ==)
     # /tmp/d20141008-29654-1kfj62a/spec.rb:25: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.00702 seconds
7 examples, 6 failures

Failed examples:

rspec /tmp/d20141008-29654-1kfj62a/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-1kfj62a/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-1kfj62a/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-1kfj62a/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-1kfj62a/spec.rb:18 # format_string appends odd intervals at the end of the string when centering
rspec /tmp/d20141008-29654-1kfj62a/spec.rb:24 # format_string centers strings properly when the length difference is even
Ивайло Георгиев
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Ивайло Георгиев
def format_string(string, width)
return string.strip.upcase.gsub(/ +/, ' ').center(width, " ")
end
.......

Finished in 0.00642 seconds
7 examples, 0 failures
Станимир Митев
  • Некоректно
  • 2 успешни тест(а)
  • 5 неуспешни тест(а)
Станимир Митев
def format_string(string, width)
string.strip!
string.squeeze!(" ")
string.upcase!
if string.length % 2 == 1
string << " "
end
if string.length < width
return string.center(width)
end
return string
end
FFFF.F.

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: "BACON!! "
       
       (compared using ==)
     # /tmp/d20141008-29654-1vighvm/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) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: "BACON!! "
       
       (compared using ==)
     # /tmp/d20141008-29654-1vighvm/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
       
       expected: "DO YOUR CHALLENGE NOW"
            got: "DO YOUR CHALLENGE NOW "
       
       (compared using ==)
     # /tmp/d20141008-29654-1vighvm/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) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
       
       expected: "HASTA LA VISTA, BABY!"
            got: "HASTA LA VISTA, BABY! "
       
       (compared using ==)
     # /tmp/d20141008-29654-1vighvm/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) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
       
       expected: " TRY HARDER! "
            got: "TRY HARDER!  "
       
       (compared using ==)
     # /tmp/d20141008-29654-1vighvm/spec.rb:25: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.00673 seconds
7 examples, 5 failures

Failed examples:

rspec /tmp/d20141008-29654-1vighvm/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-1vighvm/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-1vighvm/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-1vighvm/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-1vighvm/spec.rb:24 # format_string centers strings properly when the length difference is even
Светлозар Стефанов
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Светлозар Стефанов
def format_string(string, width)
if(string.length==0)
return
end
string = string.strip.squeeze(" ").upcase.center(width)
end
puts format_string("run FOrest run!!", 20) # => " RUN FOREST RUN!! "
puts format_string(" do YouR homeWork NoW ", 10) # => "DO YOUR HOMEWORK NOW"
puts format_string("bacon", 6) # => "BACON "
RUN FOREST RUN!!  
DO YOUR HOMEWORK NOW
BACON 
.......

Finished in 0.00627 seconds
7 examples, 0 failures
Светослав Кръстев
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Светослав Кръстев
def format_string(str, width)
return str.lstrip.rstrip.split.join(" ").upcase.center(width)
end
.......

Finished in 0.00877 seconds
7 examples, 0 failures
Даяна Маринова
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Даяна Маринова
def format_string(string, width)
if width.integer? and !string.empty?
string.strip.squeeze(" ").upcase.center(width)
end
end
.......

Finished in 0.00641 seconds
7 examples, 0 failures
Филипа Петкова
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Филипа Петкова
def format_string(string, width)
stripping = string.strip
spacing = stripping.gsub(/\s+/, " ")
uppercase = spacing.upcase
if (width - uppercase.length) % 2 == 1
then uppercase + " "
end
if uppercase.length < width
centered = uppercase.center(width)
return "#{centered}"
else
return "#{uppercase}"
end
end
.......

Finished in 0.00643 seconds
7 examples, 0 failures
Николина Гюрова
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Николина Гюрова
def format_string(string, width)
string.strip.squeeze(" ").upcase.center(width)
end
.......

Finished in 0.00624 seconds
7 examples, 0 failures
Вера Бойчева
  • Некоректно
  • 2 успешни тест(а)
  • 5 неуспешни тест(а)
Вера Бойчева
def format_string( string, width)
string = string.strip
string = string.split.join(" ")
string = string.upcase()
len=string.length
if len%2 != 0
string = string + " "
width = width-1
else
string = string
end
if len < width
string = string.center(width)
else
string = string
end
end
FFFF.F.

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: "BACON!! "
       
       (compared using ==)
     # /tmp/d20141008-29654-krkmks/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) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: "BACON!! "
       
       (compared using ==)
     # /tmp/d20141008-29654-krkmks/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
       
       expected: "DO YOUR CHALLENGE NOW"
            got: "DO YOUR CHALLENGE NOW "
       
       (compared using ==)
     # /tmp/d20141008-29654-krkmks/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) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
       
       expected: "HASTA LA VISTA, BABY!"
            got: "HASTA LA VISTA, BABY! "
       
       (compared using ==)
     # /tmp/d20141008-29654-krkmks/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) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
       
       expected: " TRY HARDER! "
            got: "TRY HARDER! "
       
       (compared using ==)
     # /tmp/d20141008-29654-krkmks/spec.rb:25: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.00873 seconds
7 examples, 5 failures

Failed examples:

rspec /tmp/d20141008-29654-krkmks/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-krkmks/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-krkmks/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-krkmks/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-krkmks/spec.rb:24 # format_string centers strings properly when the length difference is even
Иван Кавалджиев
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Кавалджиев
def format_string(string, width)
string.strip.squeeze(" ").upcase.center(width)
end
.......

Finished in 0.00623 seconds
7 examples, 0 failures
Веселин Добрев
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Веселин Добрев
def format_string(s, width)
s = s.strip.upcase.gsub(/\s+/, ' ').center(width, ' ')
end
.......

Finished in 0.00638 seconds
7 examples, 0 failures
Гюлджан Купен
  • Некоректно
  • 1 успешни тест(а)
  • 6 неуспешни тест(а)
Гюлджан Купен
def format_string(string, width)
string.strip
string.squeeze(" ")
string.upcase
string.center(width)
end
.FFFFFF

Failures:

  1) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: "     BACON!!  "
       
       (compared using ==)
     # /tmp/d20141008-29654-1q1z0wh/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
       
       expected: "DO YOUR CHALLENGE NOW"
            got: "  do YouR   challengE   NoW    "
       
       (compared using ==)
     # /tmp/d20141008-29654-1q1z0wh/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)>'

  3) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
       
       expected: "HASTA LA VISTA, BABY!"
            got: " HAstA    LA vista,     bAbY!      "
       
       (compared using ==)
     # /tmp/d20141008-29654-1q1z0wh/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)>'

  4) format_string appends odd intervals at the end of the string when centering
     Failure/Error: expect(format_string('odd', 4)).to eq 'ODD '
       
       expected: "ODD "
            got: "odd "
       
       (compared using ==)
     # /tmp/d20141008-29654-1q1z0wh/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)>'

  5) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
       
       expected: " TRY HARDER! "
            got: " try harder! "
       
       (compared using ==)
     # /tmp/d20141008-29654-1q1z0wh/spec.rb:25: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) format_string works with already trimmed strings with greater width padding
     Failure/Error: expect(format_string('chunky   bacon!! ', 20)).to eq '   CHUNKY BACON!!   '
       
       expected: "   CHUNKY BACON!!   "
            got: " chunky   bacon!!   "
       
       (compared using ==)
     # /tmp/d20141008-29654-1q1z0wh/spec.rb:30: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.00689 seconds
7 examples, 6 failures

Failed examples:

rspec /tmp/d20141008-29654-1q1z0wh/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-1q1z0wh/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-1q1z0wh/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-1q1z0wh/spec.rb:18 # format_string appends odd intervals at the end of the string when centering
rspec /tmp/d20141008-29654-1q1z0wh/spec.rb:24 # format_string centers strings properly when the length difference is even
rspec /tmp/d20141008-29654-1q1z0wh/spec.rb:29 # format_string works with already trimmed strings with greater width padding
Георги Павлов
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Павлов
def format_string(string, width)
string.strip.split.join(' ').upcase.center(width)
end
.......

Finished in 0.00633 seconds
7 examples, 0 failures
Габриела Лухова
  • Некоректно
  • 1 успешни тест(а)
  • 6 неуспешни тест(а)
Габриела Лухова
def format_string (string, width)
string.squeeze.strip.upcase.center(width)
end
FFF.FFF

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: "BACON!"
       
       (compared using ==)
     # /tmp/d20141008-29654-1y780z2/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) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: "BACON!"
       
       (compared using ==)
     # /tmp/d20141008-29654-1y780z2/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
       
       expected: "DO YOUR CHALLENGE NOW"
            got: "DO YOUR CHALENGE NOW"
       
       (compared using ==)
     # /tmp/d20141008-29654-1y780z2/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) format_string appends odd intervals at the end of the string when centering
     Failure/Error: expect(format_string('odd', 4)).to eq 'ODD '
       
       expected: "ODD "
            got: " OD "
       
       (compared using ==)
     # /tmp/d20141008-29654-1y780z2/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)>'

  5) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('  Run  FOrest   run!!', 20)).to eq '  RUN FOREST RUN!!  '
       
       expected: "  RUN FOREST RUN!!  "
            got: "  RUN FOREST RUN!   "
       
       (compared using ==)
     # /tmp/d20141008-29654-1y780z2/spec.rb:26: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) format_string works with already trimmed strings with greater width padding
     Failure/Error: expect(format_string('chunky   bacon!! ', 20)).to eq '   CHUNKY BACON!!   '
       
       expected: "   CHUNKY BACON!!   "
            got: "   CHUNKY BACON!    "
       
       (compared using ==)
     # /tmp/d20141008-29654-1y780z2/spec.rb:30: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.00687 seconds
7 examples, 6 failures

Failed examples:

rspec /tmp/d20141008-29654-1y780z2/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-1y780z2/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-1y780z2/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-1y780z2/spec.rb:18 # format_string appends odd intervals at the end of the string when centering
rspec /tmp/d20141008-29654-1y780z2/spec.rb:24 # format_string centers strings properly when the length difference is even
rspec /tmp/d20141008-29654-1y780z2/spec.rb:29 # format_string works with already trimmed strings with greater width padding
Георги Димов
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Димов
def format_string(string, width)
string = string.strip
string = string.gsub( /\s+/, " ")
string = string.upcase
if string.length < width
string = string.center(width)
end
return string
end
.......

Finished in 0.00626 seconds
7 examples, 0 failures
Любомир Иванов
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Любомир Иванов
def format_string(text_to_format, width)
editted = text_to_format.upcase();
editted = editted.gsub(/\s+/, ' ');
editted = editted.strip();
editted = editted.center(width);
return editted;
end
.......

Finished in 0.00638 seconds
7 examples, 0 failures
Константин Димитров
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Константин Димитров
def format_string(string, width=0)
string.strip.gsub(/\s+/, " ").upcase.center(width)
end
.......

Finished in 0.00637 seconds
7 examples, 0 failures
Здравко Георгиев
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Здравко Георгиев
def format_string(string, width)
string.gsub(/\s+/, " ").strip.upcase.center(width)
end
.......

Finished in 0.00678 seconds
7 examples, 0 failures
Любомир Папазов
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Любомир Папазов
def format_string(string, width)
string.lstrip.rstrip.upcase.gsub(/\s+/, ' ').center(width)
#lstrip and rstrip remove empty entries
#gsub shrinks interval to one space only
#.center method does the fourth part of the task
end
puts format_string("bacon", 6)
BACON 
.......

Finished in 0.0065 seconds
7 examples, 0 failures
Стилиян Стоянов
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Стилиян Стоянов
def format_string(string, width)
string.strip().split().join(" ").upcase.center(width)
end
.......

Finished in 0.00641 seconds
7 examples, 0 failures
Нели Василева
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Нели Василева
def format_string(str, width)
if !str.nil?
str = str.tr_s(' ', ' ').strip.upcase.center(width)
end
return str
end
.......

Finished in 0.00653 seconds
7 examples, 0 failures
Симеон Мартев
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Симеон Мартев
def format_string(string, width)
frmt_str = string.strip.upcase.squeeze(' ')
if frmt_str.size < width
spaces = width - frmt_str.size
spaces.times { |n| n.even? ? frmt_str.insert(-1,' ') : frmt_str.insert(0, ' ') }
frmt_str
end
frmt_str
end
.......

Finished in 0.00632 seconds
7 examples, 0 failures
Стамо Гочев
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Стамо Гочев
def format_string(string, width)
stripped_text = string.strip.split(' ').map.with_index {|w,i|
/^[^a-zA-z]*[a-zA-Z]+.+$/.match(w) ? w.upcase : w }.join(' ')
aligned_text = stripped_text.center(width)
end
.......

Finished in 0.01411 seconds
7 examples, 0 failures
Кристиан Цветков
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Кристиан Цветков
def format_string(string, width)
uncentered = string.strip.split(" ").each{|x| x.strip}.join(" ").upcase
length = uncentered.length
mid = width - length
l_fluff = length + mid/2
r_fluff = length + 2*(mid/2) + mid%2
uncentered.rjust(l_fluff).ljust(r_fluff)
end
.......

Finished in 0.00809 seconds
7 examples, 0 failures
Петя Петрова
  • Некоректно
  • 0 успешни тест(а)
  • 7 неуспешни тест(а)
Петя Петрова
def format_string(string, width)
string = string.strip
string = string.gsub(/\s{2,}/, ' ')
string = string.upcase
num_of_sur_white = width - string.length
if num_of_sur_white > 0
left = num_of_sur_white / 2
right = num_of_sur_white / 2 + num_of_sur_white % 2
left_arr = Array.new(left, ' ')
right_arr = Array.new(right, ' ')
string.insert(0,left_arr.join)
string << right_arr.join
end
puts "\"#{string}\""
end
"BACON!!"
F"BACON!!"
F"DO YOUR CHALLENGE NOW"
F"HASTA LA VISTA, BABY!"
F"ODD "
F" TRY HARDER! "
F"   CHUNKY BACON!!   "
F

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-loo9qi/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) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-loo9qi/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
       
       expected: "DO YOUR CHALLENGE NOW"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-loo9qi/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) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
       
       expected: "HASTA LA VISTA, BABY!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-loo9qi/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) format_string appends odd intervals at the end of the string when centering
     Failure/Error: expect(format_string('odd', 4)).to eq 'ODD '
       
       expected: "ODD "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-loo9qi/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) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
       
       expected: " TRY HARDER! "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-loo9qi/spec.rb:25: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) format_string works with already trimmed strings with greater width padding
     Failure/Error: expect(format_string('chunky   bacon!! ', 20)).to eq '   CHUNKY BACON!!   '
       
       expected: "   CHUNKY BACON!!   "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-loo9qi/spec.rb:30: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.01013 seconds
7 examples, 7 failures

Failed examples:

rspec /tmp/d20141008-29654-loo9qi/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-loo9qi/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-loo9qi/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-loo9qi/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-loo9qi/spec.rb:18 # format_string appends odd intervals at the end of the string when centering
rspec /tmp/d20141008-29654-loo9qi/spec.rb:24 # format_string centers strings properly when the length difference is even
rspec /tmp/d20141008-29654-loo9qi/spec.rb:29 # format_string works with already trimmed strings with greater width padding
Стефан Чипилов
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Стефан Чипилов
def format_string(string, width)
string.strip.upcase.squeeze(" ").center(width)
end
.......

Finished in 0.00776 seconds
7 examples, 0 failures
Йордан Джамбазов
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Йордан Джамбазов
def format_string(string, width)
string.upcase.strip.gsub(/\s+/, ' ').center(width)
end
.......

Finished in 0.00814 seconds
7 examples, 0 failures
Евгений Янев
  • Некоректно
  • 0 успешни тест(а)
  • 7 неуспешни тест(а)
Евгений Янев
=begin
This function surrounds the given string with whitespaces
only if the given width arguments is greater than the
length of the string argument
string - the string to be surrounded by whitespaces
width - the desired width of the string
return - the surrounded string
=end
def surround_with_ws(string, width)
whites = width - string.length
unless whites <= 0
left_ws = ' ' * (whites / 2)
right_ws = ' ' * (whites/2 + whites%2)
string.insert(0,left_ws)
string << right_ws
end
return string
end
=begin
This function formats the given string constrained by the documentation
string - the given string to format
width - the width of the desired resulting string
return - the formatted string
=end
def format_string(string, width)
string = string.split.join(" ")
string.upcase!
string = surround_with_ws(string, width)
puts "\"#{string}\""
end
"BACON!!"
F"BACON!!"
F"DO YOUR CHALLENGE NOW"
F"HASTA LA VISTA, BABY!"
F"ODD "
F" TRY HARDER! "
F"   CHUNKY BACON!!   "
F

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-f583gk/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) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-f583gk/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
       
       expected: "DO YOUR CHALLENGE NOW"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-f583gk/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) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
       
       expected: "HASTA LA VISTA, BABY!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-f583gk/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) format_string appends odd intervals at the end of the string when centering
     Failure/Error: expect(format_string('odd', 4)).to eq 'ODD '
       
       expected: "ODD "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-f583gk/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) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
       
       expected: " TRY HARDER! "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-f583gk/spec.rb:25: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) format_string works with already trimmed strings with greater width padding
     Failure/Error: expect(format_string('chunky   bacon!! ', 20)).to eq '   CHUNKY BACON!!   '
       
       expected: "   CHUNKY BACON!!   "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-f583gk/spec.rb:30: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.00726 seconds
7 examples, 7 failures

Failed examples:

rspec /tmp/d20141008-29654-f583gk/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-f583gk/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-f583gk/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-f583gk/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-f583gk/spec.rb:18 # format_string appends odd intervals at the end of the string when centering
rspec /tmp/d20141008-29654-f583gk/spec.rb:24 # format_string centers strings properly when the length difference is even
rspec /tmp/d20141008-29654-f583gk/spec.rb:29 # format_string works with already trimmed strings with greater width padding
Людмил Делчев
  • Некоректно
  • 0 успешни тест(а)
  • 7 неуспешни тест(а)
Людмил Делчев
def string_format ( string, width )
((((string.lstrip).rstrip).gsub ' ', ' ' ) . upcase ). center width , padstr = ' '
end
FFFFFFF

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
     NoMethodError:
       undefined method `format_string' for #<RSpec::Core::ExampleGroup::Nested_1:0xb9ae1a50>
     # /tmp/d20141008-29654-wrdrsv/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) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
     NoMethodError:
       undefined method `format_string' for #<RSpec::Core::ExampleGroup::Nested_1:0xb9ae06dc>
     # /tmp/d20141008-29654-wrdrsv/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
     NoMethodError:
       undefined method `format_string' for #<RSpec::Core::ExampleGroup::Nested_1:0xb9ad7488>
     # /tmp/d20141008-29654-wrdrsv/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) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
     NoMethodError:
       undefined method `format_string' for #<RSpec::Core::ExampleGroup::Nested_1:0xb9ad4968>
     # /tmp/d20141008-29654-wrdrsv/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) format_string appends odd intervals at the end of the string when centering
     Failure/Error: expect(format_string('odd', 4)).to eq 'ODD '
     NoMethodError:
       undefined method `format_string' for #<RSpec::Core::ExampleGroup::Nested_1:0xb9ad3a40>
     # /tmp/d20141008-29654-wrdrsv/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) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
     NoMethodError:
       undefined method `format_string' for #<RSpec::Core::ExampleGroup::Nested_1:0xb9ad2960>
     # /tmp/d20141008-29654-wrdrsv/spec.rb:25: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) format_string works with already trimmed strings with greater width padding
     Failure/Error: expect(format_string('chunky   bacon!! ', 20)).to eq '   CHUNKY BACON!!   '
     NoMethodError:
       undefined method `format_string' for #<RSpec::Core::ExampleGroup::Nested_1:0xb9ad1920>
     # /tmp/d20141008-29654-wrdrsv/spec.rb:30: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.00526 seconds
7 examples, 7 failures

Failed examples:

rspec /tmp/d20141008-29654-wrdrsv/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-wrdrsv/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-wrdrsv/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-wrdrsv/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-wrdrsv/spec.rb:18 # format_string appends odd intervals at the end of the string when centering
rspec /tmp/d20141008-29654-wrdrsv/spec.rb:24 # format_string centers strings properly when the length difference is even
rspec /tmp/d20141008-29654-wrdrsv/spec.rb:29 # format_string works with already trimmed strings with greater width padding
Георги Кожухаров
  • Некоректно
  • 0 успешни тест(а)
  • 7 неуспешни тест(а)
Георги Кожухаров
def format_string(string,length)
if string[0]== " "
string[0]=''
end
if string[string.length-1]== " "
string[string.length-1]=''
end
string.gsub!(/\s+/, ' ')
string = string.upcase
if(string.length>=length)
puts string
else
if (length - string.length)%2==1
puts " " * ((length - string.length)/2) + string + " " * (((length - string.length)/2 + 1))
else
# puts (length - string.length)/2
puts " " * ((length - string.length)/2) + string + " "* ((length - string.length)/2 )
end
end
end
BACON!!
F BACON!! 
F DO YOUR CHALLENGE NOW 
FHASTA LA VISTA, BABY! 
FODD 
F TRY HARDER! 
F   CHUNKY BACON!!   
F

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1q6yqiv/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) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1q6yqiv/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
       
       expected: "DO YOUR CHALLENGE NOW"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1q6yqiv/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) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
       
       expected: "HASTA LA VISTA, BABY!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1q6yqiv/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) format_string appends odd intervals at the end of the string when centering
     Failure/Error: expect(format_string('odd', 4)).to eq 'ODD '
       
       expected: "ODD "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1q6yqiv/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) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
       
       expected: " TRY HARDER! "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1q6yqiv/spec.rb:25: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) format_string works with already trimmed strings with greater width padding
     Failure/Error: expect(format_string('chunky   bacon!! ', 20)).to eq '   CHUNKY BACON!!   '
       
       expected: "   CHUNKY BACON!!   "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-1q6yqiv/spec.rb:30: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.00753 seconds
7 examples, 7 failures

Failed examples:

rspec /tmp/d20141008-29654-1q6yqiv/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-1q6yqiv/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-1q6yqiv/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-1q6yqiv/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-1q6yqiv/spec.rb:18 # format_string appends odd intervals at the end of the string when centering
rspec /tmp/d20141008-29654-1q6yqiv/spec.rb:24 # format_string centers strings properly when the length difference is even
rspec /tmp/d20141008-29654-1q6yqiv/spec.rb:29 # format_string works with already trimmed strings with greater width padding
Антон Димов
  • Некоректно
  • 0 успешни тест(а)
  • 7 неуспешни тест(а)
Антон Димов
def format_string(string, width)
string = string.strip.squeeze(" ").upcase
if(string.length<width)
empty = ((width-string.length)/2)
puts ((width-string.length)%2)==0 ? " " * empty + string + " " * empty : " " * empty + string+ " " * (empty+1)
elsif
puts string.strip.squeeze(" ").upcase
end
end
BACON!!
FBACON!!
FDO YOUR CHALLENGE NOW
FHASTA LA VISTA, BABY!
FODD 
F TRY HARDER! 
F   CHUNKY BACON!!   
F

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-15obvv8/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) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-15obvv8/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
       
       expected: "DO YOUR CHALLENGE NOW"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-15obvv8/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) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
       
       expected: "HASTA LA VISTA, BABY!"
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-15obvv8/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) format_string appends odd intervals at the end of the string when centering
     Failure/Error: expect(format_string('odd', 4)).to eq 'ODD '
       
       expected: "ODD "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-15obvv8/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) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
       
       expected: " TRY HARDER! "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-15obvv8/spec.rb:25: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) format_string works with already trimmed strings with greater width padding
     Failure/Error: expect(format_string('chunky   bacon!! ', 20)).to eq '   CHUNKY BACON!!   '
       
       expected: "   CHUNKY BACON!!   "
            got: nil
       
       (compared using ==)
     # /tmp/d20141008-29654-15obvv8/spec.rb:30: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.00913 seconds
7 examples, 7 failures

Failed examples:

rspec /tmp/d20141008-29654-15obvv8/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-15obvv8/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-15obvv8/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-15obvv8/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-15obvv8/spec.rb:18 # format_string appends odd intervals at the end of the string when centering
rspec /tmp/d20141008-29654-15obvv8/spec.rb:24 # format_string centers strings properly when the length difference is even
rspec /tmp/d20141008-29654-15obvv8/spec.rb:29 # format_string works with already trimmed strings with greater width padding
Мая Терзиева
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Мая Терзиева
def format_string(string, width)
return string.strip.squeeze(" ").upcase.center(width)
end
.......

Finished in 0.00625 seconds
7 examples, 0 failures
Станислав Венков
  • Некоректно
  • 1 успешни тест(а)
  • 6 неуспешни тест(а)
Станислав Венков
def format_string(string, width)
string.gsub(/\s+/, " ");
string.upcase;
if string.size<width
white_spaces = width - string.size;
first_white_spaces = white_spaces/2;
if first_white_spaces.is_a?
return " "*first_white_spaces + string + " "*first_white_spaces;
else
" "*Integer(first_white_spaces) + string + " "*Integer(first_white_spaces) + " ";
end
else
return string;
end
end
.FFFFFF

Failures:

  1) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: "     BACON!!  "
       
       (compared using ==)
     # /tmp/d20141008-29654-petjq9/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
       
       expected: "DO YOUR CHALLENGE NOW"
            got: "  do YouR   challengE   NoW    "
       
       (compared using ==)
     # /tmp/d20141008-29654-petjq9/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)>'

  3) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
       
       expected: "HASTA LA VISTA, BABY!"
            got: " HAstA    LA vista,     bAbY!      "
       
       (compared using ==)
     # /tmp/d20141008-29654-petjq9/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)>'

  4) format_string appends odd intervals at the end of the string when centering
     Failure/Error: expect(format_string('odd', 4)).to eq 'ODD '
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141008-29654-petjq9/solution.rb:7:in `is_a?'
     # /tmp/d20141008-29654-petjq9/solution.rb:7:in `format_string'
     # /tmp/d20141008-29654-petjq9/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)>'

  5) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141008-29654-petjq9/solution.rb:7:in `is_a?'
     # /tmp/d20141008-29654-petjq9/solution.rb:7:in `format_string'
     # /tmp/d20141008-29654-petjq9/spec.rb:25: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) format_string works with already trimmed strings with greater width padding
     Failure/Error: expect(format_string('chunky   bacon!! ', 20)).to eq '   CHUNKY BACON!!   '
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20141008-29654-petjq9/solution.rb:7:in `is_a?'
     # /tmp/d20141008-29654-petjq9/solution.rb:7:in `format_string'
     # /tmp/d20141008-29654-petjq9/spec.rb:30:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00681 seconds
7 examples, 6 failures

Failed examples:

rspec /tmp/d20141008-29654-petjq9/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-petjq9/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-petjq9/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-petjq9/spec.rb:18 # format_string appends odd intervals at the end of the string when centering
rspec /tmp/d20141008-29654-petjq9/spec.rb:24 # format_string centers strings properly when the length difference is even
rspec /tmp/d20141008-29654-petjq9/spec.rb:29 # format_string works with already trimmed strings with greater width padding
Ралица Великова
  • Некоректно
  • 1 успешни тест(а)
  • 6 неуспешни тест(а)
Ралица Великова
def format_string(string, width)
temp_string = string.split(" ").map(&:strip)
string = ""
temp_string.each do |array|
string.concat(array)
string.concat(" ")
end
string.strip
if string.length < width then
string = string.center(width)
end
return string.upcase
end
FFFF.FF

Failures:

  1) format_string does not change already formatted strings
     Failure/Error: expect(format_string('BACON!!', 5)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: "BACON!! "
       
       (compared using ==)
     # /tmp/d20141008-29654-6xolgl/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) format_string trims spaces
     Failure/Error: expect(format_string('     BACON!!  ', 0)).to eq 'BACON!!'
       
       expected: "BACON!!"
            got: "BACON!! "
       
       (compared using ==)
     # /tmp/d20141008-29654-6xolgl/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) format_string does not attempt to center the string if the width is less than the one after processing
     Failure/Error: expect(format_string('  do YouR   challengE   NoW    ', 10)).to eq 'DO YOUR CHALLENGE NOW'
       
       expected: "DO YOUR CHALLENGE NOW"
            got: "DO YOUR CHALLENGE NOW "
       
       (compared using ==)
     # /tmp/d20141008-29654-6xolgl/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) format_string does not attempt to center the string if the width is zero
     Failure/Error: expect(format_string(' HAstA    LA vista,     bAbY!      ', 0)).to eq 'HASTA LA VISTA, BABY!'
       
       expected: "HASTA LA VISTA, BABY!"
            got: "HASTA LA VISTA, BABY! "
       
       (compared using ==)
     # /tmp/d20141008-29654-6xolgl/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) format_string centers strings properly when the length difference is even
     Failure/Error: expect(format_string('try harder!', 13)).to eq ' TRY HARDER! '
       
       expected: " TRY HARDER! "
            got: "TRY HARDER!  "
       
       (compared using ==)
     # /tmp/d20141008-29654-6xolgl/spec.rb:25: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) format_string works with already trimmed strings with greater width padding
     Failure/Error: expect(format_string('chunky   bacon!! ', 20)).to eq '   CHUNKY BACON!!   '
       
       expected: "   CHUNKY BACON!!   "
            got: "  CHUNKY BACON!!    "
       
       (compared using ==)
     # /tmp/d20141008-29654-6xolgl/spec.rb:30: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.01531 seconds
7 examples, 6 failures

Failed examples:

rspec /tmp/d20141008-29654-6xolgl/spec.rb:2 # format_string does not change already formatted strings
rspec /tmp/d20141008-29654-6xolgl/spec.rb:6 # format_string trims spaces
rspec /tmp/d20141008-29654-6xolgl/spec.rb:10 # format_string does not attempt to center the string if the width is less than the one after processing
rspec /tmp/d20141008-29654-6xolgl/spec.rb:14 # format_string does not attempt to center the string if the width is zero
rspec /tmp/d20141008-29654-6xolgl/spec.rb:24 # format_string centers strings properly when the length difference is even
rspec /tmp/d20141008-29654-6xolgl/spec.rb:29 # format_string works with already trimmed strings with greater width padding
Мартина Радева
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Мартина Радева
def format_string(string, width)
string.strip.gsub(/\s+/, ' ').upcase.center(width, ' ')
end
.......

Finished in 0.19199 seconds
7 examples, 0 failures
Беатрис Бонева
  • Коректно
  • 7 успешни тест(а)
  • 0 неуспешни тест(а)
Беатрис Бонева
def format_string(string, width)
return string.strip.gsub(/\s+/, ' ').upcase.center(width)
end
.......

Finished in 0.00705 seconds
7 examples, 0 failures