Skip to content

Commit

Permalink
divisor: implement slow version
Browse files Browse the repository at this point in the history
  • Loading branch information
j2kun committed Aug 31, 2020
1 parent 198f75e commit dd46592
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion riemann/divisor.py
@@ -1,4 +1,7 @@
'''Compute the sum of divisors of a number.'''

def divisor_sum(n: int) -> int:
raise ValueError("Not implemented.")
if n <= 0:
raise ValueError("Non-positive numbers are not supported.")

return sum(i for i in range(1, n+1) if n%i == 0)
15 changes: 15 additions & 0 deletions test/divisor_test.py
@@ -1,4 +1,19 @@
import pytest
from riemann.divisor import divisor_sum

def test_sum_of_divisors_of_1():
assert 1 == divisor_sum(1)

def test_sum_of_divisors_of_72():
assert 195 == divisor_sum(72)

def test_illegal_input_0():
with pytest.raises(ValueError):
divisor_sum(0)

def test_illegal_input_0():
with pytest.raises(ValueError):
divisor_sum(0)
def test_illegal_input_negative():
with pytest.raises(ValueError):
divisor_sum(-5)

0 comments on commit dd46592

Please sign in to comment.