create changelog entry
[debian/openrocket] / core / test / net / sf / openrocket / gui / configdialog / FinSetConfigTest.java
1 package net.sf.openrocket.gui.configdialog;
2
3 import java.lang.reflect.Method;
4 import java.util.ArrayList;
5 import java.util.List;
6
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;
12
13 import org.junit.Assert;
14 import org.junit.BeforeClass;
15 import org.junit.Test;
16
17 public class FinSetConfigTest extends BaseTestCase {
18
19     static Method method;
20
21     @BeforeClass
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);
26     }
27
28     /**
29      * Test no centering rings.
30      *
31      * @throws Exception
32      */
33     @Test
34     public void testComputeFinTabLength() throws Exception {
35         DoubleModel dm = new DoubleModel(1d);
36         List<CenteringRing> rings = new ArrayList<CenteringRing>();
37
38         RocketComponent parent = new BodyTube();
39
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);
44     }
45
46     /**
47      * Test 2 rings both ahead of the fin.
48      */
49     @Test
50     public void testCompute2LeadingRings() throws Exception {
51         DoubleModel dm = new DoubleModel(1d);
52         List<CenteringRing> rings = new ArrayList<CenteringRing>();
53
54         RocketComponent parent = new BodyTube();
55
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);
64         rings.add(ring1);
65         rings.add(ring2);
66         parent.addChild(ring1);
67         parent.addChild(ring2);
68
69         Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm, parent);
70         Assert.assertEquals(0.01, result.doubleValue(), 0.0001);
71         
72     }
73
74     /**
75      * Test one ring, ahead of the fin.
76      */
77     @Test
78     public void testCompute1Ring() throws Exception {
79         DoubleModel dm = new DoubleModel(1d);
80         List<CenteringRing> rings = new ArrayList<CenteringRing>();
81
82         CenteringRing ring1 = new CenteringRing();
83         ring1.setLength(0.004);
84         ring1.setRelativePosition(RocketComponent.Position.TOP);
85         ring1.setPositionValue(0.43);
86         rings.add(ring1);
87
88         RocketComponent parent = new BodyTube();
89         parent.addChild(ring1);
90
91         Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm, parent);
92         Assert.assertEquals(0.01, result.doubleValue(), 0.0001);
93     }
94
95     /**
96      * Test one ring ahead of the fin, one ring within the root chord.
97      */
98     @Test
99     public void testComputeOneLeadingOneRingWithinRoot() throws Exception {
100         DoubleModel dm = new DoubleModel(1d);
101         List<CenteringRing> rings = new ArrayList<CenteringRing>();
102
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);
111         rings.add(ring1);
112         rings.add(ring2);
113
114         RocketComponent parent = new BodyTube(1d, 0.01);
115         parent.addChild(ring1);
116         parent.addChild(ring2);
117
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);
120     }
121
122     /**
123      * Test one ring ahead of the fin, one ring beyond the root chord.
124      */
125     @Test
126     public void testComputeOneLeadingOneTrailingRing() throws Exception {
127         DoubleModel dm = new DoubleModel(1d);
128         List<CenteringRing> rings = new ArrayList<CenteringRing>();
129
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);
138         rings.add(ring1);
139         rings.add(ring2);
140
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);
144     }
145
146     /**
147      * Test one ring within the root chord, another ring beyond the root chord.
148      */
149     @Test
150     public void testComputeOneWithinRootOneTrailingRing() throws Exception {
151         DoubleModel dm = new DoubleModel(1d);
152         List<CenteringRing> rings = new ArrayList<CenteringRing>();
153
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);
162         rings.add(ring1);
163         rings.add(ring2);
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);
169     }
170     
171     /**
172      * Test both rings within the root chord.
173      */
174     @Test
175     public void testBothRingsWithinRootChord() throws Exception {
176         DoubleModel dm = new DoubleModel(1d);
177         List<CenteringRing> rings = new ArrayList<CenteringRing>();
178
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);
190         rings.add(ring1);
191         rings.add(ring2);
192
193         Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm, parent);
194         Assert.assertEquals(0.0009, result.doubleValue(), 0.0002);
195     }
196
197
198     /**
199      * Test both rings beyond the root chord.
200      */
201     @Test
202     public void testBothRingsBeyondRootChord() throws Exception {
203         DoubleModel dm = new DoubleModel(1d);
204         List<CenteringRing> rings = new ArrayList<CenteringRing>();
205
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);
214         rings.add(ring1);
215         rings.add(ring2);
216         RocketComponent parent = new BodyTube(1.0d, 0.1d);
217         parent.addChild(ring1);
218         parent.addChild(ring2);
219
220         Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm, parent);
221         Assert.assertEquals(0.0, result.doubleValue(), 0.0001);
222     }
223
224     /**
225      * Test both rings within the root chord - the top ring has an adjacent ring (so 3 rings total).
226      */
227     @Test
228     public void test3RingsWithinRootChord() throws Exception {
229         DoubleModel dm = new DoubleModel(1d);
230         List<CenteringRing> rings = new ArrayList<CenteringRing>();
231
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);
244         rings.add(ring1);
245         rings.add(ring2);
246         rings.add(ring3);
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);
252
253         Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm, parent);
254         Assert.assertEquals(0.0028, result.doubleValue(), 0.0001);
255     }
256
257 }