Skip to content

Commit b257d48

Browse files
Merge pull request #66 from N-BodyPhysicsSimulator/codex/introduce-ci/cd-for-quality-assurance
Add GitHub Actions CI and modernize requirements
2 parents 59a9a37 + 9c7390b commit b257d48

6 files changed

Lines changed: 90 additions & 67 deletions

File tree

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: CI
2+
on:
3+
push:
4+
branches: [ "master" ]
5+
pull_request:
6+
branches: [ "master" ]
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: Set up Python
14+
uses: actions/setup-python@v5
15+
with:
16+
python-version: '3.12'
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install -r requirements.txt -r requirements-dev.txt
21+
- name: Run tests
22+
run: |
23+
pytest -vv
24+

nbp/bodies/body.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ def from_tuple_parameters(cls, name: str, mass: float, radius: float, position:
1818
1919
>>> planet1 = Body.from_tuple_parameters("Planet1", 100.0, 20.0, (1.0, 2.0, 3.0), (4.0, 5.0, 6.0))
2020
>>> planet1.position
21-
array([[ 1.],
22-
[ 2.],
23-
[ 3.]])
21+
array([[1.],
22+
[2.],
23+
[3.]])
2424
>>> planet1.velocity
25-
array([[ 4.],
26-
[ 5.],
27-
[ 6.]])
25+
array([[4.],
26+
[5.],
27+
[6.]])
2828
>>> planet1.name
2929
'Planet1'
3030
>>> planet1.mass
@@ -42,11 +42,11 @@ def from_tuple_parameters(cls, name: str, mass: float, radius: float, position:
4242
>>> planet1.position == planet2.position
4343
array([[ True],
4444
[ True],
45-
[ True]], dtype=bool)
45+
[ True]])
4646
>>> planet1.velocity == planet2.velocity
4747
array([[ True],
4848
[ True],
49-
[ True]], dtype=bool)
49+
[ True]])
5050
"""
5151
return Body(
5252
name,

nbp/helpers/numpy.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
def tuple_to_numpy(t: tuple) -> numpy.ndarray:
55
"""
66
>>> tuple_to_numpy((1, 2, 3))
7-
array([[ 1.],
8-
[ 2.],
9-
[ 3.]])
7+
array([[1.],
8+
[2.],
9+
[3.]])
1010
>>> tuple_to_numpy((123.123, 234.234, 345.345))
11-
array([[ 123.123],
12-
[ 234.234],
13-
[ 345.345]])
11+
array([[123.123],
12+
[234.234],
13+
[345.345]])
1414
"""
1515
return numpy.array([[t[0]],
1616
[t[1]],
@@ -43,19 +43,19 @@ def dict_to_numpy(dictionary: dict) -> numpy.ndarray:
4343
"""
4444
>>> a = dict_to_numpy({'x': 1.0, 'y': 2.0, 'z': 3.0})
4545
>>> a
46-
array([[ 1.],
47-
[ 2.],
48-
[ 3.]])
46+
array([[1.],
47+
[2.],
48+
[3.]])
4949
>>> numpy_to_dict(a) == {'x': 1.0, 'y': 2.0, 'z': 3.0}
5050
True
5151
>>> dict_to_numpy({'x': 1.5, 'y': 2.5, 'z': 3.5})
52-
array([[ 1.5],
53-
[ 2.5],
54-
[ 3.5]])
52+
array([[1.5],
53+
[2.5],
54+
[3.5]])
5555
>>> dict_to_numpy({'x': -100, 'y': 212, 'z': 31234})
56-
array([[ -100.],
57-
[ 212.],
58-
[ 31234.]])
56+
array([[ -100.],
57+
[ 212.],
58+
[31234.]])
5959
"""
6060
return tuple_to_numpy((
6161
dictionary['x'],

nbp/helpers/physics.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,27 @@ def distance_to(one_body: Body, other_body: Body) -> numpy.ndarray:
1515
>>> earth = Body.from_tuple_parameters("Earth", 5.972*(10**24), 100, (1.506*(10**11), 0, 100), (0, 29290, 0))
1616
>>> moon = Body.from_tuple_parameters("Moon", 0.0735*(10**24), 100, (1.496*(10**11), 384.4*(10**6), -500), (1050, 29290, 0))
1717
>>> distance_to(moon, earth)
18-
array([[ 1.00000000e+09],
19-
[ -3.84400000e+08],
20-
[ 6.00000000e+02]])
18+
array([[ 1.000e+09],
19+
[-3.844e+08],
20+
[ 6.000e+02]])
2121
2222
Distance to itself is always 0 in all directions.
2323
2424
>>> moon = Body.from_tuple_parameters("Moon", 0.0735*(10**24), 100, (1.496*(10**11), 384.4*(10**6), -500), (1050, 29290, 0))
2525
>>> distance_to(moon, moon)
26-
array([[ 0.],
27-
[ 0.],
28-
[ 0.]])
26+
array([[0.],
27+
[0.],
28+
[0.]])
2929
3030
>>> from nbp.helpers.numpy import tuple_to_numpy
3131
>>> import numpy as np
3232
>>> velocity = tuple_to_numpy((0, 0, 0))
3333
>>> one = Body('saturn', 100, 100, np.array([[0.], [0.], [0.]]), velocity)
3434
>>> two = Body('neptune', 100, 100, tuple_to_numpy((0, 146.2, 0)), velocity)
3535
>>> distance_to(one, two)
36-
array([[ 0. ],
37-
[ 146.2],
38-
[ 0. ]])
36+
array([[ 0. ],
37+
[146.2],
38+
[ 0. ]])
3939
"""
4040
return other_body.position - one_body.position
4141

@@ -49,12 +49,12 @@ def absolute_distance_to_one(one_body: Body, other_body: Body) -> float:
4949
>>> earth = Body.from_tuple_parameters("Earth", 5.972*(10**24), 100.0, (1.496*(10**11), 0, 0), (0, 29290, 0))
5050
>>> moon = Body.from_tuple_parameters("Moon", 0.0735*(10**24), 100.0, (1.496*(10**11), 384.4*(10**6), 0), (1050, 29290, 0))
5151
>>> absolute_distance_to_one(moon, earth)
52-
384400000.0
52+
np.float64(384400000.0)
5353
5454
>>> earth = Body.from_tuple_parameters("Earth", 5.972*(10**24), 100.0, (1.496*(10**11), 0, 0), (0, 29290, 0))
5555
>>> moon = Body.from_tuple_parameters("Moon", 0.0735*(10**24), 100.0, (1.496*(10**11), -384.4*(10**6), -69834), (1050, 29290, 0))
5656
>>> absolute_distance_to_one(moon, earth)
57-
384400006.34337604
57+
np.float64(384400006.34337604)
5858
5959
>>> from nbp.helpers.numpy import tuple_to_numpy
6060
>>> import numpy as np
@@ -107,9 +107,9 @@ def acceleration_to_all(one_body: Body, bodies: [Body]) -> numpy.ndarray:
107107
>>> moon = Body.from_tuple_parameters("Moon", 0.0735*(10**24), 100.0, (0, 384.4*(10**6), -1000), (0, 0, 0))
108108
109109
>>> acceleration_to_all(moon, [kg, earth1, earth2, moon])
110-
array([[ -4.46878801e-05],
111-
[ -5.48536334e-03],
112-
[ 6.07257588e-08]])
110+
array([[-4.46878801e-05],
111+
[-5.48536334e-03],
112+
[ 6.07257588e-08]])
113113
114114
"""
115115
total_acceleration = numpy.array([[0],
@@ -130,9 +130,9 @@ def calculate_position(body: Body, delta_time: float) -> numpy.ndarray:
130130
131131
>>> test_body = Body.from_tuple_parameters("Test_body", 1.0, 1.0, (60, -20, 15), (4, 10.2, -6))
132132
>>> calculate_position(test_body, 3.0)
133-
array([[ 72. ],
134-
[ 10.6],
135-
[ -3. ]])
133+
array([[72. ],
134+
[10.6],
135+
[-3. ]])
136136
"""
137137
return body.position + (delta_time * body.velocity)
138138

@@ -151,17 +151,17 @@ def calculate_velocity(one_body: Body, delta_time: float, other_bodies: [Body])
151151
>>> e5 = Body.from_tuple_parameters("Earth5", (5.972*(10**24)), 100.0, (6371000, 9000, -532), (0, 0, 0))
152152
>>> e6 = Body.from_tuple_parameters("Earth6", (5.972*(10**24)), 100.0, (-6371000, -9000, 532), (0, 0, 0))
153153
>>> calculate_velocity(kg, 314.0, [kg, e1, e2, e3, e4, e5, e6])
154-
array([[ 0.],
155-
[ 0.],
156-
[ 0.]])
154+
array([[0.],
155+
[0.],
156+
[0.]])
157157
158158
>>> kg = Body.from_tuple_parameters("kg", 1.0, 100.0, (0, 0, 0), (0, 0, 0))
159159
>>> earth1 = Body.from_tuple_parameters("Earth1", (5.972*(10**24)), 100.0, (0, 6371000, 6280), (0, 0, 0))
160160
>>> moon = Body.from_tuple_parameters("Moon", 0.0735*(10**24), 100.0, (0, 384.4*(10**6), -1000), (0, 0, 0))
161161
>>> calculate_velocity(kg, 16.0, [kg, earth1, moon])
162-
array([[ 0.00000000e+00],
163-
[ 1.57114698e+02],
164-
[ 1.54870030e-01]])
162+
array([[0.00000000e+00],
163+
[1.57114698e+02],
164+
[1.54870030e-01]])
165165
"""
166166

167167
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:
179179
>>> planet = merge_bodies(earth, moon)
180180
181181
>>> planet.position
182-
array([[ 1.50587842e+11],
183-
[ 4.67395352e+06],
184-
[ 9.27053180e+01]])
182+
array([[1.50587842e+11],
183+
[4.67395352e+06],
184+
[9.27053180e+01]])
185185
186186
>>> planet.velocity
187-
array([[ -8.60185262e+01],
188-
[ 2.85777959e+04],
189-
[ -7.59904061e-01]])
187+
array([[-8.60185262e+01],
188+
[ 2.85777959e+04],
189+
[-7.59904061e-01]])
190190
191191
>>> planet.radius
192192
6413824.949215559
@@ -235,7 +235,7 @@ def minimal_distance(bodies: [Body]) -> float:
235235
>>> saturn = Body.from_tuple_parameters('saturn', 568000000000000000000000000, 100, (0, 1352550000000, 0), (0, 10180, 0))
236236
>>> neptune = Body.from_tuple_parameters('neptune', 102413000000000000000000000, 100, (0, -4444450000000, 500000), (-5370, 0, 0))
237237
>>> minimal_distance([sun, earth, moon, jupiter, saturn, neptune])
238-
405500037.33168757
238+
np.float64(405500037.33168757)
239239
240240
>>> sun = Body.from_tuple_parameters('Sun', 1989000000000000000000000000000, 100, (0, 0, 0), (0, 0, 0))
241241
>>> earth = Body.from_tuple_parameters('earth', 5972000000000000000000000, 100, (0, 152100000000, 1000), (29290, 0, 32))
@@ -244,15 +244,15 @@ def minimal_distance(bodies: [Body]) -> float:
244244
>>> saturn = Body.from_tuple_parameters('saturn', 568000000000000000000000000, 100, (0, 1352550000000, 0), (0, 10180, 0))
245245
>>> neptune = Body.from_tuple_parameters('neptune', 102413000000000000000000000, 100, (0, -4444450000000, 500000), (-5370, 0, 0))
246246
>>> minimal_distance([sun, earth, moon, jupiter, saturn, neptune])
247-
405500037.76202041
247+
np.float64(405500037.7620204)
248248
249249
>>> sun = Body.from_tuple_parameters('Sun', 1989000000000000000000000000000, 100, (0, 0, 0), (0, 0, 0))
250250
>>> earth = Body.from_tuple_parameters('earth', 5972000000000000000000000, 100, (107550941418, 107550941418, 100000), (29290, 0, 32))
251251
>>> jupiter = Body.from_tuple_parameters('jupiter', 1900000000000000000000000000, 100, (816620000000, 0, -1000), (40, 12440, 1))
252252
>>> saturn = Body.from_tuple_parameters('saturn', 568000000000000000000000000, 100, (0, 1352550000000, 0), (0, 10180, 0))
253253
>>> neptune = Body.from_tuple_parameters('neptune', 102413000000000000000000000, 100, (0, -4444450000000, 500000), (-5370, 0, 0))
254254
>>> minimal_distance([sun, earth, jupiter, saturn, neptune])
255-
152099999999.3627
255+
np.float64(152099999999.3627)
256256
257257
>>> from nbp.helpers.numpy import tuple_to_numpy
258258
>>> import numpy as np

requirements-dev.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
pylint==1.5.5
2-
pytest==2.9.2
3-
codecov==2.0.5
4-
coverage==4.1
5-
pytest-cov==2.2.1
1+
pylint
2+
pytest
3+
codecov
4+
coverage
5+
pytest-cov

requirements.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
gevent==1.1.2
2-
bottle==0.12.9
3-
websockets==3.2
4-
bottle==0.12.9
5-
numpy==1.11.0
6-
cerberus==0.9.2
7-
pytest==2.9.2
1+
gevent
2+
bottle
3+
websockets
4+
numpy
5+
cerberus
6+
pytest

0 commit comments

Comments
 (0)