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 23332-367b47754) Lines: 126 126 100.0 %
Date: 2018-12-10 05:41:52 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     1453764 : RgX_to_ser_i(GEN x, long l, long lx, long v, int copy)
      23             : {
      24             :   GEN y;
      25             :   long i;
      26     1453764 :   if (lx == 2) return zeroser(varn(x), l-2);
      27     1453764 :   if (l < 2) pari_err_BUG("RgX_to_ser (l < 2)");
      28     1453764 :   y = cgetg(l,t_SER); y[1] = x[1];
      29             :   /* e.g. Mod(0,3) * x^0 */
      30     1453764 :   if (v == LONG_MAX) { v = 1; lx = 3; } else { x += v; lx = minss(lx-v, l); }
      31     1453764 :   setvalp(y, v);
      32     1453764 :   if (copy)
      33          35 :     for (i = 2; i <lx; i++) gel(y,i) = gcopy(gel(x,i));
      34             :   else
      35     1453729 :     for (i = 2; i <lx; i++) gel(y,i) = gel(x,i);
      36     1453764 :   for (     ; i < l; i++) gel(y,i) = gen_0;
      37     1453764 :   return normalize(y);
      38             : }
      39             : /* enlarge/truncate t_POL x to a t_SER with lg l */
      40             : GEN
      41     1007990 : RgX_to_ser(GEN x, long l) { return RgX_to_ser_i(x, l, lg(x), RgX_val(x), 0); }
      42             : GEN
      43      445739 : RgX_to_ser_inexact(GEN x, long l)
      44             : {
      45      445739 :   long i, lx = lg(x);
      46      445739 :   int first = 1;
      47      453852 :   for (i = 2; i < lx && gequal0(gel(x,i)); i++) /* ~ RgX_valrem + normalize */
      48        8113 :     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      445739 :   return RgX_to_ser_i(x, l, lx, i - 2, 0);
      54             : }
      55             : GEN
      56         224 : rfrac_to_ser(GEN x, long l)
      57             : {
      58         224 :   GEN d = gel(x,2);
      59         224 :   if (l == 2)
      60             :   {
      61          14 :     long v = varn(d);
      62          14 :     return zeroser(varn(d), gvaluation(x, pol_x(v)));
      63             :   }
      64         210 :   return gdiv(gel(x,1), RgX_to_ser(d, l));
      65             : }
      66             : 
      67             : static GEN
      68        4172 : RgV_to_ser_i(GEN x, long v, long l, int copy)
      69             : {
      70        4172 :   long j, lx = minss(lg(x), l-1);
      71             :   GEN y;
      72        4172 :   if (lx == 1) return zeroser(v, l-2);
      73        4165 :   y = cgetg(l, t_SER); y[1] = evalvarn(v)|evalvalp(0);
      74        4165 :   x--;
      75        4165 :   if (copy)
      76         231 :     for (j = 2; j <= lx; j++) gel(y,j) = gcopy(gel(x,j));
      77             :   else
      78        3934 :     for (j = 2; j <= lx; j++) gel(y,j) = gel(x,j);
      79        4165 :   for (     ; j < l;   j++) gel(y,j) = gen_0;
      80        4165 :   return normalize(y);
      81             : }
      82             : GEN
      83        3934 : RgV_to_ser(GEN x, long v, long l) { return RgV_to_ser_i(x, v, l, 0); }
      84             : 
      85             : /* x a t_SER, prec >= 0 */
      86             : GEN
      87        1813 : sertoser(GEN x, long prec)
      88             : {
      89        1813 :   long i, lx = lg(x), l;
      90             :   GEN y;
      91        1813 :   if (lx == 2) return zeroser(varn(x), prec);
      92        1799 :   l = prec+2; lx = minss(lx, l);
      93        1799 :   y = cgetg(l,t_SER); y[1] = x[1];
      94        1799 :   for (i = 2; i < lx; i++) gel(y,i) = gel(x,i);
      95        1799 :   for (     ; i < l;  i++) gel(y,i) = gen_0;
      96        1799 :   return y;
      97             : }
      98             : 
      99             : /* R(1/x) + O(x^N) */
     100             : GEN
     101          77 : rfracrecip_to_ser_absolute(GEN R, long N)
     102             : {
     103          77 :   GEN n = gel(R,1), d = gel(R,2);
     104          77 :   long vx = varn(d), vn, v, dn;
     105             : 
     106          77 :   if (typ(n) != t_POL || varn(n) != vx) { vn = 0; dn = 0; }
     107             :   else
     108             :   {
     109           7 :     vn = RgX_valrem(n, &n);
     110           7 :     n = RgX_recip(n);
     111           7 :     dn = degpol(n);
     112             :   }
     113          77 :   v = vn - RgX_valrem(d, &d);
     114          77 :   d = RgX_recip(d);
     115          77 :   R = gdiv(n, RgX_to_ser(d, N+2));
     116          77 :   setvalp(R, valp(R) + degpol(d)-dn-v);
     117          77 :   return R;
     118             : }
     119             : 
     120             : /* assume prec >= 0 */
     121             : GEN
     122       25795 : scalarser(GEN x, long v, long prec)
     123             : {
     124             :   long i, l;
     125             :   GEN y;
     126             : 
     127       25795 :   if (gequal0(x))
     128             :   {
     129        1141 :     if (isrationalzero(x)) return zeroser(v, prec);
     130         427 :     if (!isexactzero(x)) prec--;
     131         427 :     y = cgetg(3, t_SER);
     132         427 :     y[1] = evalsigne(0) | _evalvalp(prec) | evalvarn(v);
     133         427 :     gel(y,2) = gcopy(x); return y;
     134             :   }
     135       24654 :   l = prec + 2; y = cgetg(l, t_SER);
     136       24654 :   y[1] = evalsigne(1) | _evalvalp(0) | evalvarn(v);
     137       24654 :   gel(y,2) = gcopy(x); for (i=3; i<l; i++) gel(y,i) = gen_0;
     138       24654 :   return y;
     139             : }
     140             : 
     141             : /* assume x a t_[SER|POL], apply gtoser to all coeffs */
     142             : static GEN
     143           7 : coefstoser(GEN x, long v, long prec)
     144             : {
     145             :   long i, lx;
     146           7 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
     147           7 :   for (i=2; i<lx; i++) gel(y,i) = gtoser(gel(x,i), v, prec);
     148           7 :   return y;
     149             : }
     150             : 
     151             : static void
     152          14 : err_ser_priority(GEN x, long v) { pari_err_PRIORITY("Ser", x, "<", v); }
     153             : /* x a t_POL */
     154             : static GEN
     155          56 : poltoser(GEN x, long v, long prec)
     156             : {
     157          56 :   long s = varncmp(varn(x), v);
     158          56 :   if (s < 0) err_ser_priority(x,v);
     159          49 :   if (s > 0) return scalarser(x, v, prec);
     160          35 :   return RgX_to_ser_i(x, prec+2, lg(x), RgX_val(x), 1);
     161             : }
     162             : /* x a t_RFRAC */
     163             : static GEN
     164          77 : rfractoser(GEN x, long v, long prec)
     165             : {
     166          77 :   long s = varncmp(varn(gel(x,2)), v);
     167             :   pari_sp av;
     168          77 :   if (s < 0) err_ser_priority(x,v);
     169          70 :   if (s > 0) return scalarser(x, v, prec);
     170          35 :   av = avma; return gerepileupto(av, rfrac_to_ser(x, prec+2));
     171             : }
     172             : GEN
     173      764556 : toser_i(GEN x)
     174             : {
     175      764556 :   switch(typ(x))
     176             :   {
     177      109305 :     case t_SER: return x;
     178        1694 :     case t_POL: return RgX_to_ser(x, precdl+2);
     179         140 :     case t_RFRAC: return rfrac_to_ser(x, precdl+2);
     180             :   }
     181      653417 :   return NULL;
     182             : }
     183             : 
     184             : /* conversion: prec ignored if t_VEC or t_SER in variable v */
     185             : GEN
     186         392 : gtoser(GEN x, long v, long prec)
     187             : {
     188         392 :   long tx = typ(x);
     189             : 
     190         392 :   if (v < 0) v = 0;
     191         392 :   if (prec < 0) pari_err_DOMAIN("Ser", "precision", "<", gen_0, stoi(prec));
     192         392 :   if (tx == t_SER)
     193             :   {
     194          35 :     long s = varncmp(varn(x), v);
     195          35 :     if      (s < 0) return coefstoser(x, v, prec);
     196          28 :     else if (s > 0) return scalarser(x, v, prec);
     197          14 :     return gcopy(x);
     198             :   }
     199         357 :   if (is_scalar_t(tx)) return scalarser(x,v,prec);
     200         315 :   switch(tx)
     201             :   {
     202          56 :     case t_POL: return poltoser(x, v, prec);
     203          77 :     case t_RFRAC: return rfractoser(x, v, prec);
     204             :     case t_QFR:
     205          42 :     case t_QFI: return RgV_to_ser_i(x, v, 4+1, 1);
     206          14 :     case t_VECSMALL: x = zv_to_ZV(x);/*fall through*/
     207             :     case t_VEC: case t_COL:
     208         133 :       if (varncmp(gvar(x), v) <= 0) pari_err_PRIORITY("Ser", x, "<=", v);
     209         126 :       return RgV_to_ser_i(x, v, lg(x)+1, 1);
     210             :   }
     211           7 :   pari_err_TYPE("Ser",x);
     212             :   return NULL; /* LCOV_EXCL_LINE */
     213             : }
     214             : /* impose prec */
     215             : GEN
     216         175 : gtoser_prec(GEN x, long v, long prec)
     217             : {
     218         175 :   pari_sp av = avma;
     219         175 :   if (v < 0) v = 0;
     220         175 :   if (prec < 0) pari_err_DOMAIN("Ser", "precision", "<", gen_0, stoi(prec));
     221         168 :   switch(typ(x))
     222             :   {
     223          28 :     case t_SER: if (varn(x) != v) break;
     224          21 :                 return gerepilecopy(av, sertoser(x, prec));
     225             :     case t_QFR:
     226             :     case t_QFI:
     227          28 :       x = RgV_to_ser_i(mkvec3(gel(x,1),gel(x,2),gel(x,3)), v, prec+2, 1);
     228          28 :       return gerepileupto(av, x);
     229          14 :     case t_VECSMALL: x = zv_to_ZV(x);/*fall through*/
     230             :     case t_VEC: case t_COL:
     231          42 :       if (varncmp(gvar(x), v) <= 0) pari_err_PRIORITY("Ser", x, "<=", v);
     232          42 :       return RgV_to_ser_i(x, v, prec+2, 1);
     233             :   }
     234          77 :   return gtoser(x, v, prec);
     235             : }
     236             : GEN
     237         469 : Ser0(GEN x, long v, GEN d, long prec)
     238             : {
     239         469 :   if (!d) return gtoser(x, v, prec);
     240         175 :   if (typ(d) != t_INT)
     241             :   {
     242           7 :     d = gceil(d);
     243           7 :     if (typ(d) != t_INT) pari_err_TYPE("Ser [precision]",d);
     244             :   }
     245         175 :   return gtoser_prec(x, v, itos(d));
     246             : }

Generated by: LCOV version 1.13