Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS130: Software Engineering Fall 2018

Assignment 2

Due Date: Friday, December 7, 2018, 11:59 PM

Late Policy: Every day incurs 10% penalty until Sunday, December 9, 2018, 11:59PM

Submission Instruction: Please submit a single pdf file to CCLE. There’s no need to submit code separately.

Q1 Regression Testing and Test Coverage [15 pts]

Take a look at the old and new version of the code given below. Consider the following test cases that were run on the old version. (Hint: abs(x) returns the absolute value of x.)

Old Version

New Version

S1: public class A {

S2: public static int sum(int a, int b){

S3: return a + b;

}

S4: public int diff(int a, int b){

S5: return a - b;

}

}

S6: public class B extends A {

S7: public int diff(int a, int b){

S8: if (a > b) return a - b;

S9: else return b - a;

}

}

S10: public class C extends A {

}

S11: public class Execute {

S12: public int executeSum(A p, int a, int b){

S13: return A.sum(a, b);

}

S14: public int executeDiff(A p, int a, int b){

S15:  return p.diff(a, b);

}

}

S1’:

S2’:

S3’:

S4’:

S5’:

S6’:

S7’:

S8’:

S9’:

S10’:

S11’:

S12’:

S13’:

S14’:

public class A {

public static int sum(int a, int b){ return a + b;

}

public int diff(int a, int b){

return a - b;

}

}

public class B extends A {

//definition of diff removed

}

public class C extends A {

public int diff(int a, int b) {

return b - a;

}

}

public class Execute {

public int executeSum(A p, int a, int b){ return A.sum(a, b);

}

public int executeDiff(A p, int a, int b){ return p.diff(a, b);

}

}


Test cases:

public void test1() {

A x = new A();

Execute e = new Execute(); assertEquals(e.executeSum (x,2,3),5); int difference = e.executeDiff(x,3,2); int abs_diff = abs(difference); assertEquals(abs_diff, 1);

}

public void test2() {

A x = new B();

Execute e = new Execute(); assertEquals(e.executeSum (x,2,3),5); int difference e.executeDiff(x,3,2); int abs_diff = abs(difference); assertEquals(abs_diff, 1);

}



public void test3() {

A x = new C();

Execute e = new Execute(); assertEquals(e.executeSum (x,2,3), 5); int difference = e.executeDiff(x,3,2); int abs_diff = abs(difference); assertEquals(abs_diff, 1);

}

public void test4() {

A x = new B();

A y = new C();

Execute e = new Execute(); assertEquals(e.executeSum (y,2,3), 5); int difference = e.executeDiff(x,2,3); int abs_diff = abs(difference); assertEquals(abs_diff, 1);

}




Figure 1

Answer the following questions:

A.   The JIG for executeDiff() of the old version is given in Figure 1. Identify all the dangerous edges from the following options (Select all that apply).

A .   Edge from x.diff(a,b) to A .diff() on runtime type C in the old version.

B .   Edge from x.diff(a,b) to B .diff() on runtime type B in the old version.

C.   Edge from x.diff(a,b) to A .diff() on runtime type A in the old version.

D.   None of the above.

B.   Which of the given test cases are selected to be run again for the new version of the code using the Regression Test Selection algorithm described in the lecture? (Select all that apply).

A .     test1

B .     test2

C.    test3

D.    test4

E.     None of the above.

Q2 Symbolic Execution [45 pts]

Alice wrote the following Java function and would like to reason about test adequacy of her function.         Please perform symbolic execution on the Java function first and then answer the following sub-questions about testing.


static int compute (int x, int y, int z) {

S1: if (x < y) {

S2: if (y <= z) {

S3: z = 200;

} else {

S4: z = y;

S5: y = 0;

}

} else {

S6: z = -1 * x;

}

S7: if (z < x + y) {

S8: x = z - 10;

} else {

S9: y = z + 10;

}

S10:return x +