kakuro-cross-sums / solver / ruby / t / check-perms.rb

require "kakuro-perms.rb"

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
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.