@Test void convertToMotorValue(){ int [] motorValues = {1,2,3,4,5,6,7,8,9,10}; EngineDataConverter EDC = new EngineDataConverter(motorValues); assertEquals(1,EDC.convertToMotorValue(1.2)); assertEquals(1,EDC.convertToMotorValue(-5)); assertEquals(5,EDC.convertToMotorValue(5.4)); assertEquals(7, EDC.convertToMotorValue(6.5)); }
public int convertToMotorValue( double throttle){ double smallestDifference = Double.POSITIVE_INFINITY; int r = 0; for (int i: validMotorValues) { System.out.println(i); double difference = Math.abs(i - throttle); if (smallestDifference > difference){ smallestDifference = difference; r = i; }else if (smallestDifference == difference && throttle < i){ r = i; } } return r; }
EngineDataConverter { public int convertToMotorValue( double throttle){ double smallestDifference = Double.POSITIVE_INFINITY; int r = 0; for (int i: validMotorValues) { System.out.println(i); double difference = Math.abs(i - throttle); if (smallestDifference > difference){ smallestDifference = difference; r = i; }else if (smallestDifference == difference && throttle < i){ r = i; } } return r; } }
EngineDataConverter { public int convertToMotorValue( double throttle){ double smallestDifference = Double.POSITIVE_INFINITY; int r = 0; for (int i: validMotorValues) { System.out.println(i); double difference = Math.abs(i - throttle); if (smallestDifference > difference){ smallestDifference = difference; r = i; }else if (smallestDifference == difference && throttle < i){ r = i; } } return r; } EngineDataConverter(int[] validMotorValues); }
EngineDataConverter { public int convertToMotorValue( double throttle){ double smallestDifference = Double.POSITIVE_INFINITY; int r = 0; for (int i: validMotorValues) { System.out.println(i); double difference = Math.abs(i - throttle); if (smallestDifference > difference){ smallestDifference = difference; r = i; }else if (smallestDifference == difference && throttle < i){ r = i; } } return r; } EngineDataConverter(int[] validMotorValues); int convertToMotorValue( double throttle); }
EngineDataConverter { public int convertToMotorValue( double throttle){ double smallestDifference = Double.POSITIVE_INFINITY; int r = 0; for (int i: validMotorValues) { System.out.println(i); double difference = Math.abs(i - throttle); if (smallestDifference > difference){ smallestDifference = difference; r = i; }else if (smallestDifference == difference && throttle < i){ r = i; } } return r; } EngineDataConverter(int[] validMotorValues); int convertToMotorValue( double throttle);  }