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

spielwiese
Last change on this file since 341696 was 341696, checked in by Hans Schönemann <hannes@…>, 14 years ago
Adding Id property to all files git-svn-id: file:///usr/local/Singular/svn/trunk@12231 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.9 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2/* $Id$ */
3
4ftestSetNameOfGame( gcd, `"
5Usage: gcd [<options>] [<envSpec>] <f> <g> [<realResult>]
6  calculates greatest common divisor of canonical forms <f> and
7  <g>.  If the gcd of <f> and <g> is already known, the optional
8  canonical form <realResult> may be used to check the result of
9  the gcd 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//{{{ static CanonicalForm normalizeGcd ( const CanonicalForm & f )
32//{{{ docu
33//
34// normalizeGcd() - normalize result of gcd computation for
35//   testing.
36//
37// Unit normalization is done in case of a field, sign
38// normalization otherwise.
39//
40//}}}
41static CanonicalForm
42normalizeGcd ( const CanonicalForm & f )
43{
44    if ( getCharacteristic() > 0 || isOn( SW_RATIONAL ) )
45        return f/Lc( f );
46    else
47        return abs( f );
48}
49//}}}
50
51//{{{ ftestStatusT gcdCheck ( const CanonicalForm & f, const CanonicalForm & g, const CanonicalForm & result, const CanonicalForm & realResult )
52//{{{ docu
53//
54// gcdCheck() - check result of gcd().
55//
56//}}}
57ftestStatusT
58gcdCheck ( const CanonicalForm & f, const CanonicalForm & g, const CanonicalForm & result, const CanonicalForm & realResult )
59{
60    // if realResult is given, use it to compare with result
61    if ( ! realResult.isZero() )
62        if ( normalizeGcd( realResult ) == normalizeGcd( result ) )
63            return Passed;
64        else {
65            ftestError( CheckError, "result and real result differ\n" );
66            return Failed;
67        }
68
69    if ( result.isZero() )
70        if ( f.isZero() && g.isZero() )
71            return Passed;
72        else {
73            ftestError( CheckError, "result is zero but f and g are not\n" );
74            return Failed;
75        }
76
77    if ( ! divides( result, f ) || ! divides( result, g ) ) {
78        ftestError( CheckError, "result is not a common divisor\n" );
79        return Failed;
80    } else if ( ! gcd( f/result, g/result ).isOne() ) {
81        ftestError( CheckError, "result is not greatest common divisor\n" );
82        return Failed;
83    } else
84        return Passed;
85}
86//}}}
87
88//
89// - main program.
90//
91int
92main ( int argc, char ** argv )
93{
94    // initialization
95    ftestMainInit();
96
97    // declare input and output variables
98    ftestOutVar( CanonicalForm, result );
99    ftestInVar( CanonicalForm, f );
100    ftestInVar( CanonicalForm, g );
101    ftestInVar( CanonicalForm, realResult );
102
103    // process argument list and set environment
104    ftestGetOpts();
105    ftestGetEnv();
106    ftestGetInVar( f );
107    ftestGetInVar( g );
108    ftestGetInVar( realResult, 0 );
109
110    // do the test!
111    ftestRun( result = gcd( f, g ); );
112
113    // do the check
114    ftestCheck( gcdCheck( f, g, result, realResult ) );
115
116    // print results
117    ftestOutput( "gcd(f, g)", result );
118
119    // clean up
120    ftestMainExit();
121}
Note: See TracBrowser for help on using the repository browser.