Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

TestMakeRandom.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Array_TestMakeRandom_h
00002 #define Impala_Core_Array_TestMakeRandom_h
00003 
00004 #include <cppunit/extensions/HelperMacros.h>
00005 #include "Core/Array/MakeRandom.h"
00006 #include "Core/Array/Equals.h"
00007 
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Array
00013 {
00014 
00015 class TestMakeRandom : public CPPUNIT_NS::TestFixture
00016 {
00017     CPPUNIT_TEST_SUITE(TestMakeRandom);
00018     CPPUNIT_TEST(testSize);
00019     CPPUNIT_TEST(testData);
00020     CPPUNIT_TEST(testRandomSeed);
00021     CPPUNIT_TEST_SUITE_END();
00022     
00023 public:
00024 
00025     void
00026     setUp()
00027     {
00028     }
00029 
00030     void
00031     tearDown()
00032     {
00033     }
00034 
00035     void
00036     testSize()
00037     {
00038         testSize(0,0);
00039         testSize(1,1);
00040         testSize(10,1);
00041         testSize(10,10);
00042     }
00043 
00044     void
00045     testData()
00046     {
00047         testData(10, 10, 1);
00048         testData(10, 10, 2.5);
00049     }
00050     
00051     void
00052     testSize(Int64 w, Int64 h)
00053     {
00054         Array2dScalarReal64* a = MakeRandomScalarReal64(w, h, 10.);
00055         CPPUNIT_ASSERT_EQUAL(w, a->CW());
00056         CPPUNIT_ASSERT_EQUAL(h, a->CH());
00057     }
00058     
00059     void
00060     testData(Int64 w, Int64 h, double maxVal)
00061     {
00062         Array2dScalarReal64* a = MakeRandomScalarReal64(w, h, maxVal);
00063         // we could use PixMax here, but PixMax itself doesn't have unit-tests...
00064         bool error = false;
00065         for(int y=0 ; y<h ; ++y)
00066             for(int x=0 ; x<w ; ++x)
00067             {
00068                 if(a->Value(x, y) > maxVal)
00069                 {
00070                     ILOG_DEBUG(a->Value(x, y) <<" > "<< maxVal <<" @ ("<< x
00071                                <<", "<< y <<")");
00072                     error = true;
00073                 }
00074             }
00075         CPPUNIT_ASSERT(!error);
00076     }
00077 
00078     void
00079     testRandomSeed()
00080     {
00081         Util::SetRandomSeed(1);
00082         Array2dScalarReal64* a = MakeRandomScalarReal64(3, 3, 1.);
00083         Util::SetRandomSeed(1);
00084         Array2dScalarReal64* b = MakeRandomScalarReal64(3, 3, 1.);
00085         Util::SetRandomSeed(2);
00086         Array2dScalarReal64* c = MakeRandomScalarReal64(3, 3, 1.);
00087         CPPUNIT_ASSERT(Equals(a,b));
00088         CPPUNIT_ASSERT(!Equals(a,c));
00089         delete a;
00090         delete b;
00091         delete c;
00092     }
00093     
00094     
00095 private:
00096     ILOG_CLASS;
00097 };
00098 
00099 ILOG_CLASS_INIT(TestMakeRandom, Impala.Core.Array.Test);
00100 CPPUNIT_TEST_SUITE_REGISTRATION(TestMakeRandom);    
00101 
00102 } // namespace
00103 } // namespace
00104 } // namespace
00105 
00106 #endif

Generated on Fri Mar 19 09:30:54 2010 for ImpalaSrc by  doxygen 1.5.1