-
Notifications
You must be signed in to change notification settings - Fork 0
/
qunit_test_legs.html
146 lines (97 loc) · 5.2 KB
/
qunit_test_legs.html
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test Suite</title>
<!-- Using local copies of QUnit: -->
<link rel="stylesheet" href="../../qunit-2.19.4/qunit-2.19.4.css">
<!-- <link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.19.4.css"> -->
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<!-- Using local copies of QUnit: -->
<!-- <script src="https://code.jquery.com/qunit/qunit-2.19.4.js"></script> -->
<script src="../../qunit-2.19.4/qunit-2.19.4.js"></script>
<script src="../../qunit-assert-close-git/qunit-assert-close/qunit-assert-close.js"></script>
<script src="debug.js"></script>
<script src="BCLegs.js"></script>
<script src="BCEndRings.js"></script>
<script src="BirdcageBuilder.js"></script>
<!-- see https://www.smashingmagazine.com/2012/06/introduction-to-javascript-unit-testing/ -->
<script>
QUnit.module('Birdcage Legs', function() {
// TODO - double check all NaN results are correct; try to make some better/more meaningful tests
// TODO - use Number.NEGATIVE_INFINITY and Inifinity to check those cases properly
// TODO - replace all deepEqual NaN checks with assert.true( isNaN(...))
QUnit.test('Rectangular Self Inductance', function(assert) {
var bb = new BirdcageBuilder(16, 128e6, 10, 12);
// TODO - change to new BCLegs subclass if only testing legs (search/replace all if possible)
assert.equal(bb.n_legs, 16);
// TODO equal vs. deepEqual; also == vs ===?
assert.deepEqual(bb.legs.calc_leg_self_inductance_rect(0, 1), NaN);
assert.equal( bb.legs.calc_leg_self_inductance_rect(1, 2), 1);
});
QUnit.test('Leg & Shield Positions', function(assert) {
var n = 16;
var rc = 10;
var rs = 12;
var bb = new BirdcageBuilder(n, 128e6, rc, rs);
var k;
for (k = 0; k < n; k++) {
assert.equal(Math.sqrt(Math.pow(bb.legs.leg_x[k], 2) + Math.pow(bb.legs.leg_y[k], 2)), rc, 'Leg Radius i=' + k);
}
// TODO - using method of images; shield "legs" do not fall on shield radius
// TODO - instead, need to test if the E-field is 0 at the shield radius... how?
//for (k = 0; k < n; k++) {
// assert.equal(Math.sqrt(Math.pow(bb.legs.shield_x[k], 2) + Math.pow(bb.legs.shield_y[k], 2)), rs, 'Shield Radius i=' + k);
//}
});
QUnit.test('Tubular Self Inductance (R_inner = 0)', function(assert) {
var bb = new BirdcageBuilder(16, 128e6, 10, 12);
assert.equal( bb.legs.calc_leg_self_inductance_tube(1, 0, 4), -1.5);
assert.deepEqual(bb.legs.calc_leg_self_inductance_tube(0, 0, 4), NaN);
});
QUnit.test('Tubular Self Inductance (R_inner > 0)', function(assert) {
var bb = new BirdcageBuilder(16, 128e6, 10, 12);
// TODO need better tests with the k/ratio factor
// TODO can't easily force k to a nice number...
//assert.equal(bb.calc_leg_self_inductance_tube(1 0, 4), -1.5);
assert.deepEqual(bb.legs.calc_leg_self_inductance_tube(1, 2, 0), NaN);
assert.deepEqual(bb.legs.calc_leg_self_inductance_tube(0, 2, 0), NaN);
var c = 2*(0.1493 - 0.3606 - 0.0405 + 0.2526 - 1); // hack
assert.equal(bb.legs.calc_leg_self_inductance_tube(1, 4, 4), c);
});
QUnit.test('Leg Mutual Inductance (Math Test Only)', function(assert) {
var bb = new BirdcageBuilder(1, 128e6, 1, 2);
bb.legs.set_legs_rect(1, 1); // TODO
// TODO is this really a bug, or is a loose tolerance assertion ok for this?
// why isn't it exact?
//assert.close(bb.legs.helper_Lmn(1., 1.), 2*Math.log(2), 1e-15);
assert.close(bb.legs.helper_Lmn(1., 1.), 2*Math.log(1+Math.sqrt(2))-2*Math.sqrt(2) + 2, 1e-15);
assert.close(bb.legs.helper_Lmn(1., 1.), 2*(Math.log(1+Math.sqrt(2)) - Math.sqrt(2)+ 1), 1e-15);
//assert.equal(bb.helper_Lmn(1., 1.), 2*Math.log(2)); // TODO - why isn't this exact? just flotaing point error???
// Test my Lmn vs. original
var l, d;
l = 1.0;
d = 1.0;
assert.equal(bb.legs.helper_Lmn(l, d), bb.legs.helper_Lmn_orig(l, d), 'Lmn(1,1) == Original');
// Output from Java:
//Lmn(1, 1): 0.9343201
//Lmn(1, 2): 0.49028754
//Lmn(2, 1): 3.3024058
assert.close(bb.legs.helper_Lmn(1, 1), 0.9343201, 1e-7, 'Lmn(1,1) close to Java output');
assert.close(bb.legs.helper_Lmn(1, 2), 0.49028754, 1e-6, 'Lmn(1,1) close to Java output'); // adjusted tolerance to 10^-6
assert.close(bb.legs.helper_Lmn(2, 1), 3.3024058, 1e-6, 'Lmn(1,1) close to Java output'); // adjusted tolerance to 10^-6
// TODO continue tests
// TODO test final mutual inductance result
});
QUnit.test('Shield Mutual Inductance', function(assert) {
var bb = new BirdcageBuilder(1, 128e6, 1, 2);
// TODO is this really a bug, or is a loose tolerance assertion ok for this?
// why isn't it exact?
//assert.close(bb.legs.helper_Lmn(1., 1.), 2*Math.log(2), 1e-15); // from old (wrong) Lmn calculation
assert.close(bb.legs.helper_Lmn(1., 1.), 2*(Math.log(1 +Math.sqrt(2)) - Math.sqrt(2) + 1), 1e-15); // from old (wrong) Lmn calculation
// TODO continue tests
// TODO test final mutual inductance result
});
}); // end Birdcage Legs tests
</script>
</body>