source: git/standalone.test/test.cc @ dc4782

spielwiese
Last change on this file since dc4782 was dc4782, checked in by Hans Schoenemann <hannes@…>, 10 years ago
chg: factory/libfac is not optional, removing HAVE_FACTORY/HAVE_LIBFAC
  • Property mode set to 100644
File size: 3.1 KB
Line 
1#include <omalloc/omalloc.h>
2#include <misc/auxiliary.h>
3
4#include <coeffs/coeffs.h>
5#include <coeffs/numbers.h>
6
7#include <reporter/reporter.h>
8#include <resources/feResource.h>
9
10// int initializeGMP(){ return 1; }
11int mmInit(void) {return 1; }
12
13#include <polys/monomials/ring.h>
14#include <polys/monomials/p_polys.h>
15
16
17BOOLEAN Test(const n_coeffType type, void* param)
18{
19  BOOLEAN ret = TRUE;
20
21  const coeffs r = nInitChar( type, param );
22
23  if( r == NULL )
24  {
25    PrintS( "Test: could not get this coeff. domain" ); PrintLn();
26    return FALSE;
27  }
28
29  assume( r->cfCoeffWrite != NULLp );
30
31  if( r->cfCoeffWrite != NULL )
32  {
33    PrintS( "Coeff-domain: " ); n_CoeffWrite(r); PrintLn();
34  }
35
36  number t = n_Init(1, r);
37  ndInpAdd(t, t, r);
38
39  number two = n_Init(2, r);
40  assume(n_Equal(two, t, r));
41  ret = ret && n_Equal(two, t, r);
42  n_Delete(&t, r);
43  n_Delete(&two, r);
44
45
46  const int N = 2; // number of vars
47  char* n[N] = {"x", "y"}; // teir names
48
49  ring R = rDefault( r, N, n);  // now r belongs to R!
50
51  if( R == NULL )
52  {
53    PrintS( "Test: could not get a polynomial ring over this coeff. domain" ); PrintLn();
54    nKillChar( r );
55    return FALSE;
56  }
57
58
59  rWrite(R); PrintLn();
60  #define RDEBUG
61  #ifdef  RDEBUG
62//    rDebugPrint(R); PrintLn();
63  #endif
64
65  const int exp[N] = {5, 8};
66
67  poly p = p_ISet(1, R);
68  assume( p != NULL );
69  assume(pNext(p) == NULL);
70  ret = ret && (pNext(p) == NULL);
71
72  p_SetExp(p,1,exp[0],R);
73  p_SetExp(p,2,exp[1],R);
74  p_Setm(p, R);
75
76  assume( p_GetExp(p, 1, R) == exp[0] );
77  assume( p_GetExp(p, 2, R) == exp[1] );
78
79  p = p_Add_q(p_Copy(p, R), p, R);
80
81  ret = ret && p_EqualPolys(p, p, R);
82
83
84  poly p2 = p_ISet(2, R);
85  assume( p2 != NULL );
86  assume(pNext(p2) == NULL);
87  ret = ret && (pNext(p2) == NULL);
88
89  p_SetExp(p2,1,exp[0],R);
90  p_SetExp(p2,2,exp[1],R);
91  p_Setm(p, R);
92
93  assume( p_GetExp(p2, 1, R) == exp[0] );
94  assume( p_GetExp(p2, 2, R) == exp[1] );
95
96  number s = p_GetCoeff(p, R);
97  two = n_Init(2, r);
98  assume(n_Equal(two, s, r));
99  ret = ret && n_Equal(s, two, r);
100  n_Delete(&two, r);
101
102  assume(p_EqualPolys(p2, p, R));
103  ret = ret && p_EqualPolys(p, p, R);
104
105  p_Delete(&p, R);
106
107  p_Delete(&p2, R);
108
109
110  rDelete(R);
111
112  return ret;
113}
114
115
116BOOLEAN simple(const n_coeffType _type, void* param = NULLp)
117{
118//  n_coeffType type = nRegister( _type, p);
119//  assume( type == _type ); // ?
120  return ( Test(_type, param) );
121}
122
123
124
125int main( int, char *argv[] )
126{
127  feInitResources(argv[0]);
128
129  StringSetS("ressources in use (as reported by feStringAppendResources(0):\n");
130  feStringAppendResources(0);
131  { StringAppendS("\n"); char* s = StringEndS(); PrintS(s); omFree(s); }
132  // longrat
133  if( simple(n_Q) )
134    PrintS("Q: Test Passed!");
135  else
136    PrintS("Q: Test: Failed!");
137  PrintLn();
138
139  // modulop
140  if( simple(n_Zp, (void*)7) )
141    PrintS("Zp: Test Passed!");
142  else
143    PrintS("Zp: Test: Failed!");
144  PrintLn();
145
146  // due to coeffs/ffields.h
147  struct
148  {
149    int GFChar;
150    int GFDegree;
151    char* GFPar_name;
152  } param;
153
154  param.GFChar= 5;
155  param.GFDegree= 2;
156  param.GFPar_name= (const char*)"Q";
157
158  if( simple(n_GF, (void*)&param) )
159    PrintS("GF: Test Passed!");
160  else
161    PrintS("GF: Test: Failed!");
162  PrintLn();
163
164  return 0;
165}
Note: See TracBrowser for help on using the repository browser.