// Path: src/test/java/com/github/rinde/opt/localsearch/InsertionsTest.java
// @SafeVarargs
// public static <T> ImmutableList<T> list(T... items) {
//   return ImmutableList.copyOf(items);
// }
// 
// Path: src/main/java/com/github/rinde/opt/localsearch/Swaps.java
// static DoubleList asDoubleList(double... values) {
//   return DoubleLists.unmodifiable(new DoubleArrayList(values));
// }
// 
// Path: src/main/java/com/github/rinde/opt/localsearch/Swaps.java
// static IntList asIntList(final int... values) {
//   return IntLists.unmodifiable(new IntArrayList(values));
// }
// 
// Path: src/main/java/com/github/rinde/opt/localsearch/Swaps.java
// static <T> ImmutableList<T> inListSwap(ImmutableList<T> originalList,
//     IntList insertionIndices, T item) {
//   checkArgument(!originalList.isEmpty(), "The list may not be empty.");
//   final List<T> newList = newArrayList(originalList);
//   final IntList indices = removeAll(newList, item);
//   checkArgument(
//     newList.size() == originalList.size() - insertionIndices.size(),
//     "The number of occurrences (%s) of item should equal the number of "
//       + "insertionIndices (%s), original list: %s, item %s, "
//       + "insertionIndices %s.",
//     indices.size(), insertionIndices.size(), originalList, item,
//     insertionIndices);
//   checkArgument(
//     !indices.equals(insertionIndices),
//     "Attempt to move the item to exactly the same locations as the input. "
//       + "Indices in original list %s, insertion indices %s.",
//     indices, insertionIndices);
//   return Insertions.insert(newList, insertionIndices, item);
// }
// 
// Path: src/main/java/com/github/rinde/opt/localsearch/Swaps.java
// static <T> IntList removeAll(List<T> list, T item) {
//   final Iterator<T> it = list.iterator();
//   final IntArrayList indices = new IntArrayList();
//   int i = 0;
//   while (it.hasNext()) {
//     if (it.next().equals(item)) {
//       it.remove();
//       indices.add(i);
//     }
//     i++;
//   }
//   return IntLists.unmodifiable(indices);
// }
// 
// Path: src/main/java/com/github/rinde/opt/localsearch/Swaps.java
// static <T> ImmutableList<T> replace(ImmutableList<T> list, IntList indices,
//     ImmutableList<T> elements) {
//   checkIndices(indices, elements);
//   final List<T> newL = newArrayList(list);
//   for (int i = 0; i < indices.size(); i++) {
//     newL.set(indices.getInt(i), elements.get(i));
//   }
//   return ImmutableList.copyOf(newL);
// }
// 
// Path: src/main/java/com/github/rinde/opt/localsearch/Swaps.java
// static <C, T> Optional<Schedule<C, T>> swap(Schedule<C, T> s, Swap<T> swap,
//     double threshold) {
//   return swap(s, swap, threshold,
//     new Object2DoubleLinkedOpenHashMap<ImmutableList<T>>());
// }
// 
// Path: src/main/java/com/github/rinde/opt/localsearch/Swaps.java
// @AutoValue
// abstract static class Swap<T> {
//   abstract T item();
// 
//   abstract int fromRow();
// 
//   abstract int toRow();
// 
//   abstract IntList toIndices();
// 
//   static <T> Swap<T> create(T i, int from, int to, IntList toInd) {
//     return new AutoValue_Swaps_Swap<T>(i, from, to, toInd);
//   }
// }


import static com.github.rinde.opt.localsearch.InsertionsTest.list;
import static com.github.rinde.opt.localsearch.Swaps.asDoubleList;
import static com.github.rinde.opt.localsearch.Swaps.asIntList;
import static com.github.rinde.opt.localsearch.Swaps.inListSwap;
import static com.github.rinde.opt.localsearch.Swaps.removeAll;
import static com.github.rinde.opt.localsearch.Swaps.replace;
import static com.github.rinde.opt.localsearch.Swaps.swap;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.truth.Truth.assertThat;
import static java.util.Collections.reverseOrder;
import static java.util.Collections.sort;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import com.github.rinde.opt.localsearch.Swaps.Swap;
import com.github.rinde.rinsim.testutil.TestUtil;
import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.truth.Truth;

  /**
   * toRow can not be too large.
   */
  @Test(expected = IllegalArgumentException.class)
  public void swapTooLargeToRow() {
    swap(schedule, Swap.<String>create(A, 1, 2, asIntList(1)), 0d);
  }

  /**
   * A is not in row 0, hence it cannot be swapped.
   */
  @Test(expected = IllegalArgumentException.class)
  public void swapWrongRow() {
    swap(schedule, Swap.<String>create(A, 0, 1, asIntList(1)), 0d);
  }

  /**
   * There are two occurrences of A in row 1, therefore there should be 2
   * indices.
   */
  @Test(expected = IllegalArgumentException.class)
  public void swapIncorrectIndicesSize() {
    swap(schedule, Swap.<String>create(A, 1, 0, asIntList(1)), 0d);
  }

  /**
   * Cannot move A to index -1 (does not exist).
   */
  @Test(expected = IllegalArgumentException.class)
// Path: src/test/java/com/github/rinde/opt/localsearch/InsertionsTest.java
// @SafeVarargs
// public static <T> ImmutableList<T> list(T... items) {
//   return ImmutableList.copyOf(items);
// }
// 
// Path: src/main/java/com/github/rinde/opt/localsearch/Swaps.java
// static DoubleList asDoubleList(double... values) {
//   return DoubleLists.unmodifiable(new DoubleArrayList(values));
// }
// 
// Path: src/main/java/com/github/rinde/opt/localsearch/Swaps.java
// static IntList asIntList(final int... values) {
//   return IntLists.unmodifiable(new IntArrayList(values));
// }
// 
// Path: src/main/java/com/github/rinde/opt/localsearch/Swaps.java
// static <T> ImmutableList<T> inListSwap(ImmutableList<T> originalList,
//     IntList insertionIndices, T item) {
//   checkArgument(!originalList.isEmpty(), "The list may not be empty.");
//   final List<T> newList = newArrayList(originalList);
//   final IntList indices = removeAll(newList, item);
//   checkArgument(
//     newList.size() == originalList.size() - insertionIndices.size(),
//     "The number of occurrences (%s) of item should equal the number of "
//       + "insertionIndices (%s), original list: %s, item %s, "
//       + "insertionIndices %s.",
//     indices.size(), insertionIndices.size(), originalList, item,
//     insertionIndices);
//   checkArgument(
//     !indices.equals(insertionIndices),
//     "Attempt to move the item to exactly the same locations as the input. "
//       + "Indices in original list %s, insertion indices %s.",
//     indices, insertionIndices);
//   return Insertions.insert(newList, insertionIndices, item);
// }
// 
// Path: src/main/java/com/github/rinde/opt/localsearch/Swaps.java
// static <T> IntList removeAll(List<T> list, T item) {
//   final Iterator<T> it = list.iterator();
//   final IntArrayList indices = new IntArrayList();
//   int i = 0;
//   while (it.hasNext()) {
//     if (it.next().equals(item)) {
//       it.remove();
//       indices.add(i);
//     }
//     i++;
//   }
//   return IntLists.unmodifiable(indices);
// }
// 
// Path: src/main/java/com/github/rinde/opt/localsearch/Swaps.java
// static <T> ImmutableList<T> replace(ImmutableList<T> list, IntList indices,
//     ImmutableList<T> elements) {
//   checkIndices(indices, elements);
//   final List<T> newL = newArrayList(list);
//   for (int i = 0; i < indices.size(); i++) {
//     newL.set(indices.getInt(i), elements.get(i));
//   }
//   return ImmutableList.copyOf(newL);
// }
// 
// Path: src/main/java/com/github/rinde/opt/localsearch/Swaps.java
// static <C, T> Optional<Schedule<C, T>> swap(Schedule<C, T> s, Swap<T> swap,
//     double threshold) {
//   return swap(s, swap, threshold,
//     new Object2DoubleLinkedOpenHashMap<ImmutableList<T>>());
// }
// 
// Path: src/main/java/com/github/rinde/opt/localsearch/Swaps.java
// @AutoValue
// abstract static class Swap<T> {
//   abstract T item();
// 
//   abstract int fromRow();
// 
//   abstract int toRow();
// 
//   abstract IntList toIndices();
// 
//   static <T> Swap<T> create(T i, int from, int to, IntList toInd) {
//     return new AutoValue_Swaps_Swap<T>(i, from, to, toInd);
//   }
// }


// Path: src/test/java/com/github/rinde/opt/localsearch/SwapsTest.java
import static com.github.rinde.opt.localsearch.InsertionsTest.list;
import static com.github.rinde.opt.localsearch.Swaps.asDoubleList;
import static com.github.rinde.opt.localsearch.Swaps.asIntList;
import static com.github.rinde.opt.localsearch.Swaps.inListSwap;
import static com.github.rinde.opt.localsearch.Swaps.removeAll;
import static com.github.rinde.opt.localsearch.Swaps.replace;
import static com.github.rinde.opt.localsearch.Swaps.swap;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.truth.Truth.assertThat;
import static java.util.Collections.reverseOrder;
import static java.util.Collections.sort;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import com.github.rinde.opt.localsearch.Swaps.Swap;
import com.github.rinde.rinsim.testutil.TestUtil;
import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.truth.Truth;


  /**
   * toRow can not be too large.
   */
  @Test(expected = IllegalArgumentException.class)
  public void swapTooLargeToRow() {
    swap(schedule, Swap.<String>create(A, 1, 2, asIntList(1)), 0d);
  }

  /**
   * A is not in row 0, hence it cannot be swapped.
   */
  @Test(expected = IllegalArgumentException.class)
  public void swapWrongRow() {
    swap(schedule, Swap.<String>create(A, 0, 1, asIntList(1)), 0d);
  }

  /**
   * There are two occurrences of A in row 1, therefore there should be 2
   * indices.
   */
  @Test(expected = IllegalArgumentException.class)
  public void swapIncorrectIndicesSize() {
    swap(schedule, Swap.<String>create(A, 1, 0, asIntList(1)), 0d);
  }

  /**
   * Cannot move A to index -1 (does not exist).
   */
  @Test(expected = IllegalArgumentException.class)
  public void swapToNegativeIndices() {