[2016][ruby][11.0] implement equality on states

profile
Alpha Chen 8 years ago
parent b7fb46656a
commit 3b132cc220

@ -10,6 +10,10 @@ class State
Floor.new(items.reject {|item| item == ?. }) Floor.new(items.reject {|item| item == ?. })
} }
end end
def ==(state)
elevator == state.elevator && floors.zip(state.floors).all? {|a,b| a == b }
end
end end
class Floor < SimpleDelegator class Floor < SimpleDelegator
@ -51,4 +55,9 @@ F1 E . HM . LM
assert_equal %w[ H L ], floor.microchips assert_equal %w[ H L ], floor.microchips
assert_empty floor.generators assert_empty floor.generators
end end
def test_equality
state = State.new(INPUT)
assert_equal @state, state
end
end end

Loading…
Cancel
Save