DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testMetrics.cpp
1 
30 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/geometry/volumes/distance/SeparableMetricHelper.h"
36 
37 using namespace std;
38 using namespace DGtal;
39 
41 // Functions for testing class Metrics.
43 bool testMetrics()
44 {
45  unsigned int nbok = 0;
46  unsigned int nb = 0;
47 
48  trace.beginBlock ( "Testing separable metrics ..." );
49 
50  Z2i::Point a( 0,0), b(5, 0), bb(5,-10), bbb(5,5),c(10,0);
51  Z2i::Point starting( 0, 5), endpoint(10,5);
52 
54 
55  trace.info()<< "a= "<<a<<std::endl;
56  trace.info()<< "b= "<<b<<std::endl;
57  trace.info()<< "bb= "<<bb<<std::endl;
58  trace.info()<< "bbb= "<<bbb<<std::endl;
59  trace.info()<< "c= "<<c<<std::endl;
60 
61 
62  bool hidden =metric.hiddenBy(a,b,c,starting,endpoint,0);
63  nbok += (!hidden) ? 1 : 0;
64  nb++;
65  trace.info() << "(" << nbok << "/" << nb << ") "
66  << "(a,b,c) returns false" << std::endl;
67 
68  hidden =metric.hiddenBy(a,bb,c,starting,endpoint,0);
69  nbok += (hidden) ? 1 : 0;
70  nb++;
71  trace.info() << "(" << nbok << "/" << nb << ") "
72  << "(a,bb,c) returns true" << std::endl;
73 
74  hidden =metric.hiddenBy(a,bbb,c,starting,endpoint,0);
75  nbok += (!hidden) ? 1 : 0;
76  nb++;
77  trace.info() << "(" << nbok << "/" << nb << ") "
78  << "(a,bbb,c) returns false" << std::endl;
79 
80  trace.endBlock();
81 
82  return nbok == nb;
83 }
84 
86 // Standard services - public :
87 
88 int main( int argc, char** argv )
89 {
90  trace.beginBlock ( "Testing class Metrics" );
91  trace.info() << "Args:";
92  for ( int i = 0; i < argc; ++i )
93  trace.info() << " " << argv[ i ];
94  trace.info() << endl;
95 
96  bool res = testMetrics(); // && ... other tests
97  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
98  trace.endBlock();
99  return res ? 0 : 1;
100 }
101 // //