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

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