@Test
public void testCalculate() {

    double[][] data = new double[][]{{0, 2}, {1, 1}, {2, 0}, {3, 3}};
    double[] labels = new double[]{1, 2, 2, 1};
    MSEImpurityMeasureCalculator calculator = new MSEImpurityMeasureCalculator(useIdx);
    StepFunction<MSEImpurityMeasure>[] impurity = calculator.calculate(new DecisionTreeData(data, labels, useIdx), fs -> true, 0);
    assertEquals(2, impurity.length);
    // Test MSE calculated for the first column.
    assertArrayEquals(new double[]{Double.NEGATIVE_INFINITY, 0, 1, 2, 3}, impurity[0].getX(), 1e-10);
    assertEquals(1.000, impurity[0].getY()[0].impurity(), 1e-3);
    assertEquals(0.666, impurity[0].getY()[1].impurity(),1e-3);
    assertEquals(1.000, impurity[0].getY()[2].impurity(),1e-3);
    assertEquals(0.666, impurity[0].getY()[3].impurity(),1e-3);
    assertEquals(1.000, impurity[0].getY()[4].impurity(),1e-3);
    // Test MSE calculated for the second column.
    assertArrayEquals(new double[]{Double.NEGATIVE_INFINITY, 0, 1, 2, 3}, impurity[1].getX(), 1e-10);
    assertEquals(1.000, impurity[1].getY()[0].impurity(),1e-3);
    assertEquals(0.666, impurity[1].getY()[1].impurity(),1e-3);
    assertEquals(0.000, impurity[1].getY()[2].impurity(),1e-3);
    assertEquals(0.666, impurity[1].getY()[3].impurity(),1e-3);
    assertEquals(1.000, impurity[1].getY()[4].impurity(),1e-3);
}