Created
July 28, 2014 23:32
-
-
Save epoch/5ae52223567acf89bed0 to your computer and use it in GitHub Desktop.
tdd_sum_of_multples
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 SumOfMultiple | |
| def initialize(lowest = 1, highest = 10) | |
| @lowest = lowest | |
| @highest = highest | |
| end | |
| def calc(*multiples) | |
| sum = 0 | |
| (@lowest..@highest).each do |num| | |
| multiples.each do |multiple| | |
| sum = sum + num if num % multiple == 0 | |
| end | |
| end | |
| sum | |
| 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 'minitest/autorun' | |
| require 'minitest/pride' | |
| require './som.rb' | |
| class TestSumOfMultiple < MiniTest::Test | |
| def test_multiples_of_three | |
| som = SumOfMultiple.new(1,10) | |
| result = som.calc(3) | |
| assert_equal(18, result) | |
| end | |
| def test_multiples_of_five | |
| som = SumOfMultiple.new | |
| result = som.calc(5) | |
| assert_equal(15, result) | |
| end | |
| def test_multiples_of_three_and_five | |
| som = SumOfMultiple.new | |
| result = som.calc(3,5) | |
| assert_equal(33, result) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment