### Question:
ResourceUsageCalculator { public static double measureBaselineDivergence(Map<String, ResourceAssignment> baseline, Map<String, ResourceAssignment> bestPossibleAssignment) { int numMatchedReplicas = 0; int numTotalBestPossibleReplicas = 0; for (Map.Entry<String, ResourceAssignment> resourceEntry : bestPossibleAssignment.entrySet()) { String resourceKey = resourceEntry.getKey(); if (!baseline.containsKey(resourceKey)) { continue; } Map<String, Map<String, String>> bestPossiblePartitions = resourceEntry.getValue().getRecord().getMapFields(); Map<String, Map<String, String>> baselinePartitions = baseline.get(resourceKey).getRecord().getMapFields(); for (Map.Entry<String, Map<String, String>> partitionEntry : bestPossiblePartitions.entrySet()) { String partitionName = partitionEntry.getKey(); if (!baselinePartitions.containsKey(partitionName)) { continue; } Map<String, String> bestPossibleReplicas = partitionEntry.getValue(); Map<String, String> baselineReplicas = baselinePartitions.get(partitionName); for (Map.Entry<String, String> replicaEntry : bestPossibleReplicas.entrySet()) { String replicaName = replicaEntry.getKey(); if (!baselineReplicas.containsKey(replicaName)) { continue; } String bestPossibleReplica = replicaEntry.getValue(); String baselineReplica = baselineReplicas.get(replicaName); if (bestPossibleReplica.equals(baselineReplica)) { numMatchedReplicas++; } } numTotalBestPossibleReplicas += bestPossibleReplicas.size(); } } return numTotalBestPossibleReplicas == 0 ? 1.0d : (1.0d - (double) numMatchedReplicas / (double) numTotalBestPossibleReplicas); }  static Map<String, Integer> getResourceUsage(ResourcesStateMap resourceAssignment,
      PartitionWeightProvider weightProvider); static double measureBaselineDivergence(Map<String, ResourceAssignment> baseline,
      Map<String, ResourceAssignment> bestPossibleAssignment); static Map<String, Integer> calculateAveragePartitionWeight(
      Map<String, Map<String, Integer>> partitionCapacityMap);  }### Answer:
@Test(dataProvider = "TestMeasureBaselineDivergenceInput") public void testMeasureBaselineDivergence(Map<String, Map<String, Map<String, String>>> baseline, Map<String, Map<String, Map<String, String>>> someMatchBestPossible, Map<String, Map<String, Map<String, String>>> noMatchBestPossible) { Map<String, ResourceAssignment> baselineAssignment = buildResourceAssignment(baseline); Map<String, ResourceAssignment> someMatchBestPossibleAssignment = buildResourceAssignment(someMatchBestPossible); Map<String, ResourceAssignment> noMatchBestPossibleAssignment = buildResourceAssignment(noMatchBestPossible); Assert.assertEquals(ResourceUsageCalculator .measureBaselineDivergence(baselineAssignment, Collections.emptyMap()), 1.0d); Assert.assertEquals(ResourceUsageCalculator .measureBaselineDivergence(Collections.emptyMap(), noMatchBestPossibleAssignment), 1.0d); Assert.assertEquals(ResourceUsageCalculator .measureBaselineDivergence(baselineAssignment, noMatchBestPossibleAssignment), 1.0d); Assert.assertEquals(ResourceUsageCalculator .measureBaselineDivergence(baselineAssignment, someMatchBestPossibleAssignment), (1.0d - (double) 1 / (double) 3)); Assert.assertEquals( ResourceUsageCalculator.measureBaselineDivergence(baselineAssignment, baselineAssignment), 0.0d); }