Research Article
Using Fuzzy Logic Techniques for Assertion-Based Software Testing Metrics
Algorithm 1
A sample Java method with assertions.
(1) public void computePrime(int Data){ | (2) int out_data = new int50; | (3) int inData = new int50; | (4) int n, p, d, temp, count, i; | (5) boolean is_prime; | (6) for(int j = 0; j < Data.length; j++) | (7) inDataj = Dataj; | (8) n = inData.length; | (9) count = −1; | (10) i = 0; | (11) assert(i >= 0 && i < n) // assertion#1 | (12) p = inDatai; | (13) while (i < Data.length){ | (14) is_prime = true; | (15) d = 2; | (16) while (d < p && is_prime){ | (17) assert(d! = 0) // assertion#2 | (18) temp = p % d; | (19) if (temp == 0) is_prime = false; | (20) d++; | (21) } // while | (22) if (is_prime){ | (23) count++; | (24) assert(count >= 0 && count < n) // assertion#3 | (25) out_datacount = p; | (26) } // if | (27) i++; | (28) assert (i >= 0 && i < n) // assertion#4 | (29) p = inDatai; | (30) } // while | (31) System.err.println(“∖n Input data:”); | (32) i = 0; | (33) while(i < Data.length){ | (34) assert(i <= 0 && i < n) // assertion#5 | (35) System.err.print(inData[i] + “ ”); | (36) i++; | (37) } | (38) System.err.println(“∖n∖nPrimes:”); | (39) i = 0; | (40) while (i <= count){ | (41) assert(i >= 0 && i <= count) // assertion#6 | (42) System.err.print(out_datai + “ ”); | (43) i++; | (44) } | (45) } // computePrime |
|