[2018][ruby][17.1] count the water

sorbet
Alpha Chen 6 years ago
parent ebbe80bde3
commit d9508f683d

@ -74,6 +74,7 @@ class Slice
end end
def water def water
@squares.select {|_, s| %w[ | ~ ].include?(s) }.keys
end end
def to_s def to_s
@ -120,7 +121,7 @@ class TestSlice < Minitest::Test
def test_simulate def test_simulate
simulation = @slice.simulate simulation = @slice.simulate
slice = 5.times { simulation.next } 5.times { simulation.next }
assert_equal <<~SLICE.chomp, @slice.to_s assert_equal <<~SLICE.chomp, @slice.to_s
......+....... ......+.......
......|.....#. ......|.....#.
@ -138,7 +139,7 @@ class TestSlice < Minitest::Test
....#######... ....#######...
SLICE SLICE
slice = 6.times { simulation.next } 6.times { simulation.next }
assert_equal <<~SLICE.chomp, @slice.to_s assert_equal <<~SLICE.chomp, @slice.to_s
......+....... ......+.......
......|.....#. ......|.....#.
@ -156,7 +157,7 @@ class TestSlice < Minitest::Test
....#######... ....#######...
SLICE SLICE
slice = 5.times { simulation.next } 5.times { simulation.next }
assert_equal <<~SLICE.chomp, @slice.to_s assert_equal <<~SLICE.chomp, @slice.to_s
......+....... ......+.......
......|.....#. ......|.....#.
@ -174,7 +175,7 @@ class TestSlice < Minitest::Test
....#######... ....#######...
SLICE SLICE
slice = 4.times { simulation.next } 4.times { simulation.next }
assert_equal <<~SLICE.chomp, @slice.to_s assert_equal <<~SLICE.chomp, @slice.to_s
......+....... ......+.......
......|.....#. ......|.....#.
@ -192,7 +193,7 @@ class TestSlice < Minitest::Test
....#######... ....#######...
SLICE SLICE
slice = 24.times { simulation.next } 24.times { simulation.next }
assert_equal <<~SLICE.chomp, @slice.to_s assert_equal <<~SLICE.chomp, @slice.to_s
......+....... ......+.......
......|.....#. ......|.....#.
@ -210,7 +211,7 @@ class TestSlice < Minitest::Test
....#######... ....#######...
SLICE SLICE
slice = 9.times { simulation.next } 9.times { simulation.next }
assert_equal <<~SLICE.chomp, @slice.to_s assert_equal <<~SLICE.chomp, @slice.to_s
......+....... ......+.......
......|.....#. ......|.....#.
@ -227,6 +228,8 @@ class TestSlice < Minitest::Test
...|#~~~~~#|.. ...|#~~~~~#|..
...|#######|.. ...|#######|..
SLICE SLICE
assert_equal 57, @slice.water.count
end end
end end

Loading…
Cancel
Save