OLD | NEW |
(Empty) | |
| 1 from recipe_engine.recipe_api import Property |
| 2 from recipe_engine import config |
| 3 import math |
| 4 |
| 5 # This recipe computes all the primes up to the value up_to. |
| 6 |
| 7 DEPS = [ |
| 8 'recipe_engine/properties', |
| 9 ] |
| 10 |
| 11 PROPERTIES = { |
| 12 'up_to': Property(kind=int, default=50), |
| 13 } |
| 14 |
| 15 RETURN_SCHEMA = config.ReturnSchema( |
| 16 result=config.List(int) |
| 17 ) |
| 18 |
| 19 def is_prime(val): |
| 20 if val % 2 == 0: |
| 21 return False |
| 22 for div in range(3, math.floor(math.sqrt(val))): |
| 23 if val % div == 0: |
| 24 return False |
| 25 return True |
| 26 |
| 27 def RunSteps(api, to_return): |
| 28 all_primes = [] |
| 29 prime = 2 |
| 30 while prime < to_return: |
| 31 all_primes.append(prime) |
| 32 res = api.depend_on('next_prime', {'curr_prime': prime}) |
| 33 prime = res.result |
| 34 if not is_prime(prime): |
| 35 raise api.StepFailure("OH NOES") |
| 36 |
| 37 return RETURN_SCHEMA(**res) |
| 38 |
| 39 def GenTests(api): |
| 40 yield ( |
| 41 api.test('basic') + |
| 42 api.properties(to_return=3) |
| 43 ) |
OLD | NEW |