public void test3Random() {
   java.util.Random r = new java.util.Random();
   int ntest = 1000;
   for (int itest = 0; itest < ntest; ++itest) {
     SymmetricTridiagonalFilter stf = makeRandomFilter();
     boolean inplace = r.nextBoolean(); // apply in-place?
     int n1 = 2 + r.nextInt(11);
     int n2 = 2 + r.nextInt(12);
     int n3 = 2 + r.nextInt(13);
     float[][][] t = randfloat(r, n1, n2, n3);
     float[][][] x = copy(t);
     float[][][] y = inplace ? x : zerofloat(n1, n2, n3);
     float[][][] z = inplace ? x : zerofloat(n1, n2, n3);
     stf.apply1(x, y);
     stf.applyInverse1(y, z);
     assertEqual(t, x);
     assertEqual(t, z);
     stf.apply2(x, y);
     stf.applyInverse2(y, z);
     assertEqual(t, x);
     assertEqual(t, z);
     stf.apply3(x, y);
     stf.applyInverse3(y, z);
     assertEqual(t, x);
     assertEqual(t, z);
   }
 }
 public void test1Random() {
   java.util.Random r = new java.util.Random();
   int ntest = 1000;
   for (int itest = 0; itest < ntest; ++itest) {
     SymmetricTridiagonalFilter stf = makeRandomFilter();
     boolean inplace = r.nextBoolean(); // apply in-place?
     int n = 2 + r.nextInt(10);
     float[] t = randfloat(r, n);
     float[] x = copy(t);
     float[] y = inplace ? x : zerofloat(n);
     float[] z = inplace ? x : zerofloat(n);
     stf.apply(x, y);
     stf.applyInverse(y, z);
     assertEqual(t, x);
     assertEqual(t, z);
   }
 }
 private static SymmetricTridiagonalFilter makeRandomFilter() {
   java.util.Random r = new java.util.Random();
   float af, ai, al, b;
   boolean aeq2b = r.nextBoolean(); // |a| = |2b|?
   boolean abneg = r.nextBoolean(); // sgn(a) = sgn(b)?
   boolean afzs = r.nextBoolean(); // af for zero-slope?
   boolean alzs = r.nextBoolean(); // al for zero-slope?
   if (aeq2b && afzs == true && alzs == true) {
     if (r.nextBoolean()) {
       afzs = false;
     } else {
       alzs = false;
     }
   }
   b = r.nextFloat();
   ai = 2.0f * b;
   if (!aeq2b) ai += max(0.001, r.nextFloat()) * b;
   if (abneg) ai = -ai;
   af = ai;
   al = ai;
   if (afzs) af = ai + b;
   if (alzs) al = ai + b;
   return new SymmetricTridiagonalFilter(af, ai, al, b);
 }