~jan-ellenbeck/openwns-rise/LTEantennaAndSpeedUp

« back to all changes in this revision

Viewing changes to src/plmapping/tests/MI2PERTest.cpp

  • Committer: Maciej Muehleisen
  • Date: 2009-01-13 15:33:59 UTC
  • Revision ID: mue@comnets.rwth-aachen.de-20090113153359-i05aqove1wv16mm8
Removed some unit tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
 * This file is part of openWNS (open Wireless Network Simulator)
3
 
 * _____________________________________________________________________________
4
 
 *
5
 
 * Copyright (C) 2004-2007
6
 
 * Chair of Communication Networks (ComNets)
7
 
 * Kopernikusstr. 5, D-52074 Aachen, Germany
8
 
 * phone: ++49-241-80-27910,
9
 
 * fax: ++49-241-80-22242
10
 
 * email: info@openwns.org
11
 
 * www: http://www.openwns.org
12
 
 * _____________________________________________________________________________
13
 
 *
14
 
 * openWNS is free software; you can redistribute it and/or modify it under the
15
 
 * terms of the GNU Lesser General Public License version 2 as published by the
16
 
 * Free Software Foundation;
17
 
 *
18
 
 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
19
 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20
 
 * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
21
 
 * details.
22
 
 *
23
 
 * You should have received a copy of the GNU Lesser General Public License
24
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
 
 *
26
 
 ******************************************************************************/
27
 
 
28
 
#include <WNS/pyconfig/helper/Functions.hpp>
29
 
#include <WNS/CppUnit.hpp>
30
 
#include <cppunit/extensions/HelperMacros.h>
31
 
#include <stdexcept>
32
 
 
33
 
#include <RISE/plmapping/PhyMode.hpp>
34
 
#include <RISE/plmapping/CodeRates.hpp>
35
 
#include <RISE/plmapping/MI2PER.hpp>
36
 
 
37
 
namespace rise { namespace plmapping { namespace tests {
38
 
 
39
 
        class MI2PERTest :
40
 
                public wns::TestFixture
41
 
        {
42
 
                CPPUNIT_TEST_SUITE( MI2PERTest );
43
 
                CPPUNIT_TEST( TestTableEntries );
44
 
                CPPUNIT_TEST( Fixed );
45
 
                CPPUNIT_TEST( TestMI2PER );
46
 
                CPPUNIT_TEST( TestPER2MIB );
47
 
                CPPUNIT_TEST_SUITE_END();
48
 
        public:
49
 
                MI2PERTest();
50
 
                virtual ~MI2PERTest();
51
 
                void prepare();
52
 
                void cleanup();
53
 
                void TestTableEntries();
54
 
                void Fixed();
55
 
                void TestMI2PER();
56
 
                void TestPER2MIB();
57
 
 
58
 
                rise::plmapping::CoderMapping* coderMapper; // Singleton
59
 
                rise::plmapping::CoderFullMapping* mi2perMapper; // Singleton
60
 
 
61
 
                wns::service::phy::phymode::MI2PERMappingInterface* testee1;
62
 
                wns::service::phy::phymode::MI2PERMappingInterface* testee2;
63
 
 
64
 
 
65
 
        };
66
 
 
67
 
 
68
 
        CPPUNIT_TEST_SUITE_REGISTRATION( MI2PERTest );
69
 
 
70
 
        MI2PERTest::MI2PERTest()
71
 
                : wns::TestFixture(),
72
 
                  coderMapper(NULL),
73
 
                  mi2perMapper(NULL),
74
 
                  testee1(NULL),
75
 
                  testee2(NULL)
76
 
        {}
77
 
 
78
 
        MI2PERTest::~MI2PERTest()
79
 
        {}
80
 
 
81
 
        void MI2PERTest::prepare()
82
 
        {
83
 
                wns::pyconfig::Parser pyconfig;
84
 
                pyconfig.loadString(
85
 
                        "import rise.CoderSpecification\n"
86
 
                        "coderMapping = rise.CoderSpecification.default\n"
87
 
                        //"\n"
88
 
                        );
89
 
                wns::pyconfig::View coderMappingConfig = pyconfig.getView("coderMapping");
90
 
                coderMapper  = dynamic_cast<CoderMapping*>(wns::service::phy::phymode::CoderMappingInterface::getCoderMapping(coderMappingConfig));
91
 
                mi2perMapper = dynamic_cast<CoderFullMapping*>(wns::service::phy::phymode::CoderFullMappingInterface::getCoderFullMapping(coderMappingConfig));
92
 
                CPPUNIT_ASSERT(coderMapper != NULL);
93
 
                CPPUNIT_ASSERT(mi2perMapper != NULL);
94
 
 
95
 
                wns::pyconfig::Parser M2Ppyconfig;
96
 
                M2Ppyconfig.loadString(
97
 
                        "import rise.CoderSpecification\n"
98
 
                        "mi2per = rise.CoderSpecification.default\n"
99
 
                        "PER = 0.05\n"
100
 
                        );
101
 
                testee1 = new WINNERM2P(M2Ppyconfig);
102
 
                testee2 = new FixedM2P(M2Ppyconfig);
103
 
        }
104
 
 
105
 
        void MI2PERTest::cleanup()
106
 
        {
107
 
                coderMapper = NULL;
108
 
                mi2perMapper = NULL;
109
 
                delete testee1;
110
 
                delete testee2;
111
 
        }
112
 
 
113
 
 
114
 
        void MI2PERTest::TestTableEntries()
115
 
        {
116
 
                //We have to take into account that here we are introducing the payload,
117
 
                //so the CWL used will be the payload multiplied by the rate of the CoderSpecification
118
 
                WNS_ASSERT_MAX_REL_ERROR( 0.9746288,
119
 
                                                  testee1->mapMI2PER(0.921, 400,coderMapper->fromString("No")),
120
 
                                                          1E-6 );
121
 
                // 300 * 3 = CWL 840 -> the CWL 600 will be used.
122
 
                WNS_ASSERT_MAX_REL_ERROR( 0.9932241,
123
 
                                                          testee1->mapMI2PER(0.35, 280,coderMapper->fromString("Turbo_UMTS-1/3")),
124
 
                                                          1E-6 );
125
 
 
126
 
                WNS_ASSERT_MAX_REL_ERROR( 0.6567467,
127
 
                                                          testee1->mapMI2PER(0.340, 100,coderMapper->fromString("RCPC_BENQ-1/3")),
128
 
                                                  1E-6 );
129
 
                // (450 * 3) / 2 = 675 -> the CWL 576 will be used
130
 
                WNS_ASSERT_MAX_REL_ERROR( 0.00502388,
131
 
                                                          testee1->mapMI2PER(0.799, 450,coderMapper->fromString("LDPC_SEUK-2/3")),
132
 
                                                          1E-6 );
133
 
 
134
 
        }
135
 
 
136
 
        void MI2PERTest::Fixed()
137
 
        {
138
 
                WNS_ASSERT_MAX_REL_ERROR( 0.05,
139
 
                                                                  testee2->mapMI2PER(1.0,   // Mutual Information
140
 
                                                                                                         42,    // any block length
141
 
                                                                                                         1234), // the coding ID has
142
 
                                                                                                                        // no effect
143
 
                                                                  1E-6 );
144
 
                // another combination should have the same effect
145
 
                WNS_ASSERT_MAX_REL_ERROR( 0.05,
146
 
                                                                  testee2->mapMI2PER(0.5,   // Mutual Information
147
 
                                                                                                         43,    // any block length
148
 
                                                                                                         123),  // the coding ID has
149
 
                                                                                                                        // no effect
150
 
                                                                  1E-6 );
151
 
        }
152
 
 
153
 
        void  MI2PERTest::TestMI2PER()
154
 
        {
155
 
                const Coding &coding = coderMapper->fromString("RCPC_BENQ-1/3");
156
 
                const TableCoder* coderFullSpec =
157
 
                        dynamic_cast<const TableCoder*>(&(mi2perMapper->getCoderFullSpecification(coding)));
158
 
                CPPUNIT_ASSERT( coderFullSpec != NULL );
159
 
                const CodeWordLengths& codeWordLengths = coderFullSpec->getCWLvector();
160
 
                unsigned int bl = (int) (coderFullSpec->getRate() * (double) codeWordLengths[0] + 0.5); // smallest CWL
161
 
                //std::cout << "TestMI2PER(): "<<coderFullSpec.getName()<<": bl="<<bl<<std::endl;
162
 
                for (double mib=0.0; mib<=1.0; mib+=0.1) {
163
 
                        // these two ways should be equivalent:
164
 
                        double per1 = testee1->mapMI2PER(mib, bl, coding);
165
 
                        double per2 = coderFullSpec->mapMI2PER(mib, bl); // faster access method
166
 
                        WNS_ASSERT_MAX_REL_ERROR( per1, per2, 1e-6 );
167
 
                }
168
 
        }
169
 
 
170
 
        void  MI2PERTest::TestPER2MIB()
171
 
        {
172
 
                const Coding &coding = coderMapper->fromString("RCPC_BENQ-1/3");
173
 
                const TableCoder* coderFullSpec =
174
 
                        dynamic_cast<const TableCoder*>(&(mi2perMapper->getCoderFullSpecification(coding)));
175
 
                CPPUNIT_ASSERT( coderFullSpec != NULL );
176
 
                const CodeWordLengths& codeWordLengths = coderFullSpec->getCWLvector();
177
 
                unsigned int bl = (int) (coderFullSpec->getRate() * (double) codeWordLengths[0] + 0.5); // smallest CWL
178
 
                //std::cout << "TestPER2MIB(): "<<coderFullSpec.getName()<<": bl="<<bl<<std::endl;
179
 
                for (double mib=0.0; mib<=1.0; mib+=0.05) {
180
 
                        // these two ways should be equivalent:
181
 
                        double per1 = testee1->mapMI2PER(mib, bl, coding);
182
 
                        double per2 = coderFullSpec->mapMI2PER(mib, bl); // faster access method
183
 
                        //std::cout << "MIB="<<mib<<" => PER="<<per1<<std::endl;
184
 
                        WNS_ASSERT_MAX_REL_ERROR( per1, per2, 1e-6 );
185
 
                        // inverse function:
186
 
                        double mib2 = coderFullSpec->PER2MIB(per1, bl);
187
 
                        //std::cout << "          PER="<<per1<<" => MIB="<<mib2<<std::endl;
188
 
                        WNS_ASSERT_MAX_REL_ERROR( mib, mib2, 0.02 );
189
 
                }
190
 
        }
191
 
 
192
 
 
193
 
} // tests
194
 
} // plmapping
195
 
} // rise
196
 
 
197