Created
September 9, 2014 21:36
-
-
Save julianvargasalvarez/e1f3b75ead46188828d5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Multiplo | |
def la_suma(limite) | |
multiplos_de_3_o_5(limite).reduce(:+) | |
end | |
def multiplos_de_3_o_5(limite) | |
rango(10).each_with_object([]) do |x, resultado| | |
resultado << x if es_multiplo_de_tres(x) || es_multiplo_de_cinco(x) | |
end | |
end | |
private | |
def es_multiplo_de_tres(numero) | |
es_multiplo_de(numero, 3) | |
end | |
def es_multiplo_de_cinco(numero) | |
es_multiplo_de(numero, 5) | |
end | |
def es_multiplo_de(numero, multiplo) | |
numero % multiplo == 0 | |
end | |
def rango(limite) | |
(1...limite) | |
end | |
end |
This file contains hidden or 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
require './multiplo.rb' | |
describe Multiplo do | |
describe "#la_suma" do | |
it "returns 23 if 10 is given" do | |
multiplo = Multiplo.new | |
expect(multiplo.la_suma(10)).to eq 23 | |
end | |
end | |
describe "#multiplos_de_3_o_5" do | |
it "returns 3, 5, 6 and 9 if 10 is given" do | |
multiplo = Multiplo.new | |
expect(multiplo.multiplos_de_3_o_5(10)).to eq [3, 5, 6, 9] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment