import java.util.Enumeration;

final class a1test {

  public static void testPiece() {
    char c='A';
    System.out.println("Piece "+c+" has value "+Piece.getValue(c));
    Piece p=new Piece('q');
    System.out.println("letter: "+p.getLetter()+
        " value: "+p.getValue()+" count: "+p.getCount());
    p=new WildcardPiece();
    System.out.println("letter: "+p.getLetter()+
        " value: "+p.getValue()+" count: "+p.getCount());
    ((WildcardPiece)p).setLetter('e');
    System.out.println("letter: "+p.getLetter()+
        " value: "+p.getValue()+" count: "+p.getCount());
  }

  public static void testPermute() {
    System.out.println("Print first 5 permuations of {0,1,2,3,4,5,6}");
    Enumeration e=new Permute(7);
    for(int i=0; i<5; i++) {
      int perm[]=(int[])e.nextElement();
      for(int j=0; j<perm.length; j++) {
        System.out.print(j>0?",":"");
        System.out.print(perm[j]);
      }
      System.out.println();
    }

    System.out.print("Number of permutations of {0,1,2,3}: ");
    int numPerm=0;
    e=new Permute(4);
    while(e.hasMoreElements()) {
      e.nextElement();
      numPerm++;
    }
    System.out.println(numPerm);

    int size=3;
    System.out.println("Create permutation table of size "+size);
    int table[][]=Permute.createTable(size);
    System.out.println("Create permutation indices for table permutation of size "+size);
    int index[][]=Permute.createIndices(size);
    System.out.println("Dump permutation of all subsets...");
    for(int i=0; i<index.length; i++) {
      System.out.println("----- "+(i+1)+": "+index[i].length);
      for(int j=0; j<index[i].length; j++) {
        StringBuffer s=new StringBuffer("");
        for(int k=0; k<i+1; k++)
          s=s.append(table[index[i][j]][k]).append(" ");
        System.out.println(s);
      }
    }
  }

  public static void main(String args[]) {
    testPiece();
    testPermute();
    System.exit(0); // assuming everything is correct. :)
  }
}
