Skip to content

Commit

Permalink
Create test_particle_in_field.py (#9)
Browse files Browse the repository at this point in the history
* Create test_particle_in_field.py

* Create basic working test

* Add ChargedParticle test
  • Loading branch information
kphlips authored Jul 29, 2020
1 parent 44def59 commit 8f322f4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output/
__pycache__/
.DS_Store
.coverage
40 changes: 40 additions & 0 deletions test_particle_in_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Tests the EMWave and ChargedParticle PhysicsModules"""

import pytest
from turbopy import Simulation
from particle_in_field import EMWave, ChargedParticle

wave_data = {"amplitude": 10, "omega": 18}
particle_data = {"position": 25, "pusher": "ForwardEuler"}


@pytest.fixture(name="sim_example")
def fixture():
""""Creates a Simulation object to be used as the owner of an
EMWave object and a ChargedParticle PhysicsModule for testing"""
input_data = {"Grid": {"N": 10, "min": 20, "max": 30},
"PhysicsModules": {"EMWave": wave_data,
"ChargedParticle": particle_data},
"Tools": {"ForwardEuler": {}},
"Clock": {"start_time": 0, "end_time": 1, "num_steps": 2}}
sim = Simulation(input_data)
sim.prepare_simulation()
return sim


def test_emwave(sim_example):
"""Tests the EMWave PhysicsModule"""
em_example = EMWave(sim_example, wave_data)
assert isinstance(em_example, EMWave)
assert em_example.c == 2.998e8
assert em_example.E0 == wave_data["amplitude"]
assert em_example.omega == wave_data["omega"]
assert em_example.k == wave_data["omega"] / 2.998e8


def test_chargedparticle(sim_example):
"""Tests the ChargedParticle PhysicsModule"""
charged_example = ChargedParticle(sim_example, particle_data)
assert isinstance(charged_example, ChargedParticle)
assert charged_example.E is None
assert charged_example.x == particle_data["position"]

0 comments on commit 8f322f4

Please sign in to comment.