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 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 - ZG.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.8.0 lcov report (development 19374-ac31b96) Lines: 44 79 55.7 %
Date: 2016-08-30 06:11:37 Functions: 8 14 57.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* $Id$
       2             : 
       3             : Copyright (C) 2011  The PARI group.
       4             : 
       5             : This file is part of the PARI/GP package.
       6             : 
       7             : PARI/GP is free software; you can redistribute it and/or modify it under the
       8             : terms of the GNU General Public License as published by the Free Software
       9             : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
      10             : ANY WARRANTY WHATSOEVER.
      11             : 
      12             : Check the License for details. You should have received a copy of it, along
      13             : with the package; see the file 'COPYING'. If not, write to the Free Software
      14             : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
      15             : 
      16             : #include "pari.h"
      17             : #include "paripriv.h"
      18             : 
      19             : static int
      20    11372354 : cmp_G(void *E, GEN x, GEN y) { (void)E; return cmp_universal(x,y); }
      21             : 
      22             : /* a ZG is either a t_INT or a t_VEC of pairs [g,e] representing
      23             :  * \sum e_i [g_i], e_i in Z, g_i in G. */
      24             : GEN
      25     1974476 : ZG_normalize(GEN x)
      26             : {
      27     1974476 :   if (typ(x) == t_INT) return x;
      28     1974476 :   return sort_factor(x, NULL, &cmp_G);
      29             : }
      30             : GEN
      31     1392041 : ZG_add(GEN x, GEN y)
      32             : {
      33     1392041 :   if (typ(x) == t_INT)
      34             :   {
      35      793856 :     if (!signe(x)) return y;
      36           0 :     if (typ(y) == t_INT)
      37             :     {
      38           0 :       if (!signe(y)) return x;
      39           0 :       return addii(x,y);
      40             :     }
      41           0 :     x = to_famat_shallow(gen_1,x);
      42             :   }
      43      598185 :   else if (typ(y) == t_INT)
      44             :   {
      45           0 :     if (!signe(y)) return x;
      46           0 :     y = to_famat_shallow(gen_1,y);
      47             :   }
      48      598185 :   x = merge_factor(x, y, NULL, &cmp_G);
      49      598185 :   if (lg(gel(x,1)) == 1) return gen_0;
      50      543263 :   return x;
      51             : }
      52             : GEN
      53         553 : ZG_neg(GEN x)
      54             : {
      55         553 :   if (typ(x) == t_INT) return negi(x);
      56         553 :   return mkmat2(gel(x,1),ZC_neg(gel(x,2)));
      57             : }
      58             : GEN
      59           0 : ZG_sub(GEN x, GEN y) { return ZG_add(x, ZG_neg(y)); }
      60             : 
      61             : /* x * c.[1], x in Z[G] */
      62             : GEN
      63           0 : ZG_Z_mul(GEN x, GEN c)
      64             : {
      65           0 :   if (is_pm1(c)) return signe(c) > 0? x: ZG_neg(x);
      66           0 :   if (typ(x) == t_INT) return mulii(x,c);
      67           0 :   return mkmat2(gel(x,1), ZC_Z_mul(gel(x,2), c));
      68             : }
      69             : 
      70             : GEN
      71           0 : ZG_mul(GEN x, GEN y)
      72             : {
      73             :   pari_sp av;
      74             :   GEN z, XG, XE;
      75             :   long i, l;
      76           0 :   if (typ(x) == t_INT) return ZG_Z_mul(y, x);
      77           0 :   if (typ(y) == t_INT) return ZG_Z_mul(x, y);
      78           0 :   av = avma;
      79           0 :   XG = gel(x,1); XE = gel(x,2); l = lg(XG);
      80           0 :   z = ZG_Z_mul(G_ZG_mul(gel(XG,1), y), gel(XE,1));
      81           0 :   for (i = 2; i < l; i++)
      82             :   {
      83           0 :     z = ZG_add(z, ZG_Z_mul(G_ZG_mul(gel(XG,i), y), gel(XE,i)));
      84           0 :     if (gc_needed(av,3))
      85             :     {
      86           0 :       if(DEBUGMEM>1) pari_warn(warnmem,"ZG_mul, i = %ld/%ld",i,l-1);
      87           0 :       z = gerepilecopy(av, z);
      88             :     }
      89             :   }
      90           0 :   return z;
      91             : }
      92             : GEN
      93      117852 : ZGCs_add(GEN x, GEN y)
      94             : {
      95      117852 :   GEN xi = gel(x,1), xv = gel(x,2);
      96      117852 :   GEN yi = gel(y,1), yv = gel(y,2);
      97      117852 :   long i = 1, j = 1, k = 1, lx = lg(xi), ly = lg(yi), l = lx+ly-1;
      98      117852 :   GEN zi = cgetg(l, t_VECSMALL), zv = cgetg(l, t_VEC);
      99     1114974 :   while (i < lx && j < ly)
     100             :   {
     101      879270 :     if      (xi[i] < yi[j]) { zi[k] = xi[i]; gel(zv,k) = gel(xv,i); i++; }
     102      431193 :     else if (xi[i] > yi[j]) { zi[k] = yi[j]; gel(zv,k) = gel(yv,j); j++; }
     103      221074 :     else { zi[k] = xi[i]; gel(zv,k) = ZG_add(gel(xv,i),gel(yv,j)); i++; j++; }
     104      879270 :     k++;
     105             :   }
     106      117852 :   for(; i < lx; i++,k++) { zi[k] = xi[i]; gel(zv,k) = gel(xv,i); }
     107      117852 :   for(; j < ly; j++,k++) { zi[k] = yi[j]; gel(zv,k) = gel(yv,j); }
     108      117852 :   setlg(zi,k);
     109      117852 :   setlg(zv,k); return mkvec2(zi, zv);
     110             : }
     111             : GEN
     112      699594 : ZG_G_mul(GEN x, GEN y)
     113             : {
     114             :   long i, l;
     115             :   GEN z, X;
     116      699594 :   if (typ(x) == t_INT) return signe(x)? to_famat_shallow(y, x): gen_0;
     117      699594 :   X = gel(x,1);
     118      699594 :   z = cgetg_copy(X, &l);
     119      699594 :   for (i = 1; i < l; i++) gel(z,i) = gmul(gel(X,i), y);
     120      699594 :   return ZG_normalize( mkmat2(z, shallowcopy(gel(x,2))) );
     121             : }
     122             : GEN
     123      532413 : G_ZG_mul(GEN x, GEN y)
     124             : {
     125             :   long i, l;
     126             :   GEN z, Y;
     127      532413 :   if (typ(y) == t_INT) return to_famat_shallow(x, y);
     128      532413 :   Y = gel(y,1);
     129      532413 :   z = cgetg_copy(Y, &l);
     130      532413 :   for (i = 1; i < l; i++) gel(z,i) = gmul(x, gel(Y,i));
     131      532413 :   return ZG_normalize( mkmat2(z, shallowcopy(gel(y,2))) );
     132             : }
     133             : void
     134      152320 : ZGC_G_mul_inplace(GEN v, GEN x)
     135             : {
     136      152320 :   long i, l = lg(v);
     137      152320 :   for (i = 1; i < l; i++) gel(v,i) = ZG_G_mul(gel(v,i), x);
     138      152320 : }
     139             : GEN
     140           0 : ZGC_G_mul(GEN v, GEN x)
     141             : {
     142             :   long i, l;
     143           0 :   GEN w = cgetg_copy(v, &l);
     144           0 :   for (i = 1; i < l; i++) gel(w,i) = ZG_G_mul(gel(v,i), x);
     145           0 :   return w;
     146             : }
     147             : GEN
     148           0 : G_ZGC_mul(GEN x, GEN v)
     149             : {
     150             :   long i, l;
     151           0 :   GEN w = cgetg_copy(v, &l);
     152           0 :   for (i = 1; i < l; i++) gel(w,i) = G_ZG_mul(gel(v,i), x);
     153           0 :   return w;
     154             : }
     155             : GEN
     156           0 : ZGC_Z_mul(GEN v, GEN x)
     157             : {
     158             :   long i, l;
     159           0 :   GEN w = cgetg_copy(v, &l);
     160           0 :   for (i = 1; i < l; i++) gel(w,i) = ZG_Z_mul(gel(v,i), x);
     161           0 :   return w;
     162             : }

Generated by: LCOV version 1.11