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

CS 408 Software Testing

Practice/Study Questions, Version 1

2022

These are questions for you to practice and test your own understanding of the course content.  They will not be graded and you do not need to submit your solutions.

1    Fault, Error, Failure

Below is a faulty Java program, which includes a test case that results in a failure.  The if-statement needs to take account of negative values. A possible fix is:

if   (x[i]%2   !=  0)

Answer the following questions for this program.

(a) If possible, identify a test case that does not execute the fault.

(b) If possible, identify a test case that executes the fault, but does not result in an error state.

(c) If possible, identify a test case that results in an error, but not a failure.

(d)  For the test case (x  =   [-10,  -9,  0,  99,  100], expected output:  2), identify the first error state.  De- scribe the complete state.

public  static  int  odd(int []  x)     {

//  Effects:  if  x==null  throw  NullPointerException,

//  else  return  the  number  of  elements  in  x  that  are  odd

int  count  =  0;

for   (int  i  =0;  i  <  x.length;  i++)   {

if   (x[i]%2==1)   {

count++;

}

}

return  count;

}

//  test:  x  =   [-10,  -9,  0,  99,  100]

//  Expected:  2

 

2    Subsumption

For an acyclic graph, does Prime Path Coverage (PPC) subsume Complete Path Coverage (CPC)? Answer yes or no explicitly and then justify your answer.

 

3    Mutation testing

Consider the following implementation of the cycle-finding algorithm from http://en.literateprograms.org/ Floyd%27s_cycle-finding_algorithm_%28C%29.  (We’ve included the complete implementation from there


in the skeleton at q3/cycle-finder.c, including a test harness.)  In your a2 sub.pdf file, propose two non- stillborn and non-equivalent mutants of this function.  Write down test inputs which strongly kill these mutants (syntax doesn’t matter) and the expected output of your test cases on the original code and on the mutant.

typedef  struct  node_s   {

void  *data;

struct  node_s  *next;

}  NODE;

int  list_has_cycle(NODE  *list)

{

NODE  *fast=list;

while (1)   {

if (!(fast=fast->next))  return  0;

if (fast==list)  return  1;

if (!(fast=fast->next))  return  0;

if (fast==list)  return  1;

list=list->next;

}

return  0;

}

 

4    Data Flow Coverage

We will identify test requirements and create a test suite to achieve prime path coverage of a specific method in the free Java application SweetHome3D (http://www.sweethome3d.eu), version 3.7.

We will work with computeIntersection() in class PlanController, which is included in the q4 subdirectory of your skeleton repo. If you want, you can find complete source code SweetHome3D-3.7-src.zip in the course git repo, or from the Internet.

(a) Creating CFGs    . Part 1) Draw a basic block control-flow graph for the computeIntersection() method using the minimum number of nodes. Label nodes with numbers only, such as 1, 2, 3, . . . . The content of each node may either contain the source code statements or line number reference. For example, float  x  =  point2   [0]; can be labelled as line 14 in your graph. Note: this question will be unmanageable unless you group statements into basic blocks.

For simplicity, begin drawing the graph by putting the big, long if-statement in one node (no need to represent Java boolean expression short-circuit evaluation), complete the rest of the graph, then merge relevant nodes to meet the minimum node requirement.

Part 2) Copy the basic block CFG once, and then replace the content in the nodes with defs and uses to create the def-use control-flow graph. Do not change the node labels, or the structure of the graph.

The input variables point1,  point2,  point3,  point4 would normally be considered as implicit definitions for the function.  However, to simplify this assignment, you can ignore those four definitions (as well as the uses of

them) for Q4 parts (a) through (d).

Ensure both graphs are clear and legible.

(b) Identifying requirements for PPC.    Identify the test requirements for prime path coverage in computeIntersection You do not have to draw the full table if you can eyeball the solution.

(c)  Identifying  requirements  for  ADUPC    .  Identify  the  test  requirements  for  All-du-Paths  Coverage  in computeIntersection().   Consider only uses that aren’t dominated by a definition of the same variable in the same basic block. Justify your answers.

(d) Comparing coverage criteria    . Compare the sets of test requirements you’ve collected. Point out strengths and  weaknesses  of these criteria,  for instance by giving scenarios where one criterion is going to help you find something that another criterion wouldn’t; discuss whether the additional number of test requirements to achieve prime path coverage is worth it in this case. Simply saying one criterion subsumes another is not enough.

(e)    Designing    tests    .         Design   a   set   of   Test   Cases   which   achieves   prime   path   coverage   in computeIntersection().  For each test case, provide the test path, the test requirement(s) that the test path satisfies, the input, the computed values of alpha1, alpha2, sameSignum, and the expected output. You do not need to code these tests. Justify your answer.

 

5    Logic Coverage

For predicate p = (a A b) V (b A c) V (a A c), answer the following questions:

●  (a) Compute and simplify the conditions under which each of the clauses determines predicate p. The condition must only use A, -, and V. Complete the table.

●  (b) Identify all pairs of rows from your table that satisfy GACC with respect to each clause.

●  (c) Identify all pairs of rows from your table that satisfy CACC with respect to each clause.

●  (d) Identify all pairs of rows from your table that satisfy RACC with respect to each clause.

 

a

b

c  

p  

pa

pb

pc

1

T

T

T  

 

 

 

 

2

T

T

F  

 

 

 

 

3

T

F

T  

 

 

 

 

4

T

F

F  

 

 

 

 

5

F

T

T  

 

 

 

 

6

F

T

F  

 

 

 

 

7

F

F

T  

 

 

 

 

8

F

F

F  

 

 

 

 

 

6    Input Space Partitioning

Answer the following questions for the method intersection() below:

public  Set  intersection   (Set  s1,  Set  s2)

//  Effects:  If  s1  or  s2  is  null,  throw  NullPointerException

//  else  return  a   (non  null)  Set  equal  to  the  intersection  of  Sets  s1  and  s2

Characteristic:  Size  of  s2

-  s2  has  even  number  of  elements   (in  other  words,  the  size  of  s2  is  an  even  number)

-  s2  has  odd  number  of  elements   (in  other  words,  the  size  of  s2  is  an  odd  number)

Characteristic:  Relation  between  s1  and  s2

-  the  size  of  s1  is  not  bigger  than  the  size  of  s2

-  the  size  of  s2  is  not  bigger  than  the  size  of  s1

●  (a) Does the partition “Size of s2” satisfy the completeness property? If not, give a value for s2 that does not fit in any block.

●  (b) Does the partition “Size of s2” satisfy the disjointness property? If not, give a value for s2 that fits in more than one block.

●  (c) Does the partition “Relation between s1 and s2” satisfy the completeness property?  If not, give a pair of values for s1 and s2 that does not fit in any block.

●  (d) Does the partition  “Relation between s1 and s2” satisfy the disjointness property?  If not, give a pair of values for s1 and s2 that fits in more than one block.

●  (e) If the  “Base Choice” criterion were applied to the two partitions  (exactly as written),  how many test requirements would result?


7    Writing Better Bug Reports

In this question, you will critique and improve an existing bug report in Mozilla and write a bug report.

●  (a) Read Mozilla bug report 112785 (https://bugzilla.mozilla.org/show_bug.cgi?id=112785). What are some problems with the initial bug report (as seen in the “Title” and the “Description”)?  Identify four problems. How would you improve this bug report?

●  (b) The class HashTable.java is an implementation of a hash table using linear open addressing and division in Java.  This program has a bug, because the put function will not update the element associated with the given key if an entry with the same key already exists.  The hash table implementation should always update the element, even if the element’s key already exists in the hash table.  (See the comment in the put function).

Write a good bug report for this bug using the Bugzilla bug report format.

(Recommended exercise: write a JUnit test that illustrates this bug.)