Home || Visual Search || Applications || Architecture || 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::Random rng;
00082         rng.SetSeed(1);
00083         Array2dScalarReal64* a = MakeRandomScalarReal64(3, 3, 1., rng);
00084         rng.SetSeed(1);
00085         Array2dScalarReal64* b = MakeRandomScalarReal64(3, 3, 1., rng);
00086         rng.SetSeed(2);
00087         Array2dScalarReal64* c = MakeRandomScalarReal64(3, 3, 1., rng);
00088         CPPUNIT_ASSERT(Equals(a,b));
00089         CPPUNIT_ASSERT(!Equals(a,c));
00090         delete a;
00091         delete b;
00092         delete c;
00093     }
00094     
00095     
00096 private:
00097     ILOG_CLASS;
00098 };
00099 
00100 ILOG_CLASS_INIT(TestMakeRandom, Impala.Core.Array.Test);
00101 CPPUNIT_TEST_SUITE_REGISTRATION(TestMakeRandom);    
00102 
00103 } // namespace
00104 } // namespace
00105 } // namespace
00106 
00107 #endif

Generated on Thu Jan 13 09:04:14 2011 for ImpalaSrc by  doxygen 1.5.1