[2016][ruby][11.0] implement equality on states
change zzoumyqwnowvlynrosypxwplqouxonzv
commit 35d065df8478dec7508e28bfce08e01373e4ec6c
author Alpha Chen <alpha.chen@gmail.com>
date
parent wkwszkwn
diff --git a/2016/ruby/day_11.rb b/2016/ruby/day_11.rb
index 4572403..b12ee5a 100644
--- a/2016/ruby/day_11.rb
+++ b/2016/ruby/day_11.rb
@@ -10,6 +10,10 @@ class State
       Floor.new(items.reject {|item| item == ?. })
     }
   end
+
+  def ==(state)
+    elevator == state.elevator && floors.zip(state.floors).all? {|a,b| a == b }
+  end
 end
 
 class Floor < SimpleDelegator
@@ -51,4 +55,9 @@ F1 E  .  HM .  LM
     assert_equal %w[ H L ], floor.microchips
     assert_empty floor.generators
   end
+
+  def test_equality
+    state = State.new(INPUT)
+    assert_equal @state, state
+  end
 end