cbc6113f3178261e997c51a7e280a61d50000224
[debian/openrocket] / test / net / sf / openrocket / gui / configdialog / FinSetConfigTest.java
1 package net.sf.openrocket.gui.configdialog;
2
3 import net.sf.openrocket.gui.adaptors.DoubleModel;
4 import net.sf.openrocket.rocketcomponent.CenteringRing;
5 import org.junit.Assert;
6 import org.junit.BeforeClass;
7 import org.junit.Test;
8
9 import java.lang.reflect.Method;
10 import java.util.ArrayList;
11 import java.util.List;
12
13 public class FinSetConfigTest {
14
15     static Method method;
16
17     @BeforeClass
18     public static void classSetup() throws Exception {
19         method = FinSetConfig.class.getDeclaredMethod("computeFinTabLength", List.class, Double.class, Double.class, DoubleModel.class);
20         Assert.assertNotNull(method);
21         method.setAccessible(true);
22     }
23
24     /**
25      * Test no centering rings.
26      *
27      * @throws Exception
28      */
29     @Test
30     public void testComputeFinTabLength() throws Exception {
31         DoubleModel dm = new DoubleModel(1d);
32         List<CenteringRing> rings = new ArrayList<CenteringRing>();
33         
34         Double result = (Double)method.invoke(null, rings, 10d, 11d, dm);
35         Assert.assertEquals(0.0001, 11d, result.doubleValue());
36         result = (Double)method.invoke(null, null, 10d, 11d, dm);
37         Assert.assertEquals(11d, result.doubleValue(), 0.0001);
38     }
39
40     /**
41      * Test 2 rings both ahead of the fin.
42      */
43     @Test
44     public void testCompute2LeadingRings() throws Exception {
45         DoubleModel dm = new DoubleModel(1d);
46         List<CenteringRing> rings = new ArrayList<CenteringRing>();
47
48         CenteringRing ring1 = new CenteringRing();
49         ring1.setLength(0.004);
50         ring1.setPositionValue(0.43);
51         CenteringRing ring2 = new CenteringRing();
52         ring2.setLength(0.004);
53         ring2.setPositionValue(0.45);
54         rings.add(ring1);
55         rings.add(ring2);
56
57         Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm);
58         Assert.assertEquals(0.01, result.doubleValue(), 0.0001);
59         
60     }
61
62     /**
63      * Test one ring, ahead of the fin.
64      */
65     @Test
66     public void testCompute1Ring() throws Exception {
67         DoubleModel dm = new DoubleModel(1d);
68         List<CenteringRing> rings = new ArrayList<CenteringRing>();
69
70         CenteringRing ring1 = new CenteringRing();
71         ring1.setLength(0.004);
72         ring1.setPositionValue(0.43);
73         rings.add(ring1);
74
75         Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm);
76         Assert.assertEquals(0.01, result.doubleValue(), 0.0001);
77     }
78
79     /**
80      * Test one ring ahead of the fin, one ring within the root chord.
81      */
82     @Test
83     public void testComputeOneLeadingOneRingWithinRoot() throws Exception {
84         DoubleModel dm = new DoubleModel(1d);
85         List<CenteringRing> rings = new ArrayList<CenteringRing>();
86
87         CenteringRing ring1 = new CenteringRing();
88         ring1.setLength(0.004);
89         ring1.setPositionValue(0.43);
90         CenteringRing ring2 = new CenteringRing();
91         ring2.setLength(0.004);
92         ring2.setPositionValue(0.45);
93         rings.add(ring1);
94         rings.add(ring2);
95
96         Double result = (Double)method.invoke(null, rings, 0.45d, 0.01, dm);
97         Assert.assertEquals(0.01 - 0.004, result.doubleValue(), 0.0001);
98     }
99
100     /**
101      * Test one ring ahead of the fin, one ring beyond the root chord.
102      */
103     @Test
104     public void testComputeOneLeadingOneTrailingRing() throws Exception {
105         DoubleModel dm = new DoubleModel(1d);
106         List<CenteringRing> rings = new ArrayList<CenteringRing>();
107
108         CenteringRing ring1 = new CenteringRing();
109         ring1.setLength(0.004);
110         ring1.setPositionValue(0.43);
111         CenteringRing ring2 = new CenteringRing();
112         ring2.setLength(0.004);
113         ring2.setPositionValue(0.48);
114         rings.add(ring1);
115         rings.add(ring2);
116
117         Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm);
118         Assert.assertEquals(0.01, result.doubleValue(), 0.0001);
119     }
120
121     /**
122      * Test one ring within the root chord, another ring beyond the root chord.
123      */
124     @Test
125     public void testComputeOneWithinRootOneTrailingRing() throws Exception {
126         DoubleModel dm = new DoubleModel(1d);
127         List<CenteringRing> rings = new ArrayList<CenteringRing>();
128
129         CenteringRing ring1 = new CenteringRing();
130         ring1.setLength(0.004);
131         ring1.setPositionValue(0.4701);
132         CenteringRing ring2 = new CenteringRing();
133         ring2.setLength(0.004);
134         ring2.setPositionValue(0.48);
135         rings.add(ring1);
136         rings.add(ring2);
137
138         Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm);
139         Assert.assertEquals(0.0059, result.doubleValue(), 0.0001);
140     }
141     
142     /**
143      * Test both rings within the root chord.
144      */
145     @Test
146     public void testBothRingsWithinRootChord() throws Exception {
147         DoubleModel dm = new DoubleModel(1d);
148         List<CenteringRing> rings = new ArrayList<CenteringRing>();
149
150         CenteringRing ring1 = new CenteringRing();
151         ring1.setLength(0.004);
152         ring1.setPositionValue(0.4701);
153         CenteringRing ring2 = new CenteringRing();
154         ring2.setLength(0.004);
155         ring2.setPositionValue(0.4750);
156         rings.add(ring1);
157         rings.add(ring2);
158
159         Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm);
160         Assert.assertEquals(0.0009, result.doubleValue(), 0.0001);
161     }
162
163
164     /**
165      * Test both rings beyond the root chord.
166      */
167     @Test
168     public void testBothRingsBeyondRootChord() throws Exception {
169         DoubleModel dm = new DoubleModel(1d);
170         List<CenteringRing> rings = new ArrayList<CenteringRing>();
171
172         CenteringRing ring1 = new CenteringRing();
173         ring1.setLength(0.004);
174         ring1.setPositionValue(0.48);
175         CenteringRing ring2 = new CenteringRing();
176         ring2.setLength(0.004);
177         ring2.setPositionValue(0.49);
178         rings.add(ring1);
179         rings.add(ring2);
180
181         Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm);
182         Assert.assertEquals(0.006, result.doubleValue(), 0.0001);
183     }
184
185     /**
186      * Test both rings within the root chord - the top ring has an adjacent ring (so 3 rings total).
187      */
188     @Test
189     public void test3RingsWithinRootChord() throws Exception {
190         DoubleModel dm = new DoubleModel(1d);
191         List<CenteringRing> rings = new ArrayList<CenteringRing>();
192
193         CenteringRing ring1 = new CenteringRing();
194         ring1.setLength(0.004);
195         ring1.setPositionValue(0.47);
196         CenteringRing ring2 = new CenteringRing();
197         ring2.setLength(0.004);
198         ring2.setPositionValue(0.4702);
199         CenteringRing ring3 = new CenteringRing();
200         ring3.setLength(0.004);
201         ring3.setPositionValue(0.4770);
202         rings.add(ring1);
203         rings.add(ring2);
204         rings.add(ring3);
205
206         Double result = (Double)method.invoke(null, rings, 0.47d, 0.01, dm);
207         Assert.assertEquals(0.0028, result.doubleValue(), 0.0001);
208     }
209
210 }