@Override
    public TestThread<ResourcePoolT, ProtocolBuilderNumeric> next() {
      // TODO Should be split into different tests for mean, variance, covariance, covariancematrix
      return new TestThread<ResourcePoolT, ProtocolBuilderNumeric>() {
        private final List<Integer> data1 = Arrays.asList(543, 520, 532, 497, 450, 432);
        private final List<Integer> data2 = Arrays.asList(432, 620, 232, 337, 250, 433);
        private final List<Integer> data3 = Arrays.asList(80, 90, 123, 432, 145, 606);
        private final List<Integer> dataMean = Arrays.asList(496, 384);
        private DRes<BigInteger> outputMean1;
        private DRes<BigInteger> outputMean2;
        private DRes<BigInteger> outputVariance;
        private DRes<BigInteger> outputCovariance;
        private List<List<DRes<BigInteger>>> outputCovarianceMatix;
        @Override
        public void test() throws Exception {
          Application<Void, ProtocolBuilderNumeric> app = builder -> {
            Numeric NumericBuilder = builder.numeric();
            List<DRes<SInt>> input1 = data1.stream().map(BigInteger::valueOf)
                .map(NumericBuilder::known).collect(Collectors.toList());
            List<DRes<SInt>> input2 = data2.stream().map(BigInteger::valueOf)
                .map(NumericBuilder::known).collect(Collectors.toList());
            List<DRes<SInt>> input3 = data3.stream().map(BigInteger::valueOf)
                .map(NumericBuilder::known).collect(Collectors.toList());
            List<DRes<SInt>> means = dataMean.stream().map(BigInteger::valueOf)
                .map(NumericBuilder::known).collect(Collectors.toList());
            DRes<SInt> mean1 = builder.seq(new Mean(input1));
            DRes<SInt> mean2 = builder.seq(new Mean(input2));
            DRes<SInt> variance = builder.seq(new Variance(input1, mean1));
            DRes<SInt> covariance = builder.seq(new Covariance(input1, input2, mean1, mean2));
            DRes<List<List<DRes<SInt>>>> covarianceMatrix =
                builder.seq(new CovarianceMatrix(Arrays.asList(input1, input2, input3), means));
            return builder.par((par) -> {
              Numeric open = par.numeric();
              outputMean1 = open.open(mean1);
              outputMean2 = open.open(mean2);
              outputVariance = open.open(variance);
              outputCovariance = open.open(covariance);
              List<List<DRes<SInt>>> covarianceMatrixOut = covarianceMatrix.out();
              List<List<DRes<BigInteger>>> openCovarianceMatrix =
                  new ArrayList<>(covarianceMatrixOut.size());
              for (List<DRes<SInt>> computations : covarianceMatrixOut) {
                List<DRes<BigInteger>> computationList = new ArrayList<>(computations.size());
                openCovarianceMatrix.add(computationList);
                for (DRes<SInt> computation : computations) {
                  computationList.add(open.open(computation));
                }
              }
              outputCovarianceMatix = openCovarianceMatrix;
              return null;
            });
          };
          runApplication(app);
          BigInteger mean1 = outputMean1.out();
          BigInteger mean2 = outputMean2.out();
          BigInteger variance = outputVariance.out();
          BigInteger covariance = outputCovariance.out();
          double sum = 0.0;
          for (int entry : data1) {
            sum += entry;
          }
          double mean1Exact = sum / data1.size();
          sum = 0.0;
          for (int entry : data2) {
            sum += entry;
          }
          double mean2Exact = sum / data2.size();
          double ssd = 0.0;
          for (int entry : data1) {
            ssd += (entry - mean1Exact) * (entry - mean1Exact);
          }
          double varianceExact = ssd / (data1.size() - 1);
          double covarianceExact = 0.0;
          for (int i = 0; i < data1.size(); i++) {
            covarianceExact += (data1.get(i) - mean1Exact) * (data2.get(i) - mean2Exact);
          }
          covarianceExact /= (data1.size() - 1);
          double tolerance = 1.0;
          Assert.assertTrue(isInInterval(mean1, mean1Exact, tolerance));
          Assert.assertTrue(isInInterval(mean2, mean2Exact, tolerance));
          Assert.assertTrue(isInInterval(variance, varianceExact, tolerance));
          System.out.println(covariance + " " + covarianceExact + " - " + tolerance);
          Assert.assertTrue(isInInterval(covariance, covarianceExact, tolerance));
          Assert.assertTrue(
              isInInterval(outputCovarianceMatix.get(0).get(0).out(), varianceExact, tolerance));
          Assert.assertTrue(
              isInInterval(outputCovarianceMatix.get(1).get(0).out(), covarianceExact, tolerance));
        }
      };
    }
@Override
    public TestThread<ResourcePoolT, ProtocolBuilderNumeric> next() {
     
      return new TestThread<ResourcePoolT, ProtocolBuilderNumeric>() {
        private final List<Integer> data1 = Arrays.asList(543, 520, 532, 497, 450, 432);
        private final List<Integer> data2 = Arrays.asList(432, 620, 232, 337, 250, 433);
        private final List<Integer> data3 = Arrays.asList(80, 90, 123, 432, 145, 606);
        private final List<Integer> dataMean = Arrays.asList(496, 384);
        private DRes<BigInteger> outputMean1;
        private DRes<BigInteger> outputMean2;
        private DRes<BigInteger> outputVariance;
        private DRes<BigInteger> outputCovariance;
        private List<List<DRes<BigInteger>>> outputCovarianceMatix;
        @Override
        public void test() throws Exception {
          Application<Void, ProtocolBuilderNumeric> app = builder -> {
            Numeric NumericBuilder = builder.numeric();
            List<DRes<SInt>> input1 = data1.stream().map(BigInteger::valueOf)
                .map(NumericBuilder::known).collect(Collectors.toList());
            List<DRes<SInt>> input2 = data2.stream().map(BigInteger::valueOf)
                .map(NumericBuilder::known).collect(Collectors.toList());
            List<DRes<SInt>> input3 = data3.stream().map(BigInteger::valueOf)
                .map(NumericBuilder::known).collect(Collectors.toList());
            List<DRes<SInt>> means = dataMean.stream().map(BigInteger::valueOf)
                .map(NumericBuilder::known).collect(Collectors.toList());
            DRes<SInt> mean1 = builder.seq(new Mean(input1));
            DRes<SInt> mean2 = builder.seq(new Mean(input2));
            DRes<SInt> variance = builder.seq(new Variance(input1, mean1));
            DRes<SInt> covariance = builder.seq(new Covariance(input1, input2, mean1, mean2));
            DRes<List<List<DRes<SInt>>>> covarianceMatrix =
                builder.seq(new CovarianceMatrix(Arrays.asList(input1, input2, input3), means));
            return builder.par((par) -> {
              Numeric open = par.numeric();
              outputMean1 = open.open(mean1);
              outputMean2 = open.open(mean2);
              outputVariance = open.open(variance);
              outputCovariance = open.open(covariance);
              List<List<DRes<SInt>>> covarianceMatrixOut = covarianceMatrix.out();
              List<List<DRes<BigInteger>>> openCovarianceMatrix =
                  new ArrayList<>(covarianceMatrixOut.size());
              for (List<DRes<SInt>> computations : covarianceMatrixOut) {
                List<DRes<BigInteger>> computationList = new ArrayList<>(computations.size());
                openCovarianceMatrix.add(computationList);
                for (DRes<SInt> computation : computations) {
                  computationList.add(open.open(computation));
                }
              }
              outputCovarianceMatix = openCovarianceMatrix;
              return null;
            });
          };
          runApplication(app);
          BigInteger mean1 = outputMean1.out();
          BigInteger mean2 = outputMean2.out();
          BigInteger variance = outputVariance.out();
          BigInteger covariance = outputCovariance.out();
          double sum = 0.0;
          for (int entry : data1) {
            sum += entry;
          }
          double mean1Exact = sum / data1.size();
          sum = 0.0;
          for (int entry : data2) {
            sum += entry;
          }
          double mean2Exact = sum / data2.size();
          double ssd = 0.0;
          for (int entry : data1) {
            ssd += (entry - mean1Exact) * (entry - mean1Exact);
          }
          double varianceExact = ssd / (data1.size() - 1);
          double covarianceExact = 0.0;
          for (int i = 0; i < data1.size(); i++) {
            covarianceExact += (data1.get(i) - mean1Exact) * (data2.get(i) - mean2Exact);
          }
          covarianceExact /= (data1.size() - 1);
          double tolerance = 1.0;
          Assert.assertTrue(isInInterval(mean1, mean1Exact, tolerance));
          Assert.assertTrue(isInInterval(mean2, mean2Exact, tolerance));
          Assert.assertTrue(isInInterval(variance, varianceExact, tolerance));
          System.out.println(covariance + " " + covarianceExact + " - " + tolerance);
          Assert.assertTrue(isInInterval(covariance, covarianceExact, tolerance));
          Assert.assertTrue(
              isInInterval(outputCovarianceMatix.get(0).get(0).out(), varianceExact, tolerance));
          Assert.assertTrue(
              isInInterval(outputCovarianceMatix.get(1).get(0).out(), covarianceExact, tolerance));
        }
      };
    }
@override public testthread<resourcepoolt, protocolbuildernumeric> next() { return new testthread<resourcepoolt, protocolbuildernumeric>() { private final list<integer> data1 = arrays.aslist(543, 520, 532, 497, 450, 432); private final list<integer> data2 = arrays.aslist(432, 620, 232, 337, 250, 433); private final list<integer> data3 = arrays.aslist(80, 90, 123, 432, 145, 606); private final list<integer> datamean = arrays.aslist(496, 384); private dres<biginteger> outputmean1; private dres<biginteger> outputmean2; private dres<biginteger> outputvariance; private dres<biginteger> outputcovariance; private list<list<dres<biginteger>>> outputcovariancematix; @override public void test() throws exception { application<void, protocolbuildernumeric> app = builder -> { numeric numericbuilder = builder.numeric(); list<dres<sint>> input1 = data1.stream().map(biginteger::valueof) .map(numericbuilder::known).collect(collectors.tolist()); list<dres<sint>> input2 = data2.stream().map(biginteger::valueof) .map(numericbuilder::known).collect(collectors.tolist()); list<dres<sint>> input3 = data3.stream().map(biginteger::valueof) .map(numericbuilder::known).collect(collectors.tolist()); list<dres<sint>> means = datamean.stream().map(biginteger::valueof) .map(numericbuilder::known).collect(collectors.tolist()); dres<sint> mean1 = builder.seq(new mean(input1)); dres<sint> mean2 = builder.seq(new mean(input2)); dres<sint> variance = builder.seq(new variance(input1, mean1)); dres<sint> covariance = builder.seq(new covariance(input1, input2, mean1, mean2)); dres<list<list<dres<sint>>>> covariancematrix = builder.seq(new covariancematrix(arrays.aslist(input1, input2, input3), means)); return builder.par((par) -> { numeric open = par.numeric(); outputmean1 = open.open(mean1); outputmean2 = open.open(mean2); outputvariance = open.open(variance); outputcovariance = open.open(covariance); list<list<dres<sint>>> covariancematrixout = covariancematrix.out(); list<list<dres<biginteger>>> opencovariancematrix = new arraylist<>(covariancematrixout.size()); for (list<dres<sint>> computations : covariancematrixout) { list<dres<biginteger>> computationlist = new arraylist<>(computations.size()); opencovariancematrix.add(computationlist); for (dres<sint> computation : computations) { computationlist.add(open.open(computation)); } } outputcovariancematix = opencovariancematrix; return null; }); }; runapplication(app); biginteger mean1 = outputmean1.out(); biginteger mean2 = outputmean2.out(); biginteger variance = outputvariance.out(); biginteger covariance = outputcovariance.out(); double sum = 0.0; for (int entry : data1) { sum += entry; } double mean1exact = sum / data1.size(); sum = 0.0; for (int entry : data2) { sum += entry; } double mean2exact = sum / data2.size(); double ssd = 0.0; for (int entry : data1) { ssd += (entry - mean1exact) * (entry - mean1exact); } double varianceexact = ssd / (data1.size() - 1); double covarianceexact = 0.0; for (int i = 0; i < data1.size(); i++) { covarianceexact += (data1.get(i) - mean1exact) * (data2.get(i) - mean2exact); } covarianceexact /= (data1.size() - 1); double tolerance = 1.0; assert.asserttrue(isininterval(mean1, mean1exact, tolerance)); assert.asserttrue(isininterval(mean2, mean2exact, tolerance)); assert.asserttrue(isininterval(variance, varianceexact, tolerance)); system.out.println(covariance + " " + covarianceexact + " - " + tolerance); assert.asserttrue(isininterval(covariance, covarianceexact, tolerance)); assert.asserttrue( isininterval(outputcovariancematix.get(0).get(0).out(), varianceexact, tolerance)); assert.asserttrue( isininterval(outputcovariancematix.get(1).get(0).out(), covarianceexact, tolerance)); } }; }