Unit Test Specification

Unit Test - White Box Unit Testing Find(int key public Node find(int key find node with given key cfw(assumes non-empty tree Node current = root

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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()
Background image of page 2
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.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 02/01/2010.

Page1 / 12

Unit Test - White Box Unit Testing Find(int key public Node find(int key find node with given key cfw(assumes non-empty tree Node current = root

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online