Commits

Anonymous committed 0afa98c

Added a test for a move and fixed "row" into "row_idx". Tests++.

Comments (0)

Files changed (2)

hitori-solver-in-ruby/hitori-solver.rb

     end
 
     class Process
+        attr_reader :moves
         def initialize(board)
             @board = board
             @moves = Array.new
             return Move.new(*coords)
         end
 
-        def solve()
+        def analyze_sequences()
             counter = Hash.new()
             counter[$DIR_X] = (0 .. @board.maxx).map { |x| Hash.new }
             counter[$DIR_Y] = (0 .. @board.maxy).map { |y| Hash.new }
                                 sorted_seqs[1..-1].each do |seq|
                                     @moves.push(
                                         self.get_move(
-                                            dir, row, seq[0],
+                                            dir, row_idx, seq[0],
                                             "black",
                                             "An adjacent pair and some standalones mark the standalones as black"
                                         )

hitori-solver-in-ruby/t/parse-board.rb

             board = HitoriSolver::Board.new(2, 4, [[3,2,1,4],[4,5,6,7], [1,1,2,1]])   
         }.should raise_error(HitoriSolver::WrongHeightException)
     end
-    
+
+    it "should mark 2,0 as black in Board No. 1" do
+        # http://www.menneske.no/hitori/5x5/eng/showpuzzle.html?number=1
+        contents = [
+            [2,1,3,2,4],
+            [4,5,3,2,2],
+            [3,4,2,5,1],
+            [1,4,3,3,2],
+            [2,5,1,4,3]
+        ]
+        board = HitoriSolver::Board.new(5, 5, contents)
+        process = HitoriSolver::Process.new(board)
+        process.analyze_sequences()
+        process.moves.length().should == 1
+        process.moves[0].x.should == 2
+        process.moves[0].y.should == 3
+        process.moves[0].color.should == "black"
+    end
 end