private void checkOrthogonality(
     final PolynomialFunction p1,
     final PolynomialFunction p2,
     final UnivariateFunction weight,
     final double a,
     final double b,
     final double nonZeroThreshold,
     final double zeroThreshold) {
   UnivariateFunction f =
       new UnivariateFunction() {
         public double value(double x) {
           return weight.value(x) * p1.value(x) * p2.value(x);
         }
       };
   double dotProduct =
       new IterativeLegendreGaussIntegrator(5, 1.0e-9, 1.0e-8, 2, 15).integrate(1000000, f, a, b);
   if (p1.degree() == p2.degree()) {
     // integral should be non-zero
     Assert.assertTrue(
         "I(" + p1.degree() + ", " + p2.degree() + ") = " + dotProduct,
         FastMath.abs(dotProduct) > nonZeroThreshold);
   } else {
     // integral should be zero
     Assert.assertEquals(
         "I(" + p1.degree() + ", " + p2.degree() + ") = " + dotProduct,
         0.0,
         FastMath.abs(dotProduct),
         zeroThreshold);
   }
 }