DGtal 1.4.0
Loading...
Searching...
No Matches
testMPolynomialReader.cpp File Reference
#include <iostream>
#include <iomanip>
#include <sstream>
#include "DGtal/base/Common.h"
#include "DGtal/math/MPolynomial.h"
#include "DGtal/io/readers/MPolynomialReader.h"
Include dependency graph for testMPolynomialReader.cpp:

Go to the source code of this file.

Functions

bool testMPolynomialReader ()
 
bool testMPolynomialReader2 ()
 
int main (int, char **)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
Date
2012/02/12

Functions for testing class Signal.

This file is part of the DGtal library.

Definition in file testMPolynomialReader.cpp.

Function Documentation

◆ main()

int main ( int ,
char **  )

Definition at line 117 of file testMPolynomialReader.cpp.

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}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
double endBlock()
Trace trace
Definition Common.h:153
bool testMPolynomialReader()
bool testMPolynomialReader2()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), testMPolynomialReader(), testMPolynomialReader2(), and DGtal::trace.

◆ testMPolynomialReader()

bool testMPolynomialReader ( )

Definition at line 46 of file testMPolynomialReader.cpp.

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}
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.
std::ostream & info()

References DGtal::Trace::info(), DGtal::MPolynomialReader< n, TRing, TAlloc, TIterator >::read(), and DGtal::trace.

Referenced by main().

◆ testMPolynomialReader2()

bool testMPolynomialReader2 ( )

Definition at line 88 of file testMPolynomialReader.cpp.

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}

References DGtal::Trace::info(), DGtal::MPolynomialReader< n, TRing, TAlloc, TIterator >::read(), and DGtal::trace.

Referenced by main().