-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_PointFieldFiles.py
42 lines (34 loc) · 1.94 KB
/
test_PointFieldFiles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from Particle import Particle
from AbstractPointField import AbstractPointFieldClass
from PointElectricField import PointElectricFieldClass
from PointMagneticField import PointMagneticFieldClass
from SumEMFields import EMFieldClass
import numpy as np
import math
import scipy
import pytest
import re
test_Particle = Particle(position=np.array([10, 100, 1000]),
velocity=np.array([1e6, 1.5e6, 2e6]), acceleration=np.array([2.5e3, 3e3, 3.5e3])
, name='test_Particle', restMass=3.0, charge=7.0)
test_Particle2 = Particle(position=np.array([4, 3, 2]),
velocity=np.array([2.5e6, 3e6, 3.5e6]), acceleration=np.array([1.0, 9.0, 2.0])
, name='test_Particle2', restMass=3.0, charge=14.0)
test_PointElectricField = PointElectricFieldClass(sourceParticle=test_Particle, name="test_Particle Electric Field")
test_PointMagneticField = PointMagneticFieldClass(sourceParticle=test_Particle, name="test_Particle Magnetic Field")
def test_PointElectricField__repr__():
# test that the repr function works
assert re.findall(
"Electric Point Field: test_Particle Electric Field", test_PointElectricField.__repr__()) == ["Electric Point Field: test_Particle Electric Field"]
def test_GenerateElectricField():
# test that the electric field is calculated correctly
assert test_PointElectricField.GenerateField(test_Particle2) == pytest.approx(
np.array([-374.41274741, -6053.00608319, -62277.32031987]), rel=0.06)
def test_PointMagneticField__repr__():
# test that the repr function works
assert re.findall(
"Magnetic Point Field: test_Particle Magnetic Field", test_PointMagneticField.__repr__()) == ["Magnetic Point Field: test_Particle Magnetic Field"]
def test_GenerateMagneticField():
# test that the magnetic field is calculated correctly
assert test_PointMagneticField.GenerateField(test_Particle2) == pytest.approx(
np.array([-9.04695408e-07, 6.84596832e-07, -6.10999201e-08]), rel=0.06)