mirror of
https://github.com/NotAShelf/projectile-simulation.git
synced 2024-11-22 13:20:47 +00:00
testing framework
This commit is contained in:
parent
1c80a7508e
commit
d2cfdd6d25
2 changed files with 76 additions and 22 deletions
7
.github/workflows/python-package.yml
vendored
7
.github/workflows/python-package.yml
vendored
|
@ -11,7 +11,6 @@ on:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
|
@ -19,16 +18,20 @@ jobs:
|
||||||
python-version: ["3.10", "3.11"]
|
python-version: ["3.10", "3.11"]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
uses: actions/setup-python@v3
|
uses: actions/setup-python@v3
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
python -m pip install flake8 pytest
|
python -m pip install flake8 pytest
|
||||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||||
|
|
||||||
- name: Lint with flake8
|
- name: Lint with flake8
|
||||||
run: |
|
run: |
|
||||||
# stop the build if there are Python syntax errors or undefined names
|
# stop the build if there are Python syntax errors or undefined names
|
||||||
|
|
51
test_main.py
Normal file
51
test_main.py
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
import unittest
|
||||||
|
from projectile.simulation import ProjectileSimulation
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
class TestProjectileSimulation(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.sim = ProjectileSimulation()
|
||||||
|
|
||||||
|
def test_reset(self):
|
||||||
|
self.sim.reset()
|
||||||
|
self.assertEqual(self.sim.x, [0])
|
||||||
|
self.assertEqual(self.sim.y, [self.sim.h_init])
|
||||||
|
self.assertEqual(self.sim.vx, [self.sim.v_init * np.cos(self.sim.theta)])
|
||||||
|
self.assertEqual(self.sim.vy, [self.sim.v_init * np.sin(self.sim.theta)])
|
||||||
|
self.assertEqual(self.sim.t, [0])
|
||||||
|
|
||||||
|
def test_calculate_acceleration(self):
|
||||||
|
state = [
|
||||||
|
0,
|
||||||
|
self.sim.h_init,
|
||||||
|
self.sim.v_init * np.cos(self.sim.theta),
|
||||||
|
self.sim.v_init * np.sin(self.sim.theta),
|
||||||
|
]
|
||||||
|
acceleration = self.sim.calculate_acceleration(0, state)
|
||||||
|
self.assertEqual(len(acceleration), 4)
|
||||||
|
|
||||||
|
def test_update_state(self):
|
||||||
|
state = [
|
||||||
|
0,
|
||||||
|
self.sim.h_init,
|
||||||
|
self.sim.v_init * np.cos(self.sim.theta),
|
||||||
|
self.sim.v_init * np.sin(self.sim.theta),
|
||||||
|
]
|
||||||
|
new_state = self.sim.update_state(0, state)
|
||||||
|
self.assertEqual(len(new_state), 4)
|
||||||
|
|
||||||
|
def test_run(self):
|
||||||
|
self.sim.run()
|
||||||
|
self.assertTrue(self.sim.t[-1] >= self.sim.t_end)
|
||||||
|
|
||||||
|
def test_print_range(self):
|
||||||
|
self.sim.run()
|
||||||
|
range_projectile = self.sim.x[-1]
|
||||||
|
self.assertEqual(
|
||||||
|
self.sim.print_range(), f"Range of projectile: {range_projectile:.2f} m"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
Loading…
Reference in a new issue