@Test(timeout = 10000)
public void testNormalize() {

  // requested resources value cannot be an arbitrary number.
  Resource ask = Resource.newInstance(1111, 2);
  Resource min = Resource.newInstance(1024, 1);
  Resource max = Resource.newInstance(8 * 1024, 8);
  Resource increment = Resource.newInstance(1024, 4);
  if (resourceCalculator instanceof DefaultResourceCalculator) {
    Resource result = Resources.normalize(resourceCalculator,
        ask, min, max, increment);
    assertEquals(2 * 1024, result.getMemorySize());
  } else if (resourceCalculator instanceof DominantResourceCalculator) {
    Resource result = Resources.normalize(resourceCalculator,
        ask, min, max, increment);
    assertEquals(2 * 1024, result.getMemorySize());
    assertEquals(4, result.getVirtualCores());
  }
  // if resources asked are less than minimum resource, then normalize it to
  // minimum resource.
  ask = Resource.newInstance(512, 0);
  min = Resource.newInstance(2 * 1024, 2);
  max = Resource.newInstance(8 * 1024, 8);
  increment = Resource.newInstance(1024, 1);
  if (resourceCalculator instanceof DefaultResourceCalculator) {
    Resource result = Resources.normalize(resourceCalculator,
        ask, min, max, increment);
    assertEquals(2 * 1024, result.getMemorySize());
  } else if (resourceCalculator instanceof DominantResourceCalculator) {
    Resource result = Resources.normalize(resourceCalculator,
        ask, min, max, increment);
    assertEquals(2 * 1024, result.getMemorySize());
    assertEquals(2, result.getVirtualCores());
  }
  // if resources asked are larger than maximum resource, then normalize it to
  // maximum resources.
  ask = Resource.newInstance(9 * 1024, 9);
  min = Resource.newInstance(2 * 1024, 2);
  max = Resource.newInstance(8 * 1024, 8);
  increment = Resource.newInstance(1024, 1);
  if (resourceCalculator instanceof DefaultResourceCalculator) {
    Resource result = Resources.normalize(resourceCalculator,
        ask, min, max, increment);
    assertEquals(8 * 1024, result.getMemorySize());
  } else if (resourceCalculator instanceof DominantResourceCalculator) {
    Resource result = Resources.normalize(resourceCalculator,
        ask, min, max, increment);
    assertEquals(8 * 1024, result.getMemorySize());
    assertEquals(8, result.getVirtualCores());
  }
  // if increment is 0, use minimum resource as the increment resource.
  ask = Resource.newInstance(1111, 2);
  min = Resource.newInstance(2 * 1024, 2);
  max = Resource.newInstance(8 * 1024, 8);
  increment = Resource.newInstance(0, 0);
  if (resourceCalculator instanceof DefaultResourceCalculator) {
    Resource result = Resources.normalize(resourceCalculator,
        ask, min, max, increment);
    assertEquals(2 * 1024, result.getMemorySize());
  } else if (resourceCalculator instanceof DominantResourceCalculator) {
    Resource result = Resources.normalize(resourceCalculator,
        ask, min, max, increment);
    assertEquals(2 * 1024, result.getMemorySize());
    assertEquals(2, result.getVirtualCores());
  }
}