content: package dk.alexandra.fresco.lib.common.compare.lt;
  
  import dk.alexandra.fresco.framework.Application;
  import dk.alexandra.fresco.framework.DRes;
  import dk.alexandra.fresco.framework.TestThreadRunner.TestThread;
  import dk.alexandra.fresco.framework.TestThreadRunner.TestThreadFactory;
  import dk.alexandra.fresco.framework.builder.numeric.NumericResourcePool;
  import dk.alexandra.fresco.framework.builder.numeric.ProtocolBuilderNumeric;
  import dk.alexandra.fresco.framework.util.MathUtils;
  import dk.alexandra.fresco.framework.value.SInt;
  import java.math.BigInteger;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Collections;
  import java.util.List;
  import java.util.Random;
  import java.util.stream.Collectors;
  import org.junit.Assert;
  
  public class BitLessThanOpenTests {
  
    public static class TestBitLessThanOpen<ResourcePoolT extends NumericResourcePool>
        extends TestThreadFactory<ResourcePoolT, ProtocolBuilderNumeric> {
  
      private List<BigInteger> left;
      private List<BigInteger> right;
  
      @Override
      public TestThread<ResourcePoolT, ProtocolBuilderNumeric> next() {
  
        return new TestThread<ResourcePoolT, ProtocolBuilderNumeric>() {
  
          @Override
          public void test() {
            Application<List<BigInteger>, ProtocolBuilderNumeric> app =
                root -> {
                  int numBits = 32;
                  setupInputs(conf.getResourcePool().getModulus(), numBits);
                  List<DRes<BigInteger>> results = new ArrayList<>(left.size());
                  for (int i = 0; i < left.size(); i++) {
                    BigInteger leftValue = left.get(i);
                    DRes<List<DRes<SInt>>> rightValue = toSecretBits(root, right.get(i),
                        numBits);
                    results.add(
                        root.numeric().open(root.seq(new BitLessThanOpen(leftValue, rightValue)))
                    );
                  }
                  return () -> results.stream().map(DRes::out).collect(Collectors.toList());
                };
            List<BigInteger> actual = runApplication(app);
            List<BigInteger> expected = new ArrayList<>(left.size());
            for (int i = 0; i < left.size(); i++) {
              boolean leq = left.get(i).compareTo(right.get(i)) < 0;
              expected.add(leq ? BigInteger.ONE : BigInteger.ZERO);
            }
            Assert.assertEquals(expected, actual);
          }
        };
      }
  
      private void setupInputs(BigInteger modulus, int numBits) {
        Random random = new Random(42);
        this.left = Arrays.asList(
            BigInteger.ZERO,
            BigInteger.ONE,
            BigInteger.ZERO,
            BigInteger.valueOf(5),
            BigInteger.valueOf(111),
            BigInteger.valueOf(111),
            modulus.subtract(BigInteger.ONE),
            modulus.subtract(BigInteger.ONE),
            BigInteger.valueOf(2055014152),
            new BigInteger(numBits, random).mod(modulus)
        );
        this.right = Arrays.asList(
            BigInteger.ONE,
            BigInteger.ZERO,
            BigInteger.ZERO,
            BigInteger.valueOf(4),
            BigInteger.valueOf(111),
            BigInteger.valueOf(112),
            modulus.subtract(BigInteger.ONE),
            modulus.subtract(BigInteger.valueOf(2)),
            BigInteger.valueOf(2055014153),
            new BigInteger(numBits, random).mod(modulus)
        );
      }
  
    }
  
    private static DRes<List<DRes<SInt>>> toSecretBits(ProtocolBuilderNumeric root,
        BigInteger value,
        int numBits) {
      List<BigInteger> openList = MathUtils.toBits(value, numBits);
      Collections.reverse(openList);
      return dk.alexandra.fresco.lib.common.collections.Collections.using(root).closeList(openList, 1);
    }
  
  }