Test Plan: Scenarios for add – maintaining orderTo come up with a test plan, consider the different scenarios in your
code and test for them. For example, if you are going to keep an
ordered list, you will need to check the following:
1. Empty List
2. Insert before cursor
a. At beginning
b. In the middle (Not at beginning)
3. Insert at end
add() – Scenario 1 – Empty List
Right before add
head
tail
Add cherry
• Create new node from head
head = new StringNode(element, null);
tail = head;
After add
tail
head
cherry
add() – Scenario 2a – insert before cursor – at beginning
Right before add
cursor
Add apple
tail
head
previous
cherry
• Create new node from head
head = new StringNode(element, head);
cursor
tail
head
After add
apple
previous
cherry
add() – Scenario 2b – insert before cursor – not at beginning
Right before add
Add banana
cursor
previous
tail
head
cherry
apple
• Create new node from previous
previous.setLink( new StringNode(element, cursor) );
cursor
previous
tail
head
After add
apple
banana
cherry
add() – Scenario 3 – insert at end
Right before add
Add watermelon
head
cursor*
previous*
tail
apple
cherry
banana
*Depending on how you advance
cursor, either cursor becomes null
and previous points to the last node
or it is determined to be at the end
when cursor.getLink() is null
• Create new node from previous*
previous.setLink( new StringNode(element, null) );
tail = tail.getLink();
cursor*
previous*
After add
tail
head
apple
banana
cherry
watermelon