### Question:
FastSyncValidationPolicy implements ValidationPolicy { @Override public HeaderValidationMode getValidationModeForNextBlock() { final HeaderValidationMode mode = Math.random() < targetFullValidationRate ? fullValidationMode : lightValidationMode; fastSyncValidationCounter.labels(mode.name()).inc(); return mode; } FastSyncValidationPolicy(
      final float targetFullValidationRate,
      final HeaderValidationMode lightValidationMode,
      final HeaderValidationMode fullValidationMode,
      final LabelledMetric<Counter> fastSyncValidationCounter); @Override HeaderValidationMode getValidationModeForNextBlock();  }### Answer:
@Test public void shouldAlwaysUseFastValidationWhenFullValidationRateIsZero() { final FastSyncValidationPolicy policy = new FastSyncValidationPolicy(0, LIGHT, FULL, NO_OP_LABELLED_1_COUNTER); assertThat(policy.getValidationModeForNextBlock()).isEqualTo(LIGHT); }
@Test public void shouldAlwaysUseFullValidationWhenFullValidationRateIsOne() { final FastSyncValidationPolicy policy = new FastSyncValidationPolicy(1, LIGHT, FULL, NO_OP_LABELLED_1_COUNTER); assertThat(policy.getValidationModeForNextBlock()).isEqualTo(FULL); }
@Test public void shouldEventuallyUseBothModesWhenValidationPolicyIsHalf() { final FastSyncValidationPolicy policy = new FastSyncValidationPolicy(0.5f, LIGHT, FULL, NO_OP_LABELLED_1_COUNTER); boolean seenLight = false; boolean seenFull = false; for (int i = 0; i < Integer.MAX_VALUE && (!seenLight || !seenFull); i++) { final HeaderValidationMode mode = policy.getValidationModeForNextBlock(); if (mode == LIGHT) { seenLight = true; } else if (mode == FULL) { seenFull = true; } else { fail("Unexpected validation mode " + mode); } } assertThat(seenLight).describedAs("used light validation").isTrue(); assertThat(seenFull).describedAs("used full validation").isTrue(); }