File: tscstr.c

package info (click to toggle)
pact 980714-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 13,096 kB
  • ctags: 26,034
  • sloc: ansic: 109,076; lisp: 9,645; csh: 7,147; fortran: 1,050; makefile: 136; lex: 95; sh: 32
file content (153 lines) | stat: -rw-r--r-- 4,986 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
 * TSCSTR.C - test SCSTR.C routines
 *
 * Source Version: 2.0
 * Software Release #92-0043
 *
 */

#include "cpyright.h"

/***********************************************************************
* File        : tscstr.c - Test program for pact/score/scstr.c
* Externals   : fltfil, intfil, pact/score
* Machines    : sandpiper, phoenix.ocf
*
* Programmer  : Carolyn Sharp
* Created     : October 30, 1991
* Revised     : November 25, 1991
*               Reorganized to match tscctl.c (no change in function).
*             : November 26, 1991
*               Added strtol tests.
* Programmer  : Dennis Braddy
*             : April 6, 1995
*               Removed strtol and other system routine calls.
*               The point of providing PACT routines is to replace
*               sytem routines that don't work right!
*
* Description : Reads FILEs fltfil and intfil of assorted float/integer
*               numbers and checks values returned by score functions
*               _SC_atof, _SC_strtod, and _SC_strtol.
***********************************************************************/

#include "score.h" 
#define MAX 32

main ()
   {char xxx[MAX];                    /* input string */
    char *endptr;                    /* pointer to remainder or NULL */
    int base;                         /* 2-36 allowed, score always 10? */
    double expected;                  /* expected result (input, float) */
    int lexpected;                    /* expected result (input, int) */
    FILE *fp;                         /* file pointer */
    char *name;                       /* name of input file */
    int fail[3];                      /* number of failures per case */
    int failsum;                      /* total number of failures */
    int i;                            /* loop variable */
    long lval;
    static char *casename[]  = {"_SC_atof", "_SC_strtod", "_SC_strtol"};

/* process fltfil for atof/strtod functions */
    fp = fopen("fltfil", "r");

    PRINT(STDOUT, "\nString\t\tFunction\t  Measured       Expected\tStatus\n");

/* initialize failure counters */
    for (i = 0; i < 3; fail[i] = 0, i++);

    while (fscanf(fp, "%13s %lg %d", xxx, &expected, &lexpected) != EOF)
       {fail[0] += checkd(_SC_atof(xxx), "_SC_atof",
			  xxx, expected, lexpected); 
	fail[1] += checkd(_SC_strtod(xxx, &endptr), "_SC_strtod",
			  xxx, expected, lexpected);};

    fclose(fp);
  
    PRINT(STDOUT, "\nString\tFunction\t  Measured     Expected   Status\n");

/* process intfil for strtol functions */
    fp = fopen("intfil", "r");

    while (fscanf(fp, "%10s %d %ld %d", xxx, &base, &lval, &lexpected) != EOF)
       fail[2] += checkl(_SC_strtol(xxx, &endptr, base), "_SC_strtol", xxx,
			 lval, lexpected);

    fclose(fp);
  
/* report failures */
    failsum = 0;
    for (i = 0; i < 3; i++)
        {if (fail[i])
	    {PRINT(STDOUT, "%d failure%s in %s \n", fail[i],
		   ((fail[i] > 1) ? "s" : "") , casename[i]);
	     failsum += fail[i];};};

    if (failsum)
       printf("%d = total \n", failsum);

    PRINT(STDOUT, "\n");

    return(failsum ? 1 : 0);}

/***********************************************************************
* Function    : checkd(...)
* Programmer  : Carolyn Sharp
* Created     : November 18, 1991
* Revised     : November 25, 1991
*               Moved debug prints in. 
*
* Description : Checks return value of named double function of one 
*               argument against expected result.
*               Prints arguments and function if test fails.
*
* Returns     : 0|1 for PASS|FAIL
***********************************************************************/

checkd(dval, fcn_name, xxx, expected, pass)
   double dval;
   char *fcn_name;
   char xxx[MAX];
   double expected;
   int pass;
   {double d, tolerance;
    int fail;

    tolerance = 1.0e-13;
    d         = 0.5*ABS(dval - expected)/(ABS(dval) + ABS(expected));
    fail      = (d > tolerance);
    PRINT(STDOUT, "%s       \t%s     \t%11e  %11e\t %s \n",
	  xxx, fcn_name, dval, expected,
	  (fail ? "Fail" : " OK"));

    return(fail);}

/***********************************************************************
* Function    : checkl(...)
* Programmer  : Carolyn Sharp
* Created     : November 22, 1991
* Revised     : November 25, 1991
*               Moved debug prints in. 
*
* Description : Checks return value of named int function of two
*               arguments against expected result.
*               Prints arguments and function if test fails.
*
* Returns     : 0|1 for PASS|FAIL
***********************************************************************/

checkl(mval, fcn_name, xxx, lval, lexpected)
   long mval;
   char *fcn_name;
   char xxx[MAX];
   long lval;
   int lexpected;
   {int fail;

    fail = (mval != lval);
    PRINT(STDOUT, "%s\t%s     \t   %5ld\t %5d\t   %s\n",
	  xxx, fcn_name, mval, lexpected,
	  (fail ? "Fail" : " OK"));

    return(fail);}

/***********************************************************************/