Homework discussion HOMEWORK 1 Odd or pos Public static int oddOrPos(int[] x){ Int count = 0; For(int i=0;i<x.length;i++) { if(x[i]%2==1 || x[i] >0) { count++; } } Return count; } //test : x=[-3,-2,0,1,4] //expected = 3 (a) Identify the faul • The if-test needs to take account of negative values (positive odd numbers are taken care of by the second test): • if (x[i]%2 == -1 || x[i] > 0) (b) If possible, identify a test case that does not execute the fault • x must be either null or empty. All other inputs result in the fault being executed. We give the empty case here. • Input: x = [] • Expected Output: 0 • Actual Output: 0 (c) If possible, identify a test case that executes the fault, but does not result in an error state. • Any nonempty x with non-negative elements and negative even integers works. • Input: x = [1, 2, 3] • Expected Output: 3 • Actual Output: 3 (d) If possible identify a test case that results in an error, but not a failure. Hint: Don't forget about the program counter • For this particular program, every input that results in error also results in failure. The reason is that error states are not repairable by subsequent processing. If there is a negative value in x, all subsequent states (after processing the negative value) will be error states no matter what else is in x. (e) For the given test case, identify the first error state. Be sure to describe the complete state. • Input: x = [-3, -2, 0, 1, 4] • Expected Output: 3 • Actual Output: 2 • First Error State: • x = [-3, -2, 0, 1, 4] • i = 0; • count = 0; • PC = at end of if statement, instead of just before count++ HOMEWORK 3 Step 1: a b 1 Step 2: a b c 1 1 1 1 2 2 1 2 2 1 3 3 1 3 3 4 1 4 4 1 4 4 2 1 2 1 5 2 1 2 2 2 2 2 2 6 2 2 1 2 3 2 3 2 3 7 2 3 4 2 4 2 4 2 4 8 2 4 3 3 1 3 1 3 1 9 3 1 3 3 2 3 2 3 2 10 3 2 4 3 3 3 3 3 3 11 3 3 1 3 4 3 4 3 4 12 3 4 2 4 1 4 1 4 1 13 4 1 4 4 2 4 2 4 2 14 4 2 3 4 3 4 3 4 3 15 4 3 2 4 4 4 4 4 4 16 4 4 1 a c b c 1 1 1 1 1 1 2 1 2 1 1 3 1 3 1 4 1 2 1 2 HOMEWORK 4 Section 2.2.1 Homework 4 a) N = {1, 2, 3, 4, 5, 6, 7} N0 = {1} Nf = {7} E = {(1, 2), (1, 7), (2, 3), (2, 4), (3, 2), (4, 5), (4, 6), (5, 6), (6, 1)} 6 1 7 2 3 4 5 b) test requirements for edge-pair coverage 6 1 7 2 3 4 5 {[(1,2),(2,3)], [(1,2),(2,4)], [(2,4),(4,5)],[(2,4),(4,6)], [(4,5),(5,6)], [(4,6),(6,1)], [(5,6),(6,1)], [(6,1),(1,7)], [(2,3),(3,2)], [(3,2),(2,3)], [(3,2),(2,4)], [(6,1),(1,2)]} (c) Does the given set of test paths satisfy edge-pair coverage? • t0 = [1, 2, 4, 5, 6, 1, 7] t1 = [1, 2, 3, 2, 4, 6, 1, 7] No tour for the following edge pair: [(6,1),(1,2)] and [(3,2),(2,3)]. 6 1 7 2 3 4 5 (d) Consider the simple path [3, 2, 4, 5, 6] and test path [1, 2, 3, 2, 4, 6, 1, 2, 4, 5, 6, 1, 7]. Does the test path tour the simple path directly? With a sidetrip? If so, identify the sidetrip. 6 1 7 2 3 4 5 • No, the test path does not tour the simple path directly. The test path does tour the simple path with a sidetrip. The sidetrip is [4,6,1,2,4]. e) node coverage, edge coverage, and prime path coverage Node Coverage Edge Coverage L0 L 1 L2 {1} {1,2} {1,2,3}! {2} {1,7}! {1,2,4} {3} {2,3} {2,3,2}* {4} {2,4} {2,4,5} {5} {3,2} {2,4,6} {6} {4,5} {3,2,3}* {7} {4,6} {3,2,4} {5,6} {4,5,6} {6,1} {4,6,1} {5,6,1} {6,1,7}! {6,1,2} L3 {1,2,4,5} {1,2,4,6} {2,4,5,6} {2,4,6,1} {3,2,4,5} {3,2,4,6} {4,5,6,1} {4,6,1,2} {4,6,1,7}! {5,6,1,2} {5,6,1,7}! {6,1,2,3}! {6,1,2,4} Length 4 {1,2,4,5,6} {1,2,4,6,1}* {2,4,5,6,1} {2,4,6,1,2}* {2,4,6,1,7}! {3,2,4,5,6} {3,2,4,6,1} {4,5,6,1,2} {4,5,6,1,7}! {4,6,1,2,4}* {4,6,1,2,3}! {5,6,1,2,3}! {5,6,1,2,4} {6,1,2,4,5} {6,1,2,4,6}* Length 5 Length 6 {1,2,4,5,6,1}* {3,2,4,5,6,1,7}! {2,4,5,6,1,7}! {2,4,5,6,1,2}* {3,2,4,5,6,1} {3,2,4,6,1,7}! {4,5,6,1,2,3}! {4,5,6,1,2,4}* {5,6,1,2,4,5}* {6,1,2,4,5,6}* PPC {3,2,4,5,6,1,7} {1,2,4,5,6,1} {2,4,5,6,1,2} {3,2,4,6,1,7} {4,5,6,1,2,4} {4,5,6,1,2,3} {5,6,1,2,4,5} {6,1,2,4,5,6} {1,2,4,6,1} {2,4,6,1,2} {4,6,1,2,4} {4,6,1,2,3} {6,1,2,4,6} {2,3,2} {3,2,3} f) List test paths that achieve node coverage but not edge coverage {1,2,3,2,4,5,6,1,7} doesn’t cover {4,6} g) List test paths that achieve edge coverage but not prime path coverage • {1,2,3,2,4,5,6,1,7} • {1,2,4,6,1,7} Some of the students put these as a test path but the test path in this example should start from node 1 and end with 7. This is not a test • {3,2,4,5,6,1,7} {1,2,3} {4,6} HOMEWORK 5 Section 2.2.3, Problem 1 (Graph III) • (a, b) List all of the du-paths with respect to x Du path D1 [1, 2, 3] D2 [1, 2, 3, 5] D3 [1, 2, 6] D4 [4, 5] D5 [4, 5, 2, 3] D6 [4, 5, 2, 6] (c)For each test path, determine which du-paths that test path tours • . Consider both direct touring and sidetrips. Hint: use a table • t1=[1,2,3,5,2,6], t2=[1,2,3,4,5,2,6] Du path direct Sidetrip D3 D1 [1, 2, 3] t1 D1, D2 D2 [1, 2, 3, 5] t2 D1, D4, D6 D3 [1, 2, 6] D4 [4, 5] D5 [4, 5, 2, 3] D6 [4, 5, 2, 6] (d) List a minimal test set that satisfies all-defs coverage with respect to x. • Test set t2 = [1, 2, 3, 4, 5, 2, 6] (e) List a minimal test set that satisfies all-uses coverage with respect to x • All 6 du-path must be toured, but given tests doesn’t have a path to directly tour either of D3 or D5. we need two additional tests: • {t1,t2, [1,2,6],[1, 2, 3,4,5,2,3, 5, 2, 6]} (f) List a minimal test set that satisfies all-du-paths coverage with respect to x • Since there is just one du-path for each du-pair all du-path coverage is the same as all-uses