/** * Compare the computed sequence against randomly generated polynomials of different length */ @Test public void checkSequence_Random() { for( int i = 3; i < 20; i++ ) { Polynomial p = new Polynomial(i); for( int trial = 0; trial < 20; trial++ ) { for( int j = 0; j < p.size; j++ ) { p.c[j] = (rand.nextDouble()-0.5)*2; } double value = (rand.nextDouble()-0.5)*4; compareSequences( p, value); compareSequences( p, Double.POSITIVE_INFINITY); compareSequences( p, Double.NEGATIVE_INFINITY); } } }
/** * Examine a case which was found to cause problems */ @Test public void checkSpecificPoly01() { Polynomial poly = Polynomial.wrap(-41.118263303597175,-120.95384505825373,-417.8477600492497,-634.5308297409192, -347.7885168491812,6.771313016808563,79.70258790927392,31.68212813610444,5.0248961592587875, 0.2879701466217739,0.0); // Compare computed sequence to the standard compareSequences( poly, -500); compareSequences( poly, Double.NEGATIVE_INFINITY); SturmSequence alg = new SturmSequence(poly.size); alg.initialize(poly); int N = alg.countRealRoots(Double.NEGATIVE_INFINITY,Double.POSITIVE_INFINITY); int M = alg.countRealRoots(-500,500); assertTrue(M <= N); }