Transcript
Page 1: Part III - Testing ( 30 Points )Part III - Testing ( 30 Points ) Perform white-box testing analysis of the code given below to generate a set of test cases to thoroughly test the code

Part III - Testing ( 30 Points )

Perform white-box testing analysis of the code given below to generate a set of test cases to thoroughly test the code. Indicate the criteria ( e.g. testing methodology ) you are using to select your test cases.

• double sine( double x, double tolerance, int limit, int & nTerms );

Uses a Taylor Series expansion about X = 0.0 to estimate the value of sine( x ) , in which each term of the series is calculated from the previous term. On input, "tolerance" wil l be the convergence criteria to terminate calculations, and "limit" wil l be an upper limit on the number of terms to include in the series. On output, "nTerms" wi l l contain the actual number of terms calculated, and the return value wil l be the estimated value of sine( x ). In the case of input errors, both "nTerms" and the return value will be set to zero.

x.^ x"^

Mathematics: sinfx + + — +

^ ^ 3! S! 7! 93

Algorithm: terrn^ - x

— term^ * term,:,, = V i > 0

'^^ 2 i * ( 2 i - i - l ) Code: double s i n e ( double x, double t o l e r a n c e , i n t l i m i t , i n t & nTerms ) {

i f ( t o l e r a n c e < 0.0 || l i m i t < 1 ) { nTerms = 0; r e t u r n 0.0;

}

double term = x; double sum = term; i n t i ;

f o r ( i = 1; i < l i m i t ; i++ ) {

i f ( fabs( term ) < t o l e r a n c e ) break;

term = -term * x * x / ( 2 * i * ( 2 * i + l ) ) ; sum += term;

} // f o r

nTerms = i ; r e t u r n sum;

} // s i n e

IX

Page 2: Part III - Testing ( 30 Points )Part III - Testing ( 30 Points ) Perform white-box testing analysis of the code given below to generate a set of test cases to thoroughly test the code

-f f

-TC i I ^ 1

5'

\ U

1 , 0 - 4

Page 3: Part III - Testing ( 30 Points )Part III - Testing ( 30 Points ) Perform white-box testing analysis of the code given below to generate a set of test cases to thoroughly test the code

1

/ o a ^ (X: OO

(X o 1^ e

/1 ^vv"i •/

So

13

<3 M ^ S

C c, s ^

. .J

X

1 e J- I

to 10

/ >

y 1-0 / 1 1 1 1 - r c 4

• 1 0 . 2_ 7 c 8 1

• 1 0 . 2_ 1

T C ^ Z-O 0.0^ h f e r m S :::

Page 4: Part III - Testing ( 30 Points )Part III - Testing ( 30 Points ) Perform white-box testing analysis of the code given below to generate a set of test cases to thoroughly test the code

R

7 ^

I

^ c k : X l ^ o t̂ i no "h

loo

V

^ > r Corrcc

^ - 1 , 0

5 ^ ^ ' J

X f-o

f 'yrwc, ^ (K ^ X


Top Related