Anonymous avatar Anonymous committed 79606bd

Convert the constants to all-caps per idiomatic ruby style.

Comments (0)

Files changed (3)

solver/ruby/kakuro-board.rb

 module Kakuro
     
     # Some constants
-    Down = Vert = 0
-    Right = Horiz = 1
+    DOWN = VERT = 0
+    RIGHT = HORIZ = 1
 
-    DIRS = [Vert, Horiz,]
+    DIRS = [VERT, HORIZ,]
 
     class ParsingError < RuntimeError
         def initialize()
     class Verdicts
         MAX_DIGIT = 9
 
-        Verdicts_Map = (1 .. MAX_DIGIT).map { |x| x-1 }.inject({}) { 
+        VERDICTS_MAP = (1 .. MAX_DIGIT).map { |x| x-1 }.inject({}) { 
             |h, n| h[1 << n] = n ; h
         }
 
         end
 
         def contains(bitmask)
-            if Verdicts_Map.has_key?(bitmask)
-                @val = Verdicts_Map[bitmask]
+            if VERDICTS_MAP.has_key?(bitmask)
+                @val = VERDICTS_MAP[bitmask]
                 return true
             else
                 @val = nil
             end
 
             @possible_cell_values = (
-                (@initial_cell_values & @total_masks[Vert]) & 
-                    @total_masks[Horiz]
+                (@initial_cell_values & @total_masks[VERT]) & 
+                    @total_masks[HORIZ]
             )
         end
 
             @is_solid = true
 
             if vert.length > 0
-                @user_sums[Kakuro::Down] = vert.to_i();
+                @user_sums[Kakuro::DOWN] = vert.to_i();
             end
             if horiz.length > 0
-                @user_sums[Kakuro::Right] = horiz.to_i();
+                @user_sums[Kakuro::RIGHT] = horiz.to_i();
             end
 
             return
         public
 
         def dir_iter_params(dir)
-            return ((dir == Down) \
+            return ((dir == DOWN) \
                 ? ['y',@height,'bump_y'] \
                 : ['x',@width,'bump_x'])
         end

solver/ruby/t/merge-constraints.rb

             :cell_values => (0..8).inject(0) { |total,x| (total | (1 << x))}
         )
         
-        merger.remaining_dir_constraints(Kakuro::Vert).should == \
+        merger.remaining_dir_constraints(Kakuro::VERT).should == \
             [(1 << 0)|(1 << 2)]
-        merger.remaining_dir_constraints(Kakuro::Horiz).should == \
+        merger.remaining_dir_constraints(Kakuro::HORIZ).should == \
             [(1 << 0)|(1 << 1)]
 
         merger.possible_cell_values.should == (1 << 0)
             :cell_values => ((0..8).inject(0) { |total,x| (total | (1 << x))})
         )
         
-        merger.remaining_dir_constraints(Kakuro::Vert).should == \
+        merger.remaining_dir_constraints(Kakuro::VERT).should == \
             [(1 << 0)|(1 << 1)]
-        merger.remaining_dir_constraints(Kakuro::Horiz).should == \
+        merger.remaining_dir_constraints(Kakuro::HORIZ).should == \
             [ ((1 << 0)|(1 << 7)), ((1 << 1)|(1 << 6)), ]
 
         merger.possible_cell_values.should == ((1 << 0)|(1 << 1))
             :cell_values => ((0..0).inject(0) { |total,x| (total | (1 << x))})
         )
         
-        merger.remaining_dir_constraints(Kakuro::Vert).should == \
+        merger.remaining_dir_constraints(Kakuro::VERT).should == \
             [(1 << 0)|(1 << 1)]
-        merger.remaining_dir_constraints(Kakuro::Horiz).should == \
+        merger.remaining_dir_constraints(Kakuro::HORIZ).should == \
             [ ((1 << 0)|(1 << 7)), ]
 
         merger.possible_cell_values.should == (1 << 0)

solver/ruby/t/parse-board.rb

     end
 
     it "should contain the correct sums" do
-        @board.cell(Position.new(:x => 2, :y => 0)).user_sum(Kakuro::Down).should == 29
-        @board.cell(Position.new(:x => 3, :y => 0)).user_sum(Kakuro::Down).should == 34
-        @board.cell(Position.new(:x => 7, :y => 2)).user_sum(Kakuro::Down).should == 3
-        @board.cell(Position.new(:x => 1, :y => 1)).user_sum(Kakuro::Down).should == 10
-        @board.cell(Position.new(:x => 1, :y => 1)).user_sum(Kakuro::Right).should == 17
-        @board.cell(Position.new(:x => 0, :y => 2)).user_sum(Kakuro::Right).should == 30
-        @board.cell(Position.new(:x => 2, :y => 0)).user_sum(Kakuro::Right).should be_nil
-        @board.cell(Position.new(:x => 0, :y => 0)).user_sum(Kakuro::Right).should be_nil
-        @board.cell(Position.new(:x => 0, :y => 0)).user_sum(Kakuro::Down).should be_nil
-        @board.cell(Position.new(:x => 0, :y => 2)).user_sum(Kakuro::Down).should be_nil
+        @board.cell(Position.new(:x => 2, :y => 0)).user_sum(Kakuro::DOWN).should == 29
+        @board.cell(Position.new(:x => 3, :y => 0)).user_sum(Kakuro::DOWN).should == 34
+        @board.cell(Position.new(:x => 7, :y => 2)).user_sum(Kakuro::DOWN).should == 3
+        @board.cell(Position.new(:x => 1, :y => 1)).user_sum(Kakuro::DOWN).should == 10
+        @board.cell(Position.new(:x => 1, :y => 1)).user_sum(Kakuro::RIGHT).should == 17
+        @board.cell(Position.new(:x => 0, :y => 2)).user_sum(Kakuro::RIGHT).should == 30
+        @board.cell(Position.new(:x => 2, :y => 0)).user_sum(Kakuro::RIGHT).should be_nil
+        @board.cell(Position.new(:x => 0, :y => 0)).user_sum(Kakuro::RIGHT).should be_nil
+        @board.cell(Position.new(:x => 0, :y => 0)).user_sum(Kakuro::DOWN).should be_nil
+        @board.cell(Position.new(:x => 0, :y => 2)).user_sum(Kakuro::DOWN).should be_nil
         @board.cell(Position.new(:x => 2, :y => 2)).human_verdict.should == 5
     end
 end
 
     it "should give the right constraints" do
 
-        @board.cell(Position.new(:x => 1, :y => 1)).init_constraint(Kakuro::Down).num_cells.should == 2
-        @board.cell(Position.new(:x => 1, :y => 1)).init_constraint(Kakuro::Down).sum.should == 8
+        @board.cell(Position.new(:x => 1, :y => 1)).init_constraint(Kakuro::DOWN).num_cells.should == 2
+        @board.cell(Position.new(:x => 1, :y => 1)).init_constraint(Kakuro::DOWN).sum.should == 8
 
-        @board.cell(Position.new(:x => 1, :y => 1)).init_constraint(Kakuro::Right).num_cells.should == 2
-        @board.cell(Position.new(:x => 1, :y => 1)).init_constraint(Kakuro::Right).sum.should == 15
+        @board.cell(Position.new(:x => 1, :y => 1)).init_constraint(Kakuro::RIGHT).num_cells.should == 2
+        @board.cell(Position.new(:x => 1, :y => 1)).init_constraint(Kakuro::RIGHT).sum.should == 15
 
-        @board.cell(Position.new(:x => 2, :y => 1)).control_cell(Kakuro::Horiz).x.should == 1
-        @board.cell(Position.new(:x => 2, :y => 1)).control_cell(Kakuro::Horiz).y.should == 1
-        @board.cell(Position.new(:x => 2, :y => 1)).control_cell(Kakuro::Vert).x.should == 2
-        @board.cell(Position.new(:x => 2, :y => 1)).control_cell(Kakuro::Vert).y.should == 0
-        @board.cell(Position.new(:x => 1, :y => 3)).control_cell(Kakuro::Vert).x.should == 1
-        @board.cell(Position.new(:x => 1, :y => 3)).control_cell(Kakuro::Vert).y.should == 1
+        @board.cell(Position.new(:x => 2, :y => 1)).control_cell(Kakuro::HORIZ).x.should == 1
+        @board.cell(Position.new(:x => 2, :y => 1)).control_cell(Kakuro::HORIZ).y.should == 1
+        @board.cell(Position.new(:x => 2, :y => 1)).control_cell(Kakuro::VERT).x.should == 2
+        @board.cell(Position.new(:x => 2, :y => 1)).control_cell(Kakuro::VERT).y.should == 0
+        @board.cell(Position.new(:x => 1, :y => 3)).control_cell(Kakuro::VERT).x.should == 1
+        @board.cell(Position.new(:x => 1, :y => 3)).control_cell(Kakuro::VERT).y.should == 1
 
         # Testing for out-of-board constraints.
-        @board.cell(Position.new(:x => 4, :y => 4)).init_constraint(Kakuro::Right).num_cells.should == 4
-        @board.cell(Position.new(:x => 4, :y => 4)).init_constraint(Kakuro::Right).sum.should == 6
+        @board.cell(Position.new(:x => 4, :y => 4)).init_constraint(Kakuro::RIGHT).num_cells.should == 4
+        @board.cell(Position.new(:x => 4, :y => 4)).init_constraint(Kakuro::RIGHT).sum.should == 6
 
-        @board.cell(Position.new(:x => 3, :y => 6)).init_constraint(Kakuro::Down).num_cells.should == 2
-        @board.cell(Position.new(:x => 3, :y => 6)).init_constraint(Kakuro::Down).sum.should == 1
+        @board.cell(Position.new(:x => 3, :y => 6)).init_constraint(Kakuro::DOWN).num_cells.should == 2
+        @board.cell(Position.new(:x => 3, :y => 6)).init_constraint(Kakuro::DOWN).sum.should == 1
     end
 end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.