@Test
 public void simpleCycleTest() {
   Block b = new Block(3);
   b.add(0, 1, 2);
   b.add(1, 2);
   debugFind(b);
 }
  @Test
  public void commuteTest() {
    Block b = new Block(8);
    b.add(0, 1, 7);
    b.add(1, 2, 6);
    b.add(2, 3, 5);
    b.add(3, 4);
    b.add(4, 5);
    b.add(5, 6);
    b.add(6, 7);

    BitSet bsA = makeBitSet(2, 3, 5, 8);
    BitSet bsB = makeBitSet(2, 3, 4, 6, 7, 8);
    BitSet bsC = makeBitSet(0, 1, 2, 4, 6, 7, 8, 9);

    System.out.println("A + B " + xor(bsA, bsB));
    System.out.println("B + A " + xor(bsB, bsA));

    System.out.println("A + C " + xor(bsA, bsC));
    System.out.println("C + A " + xor(bsC, bsA));

    System.out.println("A + B + C" + xor(xor(bsA, bsB), bsC));
    System.out.println("B + A + C" + xor(xor(bsB, bsA), bsC));

    System.out.println("A + C + B" + xor(xor(bsA, bsC), bsB));
    System.out.println("C + A + B" + xor(xor(bsC, bsA), bsB));

    System.out.println("C + B + A" + xor(xor(bsC, bsB), bsA));
    System.out.println("B + C + A" + xor(xor(bsB, bsC), bsA));
  }
 @Test
 public void disconnectedGraph() {
   Block b = new Block(7);
   b.add(0, 1, 2);
   b.add(1, 3);
   b.add(2, 3);
   b.add(4, 5, 6);
   b.add(5, 6);
   find(b);
 }
 @Test
 public void cube() {
   Block b = new Block(8);
   b.add(0, 1, 5, 7);
   b.add(1, 2, 6);
   b.add(2, 3, 7);
   b.add(3, 4, 6);
   b.add(4, 5, 7);
   b.add(5, 6);
   find(b);
 }
 @Test
 public void fusedSquares() {
   Block b = new Block(8);
   b.add(0, 1, 7);
   b.add(1, 2, 6);
   b.add(2, 3, 5);
   b.add(3, 4);
   b.add(4, 5);
   b.add(5, 6);
   b.add(6, 7);
   debugFind(b);
 }
 @Test
 public void fused566Cycles() {
   Block b = new Block(13);
   b.add(0, 1, 2);
   b.add(1, 3);
   b.add(2, 4, 5);
   b.add(3, 6);
   b.add(4, 8);
   b.add(5, 6, 7);
   b.add(7, 9, 10);
   b.add(8, 10);
   b.add(9, 11);
   b.add(10, 12);
   b.add(11, 12);
   find(b);
 }
  public void find(Block b) {
    SpanningTree tree = new SpanningTree(b);
    List<Block> basis = CycleFinder.getCycleBasis(tree);
    int basisCounter = 0;
    for (Block cycle : basis) {
      System.out.println(basisCounter + "\t" + cycle);
      basisCounter++;
    }

    List<Block> all = new ArrayList<Block>();
    CycleFinder.expand(basis, all, b);
    int fullCounter = 0;
    for (Block cycle : all) {
      System.out.println(fullCounter + "\t" + cycle.esize() + "\t" + cycle);
      fullCounter++;
    }

    // this assertion fails for disconnected graphs - does the CC number count in the formula?
    Assert.assertEquals((b.esize() - b.vsize() + 1), basisCounter);

    Assert.assertEquals((int) Math.pow(2, basisCounter), fullCounter);
  }
  public void debugFind(Block b) {
    SpanningTree tree = new SpanningTree(b);
    List<Block> basis = CycleFinder.getCycleBasis(tree);
    List<BitSet> baseSets = new ArrayList<BitSet>();

    int basisCounter = 0;
    for (Block cycle : basis) {
      baseSets.add(CycleFinder.cycleToBitSet(cycle, b));
      System.out.println(basisCounter + "\t" + cycle);
      basisCounter++;
    }

    SubsetLister<BitSet> subsetLister = new SubsetLister<BitSet>(baseSets);

    int fullCounter = 0;
    for (List<BitSet> subSet : subsetLister) {
      if (!viable(subSet)) continue;
      BitSet bS = CycleFinder.combine(subSet);
      Block cycle = CycleFinder.toCycle(bS, b);
      System.out.println(fullCounter + "\t" + cycle.esize() + "\t" + cycle + "\t" + subSet);
      fullCounter++;
    }
  }
 @Test
 public void cuneane() {
   Block b = new Block(8);
   b.add(0, 1, 3, 5);
   b.add(1, 2, 7);
   b.add(2, 3, 7);
   b.add(3, 4);
   b.add(4, 5, 6);
   b.add(5, 6);
   b.add(6, 7);
   find(b);
 }