X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=core%2Ftest%2Fnet%2Fsf%2Fopenrocket%2Fpreset%2FBulkHeadPresetTests.java;fp=core%2Ftest%2Fnet%2Fsf%2Fopenrocket%2Fpreset%2FBulkHeadPresetTests.java;h=2f393bac3748010cc9eed7335373c3f0eafc145a;hb=9349577cdfdff682b2aabd6daa24fdc3a7449b58;hp=0000000000000000000000000000000000000000;hpb=30ba0a882f0c061176ba14dbf86d3d6fad096c02;p=debian%2Fopenrocket diff --git a/core/test/net/sf/openrocket/preset/BulkHeadPresetTests.java b/core/test/net/sf/openrocket/preset/BulkHeadPresetTests.java new file mode 100644 index 00000000..2f393bac --- /dev/null +++ b/core/test/net/sf/openrocket/preset/BulkHeadPresetTests.java @@ -0,0 +1,173 @@ +package net.sf.openrocket.preset; + +import static org.junit.Assert.assertEquals; +import net.sf.openrocket.material.Material; +import net.sf.openrocket.motor.Manufacturer; + +import org.junit.Test; + +/** + * Test construction of BULK_HEAD type ComponentPresets based on TypedPropertyMap through the + * ComponentPresetFactory.create() method. + * + * Ensure required properties are populated + * + * Ensure any computed values are correctly computed. + * + */ +public class BulkHeadPresetTests { + + @Test + public void testManufacturerRequired() { + try { + TypedPropertyMap presetspec = new TypedPropertyMap(); + presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD); + ComponentPresetFactory.create(presetspec); + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, + new TypedKey[] { + ComponentPreset.MANUFACTURER, + ComponentPreset.PARTNO, + ComponentPreset.LENGTH, + ComponentPreset.OUTER_DIAMETER + }, + new String[] { + "No Manufacturer specified", + "No PartNo specified", + "No Length specified", + "No OuterDiameter specified" + } + ); + } + } + + @Test + public void testPartNoRequired() { + try { + TypedPropertyMap presetspec = new TypedPropertyMap(); + presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + ComponentPresetFactory.create(presetspec); + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, + new TypedKey[] { + ComponentPreset.PARTNO, + ComponentPreset.LENGTH, + ComponentPreset.OUTER_DIAMETER + }, + new String[] { + "No PartNo specified", + "No Length specified", + "No OuterDiameter specified" + } + ); + } + } + + @Test + public void testLengthRequired() { + try { + TypedPropertyMap presetspec = new TypedPropertyMap(); + presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + ComponentPresetFactory.create(presetspec); + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, + new TypedKey[] { + ComponentPreset.LENGTH, + ComponentPreset.OUTER_DIAMETER + }, + new String[] { + "No Length specified", + "No OuterDiameter specified" + } + ); + } + } + + @Test + public void testOuterDiameterRequired() { + try { + TypedPropertyMap presetspec = new TypedPropertyMap(); + presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + ComponentPresetFactory.create(presetspec); + } catch (InvalidComponentPresetException ex) { + PresetAssertHelper.assertInvalidPresetException(ex, + new TypedKey[] { + ComponentPreset.OUTER_DIAMETER + }, + new String[] { + "No OuterDiameter specified" + } + ); + } + } + + @Test + public void testComputeDensityNoMaterial() throws Exception { + TypedPropertyMap presetspec = new TypedPropertyMap(); + presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MASS, 100.0); + ComponentPreset preset = ComponentPresetFactory.create(presetspec); + + // Compute the volume by hand here using a slightly different formula from + // the real implementation. The magic numbers are based on the + // constants put into the presetspec above. + double volume = /*outer area*/(Math.PI * 1.0); + volume *= 2.0; /* times length */ + + double density = 100.0 / volume; + + assertEquals("BulkHeadCustom", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); + } + + @Test + public void testMaterial() throws Exception { + TypedPropertyMap presetspec = new TypedPropertyMap(); + presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); + ComponentPreset preset = ComponentPresetFactory.create(presetspec); + + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(2.0, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); + + } + + @Test + public void testComputeDensityWithMaterial() throws Exception { + TypedPropertyMap presetspec = new TypedPropertyMap(); + presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD); + presetspec.put(ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); + presetspec.put(ComponentPreset.PARTNO, "partno"); + presetspec.put(ComponentPreset.LENGTH, 2.0); + presetspec.put(ComponentPreset.OUTER_DIAMETER, 2.0); + presetspec.put(ComponentPreset.MASS, 100.0); + presetspec.put(ComponentPreset.MATERIAL, Material.newMaterial(Material.Type.BULK, "test", 2.0, true)); + ComponentPreset preset = ComponentPresetFactory.create(presetspec); + + // Compute the volume by hand here using a slightly different formula from + // the real implementation. The magic numbers are based on the + // constants put into the presetspec above. + double volume = /*outer area*/(Math.PI * 1.0); + volume *= 2.0; /* times length */ + + double density = 100.0 / volume; + + assertEquals("test", preset.get(ComponentPreset.MATERIAL).getName()); + assertEquals(density, preset.get(ComponentPreset.MATERIAL).getDensity(), 0.0005); + } + +}