public static int computeAvailableContainers(Resource available,
      Resource required, EnumSet<SchedulerResourceTypes> resourceTypes) {
    if (resourceTypes.contains(SchedulerResourceTypes.CPU)) {
      return Math.min(
        calculateRatioOrMaxValue(available.getMemorySize(), required.getMemorySize()),
        calculateRatioOrMaxValue(available.getVirtualCores(), required
            .getVirtualCores()));
    }
    return calculateRatioOrMaxValue(
      available.getMemorySize(), required.getMemorySize());
  }
@Test
  public void testComputeAvailableContainers() throws Exception {
    Resource clusterAvailableResources = Resource.newInstance(81920, 40);

    Resource nonZeroResource = Resource.newInstance(1024, 2);

    int expectedNumberOfContainersForMemory = 80;
    int expectedNumberOfContainersForCPU = 20;

    verifyDifferentResourceTypes(clusterAvailableResources, nonZeroResource,
        expectedNumberOfContainersForMemory,
        expectedNumberOfContainersForCPU);

    Resource zeroMemoryResource = Resource.newInstance(0,
        nonZeroResource.getVirtualCores());

    verifyDifferentResourceTypes(clusterAvailableResources, zeroMemoryResource,
        Integer.MAX_VALUE,
        expectedNumberOfContainersForCPU);

    Resource zeroCpuResource = Resource.newInstance(
        nonZeroResource.getMemorySize(), 0);

    verifyDifferentResourceTypes(clusterAvailableResources, zeroCpuResource,
        expectedNumberOfContainersForMemory,
        expectedNumberOfContainersForMemory);
  }