Skip to content

Commit 0d940dd

Browse files
committed
added getB vector input tests, removed bad test
1 parent 1d87012 commit 0d940dd

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

tests/test_Collection.py

-29
Original file line numberDiff line numberDiff line change
@@ -243,35 +243,6 @@ def test_GetB():
243243
assert round(result[j],rounding) == round(mockResult[j],rounding)
244244

245245

246-
def test_GetBList():
247-
# Check if sole getB throws an error
248-
# for Lists.
249-
from magpylib._lib.classes.magnets import Box
250-
#Input
251-
mockList = ( array([0.12488298, 0.10927261, 0.07805186]),
252-
array([0.12488298, 0.10927261, 0.07805186]),)
253-
mockResult = [ sum(mockList),
254-
sum(mockList)]
255-
256-
mag=(2,3,5)
257-
dim=(2,2,2)
258-
pos=array([ [2,2,2],
259-
[2,2,2]])
260-
261-
262-
with pytest.raises(IndexError):
263-
#Run
264-
b = Box(mag,dim)
265-
b2 = Box(mag,dim)
266-
c = Collection(b,b2)
267-
result = c.getB(pos)
268-
269-
rounding = 4
270-
for i in range(len(mockResult)):
271-
for j in range(3):
272-
assert round(result[i][j],rounding) == round(mockResult[i][j],rounding)
273-
274-
275246
def test_AddList():
276247
# Check if adding a list of generics to collection
277248
# does not throw an error
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import numpy as np
2+
import time
3+
import magpylib as magpy
4+
5+
POS = np.array([[1,2,3],[2,-3,4],[-3,4,5],[5,6,-7],[-3,-2,1],[-4,3,-2],[5,-4,-3],[-6,-5,-4]])
6+
7+
s = magpy.source.current.Circular(curr=123,dim=2,pos=(2,-4,5),angle=23,axis=(.2,-5,3))
8+
B = np.array([s.getB(p) for p in POS])
9+
Bv = s.getB(POS)
10+
err = np.amax(np.abs(Bv-B))
11+
assert err < 1e-12
12+
13+
VERT = POS*.333
14+
s = magpy.source.current.Line(curr=123,vertices=VERT)
15+
B = np.array([s.getB(p) for p in POS])
16+
Bv = s.getB(POS)
17+
err = np.amax(np.abs(Bv-B))
18+
assert err < 1e-12
19+
20+
s = magpy.source.moment.Dipole(moment=(.1,-5,5.5),pos=(2,-4,5),angle=33,axis=(.2,-5,3))
21+
B = np.array([s.getB(p) for p in POS])
22+
Bv = s.getB(POS)
23+
err = np.amax(np.abs(Bv-B))
24+
assert err < 1e-12
25+
26+
s = magpy.source.magnet.Box(mag=(33,22,111),dim=(3,2,1),pos=(2,-4,5),angle=33,axis=(.2,-5,3))
27+
B = np.array([s.getB(p) for p in POS])
28+
Bv = s.getB(POS)
29+
err = np.amax(np.abs(Bv-B))
30+
assert err < 1e-12
31+
32+
s = magpy.source.magnet.Cylinder(mag=(33,22,111),dim=(3,1),pos=(2,-4,5),angle=33,axis=(.2,-5,3))
33+
B = np.array([s.getB(p) for p in POS])
34+
Bv = s.getB(POS)
35+
err = np.amax(np.abs(Bv-B))
36+
assert err < 1e-12
37+
38+
s = magpy.source.magnet.Sphere(mag=(33,22,111),dim=.123,pos=(2,-4,5),angle=33,axis=(.2,-5,3))
39+
B = np.array([s.getB(p) for p in POS])
40+
Bv = s.getB(POS)
41+
err = np.amax(np.abs(Bv-B))
42+
assert err < 1e-12

0 commit comments

Comments
 (0)