-
Notifications
You must be signed in to change notification settings - Fork 0
/
template_solution.py
52 lines (39 loc) · 1.44 KB
/
template_solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
"""
import sys
import unittest
def find_summation_of_primes_brute(max_prime):
pass
def find_summation_of_primes_site(max_prime):
pass
def find_summation_of_primes(max_prime, algorithm='brute'):
if algorithm=='brute':
answer = find_summation_of_primes_brute(max_prime)
elif algorithm=='site':
answer = find_summation_of_primes_site(max_prime)
else:
raise Exception("Unknown algorithm %s" % algorithm)
return answer
class TestSummationOfPrimes(unittest.TestCase):
def _test_template_example(self, algorithm):
self.assertEqual(find_summation_of_primes(10, algorithm), 17)
def _test_template_solution(self, algorithm):
pass
# self.assertEqual(find_summation_of_primes(1000, algorithm), 31875000)
@unittest.expectedFailure
def test_site_example(self):
self._test_template_example('site')
def test_site_solution(self):
self._test_template_solution('site')
def test_brute_example(self):
self._test_template_example('brute')
def test_brute_solution(self):
self._test_template_solution('brute')
if __name__ == '__main__':
number = int(sys.argv[1])
if len(sys.argv) < 3:
answer = find_summation_of_primes(number)
else:
answer = find_summation_of_primes(number, sys.argv[2])
print 'answer=%r' % answer