fork(1) download
  1. F=
  2. # 80
  3. ->s,l{s+=' '*(l-s.size%l)
  4. (s.size/l).times{|i|puts [x=s[i*l,l],x.reverse][i%2]}}
  5.  
  6. require 'minitest/autorun'
  7.  
  8. describe F do
  9. def test_case_1
  10. expected = <<-EOS
  11. Prog
  12. mmar
  13. ing
  14. zzuP
  15. les
  16. oC &
  17. de G
  18. flo
  19. EOS
  20.  
  21. actual = capture_stdout(){ F['Programming Puzzles & Code Golf', 4] }
  22.  
  23. assert_equal expected, actual
  24. end
  25.  
  26. def test_case_2
  27. expected = <<-EOS
  28. Hello
  29. roW ,
  30. ld!
  31. EOS
  32.  
  33. actual = capture_stdout(){ F['Hello, World!', 5] }
  34.  
  35. assert_equal expected, actual
  36. end
  37. end
  38.  
  39.  
  40.  
  41. require 'stringio'
  42.  
  43. module Kernel
  44. def capture_stdout(console_input = '')
  45. $stdin = StringIO.new(console_input)
  46. out = StringIO.new
  47. $stdout = out
  48. yield
  49. return out.string
  50. ensure
  51. $stdout = STDOUT
  52. $stdin = STDIN
  53. end
  54. end
  55.  
Success #stdin #stdout 0.09s 10728KB
stdin
Standard input is empty
stdout
Run options: --seed 58420

# Running tests:

..

Finished tests in 0.000986s, 2028.4984 tests/s, 2028.4984 assertions/s.

2 tests, 2 assertions, 0 failures, 0 errors, 0 skips