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.Simulation;
6 import net.sf.openrocket.optimization.general.OptimizationException;
7 import net.sf.openrocket.rocketcomponent.Rocket;
8 import net.sf.openrocket.unit.UnitGroup;
10 import org.junit.Assert;
11 import org.junit.Before;
12 import org.junit.Test;
14 public class TestGenericModifier {
16 private TestValue value;
17 private GenericModifier<TestValue> gm;
18 private Simulation sim;
22 value = new TestValue();
23 sim = new Simulation(new Rocket());
25 gm = new GenericModifier<TestGenericModifier.TestValue>("Test modifier", null,
26 UnitGroup.UNITS_NONE, 2.0, TestValue.class, "value") {
28 protected TestValue getModifiedObject(Simulation simulation) {
29 Assert.assertTrue(simulation == sim);
39 public void testGetCurrentValue() throws OptimizationException {
41 assertEquals(2.0, gm.getCurrentValue(sim), EPSILON);
43 assertEquals(4.0, gm.getCurrentValue(sim), EPSILON);
47 public void testGetCurrentScaledValue() throws OptimizationException {
49 assertEquals(-0.1, gm.getCurrentScaledValue(sim), EPSILON);
51 assertEquals(0.3, gm.getCurrentScaledValue(sim), EPSILON);
53 assertEquals(0.7, gm.getCurrentScaledValue(sim), EPSILON);
55 assertEquals(1.1, gm.getCurrentScaledValue(sim), EPSILON);
59 public void testModify() throws OptimizationException {
62 assertEquals(-1.0, value.d, EPSILON);
65 assertEquals(0.25, value.d, EPSILON);
68 assertEquals(1.5, value.d, EPSILON);
71 assertEquals(2.75, value.d, EPSILON);
74 assertEquals(4.0, value.d, EPSILON);
77 public void testSingularRange() throws OptimizationException {
81 assertEquals(0.0, gm.getCurrentScaledValue(sim), EPSILON);
83 assertEquals(0.5, gm.getCurrentScaledValue(sim), EPSILON);
85 assertEquals(1.0, gm.getCurrentScaledValue(sim), EPSILON);
88 public class TestValue {
91 public double getValue() {
95 public void setValue(double value) {