![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 5, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #ifndef WNS_CPPUNIT_HPP 00029 #define WNS_CPPUNIT_HPP 00030 00031 #include <WNS/TestFixture.hpp> 00032 #include <WNS/evaluation/statistics/moments.hpp> 00033 #include <WNS/PowerRatio.hpp> 00034 #include <WNS/Conversion.hpp> 00035 00036 namespace wns { 00037 00042 inline void 00043 assertMaxRelError( 00044 const Power& expected, 00045 const Power& actual, 00046 double maxRelativeError, 00047 const std::string sourceFile, 00048 const std::string sourceLine) 00049 { 00050 std::string expectedString = wns::to<std::string>(expected.get_dBm()) + " dBm"; 00051 std::string actualString = wns::to<std::string>(actual.get_dBm()) + " dBm"; 00052 std::string msg = wns::failureMessage(sourceFile, sourceLine, expectedString, actualString); 00053 bool ok = std::fabs(expected.get_mW() - actual.get_mW()) <= std::fabs(expected.get_mW() * maxRelativeError); 00054 00055 CPPUNIT_ASSERT_MESSAGE(msg, ok); 00056 } 00057 00062 inline void 00063 assertMaxRelError( 00064 const Ratio& expected, 00065 const Ratio& actual, 00066 double maxRelativeError, 00067 const std::string sourceFile, 00068 const std::string sourceLine) 00069 { 00070 std::string expectedString = wns::to<std::string>(expected.get_dB()) + " dB"; 00071 std::string actualString = wns::to<std::string>(actual.get_dB()) + " dB"; 00072 std::string msg = failureMessage(sourceFile, sourceLine, expectedString, actualString); 00073 00074 bool ok = std::fabs(expected.get_factor() - actual.get_factor()) <= std::abs(expected.get_factor() * maxRelativeError); 00075 CPPUNIT_ASSERT_MESSAGE(msg, ok); 00076 } 00077 00078 template <class SAMPLEGENERATOR> 00079 void assertMeanValue( 00080 double expected, 00081 SAMPLEGENERATOR& sampleGenerator, 00082 unsigned long int maxTrials, 00083 const std::string sourceFile, 00084 const std::string sourceLine) 00085 { 00086 assure(maxTrials > 100, "needs a least 100 trials, please increase maxTrials"); 00087 std::stringstream maxTrialsExceeded; 00088 maxTrialsExceeded << "Exceeded maxTrials (" << maxTrials << ") without reaching the expected mean value (" << expected << ")"; 00089 const std::string maxTrialsExceededString = maxTrialsExceeded.str(); 00090 wns::evaluation::statistics::Moments m; 00091 00092 while(m.trials() <= 100) 00093 { 00094 m.put(sampleGenerator()); 00095 } 00096 00097 double relCf = 1.0; 00098 while (((relCf > 10e-4) && (std::fabs(expected - m.mean()) > m.getConfidenceInterval99Mean()/10))) 00099 { 00100 m.put(sampleGenerator()); 00101 while(m.trials()%100 != 0) 00102 { 00103 m.put(sampleGenerator()); 00104 } 00105 00106 if(m.mean() != 0) 00107 { 00108 relCf = m.getConfidenceInterval99Mean()/m.mean(); 00109 } 00110 else 00111 { 00112 relCf = m.getConfidenceInterval99Mean(); 00113 } 00114 CPPUNIT_ASSERT_MESSAGE( maxTrialsExceededString, m.trials() < maxTrials ); 00115 } 00116 00117 double ci99mean = m.getConfidenceInterval99Mean(); 00118 std::stringstream actualString; 00119 actualString << (m.mean() - ci99mean) << " ... " << (m.mean() + ci99mean) << " (" << m.trials() << " trials)"; 00120 std::string msg = failureMessage(sourceFile, sourceLine, wns::to<std::string>(expected), actualString.str()); 00121 CPPUNIT_ASSERT_MESSAGE( msg, std::fabs(expected - m.mean()) <= ci99mean); 00122 } 00123 } 00124 00125 #define WNS_ASSERT_MEAN_VALUE(expected, generator, maxTrials) wns::assertMeanValue((expected), (generator), (maxTrials),__FILE__, wns::to<std::string>(__LINE__)) 00126 00127 00128 #endif
1.5.5