DGtal 1.4.0
Loading...
Searching...
No Matches
testPattern.cpp File Reference
#include <cstdlib>
#include <iostream>
#include <map>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/CPointPredicate.h"
#include "DGtal/arithmetic/IntegerComputer.h"
#include "DGtal/arithmetic/SternBrocot.h"
#include "DGtal/arithmetic/LightSternBrocot.h"
#include "DGtal/arithmetic/LighterSternBrocot.h"
#include "DGtal/arithmetic/Pattern.h"
#include <boost/version.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_smallint.hpp>
#include <boost/random/variate_generator.hpp>
Include dependency graph for testPattern.cpp:

Go to the source code of this file.

Functions

template<typename Fraction1 , typename Fraction2 >
bool testPattern (Fraction1 f1)
 
template<typename Fraction1 , typename Fraction2 >
bool testPatterns ()
 
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 5127), University of Savoie, France
Date
2012/03/05

Functions for testing class LightSternBrocot.

This file is part of the DGtal library.

Definition in file testPattern.cpp.

Function Documentation

◆ main()

int main ( int ,
char **  )

Definition at line 130 of file testPattern.cpp.

131{
135 typedef SB::Fraction Fraction;
136 typedef LSB::Fraction LFraction;
137 typedef LLSB::Fraction LLFraction;
138 trace.beginBlock ( "Testing class Pattern" );
142 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
143 trace.endBlock();
144
145 return res ? 0 : 1;
146}
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it pr...
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it pr...
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it pr...
Definition SternBrocot.h:78
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
double endBlock()
Trace trace
Definition Common.h:153
bool testPatterns()

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

◆ testPattern()

template<typename Fraction1 , typename Fraction2 >
bool testPattern ( Fraction1 f1)

Definition at line 57 of file testPattern.cpp.

58{
59 typedef Pattern<Fraction1> Pattern1;
60 typedef Pattern<Fraction2> Pattern2;
61 Fraction2 f2( f1.p(), f1.q() );
62
63 std::cerr << " f1 =";
64 f1.selfDisplay( std::cerr );
65 std::cerr << std::endl;
66 std::cerr << "r(1)=";
67 f1.reduced(1).selfDisplay( std::cerr );
68 std::cerr << std::endl;
69 std::cerr << "r(2)=";
70 f1.reduced(2).selfDisplay( std::cerr );
71 std::cerr << std::endl;
72
73 Pattern1 p1( f1 );
74 Pattern2 p2( f2 );
75 std::cerr << "p1=" << p1.rE() << std::endl;
76 std::cerr << "p2=" << p2.rE() << std::endl;
77 std::cerr << "p1=" << p1.rEs( "(|)" ) << std::endl;
78 std::cerr << "p2=" << p2.rEs( "(|)" ) << std::endl;
79 return p1.rE() == p2.rE();
80}
Aim: This class represents a pattern, i.e. the path between two consecutive upper leaning points on a...
Definition Pattern.h:79

◆ testPatterns()

template<typename Fraction1 , typename Fraction2 >
bool testPatterns ( )

Definition at line 84 of file testPattern.cpp.

85{
86 unsigned int nbtests = 100;
87 unsigned int nb = 0;
88 unsigned int nbok = 0;
89 Fraction1 f1;
90 f1 = Fraction1( 5, 8 );
91 ++nb;
92 nbok += testPattern<Fraction1,Fraction2>( f1 ) ? 1 : 0;
93 std::cerr << "(" << nbok << "/" << nb << ") f1=";
94 f1.selfDisplay( std::cerr );
95 std::cerr << endl;
96 f1 = Fraction1( 31, 24 );
97 ++nb;
98 nbok += testPattern<Fraction1,Fraction2>( f1 ) ? 1 : 0;
99 std::cerr << "(" << nbok << "/" << nb << ") f1=";
100 f1.selfDisplay( std::cerr );
101 std::cerr << endl;
102 f1 = Fraction1( 5, 13 );
103 ++nb;
104 nbok += testPattern<Fraction1,Fraction2>( f1 ) ? 1 : 0;
105 std::cerr << "(" << nbok << "/" << nb << ") f1=";
106 f1.selfDisplay( std::cerr );
107 std::cerr << endl;
109
110 for ( unsigned int i = 0; i < nbtests; ++i )
111 {
112 unsigned int p = 1 + std::rand() % 999;
113 unsigned int q = 1 + std::rand() % 999;
114 unsigned int g = ic.gcd( p, q );
115 p /= g; q /= g;
116 std::cerr << "*- p / q = " << p << "/" << q << std::endl;
117 f1 = Fraction1( p, q );
118 ++nb;
119 nbok += testPattern<Fraction1,Fraction2>( f1 ) ? 1 : 0;
120 std::cerr << "(" << nbok << "/" << nb << ") f1=";
121 f1.selfDisplay( std::cerr );
122 std::cerr << endl;
123 }
124 return nbok == nb;
125}
Aim: This class gathers several types and methods to make computation with integers.
Integer gcd(IntegerParamType a, IntegerParamType b) const
bool testPattern()

References DGtal::IntegerComputer< TInteger >::gcd(), and testPattern().

Referenced by main().