Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e4fb121

Browse files
committedJun 14, 2019
Add test file for cases pertaining magpylib#132
1 parent a65fd18 commit e4fb121

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
 

‎tests/test_tarcisBug.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import magpylib as magpy
2+
import numpy
3+
import unittest
4+
5+
def test_rounding_error():
6+
## This describes the rotation bug.
7+
## Once it is fixed, this test will break.
8+
I = 1
9+
d = 10e+05
10+
p0 = [0,0,0]
11+
12+
c = magpy.source.current.Circular(curr=I, dim=d,pos=[0,0,d/4])
13+
14+
c.rotate(90,[0,0,1],anchor=[0,0,0])
15+
c.rotate(90,[1,0,0],anchor=[0,0,0])
16+
#print(c.angle) #These turn out differently for both cases.
17+
#print(c.axis)
18+
19+
result1 = c.getB(p0)
20+
21+
c = magpy.source.current.Circular(curr=I, dim=d,pos=[0,0,d/4])
22+
23+
c.rotate(90,[1,0,0],anchor=[0,0,0])
24+
#print(c.angle)
25+
#print(c.axis)
26+
27+
result2 = c.getB(p0)
28+
assert all(numpy.isclose(result1,result2)==True) is False
29+
30+
31+
def test_rounding_error_small_dimension():
32+
## This describes a case where the bug does not occur.
33+
I = 1
34+
d = 10e+03
35+
p0 = [0,0,0]
36+
37+
c = magpy.source.current.Circular(curr=I, dim=d,pos=[0,0,d/4])
38+
39+
c.rotate(90,[0,0,1],anchor=[0,0,0])
40+
c.rotate(90,[1,0,0],anchor=[0,0,0])
41+
42+
result1 = c.getB(p0)
43+
44+
c = magpy.source.current.Circular(curr=I, dim=d,pos=[0,0,d/4])
45+
46+
c.rotate(90,[1,0,0],anchor=[0,0,0])
47+
48+
result2 = c.getB(p0)
49+
assert all(numpy.isclose(result1,result2)==True)
50+
51+
def test_rounding_error_large_dimension():
52+
## This describes a case where the bug does not occur.
53+
I = 1
54+
d = 10e+08
55+
p0 = [0,0,0]
56+
57+
c = magpy.source.current.Circular(curr=I, dim=d,pos=[0,0,d/4])
58+
59+
c.rotate(90,[0,0,1],anchor=[0,0,0])
60+
c.rotate(90,[1,0,0],anchor=[0,0,0])
61+
62+
result1 = c.getB(p0)
63+
64+
c = magpy.source.current.Circular(curr=I, dim=d,pos=[0,0,d/4])
65+
66+
c.rotate(90,[1,0,0],anchor=[0,0,0])
67+
68+
result2 = c.getB(p0)
69+
assert all(numpy.isclose(result1,result2)==True)
70+

0 commit comments

Comments
 (0)
Please sign in to comment.