mirror of
https://github.com/wassname/ray.git
synced 2026-07-04 11:03:54 +08:00
Moving tests from test/ to python/ray/tests/ (#3950)
This commit is contained in:
committed by
Robert Nishihara
parent
acbe0b4e5f
commit
c7a4c74f55
@@ -0,0 +1,39 @@
|
||||
# This test is not inside of runtest.py because when a recursive remote
|
||||
# function is defined inside of another function, we currently can't handle
|
||||
# that.
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import pytest
|
||||
|
||||
import ray
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ray_start():
|
||||
# Start ray instance
|
||||
ray.init(num_cpus=1)
|
||||
|
||||
# Run test using this fixture
|
||||
yield None
|
||||
|
||||
# Shutdown ray instance
|
||||
ray.shutdown()
|
||||
|
||||
|
||||
@ray.remote
|
||||
def factorial(n):
|
||||
if n == 0:
|
||||
return 1
|
||||
return n * ray.get(factorial.remote(n - 1))
|
||||
|
||||
|
||||
def test_recursion(ray_start):
|
||||
assert ray.get(factorial.remote(0)) == 1
|
||||
assert ray.get(factorial.remote(1)) == 1
|
||||
assert ray.get(factorial.remote(2)) == 2
|
||||
assert ray.get(factorial.remote(3)) == 6
|
||||
assert ray.get(factorial.remote(4)) == 24
|
||||
assert ray.get(factorial.remote(5)) == 120
|
||||
Reference in New Issue
Block a user