Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: recipes/next_prime.py

Issue 1421843006: Add simple depends_on API. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/recipes-py@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « recipes/list_primes.py ('k') | recipes/top.py » ('j') | recipes/top.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: recipes/next_prime.py
diff --git a/recipes/next_prime.py b/recipes/next_prime.py
new file mode 100644
index 0000000000000000000000000000000000000000..af28cf1cbfa0cf320c6c6d768e10c07a84fd3906
--- /dev/null
+++ b/recipes/next_prime.py
@@ -0,0 +1,36 @@
+from recipe_engine.recipe_api import Property
+from recipe_engine import config
+import math
+
+DEPS = [
+ 'recipe_engine/properties',
+]
+
+PROPERTIES = {
+ 'curr_prime': Property(kind=int),
+}
+
+RETURN_SCHEMA = config.ReturnSchema(
+ result=config.Single(int),
+)
+
+def is_prime(val):
+ if val % 2 == 0:
+ return False
+ for div in range(3, math.ceil(math.sqrt(val))):
+ if val % div == 0:
+ return False
+ return True
+
+def RunSteps(api, curr_prime):
+ curr_prime += 2
+ while not is_prime(curr_prime):
+ curr_prime += 2
+
+ return RETURN_SCHEMA(result=curr_prime)
+
+def GenTests(api):
+ yield (
+ api.test('basic') +
+ api.properties(curr_prime=3)
+ )
« no previous file with comments | « recipes/list_primes.py ('k') | recipes/top.py » ('j') | recipes/top.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698