Main Page   Namespace List   Class Hierarchy   Compound List   File List   Header Files   Sources   Namespace Members   Compound Members   File Members  

test_distance_constraint.cpp

00001 //$Header: /home/ben/Mapper/c++/test/RCS/test_distance_constraint.cpp,v 6.4 2002/06/23 12:38:16 ben Exp $
00002 //Unit tests of Mapper distance_constraint classes.
00003 // Copyright Benedict Adamson 2002.
00004 // This file is part of Mapper.
00005 
00006 // Mapper is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 2 of the License, or
00009 // (at your option) any later version.
00010 
00011 // Mapper is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // You should have received a copy of the GNU General Public License
00017 // along with Mapper; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00030 #include <cmath>
00031 
00032 #include "distance_constraint.h"
00033 #include "test/constraints.h"
00034 #include "test/test.h"
00035 #include "through_constraint.h"
00036 
00037 
00038 
00039 void test::test_distance_constraint(void)
00040 {
00041    test_start_section("distance_constraint");
00042    {
00043       test_start_section("distance_constraint::distance_constraint");
00044       const double u = 1.0;
00045       const double d = 1.0;
00046       distance_constraint dc( u, d );
00047       require( dc.uncertainty() == u );
00048       require( dc.wanted_distance() == d );
00049       require( dc.points().size() == 2 );
00050    };
00051    {
00052       test_start_section("distance_constraint::wanted_distance");
00053       const double u = 1.0;
00054       const double d0 = 0.0;
00055       const double d1 = 2.0;
00056       distance_constraint dc( u, d0 );
00057       assert( dc.wanted_distance() == d0 );
00058       dc.wanted_distance( d1 );
00059       require( dc.wanted_distance() == d1 );
00060    };
00061    {
00062       test_start_section("distance_constraint::energy");
00063       const double u = 1.0;
00064       const double d = 1.0;
00065       distance_constraint dc( u, d );
00066       vector< vector2 > p(2), dedp(2);
00067       double e;
00068       p[0] = vector2( 0, 0 );
00069       {
00070          p[1] = vector2( 1.0, 0.0 );
00071          dc.energy( tol, p, e, dedp );
00072          require( 0 == e );
00073          require( 0 == dedp[0].x && 0 == dedp[0].y );
00074          require( 0 == dedp[1].x && 0 == dedp[1].y );
00075       };
00076       {
00077          p[1] = vector2( 0.0, 1.0 );
00078          dc.energy( tol, p, e, dedp );
00079          require( 0 == e );
00080          require( 0 == dedp[0].x && 0 == dedp[0].y );
00081          require( 0 == dedp[1].x && 0 == dedp[1].y );
00082       };
00083       {
00084          p[1] = vector2( 0.5, 0.5 );
00085          dc.energy( tol, p, e, dedp );
00086          require( 0.0 < e );
00087          require( dedp[0].x == -dedp[1].x && dedp[0].y == -dedp[1].y );
00088          require( dedp[1].x < 0 && dedp[1].y < 0 );
00089       };
00090       {
00091          p[1] = vector2( 2.0, 0.0 );
00092          dc.energy( tol, p, e, dedp );
00093          require( 0 < e );
00094          require( dedp[0].x == -dedp[1].x && dedp[0].y == -dedp[1].y );
00095          require( 0 < dedp[1].x && 0 == dedp[1].y );
00096       };
00097       {
00098          p[1] = vector2( 1.0, 1.0 );
00099          dc.energy( tol, p, e, dedp );
00100          require( 0 < e );
00101          require( dedp[0].x == -dedp[1].x && dedp[0].y == -dedp[1].y );
00102          require( 0 < dedp[1].x && 0 < dedp[1].y );
00103       };
00104    };
00105 }

Generated at Sun Jul 14 20:38:11 2002 for Mapper by doxygen 1.0.0 written by Dimitri van Heesch, © 1997-1999