source: git/factory/ftest/gcd.m4 @ a40e7b

spielwiese
Last change on this file since a40e7b was 47941c, checked in by Jens Schmidt <schmidt@…>, 26 years ago
* gcd.m4 (gcdCheck): error messages for checks added git-svn-id: file:///usr/local/Singular/svn/trunk@923 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.5 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2/* $Id: gcd.m4,v 1.6 1997-11-21 11:22:42 schmidt Exp $ */
3
4ftestSetNameOfGame( gcd, `"
5Usage: gcd [<options>] [<envSpec>] <f> <g> [<realResult>]
6  calculates greatest common divider of canonical forms f and g.
7  If the gcd of f and g is already known, the optional canonical
8  form realResult may be used to check the result of the gcd
9  computation.
10"'`' )
11
12//{{{ docu
13//
14// ftestAlgorithm.m4 - ftestAlgorithm test program.
15//
16// To create ftestAlgorithm.cc, run m4 using the ftest_util.m4 library in
17// the following way:
18//
19// m4 ftest_util.m4 ftestAlgorithm.m4 > ftestAlgorithm.cc
20//
21//}}}
22
23ftestPreprocInit();
24
25ftestGlobalInit();
26
27//
28// - functions.
29//
30
31//{{{ ftestStatusT gcdCheck ( const CanonicalForm & f, const CanonicalForm & g, const CanonicalForm & result, const CanonicalForm & realResult )
32//{{{ docu
33//
34// gcdCheck() - check result of gcd().
35//
36//}}}
37ftestStatusT
38gcdCheck ( const CanonicalForm & f, const CanonicalForm & g, const CanonicalForm & result, const CanonicalForm & realResult )
39{
40    // if realResult is given, use it to compare with result
41    if ( ! realResult.isZero() )
42        if ( realResult == result )
43            return Passed;
44        else if ( -realResult == result )
45            return Passed;
46        else {
47            ftestError( CheckError, "result and real result differ\n" );
48            return Failed;
49        }
50
51    if ( result.isZero() )
52        if ( f.isZero() && g.isZero() )
53            return Passed;
54        else {
55            ftestError( CheckError, "result is zero but f and g are not\n" );
56            return Failed;
57        }
58
59    if ( divides( result, f ) && divides( result, g ) )
60        if ( gcd( f/result, g/result ).isOne() )
61            return Passed;
62        else {
63            ftestError( CheckError, "result is not greatest common divisor\n" );
64            return Failed;
65        }
66    else {
67        ftestError( CheckError, "result is not a common divisor\n" );
68        return Failed;
69    }
70}
71//}}}
72
73//
74// - main program.
75//
76int
77main ( int argc, char ** argv )
78{
79    // initialization
80    ftestMainInit();
81
82    // declare input and output variables
83    ftestOutVar( CanonicalForm, result );
84    ftestInVar( CanonicalForm, f );
85    ftestInVar( CanonicalForm, g );
86    ftestInVar( CanonicalForm, realResult );
87
88    // process argument list and set environment
89    ftestGetOpts();
90    ftestGetEnv();
91    ftestGetInVar( f );
92    ftestGetInVar( g );
93    ftestGetInVar( realResult, 0 );
94
95    // do the test!
96    ftestRun(
97        result = gcd( f, g ); );
98
99    // do the check
100    ftestCheck(
101        gcdCheck( f, g, result, realResult ) );
102
103    // print results
104    ftestOutput( "gcd(f, g)", result );
105
106    // clean up
107    ftestMainExit();
108}
Note: See TracBrowser for help on using the repository browser.