Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
19 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |