Change nose cone preset to use Aft Outer Diameter, Aft Shoulder Length, and Aft Shoul...
[debian/openrocket] / core / test / net / sf / openrocket / preset / NoseConePresetTests.java
1 package net.sf.openrocket.preset;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertTrue;
5 import net.sf.openrocket.material.Material;
6 import net.sf.openrocket.motor.Manufacturer;
7 import net.sf.openrocket.rocketcomponent.Transition;
8 import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
9
10 import org.junit.Test;
11
12 /**
13  * Test construction of NOSE_CONE type ComponentPresets based on TypedPropertyMap through the
14  * ComponentPresetFactory.create() method.
15  * 
16  * Ensure required properties are populated
17  * 
18  * Ensure any computed values are correctly computed.
19  * 
20  */
21 public class NoseConePresetTests extends BaseTestCase {
22
23         @Test
24         public void testManufacturerRequired() {
25                 try {
26                         TypedPropertyMap presetspec = new TypedPropertyMap();
27                         presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
28                         ComponentPresetFactory.create(presetspec);
29                 } catch ( InvalidComponentPresetException ex ) {
30                         assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified"));
31                 }
32         }
33
34         @Test
35         public void testPartNoRequired() {
36                 try {
37                         TypedPropertyMap presetspec = new TypedPropertyMap();
38                         presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
39                         presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
40                         ComponentPresetFactory.create(presetspec);
41                 } catch ( InvalidComponentPresetException ex ) {
42                         assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified"));
43                 }
44         }
45
46         @Test
47         public void testLengthRequired() {
48                 try {
49                         TypedPropertyMap presetspec = new TypedPropertyMap();
50                         presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
51                         presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
52                         presetspec.put( ComponentPreset.PARTNO, "partno");
53                         ComponentPresetFactory.create(presetspec);
54                 } catch ( InvalidComponentPresetException ex ) {
55                         assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified"));
56                 }
57         }
58
59         @Test
60         public void testShapeRequired() {
61                 try {
62                         TypedPropertyMap presetspec = new TypedPropertyMap();
63                         presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
64                         presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
65                         presetspec.put( ComponentPreset.PARTNO, "partno");
66                         presetspec.put( ComponentPreset.LENGTH, 2.0);
67                         ComponentPresetFactory.create(presetspec);
68                 } catch ( InvalidComponentPresetException ex ) {
69                         assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Shape"));
70                 }
71         }
72
73         @Test
74         public void testAftOuterDiameterRequired() {
75                 try {
76                         TypedPropertyMap presetspec = new TypedPropertyMap();
77                         presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
78                         presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
79                         presetspec.put( ComponentPreset.PARTNO, "partno");
80                         presetspec.put( ComponentPreset.LENGTH, 2.0);
81                         presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
82                         ComponentPresetFactory.create(presetspec);
83                 } catch ( InvalidComponentPresetException ex ) {
84                         assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No AftOuterDiameter"));
85                 }
86         }
87
88         @Test
89         public void testComputeDensityNoMaterial() throws Exception {
90                 TypedPropertyMap presetspec = new TypedPropertyMap();
91                 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
92                 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
93                 presetspec.put( ComponentPreset.PARTNO, "partno");
94                 presetspec.put( ComponentPreset.LENGTH, 2.0);
95                 presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
96                 presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
97                 presetspec.put( ComponentPreset.FILLED, true);
98                 presetspec.put( ComponentPreset.MASS, 100.0);
99                 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
100
101                 // constants put into the presetspec above.
102                 double volume = /*base area*/ Math.PI;
103                 volume *= 2.0 /* times height */ / 3.0; /* one third */
104                 
105                 double density = 100.0 / volume;
106                 
107                 assertEquals("NoseConeCustom",preset.get(ComponentPreset.MATERIAL).getName());
108                 // FIXME - I would expect the nc volume computation to be closer for such a simple shape.
109                 // simple math yields 47.74648
110                 // 100.0/nc.getComponentVolume yields 48.7159
111                 assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),1.0);
112         }
113
114         @Test
115         public void testMaterial() throws Exception {
116                 TypedPropertyMap presetspec = new TypedPropertyMap();
117                 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
118                 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
119                 presetspec.put( ComponentPreset.PARTNO, "partno");
120                 presetspec.put( ComponentPreset.LENGTH, 2.0);
121                 presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
122                 presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
123                 presetspec.put( ComponentPreset.MATERIAL, new Material.Bulk("test", 2.0, true));
124                 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
125
126                 assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
127                 assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
128                 
129         }
130
131         @Test
132         public void testComputeDensityWithMaterial() throws Exception {
133                 TypedPropertyMap presetspec = new TypedPropertyMap();
134                 presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
135                 presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
136                 presetspec.put( ComponentPreset.PARTNO, "partno");
137                 presetspec.put( ComponentPreset.LENGTH, 2.0);
138                 presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
139                 presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
140                 presetspec.put( ComponentPreset.FILLED, true);
141                 presetspec.put( ComponentPreset.MASS, 100.0);
142                 presetspec.put( ComponentPreset.MATERIAL, new Material.Bulk("test", 2.0, true));
143                 ComponentPreset preset = ComponentPresetFactory.create(presetspec);
144
145                 // constants put into the presetspec above.
146                 double volume = /*base area*/ Math.PI;
147                 volume *= 2.0 /* times height */ / 3.0; /* one third */
148                 
149                 double density = 100.0 / volume;
150                 
151                 assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
152                 // FIXME - I would expect the nc volume computation to be closer for such a simple shape.
153                 assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),1.5);
154         }
155
156 }