StepModelFit extends StepModel { @Override public double getValue() { if (steps == null || scale == null || !scale.isDefined()) return super.getValue(); double curStep = steps[0]; double oldDistance = Math.abs((scale.length().doubleValue() / curStep)-super.getValue() ); for (double step : steps) { double newDistance = Math.abs((scale.length().doubleValue() / step)-super.getValue() ); if (newDistance < oldDistance){ curStep = step; oldDistance = newDistance; } } return curStep; } StepModelFit(Region axisRegion, double[] increments, double numLines); double[] getSteps(); void setSteps(double[] steps); Region getScale(); void setScale(Region scale); @Override double getValue(); @Override String toString();  }
@Test public void getValue() throws Exception { StepModelFit model = new StepModelFit(regionSmall,stpSmall,3); assertEquals(5.0, model.getValue(), 0.0); model.setValue(5.0); assertEquals(2.0, model.getValue(), 0.0); model.setValue(7.0); assertEquals(2.0, model.getValue(), 0.0); model.setSteps(stpBig); assertEquals(1.0, model.getValue(), 0.0); model.setScale(regionBig); assertEquals(100.0, model.getValue(), 0.0); model.setValue(1000.0); assertEquals(1.0, model.getValue(), 0.0); model.setSteps(nonsense); assertArrayEquals(stpBig,model.getSteps(), 0.0); model.setScale(regionZero); assertEquals(stpBig[0], model.getValue(), 0.0); model.setScale(regionUndef); model.setValue(1.1); assertEquals(1.1, model.getValue(), 0.0); }