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 - graph - plottty.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.12.1 lcov report (development 25819-e703fe1174) Lines: 88 88 100.0 %
Date: 2020-09-18 06:10:04 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2016  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             : /**                                                                **/
      19             : /**                         LOW-RES PLOT                           **/
      20             : /**                                                                **/
      21             : /********************************************************************/
      22             : #define ISCR 64
      23             : #define JSCR 22
      24             : 
      25             : INLINE long
      26        1920 : DTOL(double t) { return (long)(t + 0.5); }
      27             : 
      28             : static char
      29        1920 : PICT(long j) {
      30        1920 :   switch(j%3) {
      31         862 :     case 0:  return '_';
      32         368 :     case 1:  return 'x';
      33         690 :     default: return '"';
      34             :   }
      35             : }
      36             : static char
      37          30 : PICTZERO(long j) {
      38          30 :   switch(j%3) {
      39           8 :     case 0:  return ',';
      40          11 :     case 1:  return '-';
      41          11 :     default: return '`';
      42             :   }
      43             : }
      44             : 
      45             : static char *
      46          60 : dsprintf9(double d, char *buf)
      47             : {
      48          60 :   int i = 10;
      49             : 
      50         115 :   while (--i >= 0) {
      51         115 :     sprintf(buf, "%9.*g", i, d);
      52         115 :     if (strlen(buf) <= 9) break;
      53             :   }
      54          60 :   return buf;
      55             : }
      56             : 
      57             : typedef unsigned char screen[ISCR+1][JSCR+1];
      58             : 
      59             : static void
      60        1890 : fill_gap(screen scr, long i, int jnew, int jpre)
      61             : {
      62             :   int mid, i_up, i_lo, up, lo;
      63             : 
      64        1890 :   if (jpre < jnew - 2) {
      65          60 :     up = jnew - 1; i_up = i;
      66          60 :     lo = jpre + 1; i_lo = i - 1;
      67        1830 :   } else if (jnew < jpre - 2) {
      68          88 :     up = jpre - 1; i_up = i - 1;
      69          88 :     lo = jnew + 1; i_lo = i;
      70        1742 :   } else return; /* if gap < 2, leave it as it is. */
      71             : 
      72         148 :   mid = (jpre+jnew)/2;
      73         148 :   if (mid>JSCR) mid=JSCR; else if (mid<0) mid=0;
      74         148 :   if (lo<0) lo=0;
      75         438 :   if (lo<=JSCR) while (lo <= mid) scr[i_lo][lo++] = ':';
      76         148 :   if (up>JSCR) up=JSCR;
      77         424 :   if (up>=0) while (up > mid) scr[i_up][up--] = ':';
      78             : }
      79             : 
      80             : static double
      81          60 : todbl(GEN x) { return rtodbl(gtofp(x, LOWDEFAULTPREC)); }
      82             : 
      83             : void
      84          30 : pariplot(void* E, GEN (*fun)(void *E, GEN x), GEN a, GEN b, GEN ysmlu,GEN ybigu, long prec)
      85             : {
      86          30 :   const char BLANK = ' ', YY = '|', XX_UPPER = '\'', XX_LOWER = '.';
      87             :   long jz, j, i, sig;
      88          30 :   pari_sp av = avma;
      89          30 :   int jnew, jpre = 0; /* for lint */
      90             :   GEN x, dx;
      91             :   double diff, dyj, ysml, ybig, y[ISCR+1];
      92             :   screen scr;
      93             :   char buf[80], z;
      94             : 
      95          30 :   sig=gcmp(b,a); if (!sig) return;
      96          30 :   if (sig<0) { x=a; a=b; b=x; }
      97          30 :   x = gtofp(a, prec);
      98          30 :   dx = divru(gtofp(gsub(b,a),prec), ISCR-1);
      99         690 :   for (j=1; j<=JSCR; j++) scr[1][j]=scr[ISCR][j]=YY;
     100        1890 :   for (i=2; i<ISCR; i++)
     101             :   {
     102        1860 :     scr[i][1]   = XX_LOWER;
     103        1860 :     scr[i][JSCR]= XX_UPPER;
     104       39060 :     for (j=2; j<JSCR; j++) scr[i][j] = BLANK;
     105             :   }
     106          30 :   ysml = ybig = 0.; /* -Wall */
     107        1950 :   for (i=1; i<=ISCR; i++)
     108             :   {
     109        1920 :     pari_sp av2 = avma;
     110        1920 :     y[i] = gtodouble( fun(E, x) );
     111        1920 :     set_avma(av2);
     112        1920 :     if (i == 1)
     113          30 :       ysml = ybig = y[1];
     114             :     else
     115             :     {
     116        1890 :       if (y[i] < ysml) ysml = y[i];
     117        1890 :       if (y[i] > ybig) ybig = y[i];
     118             :     }
     119        1920 :     x = addrr(x,dx);
     120             :   }
     121          30 :   set_avma(av);
     122          30 :   if (ysmlu) ysml = gtodouble(ysmlu);
     123          30 :   if (ybigu) ybig = gtodouble(ybigu);
     124          30 :   diff = ybig - ysml;
     125          30 :   if (!diff) { ybig += 1; diff= 1.; }
     126          30 :   dyj = ((JSCR-1)*3+2) / diff;
     127             :   /* work around bug in gcc-4.8 (32bit): plot(x=-5,5,sin(x)))) */
     128          30 :   jz = 3 - (long)(ysml*dyj + 0.5); /* 3 - DTOL(ysml*dyj) */
     129          30 :   z = PICTZERO(jz); jz /= 3;
     130        1950 :   for (i=1; i<=ISCR; i++)
     131             :   {
     132        1920 :     if (0<=jz && jz<=JSCR) scr[i][jz]=z;
     133        1920 :     j = 3 + DTOL((y[i]-ysml)*dyj);
     134        1920 :     jnew = j/3;
     135        1920 :     if (i > 1) fill_gap(scr, i, jnew, jpre);
     136        1920 :     if (0<=jnew && jnew<=JSCR) scr[i][jnew] = PICT(j);
     137        1920 :     jpre = jnew;
     138             :   }
     139          30 :   pari_putc('\n');
     140          30 :   pari_printf("%s ", dsprintf9(ybig, buf));
     141        1950 :   for (i=1; i<=ISCR; i++) pari_putc(scr[i][JSCR]);
     142          30 :   pari_putc('\n');
     143         630 :   for (j=(JSCR-1); j>=2; j--)
     144             :   {
     145         600 :     pari_puts("          ");
     146       39000 :     for (i=1; i<=ISCR; i++) pari_putc(scr[i][j]);
     147         600 :     pari_putc('\n');
     148             :   }
     149          30 :   pari_printf("%s ", dsprintf9(ysml, buf));
     150        1950 :   for (i=1; i<=ISCR; i++)  pari_putc(scr[i][1]);
     151          30 :   pari_putc('\n');
     152             :   {
     153             :     char line[10 + 32 + 32 + ISCR - 9];
     154          30 :     sprintf(line, "%10s%-9.7g%*.7g\n"," ",todbl(a),ISCR-9,todbl(b));
     155          30 :     pari_printf(line);
     156             :   }
     157             : }
     158             : 
     159             : void
     160          30 : pariplot0(GEN a, GEN b, GEN code, GEN ysmlu,GEN ybigu, long prec)
     161             : {
     162          30 :   push_lex(gen_0, code);
     163          30 :   pariplot((void*)code, &gp_eval, a, b, ysmlu, ybigu, prec);
     164          30 :   pop_lex(1);
     165          30 : }

Generated by: LCOV version 1.13