// Path: mug/src/main/java/com/google/mu/util/concurrent/Parallelizer.java
// static <T> Stream<Runnable> forAll(Stream<? extends T> inputs, Consumer<? super T> consumer) {
//   requireNonNull(consumer);
//   return inputs.map(input -> () -> consumer.accept(input));
// }
// 
// Path: mug/src/main/java/com/google/mu/util/concurrent/Parallelizer.java
// static class UncheckedExecutionException extends RuntimeException {
//   UncheckedExecutionException(Throwable cause) {
//     super(cause);
//   }
//   private static final long serialVersionUID = 1L;
// }


import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.util.concurrent.Parallelizer.forAll;
import static java.util.Arrays.asList;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Verifier;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.truth.IterableSubject;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.mu.util.concurrent.Parallelizer.UncheckedExecutionException;
  }

  @Test public void testOneInFlight() throws Exception {
    maxInFlight = 1;
    List<Integer> numbers = asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
    parallelize(numbers.stream(), this::translateToString);
    assertThat(translated).containsExactlyEntriesIn(mapToString(numbers));
  }

  @Test public void testFastTasks() throws Exception {
    List<Integer> numbers = asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
    parallelize(numbers.stream(), this::translateToString);
    assertThat(translated).containsExactlyEntriesIn(mapToString(numbers));
  }

  @Test public void testSlowTasks() throws Exception {
    List<Integer> numbers = asList(1, 2, 3, 4, 5);
    parallelize(numbers.stream(), delayed(Duration.ofMillis(2), this::translateToString));
    assertThat(translated).containsExactlyEntriesIn(mapToString(numbers));
  }

  @Test public void testLargeMaxInFlight() throws Exception {
    maxInFlight = Integer.MAX_VALUE;
    List<Integer> numbers = asList(1, 2, 3);
    parallelize(numbers.stream(), this::translateToString);
    assertThat(translated).containsExactlyEntriesIn(mapToString(numbers));
  }

  @Test public void testTaskExceptionDismissesPendingTasks() {
    maxInFlight = 2;
// Path: mug/src/main/java/com/google/mu/util/concurrent/Parallelizer.java
// static <T> Stream<Runnable> forAll(Stream<? extends T> inputs, Consumer<? super T> consumer) {
//   requireNonNull(consumer);
//   return inputs.map(input -> () -> consumer.accept(input));
// }
// 
// Path: mug/src/main/java/com/google/mu/util/concurrent/Parallelizer.java
// static class UncheckedExecutionException extends RuntimeException {
//   UncheckedExecutionException(Throwable cause) {
//     super(cause);
//   }
//   private static final long serialVersionUID = 1L;
// }


// Path: mug/src/test/java/com/google/mu/util/concurrent/ParallelizerTest.java
import static com.google.common.truth.Truth.assertThat;
import static com.google.mu.util.concurrent.Parallelizer.forAll;
import static java.util.Arrays.asList;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Verifier;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.truth.IterableSubject;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.mu.util.concurrent.Parallelizer.UncheckedExecutionException;

  }

  @Test public void testOneInFlight() throws Exception {
    maxInFlight = 1;
    List<Integer> numbers = asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
    parallelize(numbers.stream(), this::translateToString);
    assertThat(translated).containsExactlyEntriesIn(mapToString(numbers));
  }

  @Test public void testFastTasks() throws Exception {
    List<Integer> numbers = asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
    parallelize(numbers.stream(), this::translateToString);
    assertThat(translated).containsExactlyEntriesIn(mapToString(numbers));
  }

  @Test public void testSlowTasks() throws Exception {
    List<Integer> numbers = asList(1, 2, 3, 4, 5);
    parallelize(numbers.stream(), delayed(Duration.ofMillis(2), this::translateToString));
    assertThat(translated).containsExactlyEntriesIn(mapToString(numbers));
  }

  @Test public void testLargeMaxInFlight() throws Exception {
    maxInFlight = Integer.MAX_VALUE;
    List<Integer> numbers = asList(1, 2, 3);
    parallelize(numbers.stream(), this::translateToString);
    assertThat(translated).containsExactlyEntriesIn(mapToString(numbers));
  }

  @Test public void testTaskExceptionDismissesPendingTasks() {
    maxInFlight = 2;
    UncheckedExecutionException exception = assertThrows(