fork download
  1. # coding: utf-8
  2. require 'minitest/autorun'
  3.  
  4. PROGRAM =-> {
  5. ###
  6. gets.split(/(\d)(?!\d)/).each_slice(2){|s,i|s.chars.map{|c|$><<c*i.to_i}}
  7. ###
  8. }
  9.  
  10. describe PROGRAM do
  11. def test_case_1
  12. assert_equal 'aaabbbccccc', execute('ab3c5')
  13. end
  14.  
  15. def test_case_2
  16. assert_equal 'bbb', execute('a0b3')
  17. end
  18.  
  19. def test_case_3
  20. assert_equal '111b', execute('13b1')
  21. end
  22.  
  23. def test_case_4
  24. assert_equal 'aaa111b', execute('a13b1')
  25. end
  26.  
  27. def test_case_5
  28. assert_equal 'aaa111222b', execute('a123b1')
  29. end
  30.  
  31. def test_case_6
  32. assert_equal 'aaaaab', execute('aa2a1b1')
  33. end
  34.  
  35.  
  36. def execute(input)
  37. capture_stdout(input){ PROGRAM[] }
  38. end
  39. end
  40.  
  41. # capture STDIN/STDOUT for testing purposes
  42. require 'stringio'
  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.chomp
  50. ensure
  51. $stdout = STDOUT
  52. $stdin = STDIN
  53. end
  54. end
  55.  
  56.  
Success #stdin #stdout 0.06s 8624KB
stdin
Standard input is empty
stdout
Run options: --seed 3909

# Running tests:

......

Finished tests in 0.001021s, 5875.4752 tests/s, 5875.4752 assertions/s.

6 tests, 6 assertions, 0 failures, 0 errors, 0 skips