/**
 * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.financial.analytics.fudgemsg;

import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.Test;
import com.opengamma.OpenGammaRuntimeException;
import com.opengamma.financial.interestrate.NelsonSiegelSvennsonBondCurveModel;
import com.opengamma.math.curve.ConstantDoublesCurve;
import com.opengamma.math.curve.Curve;
import com.opengamma.math.curve.FunctionalDoublesCurve;
import com.opengamma.math.curve.InterpolatedDoublesCurve;
import com.opengamma.math.function.Function1D;
import com.opengamma.math.interpolation.LinearInterpolator1D;
import com.opengamma.math.matrix.DoubleMatrix1D;

/**
 * 
 */
public class MathCurveTest extends AnalyticsTestBase {

  @SuppressWarnings("unchecked")
  @Test
  public void testConstantCurve() {
    Curve<Double, Double> c1 = ConstantDoublesCurve.from(4.);
    Curve<Double, Double> c2 = cycleObject(Curve.class, c1);
    assertEquals(c1, c2);
    c1 = ConstantDoublesCurve.from(4., "NAME");
    c2 = cycleObject(Curve.class, c1);
    assertEquals(c1, c2);
  }

  @SuppressWarnings("unchecked")
  @Test
  public void testInterpolatedCurve() {
    Curve<Double, Double> c1 = InterpolatedDoublesCurve.from(new double[] {1, 2, 3, 4}, new double[] {4, 5, 6, 7}, new LinearInterpolator1D());
    Curve<Double, Double> c2 = cycleObject(Curve.class, c1);
    assertEquals(c1, c2);
    c1 = InterpolatedDoublesCurve.from(new double[] {1, 2, 3, 4}, new double[] {4, 5, 6, 7}, new LinearInterpolator1D(), "NAME");
    c2 = cycleObject(Curve.class, c1);
    assertEquals(c1, c2);
  }

  @Test(expectedExceptions = OpenGammaRuntimeException.class)
  public void testWrongFunctionType() {
    final Function1D<Double, Double> f = new Function1D<Double, Double>() {

      @Override
      public Double evaluate(final Double x) {
        return x * x;
      }

    };
    cycleObject(Curve.class, FunctionalDoublesCurve.from(f));
  }

  @SuppressWarnings("unchecked")
  @Test
  public void testFunctionalCurve() {
    final Function1D<Double, Double> f = new NelsonSiegelSvennsonBondCurveModel(new DoubleMatrix1D(new double[] {1, 2, 3, 4, 5, 6}));
    Curve<Double, Double> c1 = FunctionalDoublesCurve.from(f);
    Curve<Double, Double> c2 = cycleObject(Curve.class, c1);
    assertEquals(c1, c2);
    c1 = FunctionalDoublesCurve.from(f, "NAME");
    c2 = cycleObject(Curve.class, c1);
    assertEquals(c1, c2);
  }
}

@@ -235,16 +235,17 @@
 Equals;%0A
+%0A
 import o
@@ -272,16 +272,17 @@
 s.Test;%0A
+%0A
 import c
@@ -321,16 +321,88 @@
 eption;%0A
+import com.opengamma.financial.interestrate.NelsonSiegelBondCurveModel;%0A
 import c
@@ -672,32 +672,77 @@
 edDoublesCurve;%0A
+import com.opengamma.math.function.Function;%0A
 import com.openg
@@ -2225,24 +2225,26 @@
 ctionalCurve
+_1
 () %7B%0A    fin
@@ -2637,11 +2637,611 @@
 c2);%0A  %7D
+%0A%0A  @SuppressWarnings(%22unchecked%22)%0A  @Test%0A  public void testFunctionalCurve_2 () %7B%0A    final NelsonSiegelBondCurveModel curveBondModel = new NelsonSiegelBondCurveModel();%0A    final Function%3CDouble, Double%3E func = curveBondModel.getParameterizedFunction().asFunctionOfArguments(new DoubleMatrix1D(new double%5B%5D %7B1, 2, 3, 4 %7D));%0A    Curve%3CDouble, Double%3E c1 = FunctionalDoublesCurve.from(func);%0A    Curve%3CDouble, Double%3E c2 = cycleObject(Curve.class, c1);%0A    assertEquals(c1, c2);%0A    c1 = FunctionalDoublesCurve.from(func, %22NAME%22);%0A    c2 = cycleObject(Curve.class, c1);%0A    assertEquals(c1, c2);%0A  %7D
 %0A%7D%0A

Establish failing test-case to work from.