Created
April 5, 2016 18:51
-
-
Save brunodles/e418baa383b4c421df8a6f918229a421 to your computer and use it in GitHub Desktop.
My history through Java Testing — Main Methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
public class Stack<T> { | |
private List<T> list = new ArrayList<>(); | |
public boolean isEmpty() { | |
return list.isEmpty(); | |
} | |
public void enqueue(T item) { | |
list.add(item); | |
} | |
public T dequeue() { | |
int index = list.size() - 1; | |
if (index < 0 || index >= list.size()) | |
return null; | |
T result = list.get(index); | |
list.remove(index); | |
return result; | |
} | |
public long size() { | |
return list.size(); | |
} | |
public static void main(String[] args) { | |
Stack<Integer> stack = new Stack<>(); | |
stack.enqueue(1); | |
Integer item = stack.dequeue(); | |
if (item == 1){ | |
System.out.println("Ok"); | |
} else { | |
System.out.println("Error"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StaskTest_main { | |
public static void main(String[] args) { | |
Stack<Integer> stack = new Stack<>(); | |
if (!stack.isEmpty()) { | |
System.out.println("Erro!"); | |
return; | |
} | |
stack.enqueue(1); | |
if (stack.isEmpty() || stack.size() != 1) { | |
System.out.println("Erro!"); | |
return; | |
} | |
Integer number = stack.dequeue(); | |
if (!number.equals(1)) { | |
System.out.println("Erro!"); | |
return; | |
} | |
System.out.println("Ok"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment