package senac_turma02.stack;

import junit.framework.TestCase;

public class StackImplArrayTest extends TestCase {

	StackImplArray<Integer> s_;

	protected void setUp() throws Exception {
		super.setUp();
		s_ = new StackImplArray<Integer>(new Integer[] { 30, 20, 10 });
	}

	// ///////////////////////
	// Construtores
	// ///////////////////////
	public void testStackImpl() {
		StackImplArray<Integer> s = new StackImplArray<Integer>();
		try {
			s.push(1);
			assertTrue(s.isFull());
		} catch (StackFullException e) {
			e.printStackTrace();
		}
	}

	public void testStackImpl2() {
		assertTrue(s_.isFull());
	}

	public void testStackImpl3() {
		StackImplArray<Integer> s = new StackImplArray<Integer>(5);
		try {
			s.push(1);
			s.push(2);
			s.push(3);
			s.push(4);
			s.push(5);
			assertTrue(s.isFull());
		} catch (StackFullException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	// ///////////////////////
	// Interface
	// ///////////////////////
	public void testPop() {
		int n;
		try {
			n = s_.pop();
			assertEquals(n, 30);
		} catch (StackEmptyException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void testPush() {
		StackImplArray<Integer> s = new StackImplArray<Integer>();
		try {
			s.push(40);
			assertEquals(s.top(), new Integer(40));
		} catch (StackFullException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (StackEmptyException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void testTop() {
		try {
			assertEquals(s_.top(), new Integer(30));
		} catch (StackEmptyException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void testIsEmpty() {
		StackImplArray<Integer> s = new StackImplArray<Integer>();
		assertTrue(s.isEmpty());
	}

	public void testIsEmpty2() {
		assertFalse(s_.isEmpty());
	}

	public void testIsFull() {
		assertTrue(s_.isFull());
	}

	public void testIsFull2() {
		StackImplArray<Integer> s = new StackImplArray<Integer>();
		assertFalse(s.isFull());
	}

	// ///////////////////////
	// Exceptions
	// ///////////////////////
	public void testStackFullException() {
		try {
			s_.push(40);
			fail("A excecao StackFullException tinha que ser gerada ");
		} catch (StackFullException ex) {
			// sucesso teste OK
		}
	}

	public void testStackEmptyException() {
		StackImplArray<Integer> s = new StackImplArray<Integer>();
		try {
			s.pop();
			fail("A excecao StackEmptyException tinha que ser gerada ");
		} catch (StackEmptyException ex) {
			// sucesso teste OK
		}
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

}
