CoinTossing { public StrictBitVector toss(int size) { if (!initialized) { throw new IllegalStateException("Not initialized"); } byte[] res = new byte[(size + 8 - 1) / 8]; coinTossingPrg.nextBytes(res); return new StrictBitVector(res); } CoinTossing(int myId, int otherId, Drbg rand); void initialize(Network network); StrictBitVector toss(int size);  }
@Test public void testCt() { int size = 10000; Callable<Exception> partyOneInit = this::initCtOne; Callable<Exception> partyTwoInit = this::initCtTwo; List<Exception> initResults = testRuntime .runPerPartyTasks(Arrays.asList(partyOneInit, partyTwoInit)); for (Exception current : initResults) { assertNull(current); } StrictBitVector tossOne = ctOne.toss(size); StrictBitVector tossTwo = ctTwo.toss(size); assertTrue(tossOne.equals(tossTwo)); StrictBitVector zeroVec = new StrictBitVector(size); assertNotEquals(zeroVec, tossOne); }
@Test public void testNotInitialized() { boolean thrown = false; try { ctOne.toss(128); } catch (IllegalStateException e) { assertEquals("Not initialized", e.getMessage()); thrown = true; } assertEquals(true, thrown); }