Skip to content

Commit

Permalink
Junit Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Pan committed Feb 26, 2017
1 parent cf46536 commit 56302de
Show file tree
Hide file tree
Showing 6 changed files with 291 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public void testRightShift() {

x = x << 1;
x = x >> 1;

System.out.println(x);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.apn.coding2017.basic;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* Created by Pan on 2017/2/26.
*/
public class ArrayListTest {

ArrayList arrayList;

@Before
public void before(){
arrayList = new ArrayList();
arrayList.add(1);
arrayList.add(2);
arrayList.add(3);
}

@Test
public void add() throws Exception {
ArrayList arrayList = new ArrayList();
arrayList.add(3);
System.out.println(arrayList);
}

@Test
public void set() throws Exception {
arrayList.add(3);
arrayList.set(0, 4);
System.out.println(arrayList);
}

@Test
public void get() throws Exception {
arrayList.add(1);
arrayList.add(2);
arrayList.add(3);
Object o = arrayList.get(1);
System.out.println(o);
}

@Test
public void remove() throws Exception {
arrayList.add(1);
arrayList.add(2);
arrayList.add(3);
arrayList.remove(1);
System.out.println(arrayList);
}

@Test
public void size() throws Exception {
System.out.println(arrayList.size());
}

@Test
public void isEmpty() throws Exception {
System.out.println(arrayList.isEmpty());
}

@Test
public void iterator() throws Exception {
Iterator iterator = arrayList.iterator();
while (iterator.hasNext()){
Object next = iterator.next();
System.out.println(next);
iterator.remove();
}
System.out.println(arrayList.isEmpty());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.apn.coding2017.basic;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* Created by Pan on 2017/2/26.
*/
public class BinaryTreeNodeTest {

BinaryTreeNode binaryTreeNode;

@Before
public void setUp() throws Exception {
binaryTreeNode = new BinaryTreeNode();
binaryTreeNode.push(1, "A");
binaryTreeNode.push(2, "B");
binaryTreeNode.push(3, "C");
binaryTreeNode.push(4, "D");
}

@Test
public void size() throws Exception {
System.out.println(binaryTreeNode.size());
}

@Test
public void get() throws Exception {
System.out.println(binaryTreeNode.get(3));
}

@Test
public void push() throws Exception {
binaryTreeNode.push(5, "E");
System.out.println(binaryTreeNode);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.apn.coding2017.basic;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* Created by Pan on 2017/2/26.
*/
public class LinkedListTest {

LinkedList linkedList;

@Before
public void setUp() throws Exception {
linkedList = new LinkedList();
linkedList.add(0);
linkedList.add(1);
linkedList.add(2);
linkedList.add(3);
}

@Test
public void add() throws Exception {
linkedList.add(0);
System.out.println(linkedList);
}

@Test
public void get() throws Exception {
Object o = linkedList.get(1);
System.out.println(o);
}

@Test
public void remove() throws Exception {
linkedList.remove(1);
System.out.println(linkedList);
}

@Test
public void size() throws Exception {
System.out.println(linkedList.size());
}

@Test
public void addFirst() throws Exception {
linkedList.addFirst(4);
System.out.println(linkedList);
}

@Test
public void addLast() throws Exception {
linkedList.addLast(5);
System.out.println(linkedList);
}

@Test
public void removeFirst() throws Exception {
linkedList.removeFirst();
System.out.println(linkedList);
}

@Test
public void removeLast() throws Exception {
linkedList.removeLast();
System.out.println(linkedList);
}

@Test
public void iterator() throws Exception {
Iterator iterator = linkedList.iterator();
while (iterator.hasNext()){
Object next = iterator.next();
System.out.println(next);
iterator.remove();
}
System.out.println(linkedList);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.apn.coding2017.basic;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* Created by Pan on 2017/2/26.
*/
public class QueueTest {

Queue queue;

@Before
public void setUp() throws Exception {
queue = new Queue();
queue.enQueue(1);
queue.enQueue(2);
queue.enQueue(3);

}

@Test
public void enQueue() throws Exception {
queue.enQueue(1);
System.out.println(queue);
}

@Test
public void deQueue() throws Exception {
queue.deQueue();
System.out.println(queue);
}

@Test
public void isEmpty() throws Exception {
System.out.println(queue.isEmpty());
}

@Test
public void size() throws Exception {
System.out.println(queue.size());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.apn.coding2017.basic;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* Created by Pan on 2017/2/26.
*/
public class StackTest {

Stack stack;

@Before
public void setUp() throws Exception {
stack = new Stack(3);
stack.push(1);
stack.push(2);
stack.push(3);
}

@Test
public void isEmpty() throws Exception {
System.out.println(stack.isEmpty());
}

@Test
public void size() throws Exception {
System.out.println(stack.size());
}

@Test
public void push() throws Exception {
stack.push(1);
stack.push(2);
stack.push(3);
System.out.println(stack);
}

@Test
public void pop() throws Exception {
stack.pop();
System.out.println(stack);
}

}

0 comments on commit 56302de

Please sign in to comment.