PowerModelLinear implements PowerModel { @Override public double getPower(double utilization) throws IllegalArgumentException { if (utilization < 0 || utilization > 1) { throw new IllegalArgumentException("Utilization value must be between 0 and 1"); } if (utilization == 0) { return 0; } return getStaticPower() + getConstant() * utilization * 100; } PowerModelLinear(double maxPower, double staticPowerPercent); @Override double getPower(double utilization);  }
@Test (expected = IllegalArgumentException.class) public void testGetPowerArgumentLessThenZero() throws IllegalArgumentException { powerModel.getPower(-1); }
@Test (expected = IllegalArgumentException.class) public void testGetPowerArgumentLargerThenOne() throws IllegalArgumentException { powerModel.getPower(2); }
@Test public void testGetPower() { assertEquals(0, powerModel.getPower(0.0), 0); assertEquals(MAX_POWER, powerModel.getPower(1.0), 0); assertEquals(MAX_POWER * STATIC_POWER_PERCENT + ((MAX_POWER - MAX_POWER * STATIC_POWER_PERCENT) / 100) * 0.5 * 100, powerModel.getPower(0.5), 0); }
@Test @Ignore public void testPrintPower() { for (int i = 0; i <= 100; i++) { Log.print(String.format("%d;%.2f\n", i, powerModel.getPower((double) i / 100))); } }