### Question:
GlassesWithWater { public static double getAmountOfWater(int level, int column, double x) { if (x <= 0) { throw new IllegalArgumentException("Amount of water should be positive"); } if (level < 0) { throw new IllegalArgumentException("Level should be non-negative"); } if (column < 0) { throw new IllegalArgumentException("Column should be non-negative"); } if (level < column) { throw new IllegalArgumentException("Level should be greater or equal to column"); } if (level == 0) { return min(MAX_AMOUNT_OF_WATER_IN_GLASS, x); } else if (level == 1) { return max((x - MAX_AMOUNT_OF_WATER_IN_GLASS) / 2, 0); } double[] prevLevelVolumes = new double[]{ max((x - MAX_AMOUNT_OF_WATER_IN_GLASS) / 2, 0), max((x - MAX_AMOUNT_OF_WATER_IN_GLASS) / 2, 0)}; int i = 1; while (true) { i++; double[] levelVolumes = new double[i + 1]; levelVolumes[0] = max((prevLevelVolumes[0] - 1) / 2, 0); levelVolumes[i] = max((prevLevelVolumes[i - 1] - 1) / 2, 0); for (int j = 1; j < levelVolumes.length - 1; j++) { levelVolumes[j] = max((prevLevelVolumes[j - 1] - MAX_AMOUNT_OF_WATER_IN_GLASS) / 2, 0) + max((prevLevelVolumes[j] - MAX_AMOUNT_OF_WATER_IN_GLASS) / 2, 0); } if (i == level) { return levelVolumes[column]; } prevLevelVolumes = levelVolumes; } }  static double getAmountOfWater(int level, int column, double x);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void testGetAmountOfWaterNegativeX() { getAmountOfWater(0, 0, -1); }
@Test(expected = IllegalArgumentException.class) public void testGetAmountOfWaterColumnBiggerThanRow() { getAmountOfWater(0, 1, 2); }
@Test(expected = IllegalArgumentException.class) public void testGetAmountOfWaterLevelNegative() { getAmountOfWater(-1, 1, 2); }
@Test(expected = IllegalArgumentException.class) public void testGetAmountOfWaterColumnNegative() { getAmountOfWater(1, -1, 2); }
@Test public void testGetAmountOfWater1() { assertThat(getAmountOfWater(0, 0, 2), is(1.0)); }
@Test public void testGetAmountOfWater2() { assertThat(getAmountOfWater(1, 0, 2), is(0.5)); }
@Test public void testGetAmountOfWater3() { assertThat(getAmountOfWater(1, 1, 2), is(0.5)); }
@Test public void testGetAmountOfWater4() { assertThat(getAmountOfWater(1, 0, 1), is(0.0)); }
@Test public void testGetAmountOfWater5() { assertThat(getAmountOfWater(2, 0, 2), is(0.0)); }
@Test public void testGetAmountOfWater6() { assertThat(getAmountOfWater(2, 0, 4), is(0.25)); }
@Test public void testGetAmountOfWater7() { assertThat(getAmountOfWater(2, 1, 4), is(0.5)); }
@Test public void testGetAmountOfWater8() { assertThat(getAmountOfWater(2, 2, 4), is(0.25)); }