2 * FinSetHandlerTest.java
4 package net.sf.openrocket.file.rocksim.importt;
6 import junit.framework.TestCase;
7 import net.sf.openrocket.aerodynamics.WarningSet;
8 import net.sf.openrocket.rocketcomponent.BodyTube;
9 import net.sf.openrocket.rocketcomponent.EllipticalFinSet;
10 import net.sf.openrocket.rocketcomponent.FinSet;
11 import net.sf.openrocket.rocketcomponent.TrapezoidFinSet;
12 import net.sf.openrocket.util.Coordinate;
14 import java.lang.reflect.Method;
15 import java.util.HashMap;
18 * FinSetHandler Tester.
21 public class FinSetHandlerTest extends TestCase {
24 * Method: asOpenRocket(WarningSet warnings)
26 * @throws Exception thrown if something goes awry
29 public void testAsOpenRocket() throws Exception {
31 FinSetHandler dto = new FinSetHandler(new BodyTube());
33 HashMap<String, String> attributes = new HashMap<String, String>();
34 WarningSet warnings = new WarningSet();
36 dto.closeElement("Name", attributes, "The name", warnings);
37 dto.closeElement("ShapeCode", attributes, "0", warnings);
38 dto.closeElement("Xb", attributes, "2", warnings);
39 dto.closeElement("FinCount", attributes, "4", warnings);
40 dto.closeElement("RootChord", attributes, "10", warnings);
41 dto.closeElement("TipChord", attributes, "11", warnings);
42 dto.closeElement("SemiSpan", attributes, "12", warnings);
43 dto.closeElement("MidChordLen", attributes, "13", warnings);
44 dto.closeElement("SweepDistance", attributes, "14", warnings);
45 dto.closeElement("Thickness", attributes, "200", warnings);
46 dto.closeElement("TipShapeCode", attributes, "1", warnings);
47 dto.closeElement("TabLength", attributes, "400", warnings);
48 dto.closeElement("TabDepth", attributes, "500", warnings);
49 dto.closeElement("TabOffset", attributes, "30", warnings);
50 dto.closeElement("RadialAngle", attributes, ".123", warnings);
51 dto.closeElement("PointList", attributes, "20,0|2,2|0,0", warnings);
52 dto.closeElement("LocationMode", attributes, "0", warnings);
54 WarningSet set = new WarningSet();
55 FinSet fins = dto.asOpenRocket(set);
57 assertEquals(0, set.size());
59 assertEquals("The name", fins.getName());
60 assertTrue(fins instanceof TrapezoidFinSet);
61 assertEquals(4, fins.getFinCount());
63 assertEquals(0.012d, ((TrapezoidFinSet) fins).getHeight());
64 assertEquals(0.012d, fins.getSpan());
66 assertEquals(0.2d, fins.getThickness());
67 assertEquals(0.4d, fins.getTabLength());
68 assertEquals(0.5d, fins.getTabHeight());
69 assertEquals(0.03d, fins.getTabShift());
70 assertEquals(.123d, fins.getBaseRotation());
72 dto.closeElement("ShapeCode", attributes, "1", warnings);
73 fins = dto.asOpenRocket(set);
75 assertEquals(0, set.size());
77 assertEquals("The name", fins.getName());
78 assertTrue(fins instanceof EllipticalFinSet);
79 assertEquals(4, fins.getFinCount());
81 assertEquals(0.2d, fins.getThickness());
82 assertEquals(0.4d, fins.getTabLength());
83 assertEquals(0.5d, fins.getTabHeight());
84 assertEquals(0.03d, fins.getTabShift());
85 assertEquals(.123d, fins.getBaseRotation());
90 * Method: toCoordinates(String pointList)
92 * @throws Exception thrown if something goes awry
95 public void testToCoordinates() throws Exception {
96 FinSetHandler holder = new FinSetHandler(new BodyTube());
97 Method method = FinSetHandler.class.getDeclaredMethod("toCoordinates", String.class, WarningSet.class);
98 method.setAccessible(true);
100 WarningSet warnings = new WarningSet();
102 String finlist = null;
103 Coordinate[] result = (Coordinate[])method.invoke(holder, finlist, warnings);
104 assertNotNull(result);
105 assertTrue(0 == result.length);
107 //Empty string finlist
109 result = (Coordinate[])method.invoke(holder, finlist, warnings);
110 assertNotNull(result);
111 assertTrue(0 == result.length);
113 //Invalid finlist (only x coordinate)
115 result = (Coordinate[])method.invoke(holder, finlist, warnings);
116 assertNotNull(result);
117 assertTrue(0 == result.length);
118 assertEquals(1, warnings.size());
121 //Invalid finlist (non-numeric character)
122 finlist = "10.0,asdf";
123 result = (Coordinate[])method.invoke(holder, finlist, warnings);
124 assertNotNull(result);
125 assertTrue(0 == result.length);
126 assertEquals(1, warnings.size());
129 //Invalid finlist (all delimiters)
131 result = (Coordinate[])method.invoke(holder, finlist, warnings);
132 assertNotNull(result);
133 assertTrue(0 == result.length);
134 assertEquals(0, warnings.size());
137 //One point finlist - from a parsing view it's valid; from a practical view it may not be, but that's outside
138 //the scope of this test case
139 finlist = "10.0,5.0";
140 result = (Coordinate[])method.invoke(holder, finlist, warnings);
141 assertNotNull(result);
142 assertTrue(1 == result.length);
143 assertEquals(0, warnings.size());
146 //Two point finlist - from a parsing view it's valid; from a practical view it may not be, but that's outside
147 //the scope of this test case
148 finlist = "10.0,5.0|3.3,4.4";
149 result = (Coordinate[])method.invoke(holder, finlist, warnings);
150 assertNotNull(result);
151 assertTrue(2 == result.length);
152 assertEquals(0, warnings.size());
155 //Normal four point finlist.
156 finlist = "518.16,0|517.494,37.2145|1.31261,6.77283|0,0|";
157 result = (Coordinate[])method.invoke(holder, finlist, warnings);
158 assertNotNull(result);
159 assertTrue(4 == result.length);
160 assertEquals(new Coordinate(0,0), result[0]);
161 assertEquals(0, warnings.size());
164 //Normal four point finlist with spaces.
165 finlist = "518.16 , 0 | 517.494 , 37.2145 | 1.31261,6.77283|0,0|";
166 result = (Coordinate[])method.invoke(holder, finlist, warnings);
167 assertNotNull(result);
168 assertTrue(4 == result.length);
169 assertEquals(new Coordinate(0,0), result[0]);
170 assertEquals(new Coordinate(.51816,0), result[3]);
171 assertEquals(0, warnings.size());
174 //Reversed Normal four point finlist.
175 finlist = "0,0|1.31261,6.77283|517.494,37.2145|518.16,0|";
176 result = (Coordinate[])method.invoke(holder, finlist, warnings);
177 assertNotNull(result);
178 assertTrue(4 == result.length);
179 assertEquals(new Coordinate(0,0), result[0]);
180 assertEquals(new Coordinate(.51816,0), result[3]);
181 assertEquals(0, warnings.size());