fork(2) download
  1. require 'minitest/autorun'
  2.  
  3. F=->i{l=i.lines.to_a
  4. g={}
  5. l.size.times{|y|i.size.times{|x|l[y][x]==?+&&g[[y,x]]=[[y,x]]}}
  6. c=->a,b{w=g[b]+g[a];w.map{|x|g[x]=w}}
  7. k=g.keys
  8. k.product(k).map{|n,o|
  9. r,p=n
  10. s,q=o
  11. ((r==s&&p<q&&l[r][p...q]=~/^\+-[|-]*$/)||(p==q&&r<s&&l[r...s].map{|l|l[p]||c}.join=~/^\+\|[|-]*$/))&&c[n,o]}
  12. g.values.uniq.size}
  13.  
  14.  
  15. describe '#f' do
  16. def test_empty
  17. assert_equal 0, F['']
  18. end
  19.  
  20. def test_1
  21. input = <<-EOS
  22. +---+
  23. | |
  24. +--+ |
  25. | |
  26. +--+ |
  27. | |
  28. | |
  29. | |
  30. +--+ +--+
  31. | |
  32. +---------+
  33. EOS
  34. assert_equal 1, F[input]
  35. end
  36.  
  37. def test_2
  38. input = <<-EOS
  39. +--+
  40. | |
  41. +---+ +----+ |
  42. | | | |
  43. +---+ +-------+
  44. EOS
  45. assert_equal 2, F[input]
  46. end
  47.  
  48. def test_3
  49. input = <<-EOS
  50. +---------+
  51. | +-----+ |
  52. | | +-+ | |
  53. | | | | | |
  54. | | +-+ | |
  55. | +-----+ |
  56. +---------+
  57. EOS
  58. assert_equal 3, F[input]
  59. end
  60.  
  61. def test_4
  62. input = <<-EOS
  63. +--------------+
  64. | +--+ +--+ |
  65. | | | | | |
  66. +-|-----|-----|----+
  67. | | | | | | | |
  68. | +--+ +--+ +--+ |
  69. +------------------+
  70.  
  71. +------------+
  72. | |
  73. +-----+ +-----+ |
  74. | | | |
  75. +-----|-----------+ | |
  76. | | +--+ | | | |
  77. +-+ +--|--|--+ +---------+
  78. | | +-+ | | |
  79. +------+ | | | |
  80. +-------+ | |
  81. || | |
  82. |+-----+
  83. | |
  84. +---+
  85. EOS
  86. assert_equal 4, F[input]
  87. end
  88.  
  89. def test_5
  90. input = <<-EOS
  91. +--------+ +--------+ +--------+
  92. | | | | | |
  93. | +--|-----+ +--|-----+ |
  94. | | | | | | | | | |
  95. +-----|--+ +-----|--+ +--------+
  96. | | | |
  97. +--------+ +--------+
  98. EOS
  99. assert_equal 5, F[input]
  100. end
  101.  
  102. def test_3_neaky
  103. input = <<-EOS
  104. +----+
  105. +-+|+-+ |
  106. | ||| | |
  107. +-+|+-+ |
  108. +----+
  109. EOS
  110. assert_equal 3, F[input]
  111. end
  112. end
  113.  
Success #stdin #stdout 0.07s 8544KB
stdin
Standard input is empty
stdout
Run options: --seed 31151

# Running tests:

.......

Finished tests in 0.018361s, 381.2521 tests/s, 381.2521 assertions/s.

7 tests, 7 assertions, 0 failures, 0 errors, 0 skips