@Test public void testModify() { final ModifierProperties modifierProperties = new ModifierProperties(); modifierProperties.put("minimum", Integer.MIN_VALUE); modifierProperties.put("maximum", Integer.MAX_VALUE); modifierProperties.put("minimumStep", 1); modifierProperties.put("maximumStep", 10); final Integer32Modifier modifier = new Integer32Modifier(); modifier.init(modifierProperties); final Integer32 integer32 = new Integer32(0); assertEquals(integer32.getValue(), 0); final Integer32 modifiedVariable = modifier.modify(integer32); assertNotEquals(modifiedVariable.getValue(), 0); }
protected int modify(final int currentValue, final int minimum, final int maximum, final int minimumStep, final int maximumStep) { int currentValidValue = currentValue; if (currentValue < minimum || currentValue > maximum) { currentValidValue = minimum; } int step = (int) (Math.round(Math.random() * (maximumStep - minimumStep)) + minimumStep); int stepUntilMaximum = maximum - currentValidValue; int newValue; if (Math.abs(step) > Math.abs(stepUntilMaximum)) { newValue = minimum + (step - stepUntilMaximum - 1); } else { newValue = currentValidValue + step; } if (newValue < minimum) { newValue = minimum; } else if (newValue > maximum) { newValue = maximum; } return newValue; }
Integer32Modifier implements VariableModifier<Integer32> { protected int modify(final int currentValue, final int minimum, final int maximum, final int minimumStep, final int maximumStep) { int currentValidValue = currentValue; if (currentValue < minimum || currentValue > maximum) { currentValidValue = minimum; } int step = (int) (Math.round(Math.random() * (maximumStep - minimumStep)) + minimumStep); int stepUntilMaximum = maximum - currentValidValue; int newValue; if (Math.abs(step) > Math.abs(stepUntilMaximum)) { newValue = minimum + (step - stepUntilMaximum - 1); } else { newValue = currentValidValue + step; } if (newValue < minimum) { newValue = minimum; } else if (newValue > maximum) { newValue = maximum; } return newValue; } }
Integer32Modifier implements VariableModifier<Integer32> { protected int modify(final int currentValue, final int minimum, final int maximum, final int minimumStep, final int maximumStep) { int currentValidValue = currentValue; if (currentValue < minimum || currentValue > maximum) { currentValidValue = minimum; } int step = (int) (Math.round(Math.random() * (maximumStep - minimumStep)) + minimumStep); int stepUntilMaximum = maximum - currentValidValue; int newValue; if (Math.abs(step) > Math.abs(stepUntilMaximum)) { newValue = minimum + (step - stepUntilMaximum - 1); } else { newValue = currentValidValue + step; } if (newValue < minimum) { newValue = minimum; } else if (newValue > maximum) { newValue = maximum; } return newValue; }  }
Integer32Modifier implements VariableModifier<Integer32> { protected int modify(final int currentValue, final int minimum, final int maximum, final int minimumStep, final int maximumStep) { int currentValidValue = currentValue; if (currentValue < minimum || currentValue > maximum) { currentValidValue = minimum; } int step = (int) (Math.round(Math.random() * (maximumStep - minimumStep)) + minimumStep); int stepUntilMaximum = maximum - currentValidValue; int newValue; if (Math.abs(step) > Math.abs(stepUntilMaximum)) { newValue = minimum + (step - stepUntilMaximum - 1); } else { newValue = currentValidValue + step; } if (newValue < minimum) { newValue = minimum; } else if (newValue > maximum) { newValue = maximum; } return newValue; }  @Override void init(final ModifierProperties properties); @Override Integer32 modify(final Integer32 variable); }
Integer32Modifier implements VariableModifier<Integer32> { protected int modify(final int currentValue, final int minimum, final int maximum, final int minimumStep, final int maximumStep) { int currentValidValue = currentValue; if (currentValue < minimum || currentValue > maximum) { currentValidValue = minimum; } int step = (int) (Math.round(Math.random() * (maximumStep - minimumStep)) + minimumStep); int stepUntilMaximum = maximum - currentValidValue; int newValue; if (Math.abs(step) > Math.abs(stepUntilMaximum)) { newValue = minimum + (step - stepUntilMaximum - 1); } else { newValue = currentValidValue + step; } if (newValue < minimum) { newValue = minimum; } else if (newValue > maximum) { newValue = maximum; } return newValue; }  @Override void init(final ModifierProperties properties); @Override Integer32 modify(final Integer32 variable);  }