source: git/factory/ftest/bgcd.m4 @ b1dfaf

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