~ubuntu-branches/ubuntu/saucy/gfan/saucy-proposed

« back to all changes in this revision

Viewing changes to app_test.cpp

  • Committer: Package Import Robot
  • Author(s): Cédric Boutillier
  • Date: 2013-07-09 10:44:01 UTC
  • mfrom: (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130709104401-5q66ozz5j5af0dak
Tags: 0.5+dfsg-3
* Upload to unstable.
* modify remove_failing_tests_on_32bits.patch to replace command of
  0009RenderStairCase test with an empty one instead of deleting it.
* remove lintian override about spelling error

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <iostream>
 
2
#include <stdlib.h>
1
3
#include "parser.h"
2
4
#include "printer.h"
3
5
#include "polynomial.h"
14
16
#include "saturation.h"
15
17
#include "field_rationals.h"
16
18
#include "field_zmodpz.h"
 
19
#include "field_rationalfunctions.h"
 
20
#include "symmetry.h"
 
21
#include "linalg.h"
 
22
#include "fieldlp.h"
17
23
 
18
24
class TestApplication : public GFanApplication
19
25
{
20
 
  FieldOption theFieldOption;
 
26
  StringOption testSuiteFolderOption;
 
27
  StringOption executableOption;
21
28
public:
22
29
  bool includeInDefaultInstallation()
23
30
  {
25
32
  }
26
33
  const char *helpText()
27
34
  {
28
 
    return "This\n";
 
35
    return "This runs the test suite and checks against the stored result. If no result exists, it is generated.\n";
29
36
  }
30
 
  TestApplication()
 
37
  TestApplication():
 
38
        testSuiteFolderOption("--suite","Specify the folder which contains the test suite.","testsuite"),
 
39
        executableOption("--gfan","Specify name of gfan executable to test.","./gfan")
31
40
  {
32
41
    registerOptions();
33
42
  }
34
43
 
35
 
  char *name()
 
44
  const char *name()
36
45
  {
37
46
    return "_test";
38
47
  }
39
48
 
40
 
  Field test(Field &a)
41
 
  {
42
 
    return a;
43
 
  }
44
 
 
45
 
  FieldElement test2()
46
 
  {
47
 
    FieldZModPZ f(3);
48
 
    return f.zHomomorphism(1);
49
 
  }
50
 
 
51
 
  FieldElement test3(FieldElement &a)
52
 
  {
53
 
    return a.one();
54
 
  }
55
 
    
 
49
  void lpRationalFunctionTest()
 
50
  {
 
51
    //int n=3;
 
52
        //     IntegerVectorList L=StringParser("{(1,0,2),(1,2,0)}").parseIntegerVectorList();
 
53
    //  IntegerVectorList L=StringParser("{(1,2,0)}").parseIntegerVectorList();
 
54
 
 
55
    //     int n=4;
 
56
    //  IntegerVectorList L=StringParser("{(1,0,2,3),(1,2,3,0)}").parseIntegerVectorList();
 
57
 
 
58
    /*     int n=16;
 
59
     IntegerVectorList L=StringParser("{(1,0,2,3,5,4,6,7,9,8,10,11,13,12,14,15),"
 
60
                                      "(3,0,1,2,7,4,5,6,11,8,9,10,15,12,13,14),"
 
61
                                      "(0,4,8,12,1,5,9,13,2,6,10,14,3,7,11,15)}").parseIntegerVectorList();
 
62
    */
 
63
    int n=9;
 
64
     IntegerVectorList L=StringParser("{(1,0,2,4,3,5,7,6,8),"
 
65
                                      "(1,2,0,4,5,3,7,8,6),"
 
66
                                      "(3,4,5,0,1,2,6,7,8),"
 
67
                                      "(3,4,5,6,7,8,0,1,2)"
 
68
                                      "}").parseIntegerVectorList();
 
69
     /*
 
70
    int n=9;
 
71
     IntegerVectorList L=StringParser("{(1,0,2,4,3,5,7,6,8),"
 
72
                                      "(1,2,0,4,5,3,7,8,6),"
 
73
                                      "(0,3,6,1,4,7,2,5,8)}").parseIntegerVectorList();
 
74
     */
 
75
 
 
76
    SymmetryGroup s(n);
 
77
    s.computeClosure(L);
 
78
 
 
79
    FieldRationalFunctions F(Q,"t");
 
80
    FieldMatrix M(F,s.elements.size(),n);
 
81
    int I=0;
 
82
    for(SymmetryGroup::ElementContainer::const_iterator i=s.elements.begin();i!=s.elements.end();i++,I++)
 
83
      {
 
84
        for(int j=0;j<n;j++)
 
85
          {
 
86
            M[I][j]=M[I][j]+F.exponent(j);
 
87
            M[I][j]=M[I][j]-F.exponent(((SymmetryGroup::inverse(*i))[j]));
 
88
          }
 
89
      }
 
90
    AsciiPrinter P(Stderr);
 
91
    //    M.printMatrix(P);
 
92
 
 
93
 
 
94
    FieldMatrix M2(Q,M.getHeight(),M.getWidth());
 
95
    for(int i=0;i<M.getHeight();i++)
 
96
      for(int j=0;j<M.getWidth();j++)
 
97
        M2[i][j]=F.substitute(M[i][j],Q.zHomomorphism(10000).inverse());
 
98
 
 
99
        Field &myField=F;
 
100
        {
 
101
      M=M2;
 
102
      myField=Q;//HERE
 
103
      }
 
104
    IntegerVectorList extreme;
 
105
 
 
106
    M.printMatrix(P);
 
107
 
 
108
 
 
109
    I=0;
 
110
    FieldElement minusOne=myField.zHomomorphism(-1);//HERE
 
111
    for(SymmetryGroup::ElementContainer::const_iterator i=s.elements.begin();i!=s.elements.end();i++,I++)
 
112
      //    for(int i=0;i<s.elements.size();i++)
 
113
      {
 
114
        fprintf(Stderr,"IIII:%i\n",I);
 
115
        M[I]=minusOne*M[I];
 
116
        FieldVector b(myField,s.elements.size());//HERE
 
117
        b[I]=minusOne;
 
118
        FieldLP lp(M,b);
 
119
        FieldLP lp2=lp.withNoLineality();
 
120
 
 
121
        AsciiPrinter P(Stderr);
 
122
        //lp2.print(P);
 
123
 
 
124
        //      cerr <<"Result" << lp2.findFeasibleBasis()<<endl;
 
125
 
 
126
        if(lp2.findFeasibleBasis())
 
127
          extreme.push_back(*i);
 
128
 
 
129
        M[I]=minusOne*M[I];
 
130
      }
 
131
    fprintf(Stdout,"Extreme permutations (%i):\n",extreme.size());
 
132
    P.printVectorList(extreme);
 
133
  }
 
134
 
 
135
 
 
136
  class TestCase
 
137
  {
 
138
  public:
 
139
          string folder;
 
140
          TestCase(string const &folder_):
 
141
                  folder(folder_)
 
142
                  {
 
143
 
 
144
                  }
 
145
          void fail()
 
146
          {
 
147
                  cerr<<"Test failed:"<<folder<<endl;
 
148
                  assert(0);
 
149
          }
 
150
          void compare(string a, string b)
 
151
          {
 
152
                  FILE *A=fopen(a.c_str(),"r");
 
153
                  FILE *B=fopen(b.c_str(),"r");
 
154
                  assert(A);
 
155
                  assert(B);
 
156
                  while((!feof(A))&&(!feof(B)))
 
157
                  {
 
158
                          if(fgetc(A)!=fgetc(B))fail();
 
159
                  }
 
160
                  if(feof(A)!=feof(B))fail();
 
161
          }
 
162
          bool fileExists(string name)
 
163
          {
 
164
                  FILE *f=fopen(name.c_str(),"r");
 
165
                  if(f)fclose(f);
 
166
                  return f;
 
167
          }
 
168
          /*
 
169
           * Returns true if test was successful.
 
170
           * Returns false if test was performed for the first time.
 
171
           * Asserts if test fails
 
172
           */
 
173
          bool perform(const char *exe)
 
174
          {
 
175
                  string fileName=folder+"/command";
 
176
                  FILE *f=fopen(fileName.c_str(),"r");
 
177
                  if(!f)
 
178
                  {
 
179
                          cerr<<"Could not open file:\""<<fileName<<"\""<<endl;
 
180
                          assert(f);
 
181
                  }
 
182
                  char command[4096];
 
183
                  char *temp=fgets(command,4095,f);
 
184
                  fclose(f);
 
185
                  assert(temp);
 
186
                  for(int i=0;i<4096 && command[i];i++)if(command[i]=='\n'){command[i]=0;}
 
187
                  char command2[4096];
 
188
                  string input=folder+"/input";
 
189
                  sprintf(command2,command,exe,exe,exe,exe);
 
190
                  bool outputExists=fileExists(folder+"/output");
 
191
                  string outputName=folder+"/output";
 
192
                  if(outputExists)
 
193
                  {
 
194
                          outputName=outputName+"New";
 
195
                  }
 
196
                  {
 
197
                          string t="rm "+outputName;
 
198
                          system(t.c_str());
 
199
                  }
 
200
                  string command3="cat <"+input+"|"+string(command2)+">"+outputName;
 
201
                  cerr<<"Running command:\""<<command3<<"\""<<endl;
 
202
                  system(command3.c_str());
 
203
                  if(outputExists)compare(folder+"/output",folder+"/outputNew");
 
204
                  return outputExists;
 
205
          }
 
206
  };
 
207
 
 
208
  list<string> subFolderNames()
 
209
  {
 
210
#define tempName "GfAnTeMpTeStS"
 
211
          char command[256];
 
212
          system("rm "tempName);
 
213
          sprintf(command,"ls %s>" tempName ,testSuiteFolderOption.getValue());
 
214
          system(command);
 
215
 
 
216
          list<string> ret;
 
217
          FILE *f=fopen(tempName,"r");
 
218
          assert(f);
 
219
          char name[256];
 
220
          while(fgets(name,255,f))
 
221
          {
 
222
                  for(int i=0;i<255 && name[i];i++)if(name[i]=='\n'){name[i]=0;}
 
223
                  if(name[0]>='0' && name[0]<='9')ret.push_back(string(testSuiteFolderOption.getValue())+"/"+string(name));
 
224
          }
 
225
          fclose(f);
 
226
          return ret;
 
227
  }
 
228
 
56
229
  int main()
57
230
  {
58
 
    FieldElement a=Q.zHomomorphism(2);
59
 
    FieldElement b=Q.zHomomorphism(3);
60
 
 
61
 
    FieldElement c=Q.zHomomorphism(3);
62
 
    c=a*b;
63
 
 
64
 
    Field QQ(Q);
65
 
    QQ=Q;
66
 
    QQ=QQ;
67
 
    QQ=test(Q);
68
 
    QQ=test(Q);
69
 
 
70
 
    c=c;
71
 
    c=test3(c);
72
 
 
73
 
    PolynomialRing R=StringParser("Q[a]").parsePolynomialRing();
74
 
    //    Term s=StringParser("a").parseTerm(R);
75
 
 
76
 
    FieldElement k(R.getField());
77
 
    //    k=R.getField().zHomomorphism(1);
78
 
    
79
 
    /*
80
 
{
81
 
    {
82
 
      FieldElement k(r.getField());
83
 
      k=r.getField().zHomomorphism(1);
84
 
      Monomial m=parseMonomial(r);
85
 
      return Term(k,m);
86
 
    }
87
 
}
88
 
 
89
 
    */
90
 
 
91
 
 
92
 
    //    Polynomial s2=s;
93
 
 
94
 
    FieldElement e=test2();
95
 
    
96
 
 
97
 
 
98
 
    AsciiPrinter(Stdout).printFieldElement(e);
99
 
 
100
 
    //  fprintf(Stderr,"Number of living FieldImplementations:%i\n",FieldImplementation::getNumberOfLivingFieldImplementations());
101
 
 
102
 
    AsciiPrinter(Stdout).printField(e.getField());
103
 
    //    AsciiPrinter(Stdout).printFieldElement(c);
104
 
    /*    PolynomialSet g=FileParser(Stdin).parsePolynomialSetWithRing();
105
 
 
106
 
    AsciiPrinter(Stdout).printPolynomialSet(nonHomogeneousSaturation(g));
107
 
    */
108
 
 
109
 
 
110
 
    //    Field FF=c.getField();
111
 
 
112
 
    return 0;
 
231
//    lpRationalFunctionTest();
 
232
//    testRationalFunctionField();
 
233
 
 
234
          list<string> testFolders=subFolderNames();
 
235
          list<TestCase> testList;
 
236
          for(list<string>::const_iterator i=testFolders.begin();i!=testFolders.end();i++)
 
237
          {
 
238
                  testList.push_back(TestCase(*i));
 
239
          }
 
240
 
 
241
          cout<<"Number of tests to perform "<<testList.size()<<endl;
 
242
 
 
243
          int good=0;
 
244
          int bad=0;
 
245
          for(list<TestCase>::iterator i=testList.begin();i!=testList.end();i++)
 
246
                  if(i->perform(executableOption.getValue()))
 
247
                          good++;
 
248
                  else
 
249
                          bad++;
 
250
          cout<<"Number of successful tests "<<good<<endl;
 
251
          cout<<"Number of initialized tests "<<bad<<endl;
 
252
 
 
253
          return 0;
113
254
  }
114
255
};
115
256
 
116
257
static TestApplication theApplication;
117