Code coverage tests

This page documents the degree to which the PARI/GP source code is tested by our public test suite, distributed with the source distribution in directory src/test/. This is measured by the gcov utility; we then process gcov output using the lcov frond-end.

We test a few variants depending on Configure flags on the pari.math.u-bordeaux.fr machine (x86_64 architecture), and agregate them in the final report:

The target is to exceed 90% coverage for all mathematical modules (given that branches depending on DEBUGLEVEL or DEBUGMEM are not covered). This script is run to produce the results below.

LCOV - code coverage report
Current view: top level - basemath - Ser.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.12.0 lcov report (development 23036-b751c0af5) Lines: 122 122 100.0 %
Date: 2018-09-26 05:46:06 Functions: 17 17 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2000, 2012  The PARI group.
       2             : 
       3             : This file is part of the PARI/GP package.
       4             : 
       5             : PARI/GP is free software; you can redistribute it and/or modify it under the
       6             : terms of the GNU General Public License as published by the Free Software
       7             : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
       8             : ANY WARRANTY WHATSOEVER.
       9             : 
      10             : Check the License for details. You should have received a copy of it, along
      11             : with the package; see the file 'COPYING'. If not, write to the Free Software
      12             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      13             : 
      14             : #include "pari.h"
      15             : #include "paripriv.h"
      16             : /*******************************************************************/
      17             : /*                                                                 */
      18             : /*                     Conversion --> t_SER                        */
      19             : /*                                                                 */
      20             : /*******************************************************************/
      21             : static GEN
      22     1452287 : RgX_to_ser_i(GEN x, long l, long lx, long v, int copy)
      23             : {
      24             :   GEN y;
      25             :   long i;
      26     1452287 :   if (lx == 2) return zeroser(varn(x), l-2);
      27     1452287 :   if (l <= 2) pari_err_BUG("RgX_to_ser (l <= 2)");
      28     1452287 :   y = cgetg(l,t_SER); y[1] = x[1];
      29             :   /* e.g. Mod(0,3) * x^0 */
      30     1452287 :   if (v == LONG_MAX) { v = 1; lx = 3; } else { x += v; lx = minss(lx-v, l); }
      31     1452287 :   setvalp(y, v);
      32     1452287 :   if (copy)
      33          21 :     for (i = 2; i <lx; i++) gel(y,i) = gcopy(gel(x,i));
      34             :   else
      35     1452266 :     for (i = 2; i <lx; i++) gel(y,i) = gel(x,i);
      36     1452287 :   for (     ; i < l; i++) gel(y,i) = gen_0;
      37     1452287 :   return normalize(y);
      38             : }
      39             : /* enlarge/truncate t_POL x to a t_SER with lg l */
      40             : GEN
      41     1006695 : RgX_to_ser(GEN x, long l) { return RgX_to_ser_i(x, l, lg(x), RgX_val(x), 0); }
      42             : GEN
      43      445571 : RgX_to_ser_inexact(GEN x, long l)
      44             : {
      45      445571 :   long i, lx = lg(x);
      46      445571 :   int first = 1;
      47      453656 :   for (i = 2; i < lx && gequal0(gel(x,i)); i++) /* ~ RgX_valrem + normalize */
      48        8085 :     if (first && !isexactzero(gel(x,i)))
      49             :     {
      50           7 :       pari_warn(warner,"normalizing a series with 0 leading term");
      51           7 :       first = 0;
      52             :     }
      53      445571 :   return RgX_to_ser_i(x, l, lx, i - 2, 0);
      54             : }
      55             : GEN
      56         203 : rfrac_to_ser(GEN x, long l)
      57         203 : { return gdiv(gel(x,1), RgX_to_ser(gel(x,2), l)); }
      58             : 
      59             : static GEN
      60        4445 : RgV_to_ser_i(GEN x, long v, long l, int copy)
      61             : {
      62        4445 :   long j, lx = minss(lg(x), l-1);
      63             :   GEN y;
      64        4445 :   if (lx == 1) return zeroser(v, l-2);
      65        4438 :   y = cgetg(l, t_SER); y[1] = evalvarn(v)|evalvalp(0);
      66        4438 :   x--;
      67        4438 :   if (copy)
      68         231 :     for (j = 2; j <= lx; j++) gel(y,j) = gcopy(gel(x,j));
      69             :   else
      70        4207 :     for (j = 2; j <= lx; j++) gel(y,j) = gel(x,j);
      71        4438 :   for (     ; j < l;   j++) gel(y,j) = gen_0;
      72        4438 :   return normalize(y);
      73             : }
      74             : GEN
      75        4207 : RgV_to_ser(GEN x, long v, long l) { return RgV_to_ser_i(x, v, l, 0); }
      76             : 
      77             : /* x a t_SER, prec >= 0 */
      78             : GEN
      79        1806 : sertoser(GEN x, long prec)
      80             : {
      81        1806 :   long i, lx = lg(x), l;
      82             :   GEN y;
      83        1806 :   if (lx == 2) return zeroser(varn(x), prec);
      84        1792 :   l = prec+2; lx = minss(lx, l);
      85        1792 :   y = cgetg(l,t_SER); y[1] = x[1];
      86        1792 :   for (i = 2; i < lx; i++) gel(y,i) = gel(x,i);
      87        1792 :   for (     ; i < l;  i++) gel(y,i) = gen_0;
      88        1792 :   return y;
      89             : }
      90             : 
      91             : /* R(1/x) + O(x^N) */
      92             : GEN
      93          77 : rfracrecip_to_ser_absolute(GEN R, long N)
      94             : {
      95          77 :   GEN n = gel(R,1), d = gel(R,2);
      96          77 :   long vx = varn(d), vn, v, dn;
      97             : 
      98          77 :   if (typ(n) != t_POL || varn(n) != vx) { vn = 0; dn = 0; }
      99             :   else
     100             :   {
     101           7 :     vn = RgX_valrem(n, &n);
     102           7 :     n = RgX_recip(n);
     103           7 :     dn = degpol(n);
     104             :   }
     105          77 :   v = vn - RgX_valrem(d, &d);
     106          77 :   d = RgX_recip(d);
     107          77 :   R = gdiv(n, RgX_to_ser(d, N+2));
     108          77 :   setvalp(R, valp(R) + degpol(d)-dn-v);
     109          77 :   return R;
     110             : }
     111             : 
     112             : /* assume prec >= 0 */
     113             : GEN
     114       25690 : scalarser(GEN x, long v, long prec)
     115             : {
     116             :   long i, l;
     117             :   GEN y;
     118             : 
     119       25690 :   if (gequal0(x))
     120             :   {
     121        1141 :     if (isrationalzero(x)) return zeroser(v, prec);
     122         427 :     if (!isexactzero(x)) prec--;
     123         427 :     y = cgetg(3, t_SER);
     124         427 :     y[1] = evalsigne(0) | _evalvalp(prec) | evalvarn(v);
     125         427 :     gel(y,2) = gcopy(x); return y;
     126             :   }
     127       24549 :   l = prec + 2; y = cgetg(l, t_SER);
     128       24549 :   y[1] = evalsigne(1) | _evalvalp(0) | evalvarn(v);
     129       24549 :   gel(y,2) = gcopy(x); for (i=3; i<l; i++) gel(y,i) = gen_0;
     130       24549 :   return y;
     131             : }
     132             : 
     133             : /* assume x a t_[SER|POL], apply gtoser to all coeffs */
     134             : static GEN
     135           7 : coefstoser(GEN x, long v, long prec)
     136             : {
     137             :   long i, lx;
     138           7 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
     139           7 :   for (i=2; i<lx; i++) gel(y,i) = gtoser(gel(x,i), v, prec);
     140           7 :   return y;
     141             : }
     142             : 
     143             : static void
     144          14 : err_ser_priority(GEN x, long v) { pari_err_PRIORITY("Ser", x, "<", v); }
     145             : /* x a t_POL */
     146             : static GEN
     147          42 : poltoser(GEN x, long v, long prec)
     148             : {
     149          42 :   long s = varncmp(varn(x), v);
     150          42 :   if (s < 0) err_ser_priority(x,v);
     151          35 :   if (s > 0) return scalarser(x, v, prec);
     152          21 :   return RgX_to_ser_i(x, prec+2, lg(x), RgX_val(x), 1);
     153             : }
     154             : /* x a t_RFRAC */
     155             : static GEN
     156          49 : rfractoser(GEN x, long v, long prec)
     157             : {
     158          49 :   long s = varncmp(varn(gel(x,2)), v);
     159             :   pari_sp av;
     160          49 :   if (s < 0) err_ser_priority(x,v);
     161          42 :   if (s > 0) return scalarser(x, v, prec);
     162          14 :   av = avma; return gerepileupto(av, rfrac_to_ser(x, prec+2));
     163             : }
     164             : GEN
     165      705660 : toser_i(GEN x)
     166             : {
     167      705660 :   switch(typ(x))
     168             :   {
     169      108969 :     case t_SER: return x;
     170        1694 :     case t_POL: return RgX_to_ser(x, precdl+2);
     171         140 :     case t_RFRAC: return rfrac_to_ser(x, precdl+2);
     172             :   }
     173      594857 :   return NULL;
     174             : }
     175             : 
     176             : /* conversion: prec ignored if t_VEC or t_SER in variable v */
     177             : GEN
     178         350 : gtoser(GEN x, long v, long prec)
     179             : {
     180         350 :   long tx = typ(x);
     181             : 
     182         350 :   if (v < 0) v = 0;
     183         350 :   if (prec < 0) pari_err_DOMAIN("Ser", "precision", "<", gen_0, stoi(prec));
     184         350 :   if (tx == t_SER)
     185             :   {
     186          35 :     long s = varncmp(varn(x), v);
     187          35 :     if      (s < 0) return coefstoser(x, v, prec);
     188          28 :     else if (s > 0) return scalarser(x, v, prec);
     189          14 :     return gcopy(x);
     190             :   }
     191         315 :   if (is_scalar_t(tx)) return scalarser(x,v,prec);
     192         273 :   switch(tx)
     193             :   {
     194          42 :     case t_POL: return poltoser(x, v, prec);
     195          49 :     case t_RFRAC: return rfractoser(x, v, prec);
     196             :     case t_QFR:
     197          42 :     case t_QFI: return RgV_to_ser_i(x, v, 4+1, 1);
     198          14 :     case t_VECSMALL: x = zv_to_ZV(x);/*fall through*/
     199             :     case t_VEC: case t_COL:
     200         133 :       if (varncmp(gvar(x), v) <= 0) pari_err_PRIORITY("Ser", x, "<=", v);
     201         126 :       return RgV_to_ser_i(x, v, lg(x)+1, 1);
     202             :   }
     203           7 :   pari_err_TYPE("Ser",x);
     204             :   return NULL; /* LCOV_EXCL_LINE */
     205             : }
     206             : /* impose prec */
     207             : GEN
     208         140 : gtoser_prec(GEN x, long v, long prec)
     209             : {
     210         140 :   pari_sp av = avma;
     211         140 :   if (v < 0) v = 0;
     212         140 :   if (prec < 0) pari_err_DOMAIN("Ser", "precision", "<", gen_0, stoi(prec));
     213         133 :   switch(typ(x))
     214             :   {
     215          28 :     case t_SER: if (varn(x) != v) break;
     216          21 :                 return gerepilecopy(av, sertoser(x, prec));
     217             :     case t_QFR:
     218             :     case t_QFI:
     219          28 :       x = RgV_to_ser_i(mkvec3(gel(x,1),gel(x,2),gel(x,3)), v, prec+2, 1);
     220          28 :       return gerepileupto(av, x);
     221          14 :     case t_VECSMALL: x = zv_to_ZV(x);/*fall through*/
     222             :     case t_VEC: case t_COL:
     223          42 :       if (varncmp(gvar(x), v) <= 0) pari_err_PRIORITY("Ser", x, "<=", v);
     224          42 :       return RgV_to_ser_i(x, v, prec+2, 1);
     225             :   }
     226          42 :   return gtoser(x, v, prec);
     227             : }
     228             : GEN
     229         434 : Ser0(GEN x, long v, GEN d, long prec)
     230             : {
     231         434 :   if (!d) return gtoser(x, v, prec);
     232         140 :   if (typ(d) != t_INT)
     233             :   {
     234           7 :     d = gceil(d);
     235           7 :     if (typ(d) != t_INT) pari_err_TYPE("Ser [precision]",d);
     236             :   }
     237         140 :   return gtoser_prec(x, v, itos(d));
     238             : }

Generated by: LCOV version 1.13