package stack;

import shape.Circle;
import shape.Shape;
import shape.Square;

public class TestShapeStack {

	public static void testShapeStack(Stack<Shape> stack) {
		try {
			System.out.println(stack);
			System.out.println("Est vide ? : " + stack.isEmpty()); // true
			stack.push(new Circle());
			System.out.println(stack);
			System.out.println("Est vide ? : " + stack.isEmpty()); // false
			stack.push(new Square());
			System.out.println(stack);
			stack.pop();
			System.out.println(stack);
			stack.push(new Square());
			stack.push(new Square());
			System.out.println("Sommet : " + stack.peek());
			System.out.println(stack);
			stack.push(new Circle()); // exception levée pour pile avec taille
										// fixé à 3 : pile vide
			System.out.println(stack);
			stack.pop();
			stack.pop();
			stack.pop();
			stack.pop();
			stack.pop(); // exception levée : pile vide
		} catch (FullStackException | EmptyStackException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		System.out.println("Pile de formes avec tableau de taille fixe");
		testShapeStack(new StackFixedSizeArray<Shape>(3));
		System.out.println("Pile de formes avec tableau extensible");
		testShapeStack(new StackExtensibleArray<Shape>());
		System.out.println("Pile de formes avec liste doublement chaînée");
		testShapeStack(new StackList<Shape>());
		Stack<Integer> s1 = new StackFixedSizeArray<Integer>(3);
		Stack<Integer> s2 = new StackExtensibleArray<Integer>();
		try {
			s1.push(1);
			s1.push(2);
			s2.push(1);
			s2.push(2);
			System.out.println("Piles égales ? : " + s1.equals(s2));
			s2.pop();
			System.out.println("Piles égales ? : " + s1.equals(s2));
			s2.push(3);
			System.out.println("Piles égales ? : " + s1.equals(s2));
		} catch (FullStackException | EmptyStackException e) {
			e.printStackTrace();
		}
	}
}
