Skip to content

Commit

Permalink
Merge pull request #7 from fei9009/master
Browse files Browse the repository at this point in the history
update junit test
  • Loading branch information
Rong Huang authored Feb 26, 2017
2 parents 2ff2c32 + dca4822 commit b33c76f
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 0 deletions.
1 change: 1 addition & 0 deletions group02/527705641/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.github.fei9009.coding2017.basic;

import static org.junit.Assert.*;

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

public class ArrayListTest {

private static ArrayList testArray = new ArrayList();
@Before
public void setUp() throws Exception {
//testArray.clear();
}

@Test
public void testArrayList() {
//fail("Not yet implemented");
}

@Test
public void testAddObject() {
testArray.add(10);
assertEquals(10, testArray.get(0));
//fail("Not yet implemented");
}

@Test
public void testAddIntObject() {
testArray.add(10);
testArray.add(0, 3);
testArray.add(0, 2);
assertEquals(3, testArray.get(1));
assertEquals(2, testArray.get(0));
//fail("Not yet implemented");
}

@Test
public void testGet() {
testArray.add(10);
assertEquals(10, testArray.get(0));
//fail("Not yet implemented");
}

@Test
public void testRemove() {
fail("Not yet implemented");
}

@Test
public void testSize() {
fail("Not yet implemented");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.github.fei9009.coding2017.basic;

import static org.junit.Assert.*;

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

public class LinkedListTest {

private LinkedList aLinkedList;

@Before
public void setUpLinkedList() {
aLinkedList = new LinkedList();
}

@Test
public void testAddFirst() {
aLinkedList.addFirst(5);
assertEquals(5, aLinkedList.get(0));

aLinkedList.addFirst(6);
assertEquals(6, aLinkedList.get(0));
assertEquals(5, aLinkedList.get(1));
assertEquals(2, aLinkedList.size());
}

@Test
public void testAddLast() {
aLinkedList.addLast("hello");
assertEquals("hello", aLinkedList.get(0));

aLinkedList.addLast("world");
assertEquals("hello", aLinkedList.get(0));
assertEquals("world", aLinkedList.get(1));
assertEquals(2, aLinkedList.size());
}

@Test
public void testRemoveFirst() {
aLinkedList.addLast("hello");
aLinkedList.addLast("world");

aLinkedList.removeFirst();
assertEquals("world", aLinkedList.get(0));
assertEquals(1, aLinkedList.size());

aLinkedList.removeFirst();
assertEquals(0, aLinkedList.size());
}

@Test
public void testRemoveLast() {
aLinkedList.addFirst("world");
aLinkedList.addFirst("hello");

aLinkedList.removeLast();
assertEquals("hello", aLinkedList.get(0));
assertEquals(1, aLinkedList.size());

aLinkedList.removeLast();
assertEquals(0, aLinkedList.size());
}

@Test
public void testLinkedListFunctional() {
for (int i=1; i<4; i++) {
aLinkedList.add(i); // [1,2,3]
}
aLinkedList.remove(1); // [1,3]

aLinkedList.add(1, 0); // [1,0,3]
for (int i=4; i<6; i++) {
aLinkedList.addFirst(i); // [5, 4, 1, 0, 3]
}
assertEquals(5, aLinkedList.size());
assertEquals(5, aLinkedList.get(0));
assertEquals(1, aLinkedList.get(2));
assertEquals(0, aLinkedList.get(3));

aLinkedList.remove(3); // [5, 4, 1, 3]
assertEquals(3, aLinkedList.get(aLinkedList.size()-1));
aLinkedList.removeLast(); // [5, 4, 1]
assertEquals(1, aLinkedList.get(aLinkedList.size()-1));
aLinkedList.removeFirst(); // [4,1]

assertEquals(4, aLinkedList.get(0));
assertEquals(1, aLinkedList.get(1));
assertEquals(2, aLinkedList.size());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.github.fei9009.coding2017.basic;

import static org.junit.Assert.*;

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

public class QueueTest {

private Queue queue;

@Before
public void setUpQueue() {
queue = new Queue();
}

@Test
public void testQueueFunctional() {
assertEquals(true, queue.isEmpty());
queue.enQueue(4);
queue.enQueue(2);
assertEquals(2, queue.size());
assertEquals(false, queue.isEmpty());

int i = (Integer)queue.deQueue();
assertEquals(4, i);
i = (Integer)queue.deQueue();
assertEquals(2, i);

assertEquals(0, queue.size());
assertEquals(true, queue.isEmpty());
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.github.fei9009.coding2017.basic;

import static org.junit.Assert.*;

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

public class StackTest {

private Stack stack;

@Before
public void setUpStack() {
stack = new Stack();
}

@Test
public void testStackFunctional() {
assertEquals(true, stack.isEmpty());
stack.push(4);
stack.push(2);
assertEquals(2, stack.size());
assertEquals(false, stack.isEmpty());

int i = (Integer)stack.pop();
assertEquals(2, i);

i = (Integer)stack.peek();
assertEquals(4, i);

i = (Integer)stack.pop();
assertEquals(4, i);

assertEquals(0, stack.size());
assertEquals(true, stack.isEmpty());
}
}

0 comments on commit b33c76f

Please sign in to comment.