1 package net.sf.openrocket.optimization.rocketoptimization.modifiers;
3 import static net.sf.openrocket.util.MathUtil.EPSILON;
4 import static org.junit.Assert.assertEquals;
5 import net.sf.openrocket.document.OpenRocketDocument;
6 import net.sf.openrocket.document.Simulation;
7 import net.sf.openrocket.optimization.general.OptimizationException;
8 import net.sf.openrocket.rocketcomponent.Rocket;
9 import net.sf.openrocket.unit.UnitGroup;
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
15 public class TestGenericModifier {
17 private TestValue value;
18 private GenericModifier<TestValue> gm;
19 private Simulation sim;
23 value = new TestValue();
24 Rocket rocket = new Rocket();
26 sim = new Simulation(new OpenRocketDocument(rocket), rocket);
28 Object related = new Object();
30 gm = new GenericModifier<TestGenericModifier.TestValue>("Test modifier", "Description", related,
31 UnitGroup.UNITS_NONE, 2.0, TestValue.class, "value") {
33 protected TestValue getModifiedObject(Simulation simulation) {
34 Assert.assertTrue(simulation == sim);
44 public void testGetCurrentValue() throws OptimizationException {
46 assertEquals(2.0, gm.getCurrentSIValue(sim), EPSILON);
48 assertEquals(4.0, gm.getCurrentSIValue(sim), EPSILON);
52 public void testGetCurrentScaledValue() throws OptimizationException {
54 assertEquals(-0.1, gm.getCurrentScaledValue(sim), EPSILON);
56 assertEquals(0.3, gm.getCurrentScaledValue(sim), EPSILON);
58 assertEquals(0.7, gm.getCurrentScaledValue(sim), EPSILON);
60 assertEquals(1.1, gm.getCurrentScaledValue(sim), EPSILON);
64 public void testModify() throws OptimizationException {
67 assertEquals(-1.0, value.d, EPSILON);
70 assertEquals(0.25, value.d, EPSILON);
73 assertEquals(1.5, value.d, EPSILON);
76 assertEquals(2.75, value.d, EPSILON);
79 assertEquals(4.0, value.d, EPSILON);
82 public void testSingularRange() throws OptimizationException {
86 assertEquals(0.0, gm.getCurrentScaledValue(sim), EPSILON);
88 assertEquals(0.5, gm.getCurrentScaledValue(sim), EPSILON);
90 assertEquals(1.0, gm.getCurrentScaledValue(sim), EPSILON);
93 public class TestValue {
96 public double getValue() {
100 public void setValue(double value) {