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

test_vector_constraint.cpp

00001 //$Header: /home/ben/Mapper/c++/test/RCS/test_vector_constraint.cpp,v 6.4 2002/06/23 12:38:17 ben Exp $
00002 //Unit tests of Mapper vector_constraint class.
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 "test/constraints.h"
00033 #include "test/test.h"
00034 #include "vector_constraint.h"
00035 
00036 
00037 
00038 void test::test_vector_constraint(void)
00039 {
00040    test_start_section("vector_constraint");
00041    {
00042       test_start_section("vector_constraint::vector_constraint");
00043       const double u = 1.0;
00044       const double x1 = 0.0;
00045       const double y1 = 2.0;
00046       vector_constraint vc( u, x1, y1 );
00047       require( vc.uncertainty() == u );
00048       require( vc.x == x1 );
00049       require( vc.y == y1 );
00050       require( vc.points().size() == 2 );
00051    };
00052    {
00053       test_start_section("vector_constraint::energy");
00054       const double u = 1.0;
00055       const double x1 = 0.0;
00056       const double y1 = 2.0;
00057       vector_constraint vc( u, x1, y1 );
00058       vector< vector2 > p(2), dedp(2);
00059       double e;
00060       p[0] = vector2( 0.0, 0.0 );
00061       {
00062          p[1] = p[0] + vector2( x1, y1 );
00063          vc.energy( tol, p, e, dedp );
00064          require( 0 == e );
00065          require( 0 == dedp[0].x && 0 == dedp[0].y );
00066          require( 0 == dedp[1].x && 0 == dedp[1].y );
00067       };
00068       {
00069          p[1] = p[0] + vector2( x1+1, y1+1 );
00070          vc.energy( tol, p, e, dedp );
00071          require( 0 < e );
00072          require( dedp[0].x == -dedp[1].x && dedp[0].y == -dedp[1].y );
00073          require( 0 < dedp[1].x && 0 < dedp[1].y );
00074       };
00075       {
00076          p[1] = p[0] + vector2( x1+1, y1-1 );
00077          vc.energy( tol, p, e, dedp );
00078          require( 0 < e );
00079          require( dedp[0].x == -dedp[1].x && dedp[0].y == -dedp[1].y );
00080          require( 0 < dedp[1].x && dedp[1].y < 0 );
00081       };
00082       {
00083          p[1] = p[0] + vector2( x1-1, y1-1 );
00084          vc.energy( tol, p, e, dedp );
00085          require( 0 < e );
00086          require( dedp[0].x == -dedp[1].x && dedp[0].y == -dedp[1].y );
00087          require( dedp[1].x < 0 && dedp[1].y < 0 );
00088       };
00089       {
00090          p[1] = p[0] + vector2( x1-1, y1+1 );
00091          vc.energy( tol, p, e, dedp );
00092          require( 0 < e );
00093          require( dedp[0].x == -dedp[1].x && dedp[0].y == -dedp[1].y );
00094          require( dedp[1].x < 0 && 0 < dedp[1].y );
00095       };
00096    };
00097 }

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