algotest.cc

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 2004-2007 University of Southern California
00006 // Rob Peters <rjpeters at usc dot edu>
00007 //
00008 // created: Wed Oct 13 12:23:33 2004
00009 // commit: $Id: algotest.cc 10065 2007-04-12 05:54:56Z rjpeters $
00010 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/pkgs/whitebox/algotest.cc $
00011 //
00012 // --------------------------------------------------------------------
00013 //
00014 // This file is part of GroovX.
00015 //   [http://ilab.usc.edu/rjpeters/groovx/]
00016 //
00017 // GroovX is free software; you can redistribute it and/or modify it
00018 // under the terms of the GNU General Public License as published by
00019 // the Free Software Foundation; either version 2 of the License, or
00020 // (at your option) any later version.
00021 //
00022 // GroovX is distributed in the hope that it will be useful, but
00023 // WITHOUT ANY WARRANTY; without even the implied warranty of
00024 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025 // General Public License for more details.
00026 //
00027 // You should have received a copy of the GNU General Public License
00028 // along with GroovX; if not, write to the Free Software Foundation,
00029 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00030 //
00032 
00033 #ifndef GROOVX_PKGS_WHITEBOX_ALGOTEST_CC_UTC20050626084022_DEFINED
00034 #define GROOVX_PKGS_WHITEBOX_ALGOTEST_CC_UTC20050626084022_DEFINED
00035 
00036 #include "pkgs/whitebox/algotest.h"
00037 
00038 #include "rutz/algo.h"
00039 #include "rutz/unittest.h"
00040 
00041 #include "tcl/pkg.h"
00042 
00043 #include "rutz/trace.h"
00044 
00045 namespace
00046 {
00047   void testAlgoMinMax()
00048   {
00049     TEST_REQUIRE_EQ(rutz::min(false, true), false);
00050     TEST_REQUIRE_EQ(rutz::max(false, true), true);
00051 
00052     TEST_REQUIRE_EQ(rutz::min(0, 0), 0);
00053     TEST_REQUIRE_EQ(rutz::min(-12345, 67890), -12345);
00054 
00055     TEST_REQUIRE_EQ(rutz::max(9876, 9876), 9876);
00056     TEST_REQUIRE_EQ(rutz::max(-67890, 12345), 12345);
00057 
00058     TEST_REQUIRE_EQ(rutz::min(0.0, 0.0), 0.0);
00059     TEST_REQUIRE_EQ(rutz::min(-1e-32, -1e-33), -1e-32);
00060 
00061     TEST_REQUIRE_EQ(rutz::max(1e16, 1e16), 1e16);
00062     TEST_REQUIRE_EQ(rutz::max(1e31, 1e32), 1e32);
00063   }
00064 
00065   void testAlgoAbs()
00066   {
00067     TEST_REQUIRE_EQ(rutz::abs(-1), 1);
00068     TEST_REQUIRE_EQ(rutz::abs(0), 0);
00069     TEST_REQUIRE_EQ(rutz::abs(1), 1);
00070 
00071     TEST_REQUIRE_EQ(rutz::abs(-1e23), 1e23);
00072     TEST_REQUIRE_EQ(rutz::abs(0.0), 0.0);
00073     TEST_REQUIRE_EQ(rutz::abs(1e-3), 1e-3);
00074   }
00075 
00076   void testAlgoClamp()
00077   {
00078     TEST_REQUIRE_EQ(rutz::clamp(-1, 1, 10), 1);
00079     TEST_REQUIRE_EQ(rutz::clamp( 1, 1, 10), 1);
00080     TEST_REQUIRE_EQ(rutz::clamp(10, 1, 10), 10);
00081     TEST_REQUIRE_EQ(rutz::clamp(11, 1, 10), 10);
00082   }
00083 
00084   void testAlgoSwap2()
00085   {
00086     int a = 3;
00087     int b = 5;
00088     rutz::swap2(a, b);
00089 
00090     TEST_REQUIRE_EQ(a, 5);
00091     TEST_REQUIRE_EQ(b, 3);
00092 
00093     int* pa = &a;
00094     int* pb = &b;
00095 
00096     TEST_REQUIRE_EQ(*pa, 5);
00097     TEST_REQUIRE_EQ(*pb, 3);
00098 
00099     rutz::swap2(pa, pb);
00100 
00101     TEST_REQUIRE_EQ(*pa, 3);
00102     TEST_REQUIRE_EQ(*pb, 5);
00103 
00104     TEST_REQUIRE(pa == &b);
00105     TEST_REQUIRE(pb == &a);
00106   }
00107 }
00108 
00109 extern "C"
00110 int Algotest_Init(Tcl_Interp* interp)
00111 {
00112 GVX_TRACE("Algotest_Init");
00113 
00114   GVX_PKG_CREATE(pkg, interp, "Algotest", "4.$Revision: 10065 $");
00115 
00116   DEF_TEST(pkg, testAlgoMinMax);
00117   DEF_TEST(pkg, testAlgoAbs);
00118   DEF_TEST(pkg, testAlgoClamp);
00119   DEF_TEST(pkg, testAlgoSwap2);
00120 
00121   GVX_PKG_RETURN(pkg);
00122 }
00123 
00124 // Need these to avoid dyld errors on Mac OS X
00125 extern "C" int Algotest_SafeInit(Tcl_Interp*)
00126 { return 1; }
00127 
00128 extern "C" int Algotest_Unload(Tcl_Interp* interp, int /*flags*/)
00129 {
00130 GVX_TRACE("Algotest_Unload");
00131   return tcl::pkg::destroy_on_unload(interp, "Algotest");
00132 }
00133 
00134 extern "C" int Algotest_SafeUnload(Tcl_Interp*, int /*flags*/)
00135 { return 1; }
00136 
00137 static const char __attribute__((used)) vcid_groovx_pkgs_whitebox_algotest_cc_utc20050626084022[] = "$Id: algotest.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00138 #endif // !GROOVX_PKGS_WHITEBOX_ALGOTEST_CC_UTC20050626084022_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:40 2008 by Doxygen version 1.5.5.