Test cases for a Singly Linked list

RashMans picture RashMans · Mar 25, 2011 · Viewed 13.9k times · Source

What are some good testcases for a Linked list problem in general? for example test cases for a function which finds and eliminates duplicates and returns the pointer to the first node. Some core cases could be: the function is in c# or Java and not c, c++. Assume all positive integers as nodes of the list.

  • Null
  • Empty List
  • Linked list with a loop
  • List with all dups
  • List with one node or 2 nodes (2 dups)
  • No duplicates
  • The list could encounter integer over flow, incase low memory (depending on 32 bit machine, 64 bit machine)
  • Security testing, language automation, memory issues, performance and stress

What else? expecting outrageous test cases..any experts out there?

Answer

rlb.usa picture rlb.usa · Mar 25, 2011

How about these?

  • traversing the list
  • edge cases:
    • traversing an empty list
    • traversing list where 1+ stored values are NULL
  • operations (if applicable):
    • deleting from the list
    • inserting into the list
    • inserting a sub-list into the linked list
    • traversing the list backwards (if doubly-linked list)
  • concurrency tests (if applicable):
    • race condition tests