]> git.gag.com Git - sw/motorsim/commitdiff
Added better tests
authorBill Kuker <bkuker@billkuker.com>
Wed, 15 Apr 2009 18:27:34 +0000 (18:27 +0000)
committerBill Kuker <bkuker@billkuker.com>
Wed, 15 Apr 2009 18:27:34 +0000 (18:27 +0000)
src/com/billkuker/rocketry/motorsim/test/CoredCylindricalGrainTest.java
src/com/billkuker/rocketry/motorsim/test/RocketTest.java
src/com/billkuker/rocketry/motorsim/test/ShapeUtilTest.java [new file with mode: 0644]

index f54bd1d91ced0a3f2877ca9812be553464578e10..ca7d804c9d9a2404cf6208cb91037243031bef8a 100644 (file)
@@ -2,7 +2,9 @@ package com.billkuker.rocketry.motorsim.test;
 \r
 import java.beans.PropertyVetoException;\r
 \r
+import javax.measure.quantity.Area;\r
 import javax.measure.quantity.Length;\r
+import javax.measure.quantity.Volume;\r
 import javax.measure.unit.SI;\r
 \r
 import org.jscience.physics.amount.Amount;\r
@@ -15,18 +17,20 @@ public class CoredCylindricalGrainTest extends RocketTest {
 \r
        @Test\r
        public void testSurfaceArea() throws PropertyVetoException {\r
+       \r
                CoredCylindricalGrain g = new CoredCylindricalGrain();\r
                \r
-               g.setLength(Amount.valueOf(70, SI.MILLIMETER));\r
-               \r
-               g.setOD(Amount.valueOf(23.5, SI.MILLIMETER));\r
+               g.setLength(Amount.valueOf(100, SI.MILLIMETER));\r
+               g.setOD(Amount.valueOf(30, SI.MILLIMETER));\r
+               g.setID(Amount.valueOf(10, SI.MILLIMETER));\r
                \r
-               g.setID(Amount.valueOf(7.9375, SI.MILLIMETER));\r
+               g.setForeEndInhibited(false);\r
+               g.setAftEndInhibited(false);\r
+               g.setOuterSurfaceInhibited(true);\r
+               g.setInnerSurfaceInhibited(false);\r
                \r
-               for ( int mm = 0; mm < 15; mm++ ){\r
-                       Amount<Length> r = Amount.valueOf(mm, SI.MILLIMETER);\r
-                       System.out.println( r + ", "  + g.surfaceArea(r).to(SI.MILLIMETER.pow(2)) + ", " + g.volume(r) );\r
-               }\r
+               Amount<Area> a = g.surfaceArea(Amount.valueOf(6, SI.MILLIMETER));\r
+               assertApproximate(a, Amount.valueOf(6736, sqMM), Amount.valueOf(1, sqMM) );\r
        }\r
        \r
 \r
@@ -58,7 +62,19 @@ public class CoredCylindricalGrainTest extends RocketTest {
                g.setOD(Amount.valueOf(30, SI.MILLIMETER));\r
                g.setID(Amount.valueOf(10, SI.MILLIMETER));\r
                \r
-               System.out.println(g.volume(Amount.valueOf(0, SI.MILLIMETER)));\r
+               g.setForeEndInhibited(false);\r
+               g.setAftEndInhibited(false);\r
+               g.setOuterSurfaceInhibited(true);\r
+               g.setInnerSurfaceInhibited(false);\r
+               \r
+               Amount<Volume> v = g.volume(Amount.valueOf(3, SI.MILLIMETER));\r
+               assertApproximate(v, Amount.valueOf(47545, cubeMM), Amount.valueOf(1, cubeMM));\r
+               \r
+               v = g.volume(Amount.valueOf(5, SI.MILLIMETER));\r
+               assertApproximate(v, Amount.valueOf(35343, cubeMM), Amount.valueOf(1, cubeMM));\r
+               \r
+               v = g.volume(Amount.valueOf(9, SI.MILLIMETER));\r
+               assertApproximate(v, Amount.valueOf(7471, cubeMM), Amount.valueOf(1, cubeMM));\r
        }\r
 \r
        @Test(expected=MotorPart.Validating.ValidationException.class)\r
index 99f1cb8070cf4336f4485f95efe5862589ba3bae..5c06288503e99a43110e3e4ecc6b9652cf433fb6 100644 (file)
@@ -1,11 +1,23 @@
 package com.billkuker.rocketry.motorsim.test;\r
 \r
+import javax.measure.unit.SI;\r
+import javax.measure.unit.Unit;\r
+\r
 import org.jscience.physics.amount.Amount;\r
 import org.junit.Assert;\r
 \r
 public class RocketTest {\r
+       \r
+       protected static final Unit<javax.measure.quantity.Area> sqMM = SI.MILLIMETER.pow(2).asType(javax.measure.quantity.Area.class);\r
+       \r
+       \r
+       protected static final Unit<javax.measure.quantity.Volume> cubeMM = SI.MILLIMETER.pow(3).asType(javax.measure.quantity.Volume.class);\r
 \r
        protected void assertApproximate(Amount a, Amount b){\r
-               Assert.assertTrue("" + a + " !~ " + b , a.approximates(b));\r
+               Assert.assertTrue("" + a.to(b.getUnit()) + " !~ " + b , a.approximates(b));\r
+       }\r
+       \r
+       protected void assertApproximate(Amount a, Amount b, Amount diff){\r
+               Assert.assertTrue("" + a.to(b.getUnit()) + " !~~ " + b ,  a.minus(b).abs().isLessThan(diff));\r
        }\r
 }\r
diff --git a/src/com/billkuker/rocketry/motorsim/test/ShapeUtilTest.java b/src/com/billkuker/rocketry/motorsim/test/ShapeUtilTest.java
new file mode 100644 (file)
index 0000000..d8a2be4
--- /dev/null
@@ -0,0 +1,51 @@
+package com.billkuker.rocketry.motorsim.test;\r
+\r
+import java.awt.geom.Area;\r
+import java.awt.geom.Ellipse2D;\r
+import java.awt.geom.Rectangle2D;\r
+\r
+import javax.measure.unit.SI;\r
+import javax.measure.unit.Unit;\r
+\r
+import org.jscience.physics.amount.Amount;\r
+import org.junit.Test;\r
+\r
+import com.billkuker.rocketry.motorsim.grain.ShapeUtil;\r
+\r
+\r
+public class ShapeUtilTest extends RocketTest{\r
+\r
+       Area tenByTen = new Area(new Rectangle2D.Double(-5, -5, 10, 10));\r
+       Area oneByOne = new Area(new Rectangle2D.Double(-.5, -.5, 1, 1));\r
+       Area twoByTwoFar = new Area( new Rectangle2D.Double(30,30,2,2));\r
+       \r
+       Area r2Circle = new Area(new Ellipse2D.Double(-2,-2,4,4));\r
+\r
+\r
+       Amount<javax.measure.quantity.Area> diff = Amount.valueOf(.01, sqMM);\r
+       \r
+       @Test\r
+       public void testArea(){\r
+               assertApproximate(ShapeUtil.area(tenByTen), Amount.valueOf(100, sqMM));\r
+               assertApproximate(ShapeUtil.area(oneByOne), Amount.valueOf(1, sqMM));\r
+               assertApproximate(ShapeUtil.area(twoByTwoFar), Amount.valueOf(4, sqMM));\r
+               assertApproximate(ShapeUtil.area(r2Circle), Amount.valueOf(4*Math.PI, sqMM), diff);\r
+               \r
+               Area a = new Area(tenByTen);\r
+               a.subtract(oneByOne);\r
+               \r
+               assertApproximate(ShapeUtil.area(a), ShapeUtil.area(tenByTen).minus(ShapeUtil.area(oneByOne)));\r
+               \r
+               a.add(twoByTwoFar);\r
+               \r
+               assertApproximate(ShapeUtil.area(a), \r
+                               ShapeUtil.area(tenByTen)\r
+                                       .minus(ShapeUtil.area(oneByOne))\r
+                                       .plus(ShapeUtil.area(twoByTwoFar)));\r
+               \r
+               a = new Area(tenByTen);\r
+               a.subtract(r2Circle);\r
+               \r
+               assertApproximate(ShapeUtil.area(a), ShapeUtil.area(tenByTen).minus(ShapeUtil.area(r2Circle)));\r
+       }\r
+}\r