コード例 #1
0
 // 6
 public void testGetFirstNodeFromList() {
   List<Node> nodes = createNewNodes();
   SingleLinkedList list = new SingleLinkedList(nodes);
   int first = 0;
   Node expectedNode = list.get(first);
   Node actualNode = list.first();
   assertEquals(expectedNode, actualNode);
 }
コード例 #2
0
 // 7
 public void testGetLastNodeFromList() {
   List<Node> nodes = createNewNodes();
   SingleLinkedList list = new SingleLinkedList(nodes);
   int last = list.size() - 1;
   Node expectedNode = list.get(last);
   Node actualNode = list.last();
   assertEquals(expectedNode, actualNode);
 }
コード例 #3
0
  // 8
  public void testGetBeforeNodeFromList() {
    List<Node> nodes = createNewNodes();
    SingleLinkedList list = new SingleLinkedList(nodes);
    Node node = list.get(2);
    Node expectedNode = list.get(1);

    Node actualNode = list.before(node);
    assertEquals(expectedNode, actualNode);
  }
コード例 #4
0
  // 4
  public void testInsertAfterIndexN() {
    List<Node> nodes = createNewNodes();
    SingleLinkedList list = new SingleLinkedList(nodes);
    int size = list.size();

    int n = 2;
    Node node = new Node();
    node.setValue("Node 1");
    node.setNextIndex(n + 1);

    list.insertAfter(node, n);
    assertTrue(size < list.size());
    Node nodeInsert = list.get(n);
    assertEquals(node.getValue(), nodeInsert.getValue());
    assertEquals(node.getNextIndex(), nodeInsert.getNextIndex());
    assertTrue(nodeInsert == node);
  }
コード例 #5
0
 // 5
 public void testDeleteFromList() {
   List<Node> nodes = createNewNodes();
   SingleLinkedList list = new SingleLinkedList(nodes);
   int size = list.size();
   int position = 2;
   Node node = list.get(position);
   list.delete(node);
   assertTrue(size > list.size());
   assertTrue(node != list.get(position));
 }
コード例 #6
0
 // 3
 public void testGetSizeOfLinkList() {
   List<Node> nodes = createNewNodes();
   SingleLinkedList list = new SingleLinkedList(nodes);
   assertTrue(nodes.size() == list.size());
 }
コード例 #7
0
 // 2
 public void testCreateNewLinkListWithObjectList() {
   List<Node> nodes = createNewNodes();
   SingleLinkedList list = new SingleLinkedList(nodes);
   assertEquals(nodes, list.getList());
 }
コード例 #8
0
 // 1
 public void testCreateNewLinkListWithEmptyList() {
   List<Node> nodes = new ArrayList<Node>();
   SingleLinkedList linkedList = new SingleLinkedList(nodes);
   assertTrue(linkedList.getList().isEmpty());
 }