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

TestBestFile.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Training_Test_TestBestFile_h
00002 #define Impala_Core_Training_Test_TestBestFile_h
00003 
00004 #include <cppunit/extensions/HelperMacros.h>
00005 #include "Basis/ILog.h"
00006 #include "Core/Training/BestFile.h"
00007 
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Training
00013 {
00014 
00020 class TestBestFile : public CPPUNIT_NS::TestFixture
00021 {
00022     CPPUNIT_TEST_SUITE(TestBestFile);
00023     CPPUNIT_TEST(testWrite);
00024     CPPUNIT_TEST(testReadOld);
00025     CPPUNIT_TEST(testReadNew);
00026     CPPUNIT_TEST(testDiffSimple);
00027     CPPUNIT_TEST(testDiffIgnore);
00028     CPPUNIT_TEST(testDiffDefaults);
00029     CPPUNIT_TEST_SUITE_END();
00030 
00031 public:
00032     void
00033     testWrite()
00034     {
00035         Util::PropertySet set;
00036         Util::IOBuffer buf(100);
00037         set.Add("a","1");
00038         set.Add("b","2");
00039         Util::Write(&set, &buf);
00040         CPPUNIT_ASSERT_EQUAL(String("a=1 b=2 \n"),
00041                              String(reinterpret_cast<char*>(buf.GetBuffer()),
00042                                     buf.GetPosition()));
00043         set.Add("bla","3.4");
00044         buf.Rewind();
00045         Util::Write(&set, &buf);
00046         CPPUNIT_ASSERT_EQUAL(String("a=1 b=2 bla=3.4 \n"),
00047                              String(reinterpret_cast<char*>(buf.GetBuffer()),
00048                                     buf.GetPosition()));
00049     }
00050 
00051     void
00052     testReadOld()
00053     {
00054         Util::PropertySet set;
00055         Util::IOBuffer buf("value:0.76\nw1=2 w2=0.125");
00056         Util::Read(&set, &buf);
00057         CPPUNIT_ASSERT_EQUAL(3, set.Size());
00058         CPPUNIT_ASSERT_EQUAL(0.76, set.GetDouble("value"));
00059         CPPUNIT_ASSERT_EQUAL(2, set.GetInt("w1"));
00060         CPPUNIT_ASSERT_EQUAL(0.125, set.GetDouble("w2"));
00061     }
00062 
00063     void
00064     testReadNew()
00065     {
00066         Util::PropertySet set;
00067         Util::IOBuffer buf("value=0.34 gamma=0.5 kernel=precomputed");
00068         Util::Read(&set, &buf);
00069         CPPUNIT_ASSERT_EQUAL(3, set.Size());
00070         CPPUNIT_ASSERT_EQUAL(0.34, set.GetDouble("value"));
00071         CPPUNIT_ASSERT_EQUAL(0.5, set.GetDouble("gamma"));
00072         CPPUNIT_ASSERT_EQUAL(String("precomputed"), set.GetString("kernel"));
00073     }
00074 
00075     void
00076     testDiffSimple()
00077     {
00078         Util::PropertySet set1("w1=1 w2=1 C=1");
00079         Util::PropertySet set2("w1=1 w2=1 C=1");
00080         CPPUNIT_ASSERT_EQUAL(0, BestFileDiff(&set1, &set2));
00081         set2.Add("w1","2");
00082         CPPUNIT_ASSERT_EQUAL(1, BestFileDiff(&set1, &set2));
00083         set2.Add("w2","2");
00084         CPPUNIT_ASSERT_EQUAL(2, BestFileDiff(&set1, &set2));
00085         set2.Add("C","2");
00086         CPPUNIT_ASSERT_EQUAL(3, BestFileDiff(&set1, &set2));
00087         set2.Add("gamma","2.3");
00088         CPPUNIT_ASSERT_EQUAL(4, BestFileDiff(&set1, &set2));
00089     }
00090 
00091     void
00092     testDiffIgnore()
00093     {
00094         Util::PropertySet set1("w1=1 probability=1 kernel=precomputed cache=0 gamma=1");
00095         Util::PropertySet set2("w1=1 probability=0 kernel=dist-precomputed cache=1");
00096         CPPUNIT_ASSERT_EQUAL(0, BestFileDiff(&set1, &set2));
00097         set1.Add("gamma", "0.5");
00098         CPPUNIT_ASSERT_EQUAL(1, BestFileDiff(&set1, &set2));
00099         set1.Add("kernel", "rbf");
00100         CPPUNIT_ASSERT_EQUAL(2, BestFileDiff(&set1, &set2));
00101         set2.Add("w2", "75");
00102         CPPUNIT_ASSERT_EQUAL(3, BestFileDiff(&set1, &set2));
00103     }
00104 
00105 
00106     void
00107     testDiffDefaults()
00108     {
00109         Util::PropertySet set1("w1=1 w2=1 gamma=1 C=1");
00110         Util::PropertySet set2("");
00111         CPPUNIT_ASSERT_EQUAL(0, BestFileDiff(&set1, &set2));
00112         CPPUNIT_ASSERT_EQUAL(0, BestFileDiff(&set2, &set1));
00113         set1.Add("gamma", "0.5");
00114         CPPUNIT_ASSERT_EQUAL(1, BestFileDiff(&set1, &set2));
00115         set1.Add("w2", "75");
00116         CPPUNIT_ASSERT_EQUAL(2, BestFileDiff(&set1, &set2));
00117         CPPUNIT_ASSERT_EQUAL(2, BestFileDiff(&set2, &set1));
00118     }
00119 
00120 private:
00121     ILOG_CLASS;
00122 };
00123 
00124 ILOG_CLASS_INIT(TestBestFile, Impala.Core.Training);
00125 CPPUNIT_TEST_SUITE_REGISTRATION( TestBestFile );
00126     
00127 }//namespace
00128 }//namespace
00129 }//namespace
00130 
00131 #endif
00132 

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