Testing Model

advertisement
Paper no.7
Complete testing
Author: Popescu Virgil
Date: November 15, 2006
Problem 2.12.
Compute the integer roots of a polynomial with integer coefficients.
Specification and design – the same approach as by now
Data n, (a[i], i = 0, 1, ..., n)
Results m, (r[i], i = 1, 2, ..., m)
where
* n – degree of polynomial (natural number)
* (a[i], i = 0, 1, ..., n) – coefficients of polynomial (integer numbers):
P(X) = a[n] X^n + ... + a[1] X + a[0]
where, a[n] <> 0.
* m – number of integer roots
* (r[i], i = 1, 2, ..., m) – integer roots, i.e. P(r[i]) = 0, i = 1, 2, ..., m.
* If the polynomial has no integer roots, then m = 0,
Otherwise (m > 0) and (1 <= i <= m: P(r[i]) = 0) and (i <> j => r[i] <> r[j])).
.
.
.
.
Algorithm IntegerRoots is:
ReadSeq(n, a)
Roots(n, a, m, r)
WriteSeq(m, r)
endAlg
.
.
.
.
Test by the problem specification - "black box method "
Choices:
1. degree of polynomial:
1. small - examples:
- polynomial nul
- polynomial of degree 0
- polynomial of degree 1
2. average - examples:
- polynomial of degree 3
- polynomial de of degree 7
3. large - examples:
- polynomial of degree 99
- polynomial of degree 100
2. positive, negative roots
1 only positive roots
2 only negative roots
3 positive and negative roots
4 only null roots
5 both null and non-null roots
3. polynomials with and without integer roots
1 with integer roots
2 without integer roots
4. polynomials with or without multiple integer roots
1 with multiple roots only
2 witout multiple roots
3 with both multiple and non-multiple roots
5. polynomials with monoms of small degree null or not
1 monom of degree 0 non-nul
2 monom of degree 0 nul si 1 non-nul
3 monom of degree 0..k-1 nul and of degree k non-null (k large)
Choice
Polynomial
------------------------------------------------------1.1
null polynomial
1.1, 3.2, 5.1
5
1.2, 2.1, 3.1, 4.2, 5.1
x+5
1.2, 2.3, 3.1, 4.1, 5.1
x^2-1
1.2, 3.2
x^2+1
1.2, 2.5
x^2+x^3
5.2
x
1.3, 5.3
x^100+x^99
1.3, 5.3
x^100
.
.
Test by the text of the subprogram (statements analysis) - " withe box method "
For the choice of test data we discuss the Roots subalgorithm only. Roots:
Subalgorithm Roots(n, a, m, r) is:
1. k <- 0
m <- 0
2. While (a[k] <> 0) and (k <= n) do
3.
k <- k + 1
endwh
4. If k<=n then
If k > 0 then
5.
m <- m + 1; r[m] <- 0
Endif
6.
For d := 1, abs(a[k]) do
7.
If abs(a[k]) mod d = 0 then
9.
If ValPol(n, a, d) = 0 then
10.
m <- m + 1; r[m] <- d
endif
11.
If ValPol(n, a, -d) = 0 then
12.
m <- m + 1; r[m] <- -d
endif
endif
endfor
endif
endSub
{Determine the smallest index k
(k: 0..n) with a[k] <> 0}
{d divisor of a[k]?}
{d is root?}
{-d is root?}
Discussion:
- how do we choose the data;
- who gets executed each time and who does not;
- choose such that all combinations of sets of instructions that may or may not run are selected.
Input
n | a[n], ..., a[0]
--------------------E0 -1|
E1 0 | 2
E2 1 | 1, 1
E3 1 | 1, 0
E4 1 | 1, -1
E5 2 | 1, 2, 1
E6 2 | 1, -3, 2
E7 3 | 1, -4, 5, -2
E8 3 | 1, -4, 4, 0
E9 4 | 1, 1, 1, 0, 0
Output
Statements
m | r[1], ..., r[2]
executed
------------------ ------------------0|
1,2,4
0|
1,2,4,6(7,9,11,7,9,11)
1 | -1
1,2,4,6(7,9,11,12)
1|0
1,2,3,4,5,6(7,9,11)
1|1
1,2,4,6(7,9,10,11)
1 | -1
1,2,4,6(7,9,11,12)
2 | 1, 2
1,2,4,6(7,9,10,11,7,9,10,11)
2 | 1, 2
1,2,4,6(7,9,10,11,7,9,10,11)
2 | 0, 2
1,2(3)4,5,6(7,9,11,7,9,10,11,7,9,11,7,9,11)
1|0
1,2(3,3),4,5,6(7,9,11)
Related documents
Download