Commits

shl...@b384bcd7-cfd4-0310-aca0-d78b80f7b91b  committed aa5873e

Renamed the tests as _spec.rb instead of .rb.

This is the more standard and will allow some .rb files that are not tests.

  • Participants
  • Parent commits f4739aa

Comments (0)

Files changed (12)

File solver/ruby/Manifest

 Makefile
 Rakefile
 t/
-t/check-perms.rb
-t/merge-constraints.rb
-t/parse-board.rb
-t/solve-board.rb
-t/temp-system-test-solve-board.rb
+t/check-perms_spec.rb
+t/merge-constraints_spec.rb
+t/parse-board_spec.rb
+t/solve-board_spec.rb
+t/temp-system-test-solve-board_spec.rb

File solver/ruby/Rakefile

 
 RSpec::Core::RakeTask.new(:spec) do |t|
     # t.spec_files = FileList['t/**/*.rb']
-    t.pattern = Dir.glob('t/**/*.rb')
+    t.pattern = Dir.glob('t/**/*_spec.rb')
     t.rspec_opts = ['--color']
 end
 # 

File solver/ruby/t/check-perms.rb

-#--
-# Copyright (c) 2011 Shlomi Fish
-#
-# Permission is hereby granted, free of charge, to any person obtaining
-# a copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#++
-require "kakuro_solver/perms"
-
-def human_get_perms(mutator, sum, num)
-    perms = mutator.get_perms(*mutator.human_to_internal(sum, num))
-    return perms.map {|x| mutator.internal_to_human(x) }
-end
-
-describe "Kakuro" do
-    before do
-        @perm = Kakuro::Perms.new
-    end
-
-    it "human->internal transform for 3/2" do
-        @perm.human_to_internal(3,2).should eql([1,2])
-    end
-
-    it "human->internal transform for 5/2" do
-        @perm.human_to_internal(5,2).should eql([3,2])
-    end
-
-    it "human->internal transform for 10/4" do
-        # 10 = 1 + 2 + 3 + 4
-        # 10/int = 0 + 1 + 2 + 3 == 6
-        @perm.human_to_internal(10,4).should eql([6,4])
-    end
-
-    it "internal->human transform for 1+2+3+4" do
-        @perm.internal_to_human(
-            (1 << (1-1)) | (1 << (2-1)) | (1 << (3-1)) | (1 << (4-1))
-        ).should eql([1,2,3,4])
-    end
-
-    it "internal->human transform for 7+9" do
-        @perm.internal_to_human(
-            (1 << (7-1)) | (1 << (9-1))
-        ).should eql([7,9])
-    end
-
-    it "10/4 is 1,2,3,4" do
-        (@perm.get_perms(*@perm.human_to_internal(10,4)).map {|x| @perm.internal_to_human(x) }).should eql([[1,2,3,4]])
-    end
-
-    it "get_perms(10/4)" do
-        human_get_perms(@perm, 10, 4).should eql([[1,2,3,4]])
-    end
-
-    it "get_perms(3/2)" do
-        human_get_perms(@perm, 3, 2).should eql([[1,2]])
-    end
-
-    it "get_perms(16/2)" do
-        human_get_perms(@perm, 16, 2).should eql([[7,9]])
-    end
-
-    it "get_perms(7/3)" do
-        human_get_perms(@perm, 7, 3).should eql([[1,2,4]])
-    end
-
-    it "gen_perms(25/5)" do
-        human_get_perms(@perm, 25, 5).should eql([
-            [1,2,5,8,9],
-            [1,2,6,7,9],
-            [1,3,4,8,9],
-            [1,3,5,7,9],
-            [1,3,6,7,8],
-            [1,4,5,6,9],
-            [1,4,5,7,8],
-            [2,3,4,7,9],
-            [2,3,5,6,9],
-            [2,3,5,7,8],
-            [2,4,5,6,8],
-            [3,4,5,6,7],
-        ])
-    end
-end
-
-
-

File solver/ruby/t/check-perms_spec.rb

+#--
+# Copyright (c) 2011 Shlomi Fish
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#++
+require "kakuro_solver/perms"
+
+def human_get_perms(mutator, sum, num)
+    perms = mutator.get_perms(*mutator.human_to_internal(sum, num))
+    return perms.map {|x| mutator.internal_to_human(x) }
+end
+
+describe "Kakuro" do
+    before do
+        @perm = Kakuro::Perms.new
+    end
+
+    it "human->internal transform for 3/2" do
+        @perm.human_to_internal(3,2).should eql([1,2])
+    end
+
+    it "human->internal transform for 5/2" do
+        @perm.human_to_internal(5,2).should eql([3,2])
+    end
+
+    it "human->internal transform for 10/4" do
+        # 10 = 1 + 2 + 3 + 4
+        # 10/int = 0 + 1 + 2 + 3 == 6
+        @perm.human_to_internal(10,4).should eql([6,4])
+    end
+
+    it "internal->human transform for 1+2+3+4" do
+        @perm.internal_to_human(
+            (1 << (1-1)) | (1 << (2-1)) | (1 << (3-1)) | (1 << (4-1))
+        ).should eql([1,2,3,4])
+    end
+
+    it "internal->human transform for 7+9" do
+        @perm.internal_to_human(
+            (1 << (7-1)) | (1 << (9-1))
+        ).should eql([7,9])
+    end
+
+    it "10/4 is 1,2,3,4" do
+        (@perm.get_perms(*@perm.human_to_internal(10,4)).map {|x| @perm.internal_to_human(x) }).should eql([[1,2,3,4]])
+    end
+
+    it "get_perms(10/4)" do
+        human_get_perms(@perm, 10, 4).should eql([[1,2,3,4]])
+    end
+
+    it "get_perms(3/2)" do
+        human_get_perms(@perm, 3, 2).should eql([[1,2]])
+    end
+
+    it "get_perms(16/2)" do
+        human_get_perms(@perm, 16, 2).should eql([[7,9]])
+    end
+
+    it "get_perms(7/3)" do
+        human_get_perms(@perm, 7, 3).should eql([[1,2,4]])
+    end
+
+    it "gen_perms(25/5)" do
+        human_get_perms(@perm, 25, 5).should eql([
+            [1,2,5,8,9],
+            [1,2,6,7,9],
+            [1,3,4,8,9],
+            [1,3,5,7,9],
+            [1,3,6,7,8],
+            [1,4,5,6,9],
+            [1,4,5,7,8],
+            [2,3,4,7,9],
+            [2,3,5,6,9],
+            [2,3,5,7,8],
+            [2,4,5,6,8],
+            [3,4,5,6,7],
+        ])
+    end
+end
+
+
+

File solver/ruby/t/merge-constraints.rb

-#--
-# Copyright (c) 2011 Shlomi Fish
-#
-# Permission is hereby granted, free of charge, to any person obtaining
-# a copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#++
-require "kakuro_solver/board"
-
-class Object
-    def ok()
-        self.should == true
-    end
-    def not_ok()
-        self.should == false
-    end
-end
-
-describe "Merge Two Constraints" do
-    it "[1,2] and [1,3] should be merged" do
-        vert = Kakuro::InitConstraint.new(2,2).as_list
-        horiz = Kakuro::InitConstraint.new(1,2).as_list
-
-        merger = Kakuro::CellConstraintsMerger.new(
-            :constraints => [vert,horiz,],
-            :cell_values => (0..8).inject(0) { |total,x| (total | (1 << x))}
-        )
-        
-        merger.remaining_dir_constraints(Kakuro::VERT).should == \
-            [(1 << 0)|(1 << 2)]
-        merger.remaining_dir_constraints(Kakuro::HORIZ).should == \
-            [(1 << 0)|(1 << 1)]
-
-        merger.possible_cell_values.should == (1 << 0)
-
-        merger.has_single_verdict.should == 0
-    end
-end
-
-describe "[[1,2]] and [[1,8],[2,7],[3,6],[4,5]]" do
-    it "should be merged" do
-        vert = Kakuro::InitConstraint.new(
-            *Kakuro::Perms.new.human_to_internal(3,2)
-        ).as_list
-        horiz = Kakuro::InitConstraint.new(
-            *Kakuro::Perms.new.human_to_internal(9,2)
-        ).as_list
-
-        merger = Kakuro::CellConstraintsMerger.new(
-            :constraints => [vert,horiz,],
-            :cell_values => ((0..8).inject(0) { |total,x| (total | (1 << x))})
-        )
-        
-        merger.remaining_dir_constraints(Kakuro::VERT).should == \
-            [(1 << 0)|(1 << 1)]
-        merger.remaining_dir_constraints(Kakuro::HORIZ).should == \
-            [ ((1 << 0)|(1 << 7)), ((1 << 1)|(1 << 6)), ]
-
-        merger.possible_cell_values.should == ((1 << 0)|(1 << 1))
-
-        merger.has_single_verdict.should == false
-    end
-end
-
-describe "[[1,2]] and [[1,8],[2,7],[3,6],[4,5]] with 1 alone" do
-    it "should be merged" do
-        vert = Kakuro::InitConstraint.new(
-            *Kakuro::Perms.new.human_to_internal(3,2)
-        ).as_list
-        horiz = Kakuro::InitConstraint.new(
-            *Kakuro::Perms.new.human_to_internal(9,2)
-        ).as_list
-
-        merger = Kakuro::CellConstraintsMerger.new(
-            :constraints => [vert,horiz,],
-            :cell_values => ((0..0).inject(0) { |total,x| (total | (1 << x))})
-        )
-        
-        merger.remaining_dir_constraints(Kakuro::VERT).should == \
-            [(1 << 0)|(1 << 1)]
-        merger.remaining_dir_constraints(Kakuro::HORIZ).should == \
-            [ ((1 << 0)|(1 << 7)), ]
-
-        merger.possible_cell_values.should == (1 << 0)
-
-        merger.has_single_verdict.should == 0
-    end
-end
-

File solver/ruby/t/merge-constraints_spec.rb

+#--
+# Copyright (c) 2011 Shlomi Fish
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#++
+require "kakuro_solver/board"
+
+class Object
+    def ok()
+        self.should == true
+    end
+    def not_ok()
+        self.should == false
+    end
+end
+
+describe "Merge Two Constraints" do
+    it "[1,2] and [1,3] should be merged" do
+        vert = Kakuro::InitConstraint.new(2,2).as_list
+        horiz = Kakuro::InitConstraint.new(1,2).as_list
+
+        merger = Kakuro::CellConstraintsMerger.new(
+            :constraints => [vert,horiz,],
+            :cell_values => (0..8).inject(0) { |total,x| (total | (1 << x))}
+        )
+        
+        merger.remaining_dir_constraints(Kakuro::VERT).should == \
+            [(1 << 0)|(1 << 2)]
+        merger.remaining_dir_constraints(Kakuro::HORIZ).should == \
+            [(1 << 0)|(1 << 1)]
+
+        merger.possible_cell_values.should == (1 << 0)
+
+        merger.has_single_verdict.should == 0
+    end
+end
+
+describe "[[1,2]] and [[1,8],[2,7],[3,6],[4,5]]" do
+    it "should be merged" do
+        vert = Kakuro::InitConstraint.new(
+            *Kakuro::Perms.new.human_to_internal(3,2)
+        ).as_list
+        horiz = Kakuro::InitConstraint.new(
+            *Kakuro::Perms.new.human_to_internal(9,2)
+        ).as_list
+
+        merger = Kakuro::CellConstraintsMerger.new(
+            :constraints => [vert,horiz,],
+            :cell_values => ((0..8).inject(0) { |total,x| (total | (1 << x))})
+        )
+        
+        merger.remaining_dir_constraints(Kakuro::VERT).should == \
+            [(1 << 0)|(1 << 1)]
+        merger.remaining_dir_constraints(Kakuro::HORIZ).should == \
+            [ ((1 << 0)|(1 << 7)), ((1 << 1)|(1 << 6)), ]
+
+        merger.possible_cell_values.should == ((1 << 0)|(1 << 1))
+
+        merger.has_single_verdict.should == false
+    end
+end
+
+describe "[[1,2]] and [[1,8],[2,7],[3,6],[4,5]] with 1 alone" do
+    it "should be merged" do
+        vert = Kakuro::InitConstraint.new(
+            *Kakuro::Perms.new.human_to_internal(3,2)
+        ).as_list
+        horiz = Kakuro::InitConstraint.new(
+            *Kakuro::Perms.new.human_to_internal(9,2)
+        ).as_list
+
+        merger = Kakuro::CellConstraintsMerger.new(
+            :constraints => [vert,horiz,],
+            :cell_values => ((0..0).inject(0) { |total,x| (total | (1 << x))})
+        )
+        
+        merger.remaining_dir_constraints(Kakuro::VERT).should == \
+            [(1 << 0)|(1 << 1)]
+        merger.remaining_dir_constraints(Kakuro::HORIZ).should == \
+            [ ((1 << 0)|(1 << 7)), ]
+
+        merger.possible_cell_values.should == (1 << 0)
+
+        merger.has_single_verdict.should == 0
+    end
+end
+

File solver/ruby/t/parse-board.rb

-#--
-# Copyright (c) 2011 Shlomi Fish
-#
-# Permission is hereby granted, free of charge, to any person obtaining
-# a copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#++
-require "kakuro_solver/board"
-
-class Object
-    def ok()
-        self.should == true
-    end
-    def not_ok()
-        self.should == false
-    end
-end
-
-class Position < Kakuro::Position
-end
-
-describe "Variable Width Board" do
-    it "should not be accepted with variable width" do
-        board = Kakuro::Board.new
-        got_exception = false
-        begin
-            board.parse(<<'EOF')
-[\3] [] []
-[\] []
-[\] [] []
-EOF
-
-        rescue Kakuro::ParsingError
-            got_exception = true
-        end
-        got_exception.ok()
-    end
-end
-
-describe "Parse 1" do
-    before do
-        @board = Kakuro::Board.new
-        @board.parse(<<'EOF')
-[\] [\] [29\] [34\] [\] [21\] [8\] [\] [\]
-[\] [10\17] [] [] [3\3] [] [] [\] [\]
-[\30] [] [5] [] [] [2] [] [3\] [11\]
-[\16] [] [] [6] [] [3] [12\11] [] []
-[\] [4\5] [] [] [13\10] [] [] [] []
-[\34] [] [7] [] [4] [] [] [11\] [\]
-[\4] [] [] [3\12] [] [] [1] [] [\] 
-[\] [\] [\6] [] [] [\11] [] [] [\]
-[\] [\] [\3] [] [] [\] [\] [\] [\]
-EOF
-    end
-
-    it "cells are solid or not" do
-        @board.cell(Position.new(:x => 0, :y => 0)).solid?.ok
-        @board.cell(Position.new(:x => 1, :y => 0)).solid?.ok
-        @board.cell(Position.new(:x => 2, :y => 0)).solid?.ok
-        @board.cell(Position.new(:x => 2, :y => 1)).solid?.not_ok
-        @board.cell(Position.new(:x => 3, :y => 1)).solid?.not_ok
-        @board.cell(Position.new(:x => 4, :y => 1)).solid?.ok
-        @board.cell(Position.new(:x => 5, :y => 1)).solid?.not_ok
-        @board.cell(Position.new(:x => 5, :y => 1)).solid?.not_ok
-        @board.cell(Position.new(:x => 6, :y => 1)).solid?.not_ok
-        @board.cell(Position.new(:x => 6, :y => 1)).solid?.not_ok
-        @board.cell(Position.new(:x => 7, :y => 1)).solid?.ok
-        @board.cell(Position.new(:x => 8, :y => 1)).solid?.ok
-        @board.cell(Position.new(:x => 0, :y => 8)).solid?.ok
-        @board.cell(Position.new(:x => 1, :y => 8)).solid?.ok
-        @board.cell(Position.new(:x => 2, :y => 8)).solid?.ok
-        @board.cell(Position.new(:x => 3, :y => 8)).solid?.not_ok
-        @board.cell(Position.new(:x => 4, :y => 8)).solid?.not_ok
-        @board.cell(Position.new(:x => 5, :y => 8)).solid?.ok
-        @board.cell(Position.new(:x => 6, :y => 8)).solid?.ok
-        @board.cell(Position.new(:x => 7, :y => 8)).solid?.ok
-        @board.cell(Position.new(:x => 8, :y => 8)).solid?.ok
-    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 => 2)).human_verdict.should == 5
-    end
-end
-
-describe "Cells with errors (1)" do
-    it "should throw an exception" do
-        board = Kakuro::Board.new
-        lambda {
-            board.parse(<<'EOF')
-[3forward]
-EOF
-        }.should raise_error(Kakuro::ParsingError)
-    end
-end
-
-describe "Junk after line" do
-    it "should throw an exception" do
-        board = Kakuro::Board.new
-        lambda {
-            board.parse(<<'EOF')
-[\] [\] [29\] [34\] [\] [21\] [8\] [\] [\]
-[\] [10\17] [] [] [3\3] [] [] [\] [\] This is wrong.
-[\30] [] [5] [] [] [2] [] [3\] [11\]
-EOF
-        }.should raise_error(Kakuro::ParsingError)
-    end
-end
-
-describe "Post-Parse Prepared Board" do
-    before do
-        @board = Kakuro::Board.new
-        @board.parse(<<'EOF')
-[\] [\] [29\] [34\] [\] [21\] [8\] [\] [\]
-[\] [10\17] [] [] [3\3] [] [] [\] [\]
-[\30] [] [5] [] [] [2] [] [3\] [11\]
-[\16] [] [] [6] [] [3] [12\11] [] []
-[\] [4\5] [] [] [13\10] [] [] [] []
-[\34] [] [7] [] [4] [] [] [11\] [\]
-[\4] [] [] [3\12] [] [] [1] [] [\] 
-[\] [\] [\6] [] [] [\11] [] [] [\]
-[\] [\] [\3] [] [] [\] [\] [\] [\]
-EOF
-        @board.prepare()
-    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::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
-
-        # 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 => 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

File solver/ruby/t/parse-board_spec.rb

+#--
+# Copyright (c) 2011 Shlomi Fish
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#++
+require "kakuro_solver/board"
+
+class Object
+    def ok()
+        self.should == true
+    end
+    def not_ok()
+        self.should == false
+    end
+end
+
+class Position < Kakuro::Position
+end
+
+describe "Variable Width Board" do
+    it "should not be accepted with variable width" do
+        board = Kakuro::Board.new
+        got_exception = false
+        begin
+            board.parse(<<'EOF')
+[\3] [] []
+[\] []
+[\] [] []
+EOF
+
+        rescue Kakuro::ParsingError
+            got_exception = true
+        end
+        got_exception.ok()
+    end
+end
+
+describe "Parse 1" do
+    before do
+        @board = Kakuro::Board.new
+        @board.parse(<<'EOF')
+[\] [\] [29\] [34\] [\] [21\] [8\] [\] [\]
+[\] [10\17] [] [] [3\3] [] [] [\] [\]
+[\30] [] [5] [] [] [2] [] [3\] [11\]
+[\16] [] [] [6] [] [3] [12\11] [] []
+[\] [4\5] [] [] [13\10] [] [] [] []
+[\34] [] [7] [] [4] [] [] [11\] [\]
+[\4] [] [] [3\12] [] [] [1] [] [\] 
+[\] [\] [\6] [] [] [\11] [] [] [\]
+[\] [\] [\3] [] [] [\] [\] [\] [\]
+EOF
+    end
+
+    it "cells are solid or not" do
+        @board.cell(Position.new(:x => 0, :y => 0)).solid?.ok
+        @board.cell(Position.new(:x => 1, :y => 0)).solid?.ok
+        @board.cell(Position.new(:x => 2, :y => 0)).solid?.ok
+        @board.cell(Position.new(:x => 2, :y => 1)).solid?.not_ok
+        @board.cell(Position.new(:x => 3, :y => 1)).solid?.not_ok
+        @board.cell(Position.new(:x => 4, :y => 1)).solid?.ok
+        @board.cell(Position.new(:x => 5, :y => 1)).solid?.not_ok
+        @board.cell(Position.new(:x => 5, :y => 1)).solid?.not_ok
+        @board.cell(Position.new(:x => 6, :y => 1)).solid?.not_ok
+        @board.cell(Position.new(:x => 6, :y => 1)).solid?.not_ok
+        @board.cell(Position.new(:x => 7, :y => 1)).solid?.ok
+        @board.cell(Position.new(:x => 8, :y => 1)).solid?.ok
+        @board.cell(Position.new(:x => 0, :y => 8)).solid?.ok
+        @board.cell(Position.new(:x => 1, :y => 8)).solid?.ok
+        @board.cell(Position.new(:x => 2, :y => 8)).solid?.ok
+        @board.cell(Position.new(:x => 3, :y => 8)).solid?.not_ok
+        @board.cell(Position.new(:x => 4, :y => 8)).solid?.not_ok
+        @board.cell(Position.new(:x => 5, :y => 8)).solid?.ok
+        @board.cell(Position.new(:x => 6, :y => 8)).solid?.ok
+        @board.cell(Position.new(:x => 7, :y => 8)).solid?.ok
+        @board.cell(Position.new(:x => 8, :y => 8)).solid?.ok
+    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 => 2)).human_verdict.should == 5
+    end
+end
+
+describe "Cells with errors (1)" do
+    it "should throw an exception" do
+        board = Kakuro::Board.new
+        lambda {
+            board.parse(<<'EOF')
+[3forward]
+EOF
+        }.should raise_error(Kakuro::ParsingError)
+    end
+end
+
+describe "Junk after line" do
+    it "should throw an exception" do
+        board = Kakuro::Board.new
+        lambda {
+            board.parse(<<'EOF')
+[\] [\] [29\] [34\] [\] [21\] [8\] [\] [\]
+[\] [10\17] [] [] [3\3] [] [] [\] [\] This is wrong.
+[\30] [] [5] [] [] [2] [] [3\] [11\]
+EOF
+        }.should raise_error(Kakuro::ParsingError)
+    end
+end
+
+describe "Post-Parse Prepared Board" do
+    before do
+        @board = Kakuro::Board.new
+        @board.parse(<<'EOF')
+[\] [\] [29\] [34\] [\] [21\] [8\] [\] [\]
+[\] [10\17] [] [] [3\3] [] [] [\] [\]
+[\30] [] [5] [] [] [2] [] [3\] [11\]
+[\16] [] [] [6] [] [3] [12\11] [] []
+[\] [4\5] [] [] [13\10] [] [] [] []
+[\34] [] [7] [] [4] [] [] [11\] [\]
+[\4] [] [] [3\12] [] [] [1] [] [\] 
+[\] [\] [\6] [] [] [\11] [] [] [\]
+[\] [\] [\3] [] [] [\] [\] [\] [\]
+EOF
+        @board.prepare()
+    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::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
+
+        # 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 => 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

File solver/ruby/t/solve-board.rb

-#--
-# Copyright (c) 2011 Shlomi Fish
-#
-# Permission is hereby granted, free of charge, to any person obtaining
-# a copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#++
-require "kakuro_solver/board"
-
-class Object
-    def ok()
-        self.should == true
-    end
-    def not_ok()
-        self.should == false
-    end
-end
-
-describe "Parse 1" do
-    before do
-        @board = Kakuro::Board.new
-        @board.parse(<<'EOF')
-[\]    [\]      [29\]  [34\]   [\]      [21\]  [8\]     [\]    [\]
-[\]    [10\17]  []     []      [3\3]    []     []       [\]    [\]
-[\30]  []       [5]    []      []       [2]    []       [3\]   [11\]
-[\16]  []       []     [6]     []       [3]    [12\11]  []     []
-[\]    [4\5]    []     []      [13\10]  []     []       []     []
-[\34]  []       [7]    []      [4]      []     []       [11\]  [\]
-[\4]   []       []     [3\12]  []       []     [1]      []     [\]
-[\]    [\]      [\6]   []      []       [\11]  []       []     [\]
-[\]    [\]      [\3]   []      []       [\]    [\]      [\]    [\]
-EOF
-    end
-
-    it "should merge constraints correctly" do
-        @board.prepare()
-        @board.merge_constraints()
-        @board.filter_constraints_without_cells()
-    end
-
-end
-

File solver/ruby/t/solve-board_spec.rb

+#--
+# Copyright (c) 2011 Shlomi Fish
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#++
+require "kakuro_solver/board"
+
+class Object
+    def ok()
+        self.should == true
+    end
+    def not_ok()
+        self.should == false
+    end
+end
+
+describe "Parse 1" do
+    before do
+        @board = Kakuro::Board.new
+        @board.parse(<<'EOF')
+[\]    [\]      [29\]  [34\]   [\]      [21\]  [8\]     [\]    [\]
+[\]    [10\17]  []     []      [3\3]    []     []       [\]    [\]
+[\30]  []       [5]    []      []       [2]    []       [3\]   [11\]
+[\16]  []       []     [6]     []       [3]    [12\11]  []     []
+[\]    [4\5]    []     []      [13\10]  []     []       []     []
+[\34]  []       [7]    []      [4]      []     []       [11\]  [\]
+[\4]   []       []     [3\12]  []       []     [1]      []     [\]
+[\]    [\]      [\6]   []      []       [\11]  []       []     [\]
+[\]    [\]      [\3]   []      []       [\]    [\]      [\]    [\]
+EOF
+    end
+
+    it "should merge constraints correctly" do
+        @board.prepare()
+        @board.merge_constraints()
+        @board.filter_constraints_without_cells()
+    end
+
+end
+

File solver/ruby/t/temp-system-test-solve-board.rb

-#--
-# Copyright (c) 2011 Shlomi Fish
-#
-# Permission is hereby granted, free of charge, to any person obtaining
-# a copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to
-# permit persons to whom the Software is furnished to do so, subject to
-# the following conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#++
-describe "System Test 1" do
-    before do
-        @got_output = `ruby -Ilib bin/dump-board.rb`
-    end
-
-    it "should remain the same" do
-        @got_output.should == <<'EOF'
-Before new
-After new
-After parse
-After prepare
-After merge_constraints
-
-[ \\       ][ \\       ][ \\       ][ \\       ][ \\       ][ \\       ][ \\       ][ \\       ][ \\       ]
-[ \\       ][ \\       ][7,8       ][7,8       ][ \\       ][0         ][1         ][ \\       ][ \\       ]
-[ \\       ][8         ][4         ][6,7       ][0         ][1         ][5         ][ \\       ][ \\       ]
-[ \\       ][0         ][3         ][5         ][1         ][2         ][ \\       ][1         ][8         ]
-[ \\       ][ \\       ][0         ][3         ][ \\       ][3         ][2         ][0         ][1         ]
-[ \\       ][2         ][6         ][7,8       ][3         ][4,5       ][1,5       ][ \\       ][ \\       ]
-[ \\       ][0         ][2         ][ \\       ][1,2,4,5   ][4,5       ][0         ][1,4,5     ][ \\       ]
-[ \\       ][ \\       ][ \\       ][0,1       ][0,1,4     ][ \\       ][1,5       ][1,4,5,8   ][ \\       ]
-[ \\       ][ \\       ][ \\       ][0,1       ][0,1       ][ \\       ][ \\       ][ \\       ][ \\       ]
-EOF
-    end
-end

File solver/ruby/t/temp-system-test-solve-board_spec.rb

+#--
+# Copyright (c) 2011 Shlomi Fish
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#++
+describe "System Test 1" do
+    before do
+        @got_output = `ruby -Ilib bin/dump-board.rb`
+    end
+
+    it "should remain the same" do
+        @got_output.should == <<'EOF'
+Before new
+After new
+After parse
+After prepare
+After merge_constraints
+
+[ \\       ][ \\       ][ \\       ][ \\       ][ \\       ][ \\       ][ \\       ][ \\       ][ \\       ]
+[ \\       ][ \\       ][7,8       ][7,8       ][ \\       ][0         ][1         ][ \\       ][ \\       ]
+[ \\       ][8         ][4         ][6,7       ][0         ][1         ][5         ][ \\       ][ \\       ]
+[ \\       ][0         ][3         ][5         ][1         ][2         ][ \\       ][1         ][8         ]
+[ \\       ][ \\       ][0         ][3         ][ \\       ][3         ][2         ][0         ][1         ]
+[ \\       ][2         ][6         ][7,8       ][3         ][4,5       ][1,5       ][ \\       ][ \\       ]
+[ \\       ][0         ][2         ][ \\       ][1,2,4,5   ][4,5       ][0         ][1,4,5     ][ \\       ]
+[ \\       ][ \\       ][ \\       ][0,1       ][0,1,4     ][ \\       ][1,5       ][1,4,5,8   ][ \\       ]
+[ \\       ][ \\       ][ \\       ][0,1       ][0,1       ][ \\       ][ \\       ][ \\       ][ \\       ]
+EOF
+    end
+end