{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Unit Test Specification

# Unit Test Specification - White Box Unit Testing Find(int...

This preview shows pages 1–4. Sign up to view the full content.

White Box Unit Testing Find (int key) public Node find(int key) // find node with given key { // (assumes non-empty tree) Node current = root; // start at root while(current.iData != key) // while no match, { if(key < current.iData) // go left? current = current.leftChild; else // or go right? current = current.rightChild; if(current == null) // if no child, return null; // didn't find it } return current; // found it } // end find() Cyclomatic complexity V(G)= Regions +1= 2 + 1 = 3 V(G)=8 edged -7 nodes +2 = 3 V(G)=Predicate nodes + 1 = 4 1 3 5 7 6 2 4 while (current.iData != key) If (key < current.iData) If (current == null) Return null; Return current; End while

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This means that this function has 3 minimum set of basis path test cases: 1) 1-2-3-5-6 2) 1-2-4-5-6 3) 1-2-3-5-1-2-3-5-6 4) 1-7 Test Cases: *Assumes non-empty tree Test Case No. Input Data Expected output Actual Output 1 55 Could not find 55 2 22 Could not find 22 3 37 Found (37) 4 50 Found (50) Insert (int id, double dd) public void insert(int id, double dd) { Node newNode = new Node(); // make new node newNode.iData = id; // insert data newNode.dData = dd; if(root==null) // no node in root root = newNode; else // root occupied { Node current = root; // start at root Node parent; while(true) // (exits internally) { parent = current; if(id < current.iData) // go left? { current = current.leftChild; if(current == null) // if end of the line, { // insert on left parent.leftChild = newNode; return; } } // end if go left else // or go right? { current = current.rightChild; if(current == null) // if end of the line { // insert on right parent.rightChild = newNode; return; } } // end else go right } // end while } // end else not root } // end insert()
Cyclomatic number: Num regions: 6 V(G) = 17 edges – 13 nodes + 2 = 6 V(G) = 5 predicate nodes + 1 = 6 Basis paths: 1) 1-11-13 2) 1-2-3-5-6-7-10-2-12-13 3) 1-2-3-5-7-10-2-12-13 4) 1-2-3-4-8-9-10-2-12-13 5) 1-2-3-4-9-10-2-12-13 6) 1-2-12-13 Test Cases: *Assumes an empty tree at the beginning. Test Case No. Input Data Expected output Actual Output 1 10 Changed tree 2 9 Changed tree 3 8 Changed tree 4 11 Changed tree 5 12 Changed tree 6 -- * Cannot be tested If (root == null) while (true) root = newNode; If (id < current.iData) If (current == null)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}