Skip to content

Instantly share code, notes, and snippets.

@brunodles
Created April 5, 2016 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunodles/e418baa383b4c421df8a6f918229a421 to your computer and use it in GitHub Desktop.
Save brunodles/e418baa383b4c421df8a6f918229a421 to your computer and use it in GitHub Desktop.
My history through Java Testing — Main Methods
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");
}
}
}
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