### Question:
DensityOutput extends InterpolationMeasure { public double getDensity(double q, int manifoldDimension) { double sumOfPts = measure.getHighLowSum() / sampleSize; if (sumOfPts <= 0.0) { return 0.0; } double sumOfFactors = 0; for (int i = 0; i < dimensions; i++) { double t = probMass.getHighLowSum(i) > 0 ? distances.getHighLowSum(i) / probMass.getHighLowSum(i) : 0; if (t > 0) { t = Math.exp(Math.log(t) * manifoldDimension) * probMass.getHighLowSum(i); } sumOfFactors += t; } return sumOfPts / (q * sumOfPts + sumOfFactors); } DensityOutput(int dimensions, int sampleSize);  DensityOutput(InterpolationMeasure base); double getDensity(double q, int manifoldDimension); double getDensity(); DiVector getDirectionalDensity(double q, int manifoldDimension); DiVector getDirectionalDensity(); static final double DEFAULT_SUM_OF_POINTS_SCALING_FACTOR; }### Answer:
@Test public void testGetDensity() { for (int i = 0; i < dimensions; i++) { output.probMass.high[i] = 2 * i; output.distances.high[i] = 4 * i; output.measure.high[i] = 6 * i; output.probMass.low[i] = 2 * i + 1; output.distances.low[i] = 4 * i + 2; output.measure.low[i] = 6 * i + 3; } double q = 0.5; double density = output.getDensity(q, 3); DiVector densityVector = output.getDirectionalDensity(q, 3); double sumOfPoints = output.measure.getHighLowSum() / sampleSize; double sumOfFactors = 0.0; for (int i = 0; i < dimensions; i++) { double mass = output.probMass.getHighLowSum(i); double distance = output.distances.getHighLowSum(i); double t = distance / mass; t = Math.pow(t, dimensions) * mass; sumOfFactors += t; } assertEquals(sumOfPoints / (q * sumOfPoints + sumOfFactors), density, EPSILON); sumOfPoints = output.measure.getHighLowSum(); for (int i = 0; i < dimensions; i++) { assertEquals(output.measure.high[i] * density / sumOfPoints, densityVector.high[i], EPSILON); assertEquals(output.measure.low[i] * density / sumOfPoints, densityVector.low[i], EPSILON); } assertEquals(output.getDensity(DensityOutput.DEFAULT_SUM_OF_POINTS_SCALING_FACTOR, dimensions), output.getDensity()); densityVector = output.getDirectionalDensity(DensityOutput.DEFAULT_SUM_OF_POINTS_SCALING_FACTOR, dimensions); DiVector defaultDensityVector = output.getDirectionalDensity(); for (int i = 0; i < dimensions; i++) { assertEquals(densityVector.high[i], defaultDensityVector.high[i], EPSILON); assertEquals(densityVector.low[i], defaultDensityVector.low[i], EPSILON); } }