| Index: recipes/dm.py
|
| diff --git a/recipes/dm.py b/recipes/dm.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a6f232348b0d094cc1a6b23332f447e3297d9d04
|
| --- /dev/null
|
| +++ b/recipes/dm.py
|
| @@ -0,0 +1,43 @@
|
| +from recipe_engine.recipe_api import Property
|
| +from recipe_engine import config
|
| +import math
|
| +
|
| +# This recipe computes all the primes up to the value up_to.
|
| +
|
| +DEPS = [
|
| + 'recipe_engine/properties',
|
| +]
|
| +
|
| +PROPERTIES = {
|
| + 'up_to': Property(kind=int, default=50),
|
| +}
|
| +
|
| +RETURN_SCHEMA = config.ReturnSchema(
|
| + result=config.List(int)
|
| +)
|
| +
|
| +def is_prime(val):
|
| + if val % 2 == 0:
|
| + return False
|
| + for div in range(3, math.floor(math.sqrt(val))):
|
| + if val % div == 0:
|
| + return False
|
| + return True
|
| +
|
| +def RunSteps(api, to_return):
|
| + all_primes = []
|
| + prime = 2
|
| + while prime < to_return:
|
| + all_primes.append(prime)
|
| + res = api.depend_on('next_prime', {'curr_prime': prime})
|
| + prime = res.result
|
| + if not is_prime(prime):
|
| + raise api.StepFailure("OH NOES")
|
| +
|
| + return RETURN_SCHEMA(**res)
|
| +
|
| +def GenTests(api):
|
| + yield (
|
| + api.test('basic') +
|
| + api.properties(to_return=3)
|
| + )
|
|
|