Skip to content

Instantly share code, notes, and snippets.

@zben
Created May 30, 2018 01:54
Show Gist options
  • Save zben/9cc32240425044cf60f928750a003dd6 to your computer and use it in GitHub Desktop.
Save zben/9cc32240425044cf60f928750a003dd6 to your computer and use it in GitHub Desktop.
require 'test/unit'
extend Test::Unit::Assertions
class FibonacciAggregator
def self.sum_of_even_numbers(limit: 4_000_000)
sum, lower, higher = 0, 1, 2
while lower <= limit
sum += lower if lower % 2 == 0
lower, higher = higher, lower + higher
end
sum
end
end
#tests
assert_equal(FibonacciAggregator.sum_of_even_numbers(limit: 5), 2)
assert_equal(FibonacciAggregator.sum_of_even_numbers(limit: 10), 2 + 8)
assert_equal(FibonacciAggregator.sum_of_even_numbers(limit: 100), 2 + 8 + 34)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment