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

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