/** * Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.analytics.math.interpolation; import static org.testng.AssertJUnit.assertTrue; import org.apache.commons.lang.NotImplementedException; import org.testng.annotations.Test; import com.opengamma.analytics.math.matrix.DoubleMatrix1D; import com.opengamma.analytics.math.matrix.DoubleMatrix2D; /** * Test for {@link PiecewisePolynomialResult} and subclasses */ public class PiecewisePolynomialResultTest { /** * */ @Test public void hashCodeEqualsTest() { final double[] knots1 = new double[] {1., 2., 3., 4. }; final double[] knots2 = new double[] {1., 2., 3., 4., 5., 6., 7. }; final double[][] matrix1 = new double[][] { {3., 3., 3. }, {1., 1., 1. }, {2., 2., 2. }, {3., 3., 3. }, {1., 1., 1. }, {2., 2., 2. } }; final double[][] matrix2 = new double[][] { {3., 3., 3. }, {1., 1., 1. }, {2., 2., 2. } }; final int order = 3; final int dim1 = 2; final int dim2 = 1; final PiecewisePolynomialResult res1 = new PiecewisePolynomialResult(new DoubleMatrix1D(knots1), new DoubleMatrix2D(matrix1), order, dim1); final PiecewisePolynomialResult res2 = new PiecewisePolynomialResult(new DoubleMatrix1D(knots1), new DoubleMatrix2D(matrix1), order, dim1); final PiecewisePolynomialResult res3 = new PiecewisePolynomialResult(new DoubleMatrix1D(knots2), new DoubleMatrix2D(matrix2), order, dim2); final PiecewisePolynomialResult res4 = new PiecewisePolynomialResult(new DoubleMatrix1D(knots1), new DoubleMatrix2D(matrix1), 2, dim1); final PiecewisePolynomialResult res5 = new PiecewisePolynomialResult(new DoubleMatrix1D(knots1), new DoubleMatrix2D(matrix1), order, dim1 - 1); final PiecewisePolynomialResult res6 = new PiecewisePolynomialResult(new DoubleMatrix1D(new double[] {1., 2., 3., 5. }), new DoubleMatrix2D(matrix1), order, dim1); assertTrue(res1.equals(res1)); assertTrue(res1.equals(res2)); assertTrue(res2.equals(res1)); assertTrue(res2.hashCode() == res1.hashCode()); assertTrue(!(res3.hashCode() == res1.hashCode())); assertTrue(!(res1.equals(res3))); assertTrue(!(res3.equals(res1))); assertTrue(!(res4.hashCode() == res1.hashCode())); assertTrue(!(res1.equals(res4))); assertTrue(!(res4.equals(res1))); assertTrue(!(res5.hashCode() == res1.hashCode())); assertTrue(!(res1.equals(res5))); assertTrue(!(res5.equals(res1))); assertTrue(!(res6.hashCode() == res1.hashCode())); assertTrue(!(res1.equals(res6))); assertTrue(!(res6.equals(res1))); assertTrue(!(res1.equals(null))); assertTrue(!(res1.equals(new DoubleMatrix1D(knots1)))); final DoubleMatrix2D[] sense1 = new DoubleMatrix2D[] {new DoubleMatrix2D(matrix1), new DoubleMatrix2D(matrix1) }; final DoubleMatrix2D[] sense2 = new DoubleMatrix2D[] {new DoubleMatrix2D(matrix1), new DoubleMatrix2D(matrix1), new DoubleMatrix2D(matrix1) }; final PiecewisePolynomialResultsWithSensitivity resSen1 = new PiecewisePolynomialResultsWithSensitivity(new DoubleMatrix1D(knots1), new DoubleMatrix2D(matrix1), order, 1, sense1); final PiecewisePolynomialResultsWithSensitivity resSen2 = new PiecewisePolynomialResultsWithSensitivity(new DoubleMatrix1D(knots1), new DoubleMatrix2D(matrix1), order, 1, sense1); final PiecewisePolynomialResultsWithSensitivity resSen3 = new PiecewisePolynomialResultsWithSensitivity(new DoubleMatrix1D(knots1), new DoubleMatrix2D(matrix1), order, 1, sense2); assertTrue(resSen1.equals(resSen1)); assertTrue(!(resSen1.equals(new DoubleMatrix1D(knots1)))); assertTrue(!(resSen1.equals(res5))); assertTrue(resSen1.equals(resSen2)); assertTrue(resSen2.equals(resSen1)); assertTrue(resSen1.hashCode() == resSen2.hashCode()); assertTrue(!(resSen1.hashCode() == resSen3.hashCode())); assertTrue(!(resSen1.equals(resSen3))); assertTrue(!(resSen3.equals(resSen1))); try { @SuppressWarnings("unused") final PiecewisePolynomialResultsWithSensitivity resSen0 = new PiecewisePolynomialResultsWithSensitivity(new DoubleMatrix1D(knots1), new DoubleMatrix2D(matrix1), order, 2, sense1); throw new RuntimeException(); } catch (Exception e) { assertTrue(e instanceof NotImplementedException); } } }