Skip to content
Snippets Groups Projects
Commit 9bbb954e authored by Jörn Ungermann's avatar Jörn Ungermann
Browse files

fixed some of the testcases.

parent f49e5089
No related branches found
No related tags found
No related merge requests found
......@@ -34,7 +34,7 @@ class TestCaseAnalytic(unittest.TestCase):
width = (self.dim[0]/2, self.dim[1]/2, self.dim[2]/2)
phase = an.phase_mag_slab(self.dim, self.res, self.phi, self.center, width)
reference = np.load(os.path.join(self.path, 'ref_phase_slab.npy'))
np.testing.assert_equal(phase, reference, 'Unexpected behavior in phase_mag_slab()')
np.testing.assert_almost_equal(phase, reference, err_msg='Unexpected behavior in phase_mag_slab()')
def test_phase_mag_disc(self):
'''Test of the phase_mag_disc method.'''
......@@ -42,14 +42,14 @@ class TestCaseAnalytic(unittest.TestCase):
height = self.dim[2]/2
phase = an.phase_mag_disc(self.dim, self.res, self.phi, self.center, radius, height)
reference = np.load(os.path.join(self.path, 'ref_phase_disc.npy'))
np.testing.assert_equal(phase, reference, 'Unexpected behavior in phase_mag_disc()')
np.testing.assert_almost_equal(phase, reference, err_msg='Unexpected behavior in phase_mag_disc()')
def test_phase_mag_sphere(self):
'''Test of the phase_mag_sphere method.'''
radius = self.dim[2]/4
phase = an.phase_mag_sphere(self.dim, self.res, self.phi, self.center, radius)
reference = np.load(os.path.join(self.path, 'ref_phase_sphere.npy'))
np.testing.assert_equal(phase, reference, 'Unexpected behavior in phase_mag_sphere()')
np.testing.assert_almost_equal(phase, reference, err_msg='Unexpected behavior in phase_mag_sphere()')
def test_phase_mag_vortex(self):
'''Test of the phase_mag_vortex method.'''
......@@ -57,7 +57,7 @@ class TestCaseAnalytic(unittest.TestCase):
height = self.dim[2]/2
phase = an.phase_mag_vortex(self.dim, self.res, self.center, radius, height)
reference = np.load(os.path.join(self.path, 'ref_phase_vort.npy'))
np.testing.assert_equal(phase, reference, 'Unexpected behavior in phase_mag_vortex()')
np.testing.assert_almost_equal(phase, reference, err_msg='Unexpected behavior in phase_mag_vortex()')
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestCaseAnalytic)
......
......@@ -20,52 +20,52 @@ class TestCaseMagCreator(unittest.TestCase):
def test_shape_slab(self):
test_slab = mc.Shapes.slab((5, 6, 7), (2, 3, 4), (1, 3, 5))
np.testing.assert_equal(test_slab, np.load(os.path.join(self.path, 'ref_slab.npy')),
'Created slab does not match expectation!')
np.testing.assert_almost_equal(test_slab, np.load(os.path.join(self.path, 'ref_slab.npy')),
err_msg='Created slab does not match expectation!')
def test_shape_disc(self):
test_disc_z = mc.Shapes.disc((5, 6, 7), (2, 3, 4), 2, 3, 'z')
test_disc_y = mc.Shapes.disc((5, 6, 7), (2, 3, 4), 2, 3, 'y')
test_disc_x = mc.Shapes.disc((5, 6, 7), (2, 3, 4), 2, 3, 'x')
np.testing.assert_equal(test_disc_z, np.load(os.path.join(self.path, 'ref_disc_z.npy')),
'Created disc in z-direction does not match expectation!')
np.testing.assert_equal(test_disc_y, np.load(os.path.join(self.path, 'ref_disc_y.npy')),
'Created disc in y-direction does not match expectation!')
np.testing.assert_equal(test_disc_x, np.load(os.path.join(self.path, 'ref_disc_x.npy')),
'Created disc in x-direction does not match expectation!')
np.testing.assert_almost_equal(test_disc_z, np.load(os.path.join(self.path, 'ref_disc_z.npy')),
err_msg='Created disc in z-direction does not match expectation!')
np.testing.assert_almost_equal(test_disc_y, np.load(os.path.join(self.path, 'ref_disc_y.npy')),
err_msg='Created disc in y-direction does not match expectation!')
np.testing.assert_almost_equal(test_disc_x, np.load(os.path.join(self.path, 'ref_disc_x.npy')),
err_msg='Created disc in x-direction does not match expectation!')
def test_shape_sphere(self):
test_sphere = mc.Shapes.sphere((5, 6, 7), (2, 3, 4), 2)
np.testing.assert_equal(test_sphere, np.load(os.path.join(self.path, 'ref_sphere.npy')),
'Created sphere does not match expectation!')
np.testing.assert_almost_equal(test_sphere, np.load(os.path.join(self.path, 'ref_sphere.npy')),
err_msg='Created sphere does not match expectation!')
def test_shape_filament(self):
test_filament_z = mc.Shapes.filament((5, 6, 7), (2, 3), 'z')
test_filament_y = mc.Shapes.filament((5, 6, 7), (2, 3), 'y')
test_filament_x = mc.Shapes.filament((5, 6, 7), (2, 3), 'x')
np.testing.assert_equal(test_filament_z, np.load(os.path.join(self.path, 'ref_fil_z.npy')),
'Created filament in z-direction does not match expectation!')
np.testing.assert_equal(test_filament_y, np.load(os.path.join(self.path, 'ref_fil_y.npy')),
'Created filament in y-direction does not match expectation!')
np.testing.assert_equal(test_filament_x, np.load(os.path.join(self.path, 'ref_fil_x.npy')),
'Created filament in x-direction does not match expectation!')
np.testing.assert_almost_equal(test_filament_z, np.load(os.path.join(self.path, 'ref_fil_z.npy')),
err_msg='Created filament in z-direction does not match expectation!')
np.testing.assert_almost_equal(test_filament_y, np.load(os.path.join(self.path, 'ref_fil_y.npy')),
err_msg='Created filament in y-direction does not match expectation!')
np.testing.assert_almost_equal(test_filament_x, np.load(os.path.join(self.path, 'ref_fil_x.npy')),
err_msg='Created filament in x-direction does not match expectation!')
def test_shape_pixel(self):
test_pixel = mc.Shapes.pixel((5, 6, 7), (2, 3, 4))
np.testing.assert_equal(test_pixel, np.load(os.path.join(self.path, 'ref_pixel.npy')),
'Created pixel does not match expectation!')
np.testing.assert_almost_equal(test_pixel, np.load(os.path.join(self.path, 'ref_pixel.npy')),
err_msg='Created pixel does not match expectation!')
def test_create_mag_dist_homog(self):
mag_shape = mc.Shapes.disc((1, 10, 10), (0, 4.5, 4.5), 3, 1)
magnitude = mc.create_mag_dist_homog(mag_shape, pi/4)
np.testing.assert_equal(magnitude, np.load(os.path.join(self.path, 'ref_mag_disc.npy')),
'Created homog. magnetic distribution does not match expectation')
np.testing.assert_almost_equal(magnitude, np.load(os.path.join(self.path, 'ref_mag_disc.npy')),
err_msg='Created homog. magnetic distribution does not match expectation')
def test_create_mag_dist_vortex(self):
mag_shape = mc.Shapes.disc((1, 10, 10), (0, 4.5, 4.5), 3, 1)
magnitude = mc.create_mag_dist_vortex(mag_shape)
np.testing.assert_equal(magnitude, np.load(os.path.join(self.path, 'ref_mag_vort.npy')),
'Created vortex magnetic distribution does not match expectation')
np.testing.assert_almost_equal(magnitude, np.load(os.path.join(self.path, 'ref_mag_vort.npy')),
err_msg='Created vortex magnetic distribution does not match expectation')
if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment