diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..85a2392 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,24 @@ +name: CI +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt -r requirements-dev.txt + - name: Run tests + run: | + pytest -vv + diff --git a/nbp/bodies/body.py b/nbp/bodies/body.py index 660b16a..76083d6 100755 --- a/nbp/bodies/body.py +++ b/nbp/bodies/body.py @@ -18,13 +18,13 @@ def from_tuple_parameters(cls, name: str, mass: float, radius: float, position: >>> planet1 = Body.from_tuple_parameters("Planet1", 100.0, 20.0, (1.0, 2.0, 3.0), (4.0, 5.0, 6.0)) >>> planet1.position - array([[ 1.], - [ 2.], - [ 3.]]) + array([[1.], + [2.], + [3.]]) >>> planet1.velocity - array([[ 4.], - [ 5.], - [ 6.]]) + array([[4.], + [5.], + [6.]]) >>> planet1.name 'Planet1' >>> planet1.mass @@ -42,11 +42,11 @@ def from_tuple_parameters(cls, name: str, mass: float, radius: float, position: >>> planet1.position == planet2.position array([[ True], [ True], - [ True]], dtype=bool) + [ True]]) >>> planet1.velocity == planet2.velocity array([[ True], [ True], - [ True]], dtype=bool) + [ True]]) """ return Body( name, diff --git a/nbp/helpers/numpy.py b/nbp/helpers/numpy.py index e7ea59a..d5d14c6 100644 --- a/nbp/helpers/numpy.py +++ b/nbp/helpers/numpy.py @@ -4,13 +4,13 @@ def tuple_to_numpy(t: tuple) -> numpy.ndarray: """ >>> tuple_to_numpy((1, 2, 3)) - array([[ 1.], - [ 2.], - [ 3.]]) + array([[1.], + [2.], + [3.]]) >>> tuple_to_numpy((123.123, 234.234, 345.345)) - array([[ 123.123], - [ 234.234], - [ 345.345]]) + array([[123.123], + [234.234], + [345.345]]) """ return numpy.array([[t[0]], [t[1]], @@ -43,19 +43,19 @@ def dict_to_numpy(dictionary: dict) -> numpy.ndarray: """ >>> a = dict_to_numpy({'x': 1.0, 'y': 2.0, 'z': 3.0}) >>> a - array([[ 1.], - [ 2.], - [ 3.]]) + array([[1.], + [2.], + [3.]]) >>> numpy_to_dict(a) == {'x': 1.0, 'y': 2.0, 'z': 3.0} True >>> dict_to_numpy({'x': 1.5, 'y': 2.5, 'z': 3.5}) - array([[ 1.5], - [ 2.5], - [ 3.5]]) + array([[1.5], + [2.5], + [3.5]]) >>> dict_to_numpy({'x': -100, 'y': 212, 'z': 31234}) - array([[ -100.], - [ 212.], - [ 31234.]]) + array([[ -100.], + [ 212.], + [31234.]]) """ return tuple_to_numpy(( dictionary['x'], diff --git a/nbp/helpers/physics.py b/nbp/helpers/physics.py index eaa2561..6c8071f 100644 --- a/nbp/helpers/physics.py +++ b/nbp/helpers/physics.py @@ -15,17 +15,17 @@ def distance_to(one_body: Body, other_body: Body) -> numpy.ndarray: >>> earth = Body.from_tuple_parameters("Earth", 5.972*(10**24), 100, (1.506*(10**11), 0, 100), (0, 29290, 0)) >>> moon = Body.from_tuple_parameters("Moon", 0.0735*(10**24), 100, (1.496*(10**11), 384.4*(10**6), -500), (1050, 29290, 0)) >>> distance_to(moon, earth) - array([[ 1.00000000e+09], - [ -3.84400000e+08], - [ 6.00000000e+02]]) + array([[ 1.000e+09], + [-3.844e+08], + [ 6.000e+02]]) Distance to itself is always 0 in all directions. >>> moon = Body.from_tuple_parameters("Moon", 0.0735*(10**24), 100, (1.496*(10**11), 384.4*(10**6), -500), (1050, 29290, 0)) >>> distance_to(moon, moon) - array([[ 0.], - [ 0.], - [ 0.]]) + array([[0.], + [0.], + [0.]]) >>> from nbp.helpers.numpy import tuple_to_numpy >>> import numpy as np @@ -33,9 +33,9 @@ def distance_to(one_body: Body, other_body: Body) -> numpy.ndarray: >>> one = Body('saturn', 100, 100, np.array([[0.], [0.], [0.]]), velocity) >>> two = Body('neptune', 100, 100, tuple_to_numpy((0, 146.2, 0)), velocity) >>> distance_to(one, two) - array([[ 0. ], - [ 146.2], - [ 0. ]]) + array([[ 0. ], + [146.2], + [ 0. ]]) """ return other_body.position - one_body.position @@ -49,12 +49,12 @@ def absolute_distance_to_one(one_body: Body, other_body: Body) -> float: >>> earth = Body.from_tuple_parameters("Earth", 5.972*(10**24), 100.0, (1.496*(10**11), 0, 0), (0, 29290, 0)) >>> moon = Body.from_tuple_parameters("Moon", 0.0735*(10**24), 100.0, (1.496*(10**11), 384.4*(10**6), 0), (1050, 29290, 0)) >>> absolute_distance_to_one(moon, earth) - 384400000.0 + np.float64(384400000.0) >>> earth = Body.from_tuple_parameters("Earth", 5.972*(10**24), 100.0, (1.496*(10**11), 0, 0), (0, 29290, 0)) >>> moon = Body.from_tuple_parameters("Moon", 0.0735*(10**24), 100.0, (1.496*(10**11), -384.4*(10**6), -69834), (1050, 29290, 0)) >>> absolute_distance_to_one(moon, earth) - 384400006.34337604 + np.float64(384400006.34337604) >>> from nbp.helpers.numpy import tuple_to_numpy >>> import numpy as np @@ -107,9 +107,9 @@ def acceleration_to_all(one_body: Body, bodies: [Body]) -> numpy.ndarray: >>> moon = Body.from_tuple_parameters("Moon", 0.0735*(10**24), 100.0, (0, 384.4*(10**6), -1000), (0, 0, 0)) >>> acceleration_to_all(moon, [kg, earth1, earth2, moon]) - array([[ -4.46878801e-05], - [ -5.48536334e-03], - [ 6.07257588e-08]]) + array([[-4.46878801e-05], + [-5.48536334e-03], + [ 6.07257588e-08]]) """ total_acceleration = numpy.array([[0], @@ -130,9 +130,9 @@ def calculate_position(body: Body, delta_time: float) -> numpy.ndarray: >>> test_body = Body.from_tuple_parameters("Test_body", 1.0, 1.0, (60, -20, 15), (4, 10.2, -6)) >>> calculate_position(test_body, 3.0) - array([[ 72. ], - [ 10.6], - [ -3. ]]) + array([[72. ], + [10.6], + [-3. ]]) """ return body.position + (delta_time * body.velocity) @@ -151,17 +151,17 @@ def calculate_velocity(one_body: Body, delta_time: float, other_bodies: [Body]) >>> e5 = Body.from_tuple_parameters("Earth5", (5.972*(10**24)), 100.0, (6371000, 9000, -532), (0, 0, 0)) >>> e6 = Body.from_tuple_parameters("Earth6", (5.972*(10**24)), 100.0, (-6371000, -9000, 532), (0, 0, 0)) >>> calculate_velocity(kg, 314.0, [kg, e1, e2, e3, e4, e5, e6]) - array([[ 0.], - [ 0.], - [ 0.]]) + array([[0.], + [0.], + [0.]]) >>> kg = Body.from_tuple_parameters("kg", 1.0, 100.0, (0, 0, 0), (0, 0, 0)) >>> earth1 = Body.from_tuple_parameters("Earth1", (5.972*(10**24)), 100.0, (0, 6371000, 6280), (0, 0, 0)) >>> moon = Body.from_tuple_parameters("Moon", 0.0735*(10**24), 100.0, (0, 384.4*(10**6), -1000), (0, 0, 0)) >>> calculate_velocity(kg, 16.0, [kg, earth1, moon]) - array([[ 0.00000000e+00], - [ 1.57114698e+02], - [ 1.54870030e-01]]) + array([[0.00000000e+00], + [1.57114698e+02], + [1.54870030e-01]]) """ return one_body.velocity + (delta_time * acceleration_to_all(one_body, other_bodies)) @@ -179,14 +179,14 @@ def merge_bodies(one_body: Body, other_body: Body) -> Body: >>> planet = merge_bodies(earth, moon) >>> planet.position - array([[ 1.50587842e+11], - [ 4.67395352e+06], - [ 9.27053180e+01]]) + array([[1.50587842e+11], + [4.67395352e+06], + [9.27053180e+01]]) >>> planet.velocity - array([[ -8.60185262e+01], - [ 2.85777959e+04], - [ -7.59904061e-01]]) + array([[-8.60185262e+01], + [ 2.85777959e+04], + [-7.59904061e-01]]) >>> planet.radius 6413824.949215559 @@ -235,7 +235,7 @@ def minimal_distance(bodies: [Body]) -> float: >>> saturn = Body.from_tuple_parameters('saturn', 568000000000000000000000000, 100, (0, 1352550000000, 0), (0, 10180, 0)) >>> neptune = Body.from_tuple_parameters('neptune', 102413000000000000000000000, 100, (0, -4444450000000, 500000), (-5370, 0, 0)) >>> minimal_distance([sun, earth, moon, jupiter, saturn, neptune]) - 405500037.33168757 + np.float64(405500037.33168757) >>> sun = Body.from_tuple_parameters('Sun', 1989000000000000000000000000000, 100, (0, 0, 0), (0, 0, 0)) >>> earth = Body.from_tuple_parameters('earth', 5972000000000000000000000, 100, (0, 152100000000, 1000), (29290, 0, 32)) @@ -244,7 +244,7 @@ def minimal_distance(bodies: [Body]) -> float: >>> saturn = Body.from_tuple_parameters('saturn', 568000000000000000000000000, 100, (0, 1352550000000, 0), (0, 10180, 0)) >>> neptune = Body.from_tuple_parameters('neptune', 102413000000000000000000000, 100, (0, -4444450000000, 500000), (-5370, 0, 0)) >>> minimal_distance([sun, earth, moon, jupiter, saturn, neptune]) - 405500037.76202041 + np.float64(405500037.7620204) >>> sun = Body.from_tuple_parameters('Sun', 1989000000000000000000000000000, 100, (0, 0, 0), (0, 0, 0)) >>> earth = Body.from_tuple_parameters('earth', 5972000000000000000000000, 100, (107550941418, 107550941418, 100000), (29290, 0, 32)) @@ -252,7 +252,7 @@ def minimal_distance(bodies: [Body]) -> float: >>> saturn = Body.from_tuple_parameters('saturn', 568000000000000000000000000, 100, (0, 1352550000000, 0), (0, 10180, 0)) >>> neptune = Body.from_tuple_parameters('neptune', 102413000000000000000000000, 100, (0, -4444450000000, 500000), (-5370, 0, 0)) >>> minimal_distance([sun, earth, jupiter, saturn, neptune]) - 152099999999.3627 + np.float64(152099999999.3627) >>> from nbp.helpers.numpy import tuple_to_numpy >>> import numpy as np diff --git a/requirements-dev.txt b/requirements-dev.txt index 3d8ff94..c45f2b3 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,5 @@ - pylint==1.5.5 - pytest==2.9.2 - codecov==2.0.5 - coverage==4.1 - pytest-cov==2.2.1 +pylint +pytest +codecov +coverage +pytest-cov diff --git a/requirements.txt b/requirements.txt index b34e905..f7efbf3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ -gevent==1.1.2 -bottle==0.12.9 -websockets==3.2 -bottle==0.12.9 -numpy==1.11.0 -cerberus==0.9.2 -pytest==2.9.2 +gevent +bottle +websockets +numpy +cerberus +pytest