code: private static double AndersonDarling(double[] x) {
          int n = x.length;
          Arrays.sort(x);
  
          for (int i = 0; i < n; i++) {
              x[i] = GaussianDistribution.getInstance().cdf(x[i]);
              // in case overflow when taking log later.
              if (x[i] == 0) x[i] = 0.0000001;
              if (x[i] == 1) x[i] = 0.9999999;
          }
  
          double A = 0.0;
          for (int i = 0; i < n; i++) {
              A -= (2*i+1) * (Math.log(x[i]) + Math.log(1-x[n-i-1]));
          }
  
          A = A / n - n;
          A *= (1 + 4.0/n - 25.0/(n*n));
  
          return A;
      }
docs: Calculates the Anderson-Darling statistic for one-dimensional normality test.
  
  @param x the samples to test if drawn from a Gaussian distribution.