package com.airbnb.aerosolve.core.function;

import com.airbnb.aerosolve.core.models.NDTreeModel;
import com.airbnb.aerosolve.core.models.NDTreeModelTest;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

@Slf4j
public class MultiDimensionSplineTest {
  public MultiDimensionSpline getMultiDimensionSpline() {
    NDTreeModel tree = NDTreeModelTest.getNDTreeModel();
    return new MultiDimensionSpline(tree);
  }

  @Test
  public void evaluate() throws Exception {
    MultiDimensionSpline spline = getMultiDimensionSpline();

    spline.update((float)0.5, (float)0.5, (float)2.0);
    assertEquals(0.125, spline.evaluate((float) 0.5, (float)2.0), 0.0001);

    spline.update((float)0.8, (float)0.6, (float)2.0);
    assertEquals(0.325, spline.evaluate((float)0.5, (float)2.0), 0.0001);

    spline.update((float) 0.8, (float)2.0, (float)1.0);
    assertEquals(0.28868586584843375, spline.evaluate((float)3.0, (float)1.0), 0.0001);

    spline.update((float)0.8, (float)3.0, (float)3.0);
    assertEquals(0.40389338302461303, spline.evaluate((float)3.0, (float)3.0), 0.0001);
  }
}
@@ -206,16 +206,68 @@
 .Test;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 import s
@@ -627,16 +627,84 @@
 line();%0A
+    eval(spline);%0A  %7D%0A%0A  private static void eval(Function spline) %7B
 %0A    spl
@@ -1244,14 +1244,338 @@
 0.0001);
+%0A%0A  %7D%0A%0A  @Test%0A  public void aggregate() throws Exception %7B%0A    List%3CFunction%3E splineList = new ArrayList%3C%3E();%0A    for (int i = 0; i %3C 10; ++i) %7B%0A      MultiDimensionSpline spline = getMultiDimensionSpline();%0A      splineList.add(spline);%0A    %7D%0A    Function r = splineList.get(0).aggregate(splineList, 0.1f, 0);%0A    eval(r);
 %0A  %7D%0A%7D

Add unit test for aggregate of MultiDimensionSpline