DGtal  1.2.0
testMPolynomialReader.cpp
Go to the documentation of this file.
1 
31 #include <iostream>
32 #include <iomanip>
33 #include <sstream>
34 #include "DGtal/base/Common.h"
35 #include "DGtal/math/MPolynomial.h"
36 #include "DGtal/io/readers/MPolynomialReader.h"
38 
39 using namespace std;
40 using namespace DGtal;
41 
43 // Functions for testing class MPolynomialReader.
45 
47 {
48 
52 
53  typedef int Ring;
56  string s1 = "1.5 X_0^2 X_2^3 X_1^5 * (4 X_0^3 + X_1^2)^2";
57  //string s1 = "1.5 X_0^2 X_2^3 X_1^5";
58  string s2 = "2 X_0^2 X_2 X_1^5";
59  string s3 = s1 + " * " + s2;
60  string s4 = "(" + s2 + ")^4 * (" + s1 + ")^1 - 3 X_2^3";
61  string s5 = "x^3y+xz^3+y^3z+z^3+5z"; // Durchblick
62  string s6 = "(y^2+z^2-1)^2 +(x^2+y^2-1)^3"; // Crixxi
63  string s7 = "(y^2+z^2-1)^2 Abrahamovitch";
64  bool ok1 = reader.read( P, s1.begin(), s1.end() ) == s1.end();
65  trace.info() << "- Parsing " << s1 << " : " << ok1 << " " << P << std::endl;
66  bool ok2 = reader.read( P, s2.begin(), s2.end() ) == s2.end();
67  trace.info() << "- Parsing " << s2 << " : " << ok2 << " " << P << std::endl;
68  bool ok3 = reader.read( P, s3.begin(), s3.end() ) == s3.end();
69  trace.info() << "- Parsing " << s3 << " : " << ok3 << " " << P << std::endl;
70  bool ok4 = reader.read( P, s4.begin(), s4.end() ) == s4.end();
71  trace.info() << "- Parsing " << s4 << " : " << ok4 << " " << P << std::endl;
72  bool ok5 = reader.read( P, s5.begin(), s5.end() ) == s5.end();
73  trace.info() << "- Parsing " << s5 << " : " << ok5 << " " << P << std::endl;
74  bool ok6 = reader.read( P, s6.begin(), s6.end() ) == s6.end();
75  trace.info() << "- Parsing " << s6 << " : " << ok6 << " " << P << std::endl;
76  bool ok7 = reader.read( P, s7.begin(), s7.end() ) == s7.end();
77  trace.info() << "- Parsing " << s7 << " : " << ok7 << " " << P << std::endl;
78 
79  string s8 = "(zyx^2+x^2-1)^2 + xy AVERTY";
80  std::istringstream sin( s8 );
81  std::string other;
82  sin >> P >> other;
83  trace.info() << "- Read " << P << " and " << other << std::endl;
84 
85  return ok1 && ok2 && ok3 && ok4 && ok5 && ok6 && (!ok7);
86 }
87 
89 {
90 
91  typedef double Ring;
92  MPolynomial<3,Ring,std::allocator<Ring> > P1, P2, Q1, Q2, Q3, Q4;
94  string s1 = " x^4";
95  string s2 = "1*y^4";
96  string s3 = s1 + "+" + s2 + "-2";
97  string s4 = "(" + s1 + ")+(" + s2 + ")-2";
98  string s5 = "(" + s1 + ")+ " + s2 + " -2";
99  bool ok1 = reader.read( P1, s1.begin(), s1.end() ) == s1.end();
100  bool ok2 = reader.read( P2, s2.begin(), s2.end() ) == s2.end();
101  Q1 = P1 + P2 - 2;
102  bool ok3 = reader.read( Q2, s3.begin(), s3.end() ) == s3.end();
103  bool ok4 = reader.read( Q3, s4.begin(), s4.end() ) == s4.end();
104  bool ok4b= reader.read( Q4, s5.begin(), s5.end() ) == s5.end();
105 
106  trace.info() << "- Read Q1=" << Q1 << " from addition of monomials. " << std::endl;
107  trace.info() << "- Read Q2=" << Q2 << " from string: " << s3 << std::endl;
108  trace.info() << "- Read Q3=" << Q3 << " from string: " << s4 << std::endl;
109  trace.info() << "- Read Q4=" << Q4 << " from string: " << s5 << std::endl;
110  bool ok5 = Q1 == Q2;
111  bool ok6 = Q1 == Q3;
112  return ok1 && ok2 && ok3 && ok4 && ok5 && ok6 && ok4b;
113 }
115 // Standard services - public :
116 
117 int main( int /*argc*/, char** /*argv*/ )
118 {
119  trace.beginBlock ( "Testing class MPolynomialReader" );
120 
121  bool res = testMPolynomialReader()
123  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
124  trace.endBlock();
125  return res ? 0 : 1;
126 }
127 // //
Aim: This class converts a string polynomial expression in a multivariate polynomial.
Iterator read(Polynomial &p, Iterator begin, Iterator end)
Aim: Represents a multivariate polynomial, i.e. an element of , where K is some ring or field.
Definition: MPolynomial.h:955
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
int main(int, char **)
bool testMPolynomialReader()
bool testMPolynomialReader2()