コード例 #1
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);
  }
コード例 #2
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));
 }
コード例 #3
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);
 }
コード例 #4
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);
 }
コード例 #5
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);
  }