TEST CASES : Remove The Nth Node

0
965

Remove Nth Node Test Cases

Write test cases in the form of [ Input ,Expected Output] To test the function :

// This functions removes the Nth node from a single link list.

ReturnValue RemoveNthNodeFromLinkedList( Node** Head , unsigned short int NthNode )

Where : Head – Head node of linked list , NthNode – Node no. to delete

typedef struct Node

{ void *data;   struct Node *next; } Node;

enum ReturnValue

{ FALSE = -1; TRUE = 1; INVALID_PARAMETER; }

Rationale: Interviewer would like to observe interviewee’s approach while deducing the test cases of a sample problem.

Sample answer from a professional point of view

This task require to write test cases to test API

APPROACH

My high level approach to write test cases starts from –

  • Analysis for test items
  • Factorize test items and narrow down to sub groups if require,
  • Afterwards go for functional test cases which again divided in positive functional test cases and negative functional test case
  • Start from basic tests to advanced test cases
  • Then non-functional test cases, where one can consider about performance, stress, globalization, integration or some other aspects of testing.

POSITIVE FUNCTIONAL TESTS

TEST CASE-1

  • Pre-Condition: Linked List which have 6 elements: 1->2->3->4->5->6->Null
  • Input: Head Node of Linked List | 6th Node to Delete
  • Expected Output: Remove API will return TRUE
  • Linked List has now 5 elements 1->2->3->4->5->Null

TEST CASE-2

  • Pre-Condition: Linked List which have 5 elements: 1->2->3->4->5->Null
  • Input: Head Node of Linked List: 1th Node to Delete
  • Expected Output: Remove API will return TRUE
  • Linked list have now 4 elements: 2->3->4->5->Null

TEST CASE-3

  • Pre-Condition: Linked List which has 4 elements: 2->3->4->5->Null
  • Input: Head Node of Linked List: 2nd Node to Delete
  • Expected Output: Remove API will return TRUE
  • Linked List has now 3 elements: 2->4->5->Null

TEST CASE-4

  • Pre-Condition: Linked List which have 6 elements: 1->2->3->4->5->6->Null
  • Input: Head Node of Linked List: 7th Node to Delete
  • Expected Output: Remove API will return FALSE:
  • Linked List have now 6 elements :1->2->3->4->5->6->Null

TEST CASE-5

  • Pre-Condition: Linked List which have 6 elements: 1->2->3->4->5->6->Null
  • Input: Head Node of Linked List :0th Node to Delete
  • Expected Output: Linked List have now 6 elements
  • 1->2->3->4->5->6->Null

OTHER FUNCTIONAL TEST CASES

  • CASE: Test the case when linked list have just one element, and input has given to remove this one element
    • Expected Output: Remove API will return TRUE, And Linked list will have no element left
  • CASE: Test Case when linked list have none element and given Nth Node value is greater than 0 and head node value is correct
    • Expected Output: Remove API will return INVALID_PARAMETER
  • CASE: Test Case when linked list have none element and given Nth Node value is greater than 0 and head node value is Null
    • Expected Output: Remove API will return INVALID_PARAMETER
  • CASE: Test Case when linked list have several element and given Nth Node value is equal to 0
    • Expected Output: Remove API will return INVALID_PARAMETER
  • CASE: Test Case when linked list have several element and given Nth Node value is several number greater than the number of elements in the linked list
    • Expected Output: Remove API will return FALSE
  • CASE: Test Case when linked list have several element and given Nth Node value is just one number greater than the number of elements in the linked list
    • Expected Output: Remove API will return FALSE
  • CASE: Test case when linked list have 65535 elements Give input to remove first, last or middle, item
    • Expected Output: Test the output of this Remove API based on given input, It should returned TRUE
  • CASE: Test case when linked list have 65535 elements
    • Give the input value greater than 65535
    • [In this case the greater value will be rolled back, consider this fact while executing this test case]
    • Expected Output: Test the output of this Remove API based on given input, It should returned TRUE
  • CASE: Test the case when linked list will be circular, test it should not come into any infinite loop

NON-FUNCTIONAL TEST CASES

  • Compute the performance of this function to remove one element from a linked list, e.g.; last element, first element or any random middle element, Output: performance measure
  • Perform stress testing by calling this function when there are low memory or CPU utilization is low, Out Put: stress measure

 

If require write the automation of above test cases by using any available test framework e.g.; write test case automation, which create a random list for a random size in between 0 to 65535, and reads the given input from a given input file , and expected output value, and log the results.

 

 

SHARE
Previous articleTEST CASES - Remove All Nodes With Even Values
Next articleReads For Test Professionals
Since last 15 years in different geographical locations, Sumit prepared hiring format for several hiring managers/teams to hire the balanced talents and interviewed talents on the various stages of their selection process. He also interviewed by hundreds of companies in different geographical locations.His best conclusion for hiring teams and candidate is to prepare in advance. Here ‘advance’ means keep your interview book ready and continue to update it even you are not going to interview candidates or applying for any job in next six months.