Created
September 29, 2012 15:37
-
-
Save shostakovich/3804371 to your computer and use it in GitHub Desktop.
Lessons from the prime factorization dojo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module PrimeFactorDecomposer | |
def decompose(number) | |
if number < 4 | |
number | |
else | |
[2,2] | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe PrimeFactorDecomposer do | |
include PrimeFactorDecomposer | |
it "returns no prime factors for 1" do | |
decompose(1).should be_empty | |
end | |
it "decomposes 2 into 2" do | |
decompose(2).should be == [2] | |
end | |
it "decomposes 3 into 3" do | |
decompose(3).should be == [3] | |
end | |
it "decomposes 4 into 2,2" do | |
decompose(4).should be == [2,2] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment