/**
 * This class tests our stack of generic elements.
 * @author fpereira
 */
public final class Tester {

  /**
   * Private constructor, to avoid instantiation.
   */
  private Tester() {
  }

  /**
   * @param args The arguments passed in the command line.
   */
  public static void main(final String[] args) {
    testStack(args);
    testWordCounter(args);
    testConcat(args);
  }

  /**
   * This method tests if our stack works well to insert and remove elements.
   * @param args the list of elements to be inserted.
   */
  private static void testStack(final String[] args) {
    Stack<String> stack = new Stack<String>(args.length);
    for (String s : args) {
      stack.push(s);
    }
    while (!stack.empty()) {
      System.out.println(stack.pop());
    }
  }

  /**
   * This method tests if we can use a combinator to count the number of
   * characters in the stack.
   * @param args the list of elements to be processed.
   */
  private static void testWordCounter(final String[] args) {
    Stack<String> stack = new Stack<String>(args.length);
    for (String s : args) {
      stack.push(s);
    }
    Combinator<Integer, String> c = new WordCounter();
    System.out.println(stack.reduce(c, 0));
  }


  /**
   * This method tests if we can concatenate all the strings in the list.
   * @param args the list of elements to be processed.
   */
  private static void testConcat(final String[] args) {
    Stack<String> stack = new Stack<String>(args.length);
    for (String s : args) {
      stack.push(s);
    }
    Combinator<String, String> c = new Concatenator();
    System.out.println(stack.reduce(c, ""));
  }

}
