1 package net.sf.openrocket.gui.configdialog;
3 import java.lang.reflect.Method;
4 import java.util.ArrayList;
7 import net.sf.openrocket.gui.adaptors.DoubleModel;
8 import net.sf.openrocket.rocketcomponent.BodyTube;
9 import net.sf.openrocket.rocketcomponent.CenteringRing;
10 import net.sf.openrocket.rocketcomponent.RocketComponent;
11 import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
13 import org.junit.Assert;
14 import org.junit.BeforeClass;
15 import org.junit.Test;
17 public class FinSetConfigTest extends BaseTestCase {
22 public static void classSetup() throws Exception {
23 method = FinSetConfig.class.getDeclaredMethod("computeFinTabLength", List.class, Double.class, Double.class, DoubleModel.class, RocketComponent.class);
24 Assert.assertNotNull(method);
25 method.setAccessible(true);
29 * Test no centering rings.
34 public void testComputeFinTabLength() throws Exception {
35 DoubleModel dm = new DoubleModel(1d);
36 List<CenteringRing> rings = new ArrayList<CenteringRing>();
38 RocketComponent parent = new BodyTube();
40 Double result = (Double)method.invoke(null, rings, 10d, 11d, dm, parent);
41 Assert.assertEquals(0.0001, 11d, result.doubleValue());
42 result = (Double)method.invoke(null, null, 10d, 11d, dm, parent);
43 Assert.assertEquals(11d, result.doubleValue(), 0.0001);
47 * Test 2 rings both ahead of the fin.
50 public void testCompute2LeadingRings() throws Exception {
51 DoubleModel dm = new DoubleModel(1d);
52 List<CenteringRing> rings = new ArrayList<CenteringRing>();
54 RocketComponent parent = new BodyTube();
56 CenteringRing ring1 = new CenteringRing();
57 ring1.setLength(0.004);
58 ring1.setRelativePosition(RocketComponent.Position.TOP);
59 ring1.setPositionValue(0.43);
60 CenteringRing ring2 = new CenteringRing();
61 ring2.setLength(0.004);
62 ring2.setRelativePosition(RocketComponent.Position.TOP);
63 ring2.setPositionValue(0.45);
66 parent.addChild(ring1);
67 parent.addChild(ring2);
69 Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm, parent);
70 Assert.assertEquals(0.01, result.doubleValue(), 0.0001);
75 * Test one ring, ahead of the fin.
78 public void testCompute1Ring() throws Exception {
79 DoubleModel dm = new DoubleModel(1d);
80 List<CenteringRing> rings = new ArrayList<CenteringRing>();
82 CenteringRing ring1 = new CenteringRing();
83 ring1.setLength(0.004);
84 ring1.setRelativePosition(RocketComponent.Position.TOP);
85 ring1.setPositionValue(0.43);
88 RocketComponent parent = new BodyTube();
89 parent.addChild(ring1);
91 Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm, parent);
92 Assert.assertEquals(0.01, result.doubleValue(), 0.0001);
96 * Test one ring ahead of the fin, one ring within the root chord.
99 public void testComputeOneLeadingOneRingWithinRoot() throws Exception {
100 DoubleModel dm = new DoubleModel(1d);
101 List<CenteringRing> rings = new ArrayList<CenteringRing>();
103 CenteringRing ring1 = new CenteringRing();
104 ring1.setRelativePosition(RocketComponent.Position.TOP);
105 ring1.setLength(0.004);
106 ring1.setPositionValue(0.43);
107 CenteringRing ring2 = new CenteringRing();
108 ring2.setRelativePosition(RocketComponent.Position.TOP);
109 ring2.setLength(0.004);
110 ring2.setPositionValue(0.45);
114 RocketComponent parent = new BodyTube(1d, 0.01);
115 parent.addChild(ring1);
116 parent.addChild(ring2);
118 Double result = (Double)method.invoke(null, rings, 0.45d, 0.01, dm, parent);
119 Assert.assertEquals(0.01 - 0.004, result.doubleValue(), 0.0001);
123 * Test one ring ahead of the fin, one ring beyond the root chord.
126 public void testComputeOneLeadingOneTrailingRing() throws Exception {
127 DoubleModel dm = new DoubleModel(1d);
128 List<CenteringRing> rings = new ArrayList<CenteringRing>();
130 CenteringRing ring1 = new CenteringRing();
131 ring1.setRelativePosition(RocketComponent.Position.TOP);
132 ring1.setLength(0.004);
133 ring1.setPositionValue(0.43);
134 CenteringRing ring2 = new CenteringRing();
135 ring2.setRelativePosition(RocketComponent.Position.TOP);
136 ring2.setLength(0.004);
137 ring2.setPositionValue(0.48);
141 RocketComponent parent = new BodyTube();
142 Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm, ring1);
143 Assert.assertEquals(0.01, result.doubleValue(), 0.0001);
147 * Test one ring within the root chord, another ring beyond the root chord.
150 public void testComputeOneWithinRootOneTrailingRing() throws Exception {
151 DoubleModel dm = new DoubleModel(1d);
152 List<CenteringRing> rings = new ArrayList<CenteringRing>();
154 CenteringRing ring1 = new CenteringRing();
155 ring1.setRelativePosition(RocketComponent.Position.TOP);
156 ring1.setLength(0.004);
157 ring1.setPositionValue(0.4701);
158 CenteringRing ring2 = new CenteringRing();
159 ring2.setLength(0.004);
160 ring2.setRelativePosition(RocketComponent.Position.TOP);
161 ring2.setPositionValue(0.48);
164 RocketComponent parent = new BodyTube(1.0d, 0.1d);
165 parent.addChild(ring1);
166 parent.addChild(ring2);
167 Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm, parent);
168 Assert.assertEquals(0.0059, result.doubleValue(), 0.0001);
172 * Test both rings within the root chord.
175 public void testBothRingsWithinRootChord() throws Exception {
176 DoubleModel dm = new DoubleModel(1d);
177 List<CenteringRing> rings = new ArrayList<CenteringRing>();
179 RocketComponent parent = new BodyTube(1.0000d, 0.1d);
180 CenteringRing ring1 = new CenteringRing();
181 ring1.setRelativePosition(RocketComponent.Position.TOP);
182 ring1.setLength(0.004);
183 ring1.setPositionValue(0.4701);
184 parent.addChild(ring1);
185 CenteringRing ring2 = new CenteringRing();
186 ring2.setLength(0.004);
187 ring2.setRelativePosition(RocketComponent.Position.TOP);
188 ring2.setPositionValue(0.4750);
189 parent.addChild(ring2);
193 Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm, parent);
194 Assert.assertEquals(0.0009, result.doubleValue(), 0.0002);
199 * Test both rings beyond the root chord.
202 public void testBothRingsBeyondRootChord() throws Exception {
203 DoubleModel dm = new DoubleModel(1d);
204 List<CenteringRing> rings = new ArrayList<CenteringRing>();
206 CenteringRing ring1 = new CenteringRing();
207 ring1.setRelativePosition(RocketComponent.Position.TOP);
208 ring1.setLength(0.004);
209 ring1.setPositionValue(0.48);
210 CenteringRing ring2 = new CenteringRing();
211 ring2.setRelativePosition(RocketComponent.Position.TOP);
212 ring2.setLength(0.004);
213 ring2.setPositionValue(0.49);
216 RocketComponent parent = new BodyTube(1.0d, 0.1d);
217 parent.addChild(ring1);
218 parent.addChild(ring2);
220 Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm, parent);
221 Assert.assertEquals(0.0, result.doubleValue(), 0.0001);
225 * Test both rings within the root chord - the top ring has an adjacent ring (so 3 rings total).
228 public void test3RingsWithinRootChord() throws Exception {
229 DoubleModel dm = new DoubleModel(1d);
230 List<CenteringRing> rings = new ArrayList<CenteringRing>();
232 CenteringRing ring1 = new CenteringRing();
233 ring1.setRelativePosition(RocketComponent.Position.ABSOLUTE);
234 ring1.setLength(0.004);
235 ring1.setPositionValue(0.47);
236 CenteringRing ring2 = new CenteringRing();
237 ring2.setRelativePosition(RocketComponent.Position.ABSOLUTE);
238 ring2.setLength(0.004);
239 ring2.setPositionValue(0.4702);
240 CenteringRing ring3 = new CenteringRing();
241 ring3.setRelativePosition(RocketComponent.Position.ABSOLUTE);
242 ring3.setLength(0.004);
243 ring3.setPositionValue(0.4770);
247 BodyTube parent = new BodyTube(1.0d, 0.1d);
248 parent.setPositionValue(0);
249 parent.addChild(ring1);
250 parent.addChild(ring2);
251 parent.addChild(ring3);
253 Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm, parent);
254 Assert.assertEquals(0.0028, result.doubleValue(), 0.0001);