00001 #ifndef Impala_Core_Histogram_Test_TestEntropy_h
00002 #define Impala_Core_Histogram_Test_TestEntropy_h
00003
00004 #include <cppunit/extensions/HelperMacros.h>
00005 #include <algorithm>
00006
00007 #include "Core/Histogram/Entropy.h"
00008
00009 namespace Impala
00010 {
00011 namespace Core
00012 {
00013 namespace Histogram
00014 {
00015
00016 class TestEntropy : public CPPUNIT_NS::TestFixture
00017 {
00018 CPPUNIT_TEST_SUITE(TestEntropy);
00019 CPPUNIT_TEST(testZeroPadding);
00020 CPPUNIT_TEST(testScaling);
00021 CPPUNIT_TEST(testKnownValues);
00022 CPPUNIT_TEST_SUITE_END();
00023
00024 public:
00025
00026 void
00027 setUp()
00028 {
00029 }
00030
00031 void
00032 tearDown()
00033 {
00034 }
00035
00036 void
00037 testZeroPadding()
00038 {
00039 int data[3] = {1, 2, 3};
00040 int dataPadded[7] = {1, 2, 3, 0, 0, 0 ,0};
00041 Histogram1dTem<int> hist(0, 1, 3, 0, data);
00042 Histogram1dTem<int> histPadded(0, 1, 7, 0, dataPadded);
00043 CPPUNIT_ASSERT_EQUAL(Entropy(&hist), Entropy(&histPadded));
00044 }
00045
00046 void
00047 testScaling()
00048 {
00049 int data1[4] = {1, 2, 3, 4};
00050 int data2[4] = {10, 20, 30, 40};
00051 Histogram1dTem<int> hist1(0, 1, 4, 0, data1);
00052 Histogram1dTem<int> hist2(0, 1, 4, 0, data2);
00053 CPPUNIT_ASSERT_EQUAL(Entropy(&hist1), Entropy(&hist2));
00054 }
00055
00056 void
00057 testKnownValues()
00058 {
00059 int data1[1] = {1};
00060 int data2[2] = {1, 1};
00061 int data4[4] = {1, 1, 1, 1};
00062 int data8[8] = {1, 1, 1, 1, 1, 1, 1, 1};
00063 int data1234[4] = {1, 2, 3, 4};
00064 int data13258[5] = {1, 3, 2, 5, 8};
00065 Histogram1dTem<int> hist1(0, 1, 1, 0, data1);
00066 Histogram1dTem<int> hist2(0, 1, 2, 0, data2);
00067 Histogram1dTem<int> hist4(0, 1, 4, 0, data4);
00068 Histogram1dTem<int> hist8(0, 1, 8, 0, data8);
00069 Histogram1dTem<int> hist1234(0, 1, 4, 0, data1234);
00070 Histogram1dTem<int> hist13258(0, 1, 5, 0, data13258);
00071 CPPUNIT_ASSERT_EQUAL(0., Entropy(&hist1));
00072 CPPUNIT_ASSERT_EQUAL(1., Entropy(&hist2));
00073 CPPUNIT_ASSERT_EQUAL(2., Entropy(&hist4));
00074 CPPUNIT_ASSERT_EQUAL(3., Entropy(&hist8));
00075 ILOG_DEBUG("\n1.8464: "<< Entropy(&hist1234));
00076 ILOG_DEBUG("\n2.0182: "<< Entropy(&hist13258));
00077 }
00078
00079 private:
00080 ILOG_CLASS;
00081 };
00082
00083 ILOG_CLASS_INIT(TestEntropy, Impala.Core.Histogram);
00084
00085 CPPUNIT_TEST_SUITE_REGISTRATION( TestEntropy );
00086
00087 }
00088 }
00089 }
00090
00091 #endif
00092