1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | /* $Id: gcd.m4,v 1.3 1997-09-29 13:00:17 schmidt Exp $ */ |
---|
3 | |
---|
4 | ftestSetNameOfGame( gcd, |
---|
5 | `"Usage: gcd [<options>] [<envSpec>] <f> <g> [<realResult>]\n" |
---|
6 | " calculates greatest common divider of canonical forms f and g.\n" |
---|
7 | " If the gcd of f and g is already known, the optional canonical\n" |
---|
8 | " form <realResult> may be used to check the result of the gcd\n" |
---|
9 | " computation.\n"' ) |
---|
10 | |
---|
11 | //{{{ docu |
---|
12 | // |
---|
13 | // ftestAlgorithm.m4 - ftestAlgorithm test program. |
---|
14 | // |
---|
15 | // To create ftestAlgorithm.cc, run m4 using the ftest_util.m4 library in |
---|
16 | // the following way: |
---|
17 | // |
---|
18 | // m4 ftest_util.m4 ftestAlgorithm.m4 > ftestAlgorithm.cc' |
---|
19 | // |
---|
20 | //}}} |
---|
21 | |
---|
22 | ftestPreprocInit(); |
---|
23 | |
---|
24 | ftestGlobalInit(); |
---|
25 | |
---|
26 | // |
---|
27 | // - functions. |
---|
28 | // |
---|
29 | |
---|
30 | //{{{ ftestStatusT gcdCheck ( const CanonicalForm & f, const CanonicalForm & g, const CanonicalForm & result, const CanonicalForm & realResult ) |
---|
31 | //{{{ docu |
---|
32 | // |
---|
33 | // gcdCheck() - check result of gcd(). |
---|
34 | // |
---|
35 | //}}} |
---|
36 | ftestStatusT |
---|
37 | gcdCheck ( const CanonicalForm & f, const CanonicalForm & g, const CanonicalForm & result, const CanonicalForm & realResult ) |
---|
38 | { |
---|
39 | // if realResult is given, use it to compare with result |
---|
40 | if ( ! realResult.isZero() ) |
---|
41 | if ( realResult == result ) |
---|
42 | return Passed; |
---|
43 | else if ( -realResult == result ) |
---|
44 | return Passed; |
---|
45 | else |
---|
46 | return Failed; |
---|
47 | |
---|
48 | if ( result.isZero() ) |
---|
49 | if ( f.isZero() && g.isZero() ) |
---|
50 | return Passed; |
---|
51 | else |
---|
52 | return Failed; |
---|
53 | |
---|
54 | if ( divides( result, f ) && divides( result, g ) ) |
---|
55 | if ( gcd( f/result, g/result ).isOne() ) |
---|
56 | return Passed; |
---|
57 | else |
---|
58 | return Failed; |
---|
59 | else |
---|
60 | return Failed; |
---|
61 | } |
---|
62 | //}}} |
---|
63 | |
---|
64 | // |
---|
65 | // - main program. |
---|
66 | // |
---|
67 | int |
---|
68 | main ( int argc, char ** argv ) |
---|
69 | { |
---|
70 | // initialization |
---|
71 | ftestMainInit(); |
---|
72 | |
---|
73 | // declare input and output variables |
---|
74 | ftestOutVar( CanonicalForm, result ); |
---|
75 | ftestInVar( CanonicalForm, f ); |
---|
76 | ftestInVar( CanonicalForm, g ); |
---|
77 | ftestInVar( CanonicalForm, realResult ); |
---|
78 | |
---|
79 | // process argument list and set environment |
---|
80 | ftestGetOpts(); |
---|
81 | ftestGetEnv(); |
---|
82 | ftestGetInVar( f ); |
---|
83 | ftestGetInVar( g ); |
---|
84 | ftestGetInVar( realResult, 0 ); |
---|
85 | |
---|
86 | // do the test! |
---|
87 | ftestRun( |
---|
88 | result = gcd( f, g ); ); |
---|
89 | |
---|
90 | // do the check |
---|
91 | ftestCheck( gcdCheck( f, g, result, realResult ) ); |
---|
92 | |
---|
93 | // print results |
---|
94 | ftestOutput( "gcd(f, g)", result ); |
---|
95 | |
---|
96 | // clean up |
---|
97 | ftestMainExit(); |
---|
98 | } |
---|