Public Member Functions | |
CPPUNIT_TEST_SUITE (tPolynomialMarshalerTest) | |
CPPUNIT_TEST (testParsing) | |
CPPUNIT_TEST (testConstructor) | |
CPPUNIT_TEST (testMarshaling) | |
CPPUNIT_TEST_SUITE_END () | |
void | setUp () |
void | tearDown () |
void | testParsing () |
void | testConstructor () |
void | testMarshaling () |
void | testMarshalingWithBase () |
Private Attributes | |
tPolynomialMarshaler < nMessageMock > | marshalerA |
tPolynomialMarshaler < nMessageMock > | marshalerB |
tPolynomialMarshaler < nMessageMock > | marshalerC |
std::string | dataInA |
std::string | dataInB |
std::string | dataInC |
Definition at line 7 of file tPolynomialMarshalerTest.cpp.
tPolynomialMarshalerTest::CPPUNIT_TEST_SUITE | ( | tPolynomialMarshalerTest | ) |
tPolynomialMarshalerTest::CPPUNIT_TEST | ( | testParsing | ) |
tPolynomialMarshalerTest::CPPUNIT_TEST | ( | testConstructor | ) |
tPolynomialMarshalerTest::CPPUNIT_TEST | ( | testMarshaling | ) |
tPolynomialMarshalerTest::CPPUNIT_TEST_SUITE_END | ( | ) |
void tPolynomialMarshalerTest::setUp | ( | ) | [inline] |
Definition at line 26 of file tPolynomialMarshalerTest.cpp.
References dataInA, dataInB, dataInC, marshalerA, marshalerB, marshalerC, tPolynomialMarshaler< T >::setConstant(), and tPolynomialMarshaler< T >::setVariant().
00026 { 00027 dataInA = "3:5"; 00028 dataInB = "3;5:7;9"; 00029 dataInC = "1;2;3:4;5;6"; 00030 // populate marshaler C to : 00031 // constant = {3.0} 00032 // variant = {5.0} 00033 marshalerA.setConstant(3.0, 0); 00034 marshalerA.setVariant(5.0, 0); 00035 00036 // populate marshaler C to : 00037 // constant = {3.0, 5.0} 00038 // variant = {7.0, 9.0} 00039 marshalerB.setConstant(3.0, 0); 00040 marshalerB.setConstant(5.0, 1); 00041 marshalerB.setVariant(7.0, 0); 00042 marshalerB.setVariant(9.0, 1); 00043 00044 // populate marshaler C to : 00045 // constant = {1.0, 2.0, 3.0} 00046 // variant = {4.0, 5.0, 6.0} 00047 marshalerC.setConstant(1.0, 0); 00048 marshalerC.setConstant(2.0, 1); 00049 marshalerC.setConstant(3.0, 2); 00050 marshalerC.setVariant(4.0, 0); 00051 marshalerC.setVariant(5.0, 1); 00052 marshalerC.setVariant(6.0, 2); 00053 }
void tPolynomialMarshalerTest::tearDown | ( | ) | [inline] |
void tPolynomialMarshalerTest::testParsing | ( | ) | [inline] |
Definition at line 59 of file tPolynomialMarshalerTest.cpp.
References dataInA, dataInB, dataInC, marshalerA, marshalerB, marshalerC, and tPolynomialMarshaler< T >::parse().
00059 { 00060 tPolynomialMarshaler<nMessageMock> marshalerParsed; 00061 00062 marshalerParsed.parse(dataInB); 00063 CPPUNIT_ASSERT( marshalerB == marshalerParsed ); 00064 00065 marshalerParsed.parse(dataInA); 00066 CPPUNIT_ASSERT( marshalerA == marshalerParsed ); 00067 00068 marshalerParsed.parse(dataInC); 00069 CPPUNIT_ASSERT( marshalerC == marshalerParsed ); 00070 }
void tPolynomialMarshalerTest::testConstructor | ( | ) | [inline] |
Definition at line 72 of file tPolynomialMarshalerTest.cpp.
References dataInA, dataInB, dataInC, marshalerA, marshalerB, and marshalerC.
00072 { 00073 // copy constructor 00074 tPolynomialMarshaler<nMessageMock> marshalerCopyA(marshalerA); 00075 CPPUNIT_ASSERT( marshalerA == marshalerCopyA ); 00076 tPolynomialMarshaler<nMessageMock> marshalerCopyB(marshalerB); 00077 CPPUNIT_ASSERT( marshalerB == marshalerCopyB ); 00078 tPolynomialMarshaler<nMessageMock> marshalerCopyC(marshalerC); 00079 CPPUNIT_ASSERT( marshalerC == marshalerCopyC ); 00080 00081 // parsing constructor 00082 tPolynomialMarshaler<nMessageMock> marshalerParsedA(dataInA); 00083 CPPUNIT_ASSERT( marshalerA == marshalerParsedA ); 00084 tPolynomialMarshaler<nMessageMock> marshalerParsedB(dataInB); 00085 CPPUNIT_ASSERT( marshalerB == marshalerParsedB ); 00086 tPolynomialMarshaler<nMessageMock> marshalerParsedC(dataInC); 00087 CPPUNIT_ASSERT( marshalerC == marshalerParsedC ); 00088 00089 // constructor from 2 tPolynomial<nMessage> 00090 tPolynomial<nMessageMock> tPolynomialA1("3"); 00091 tPolynomial<nMessageMock> tPolynomialA2("5"); 00092 tPolynomialMarshaler<nMessageMock> marshalerDuoPolynomialA(tPolynomialA1, tPolynomialA2); 00093 CPPUNIT_ASSERT( marshalerA == marshalerDuoPolynomialA ); 00094 tPolynomial<nMessageMock> tPolynomialB1("3;5"); 00095 tPolynomial<nMessageMock> tPolynomialB2("7;9"); 00096 tPolynomialMarshaler<nMessageMock> marshalerDuoPolynomialB(tPolynomialB1, tPolynomialB2); 00097 CPPUNIT_ASSERT( marshalerB == marshalerDuoPolynomialB ); 00098 tPolynomial<nMessageMock> tPolynomialC1("1;2;3"); 00099 tPolynomial<nMessageMock> tPolynomialC2("4;5;6"); 00100 tPolynomialMarshaler<nMessageMock> marshalerDuoPolynomialC(tPolynomialC1, tPolynomialC2); 00101 CPPUNIT_ASSERT( marshalerC == marshalerDuoPolynomialC ); 00102 }
void tPolynomialMarshalerTest::testMarshaling | ( | ) | [inline] |
Definition at line 104 of file tPolynomialMarshalerTest.cpp.
References tPolynomial< T >::adaptToNewReferenceVarValue(), tPolynomialMarshaler< T >::marshal(), marshalerA, marshalerB, marshalerC, tPolynomialMarshaler< T >::toString(), and tPolynomial< T >::toString().
00104 { 00105 /* 00106 * the polynomial {7, 5, 3} (here noted as x) will be marshaled as: 00107 * a + b*x + c*x^2 + t * (d + e*x + f*x^2) 00108 * 00109 * For the case A: 00110 * a=3, d=5, b=c=e=f=0 00111 * should produce: 00112 * a + b*x + c*x^2 + t * (d + e*x + f*x^2) 00113 * a + t * (d) 00114 * 3 + 5t 00115 * 00116 * For the case B: 00117 * a=3, b=5, d=7, e=9, c=f=0 00118 * should produce: 00119 * a + b*x + c*x^2 + t * (d + e*x + f*x^2) 00120 * a + b*x + t * (d + e*x) 00121 * 3 + 5*x + t * (7 + 9*x) 00122 * 3 + 5*{7, 5, 3} + t * (7 + 9*{7, 5, 3}) 00123 * 3 + {35, 25, 15t} + t * (7 + {63, 45, 27}) 00124 * 3 + (35 + 25*t +15*t^2) + t * (7 + 63 + 45*t + 27*t^2}) 00125 * 38 + 25*t +15*t^2 + t * (70 + 45*t + 27*t^2}) 00126 * 38 + 25*t +15*t^2 + 70*t + 45*t^2 + 27*t^3 00127 * 38 + 95*t + 60*t^2 + 27*t^3 00128 * 00129 * For the case C: 00130 * where a=1, b=2, c=3, d=4, e=5, f=6 00131 * should produce: 00132 * a + b*x + c*x^2 + t * (d + e*x + f*x^2) 00133 * 1 + 2*x + 3*x^2 + t * (4 + 5*x + 6*x^2) 00134 * 1 + 2*{7, 5, 3} + 3*{7, 5, 3}^2 + t * (4 + 5*{7, 5, 3} + 6*{7, 5, 3}^2) 00135 * nota: {7, 5, 3}^2 => {49, 70, 67, 30, 9} 00136 * 1 + 2*{7, 5, 3} + 3*{49, 70, 67, 30, 9} + t * (4 + 5*{7, 5, 3} + 6*{49, 70, 67, 30, 9}) 00137 * 1 + {14, 10, 6} + {147, 210, 201, 90, 27} + t * (4 + {35, 25, 15} + {294, 420, 402, 180, 54}) 00138 * 1 + 14 + 10*t + 6*t^2 + 147 + 210*t + 201*t^2 + 90*t^3 + 27*t^4 + t * (4 + 35 + 25*t + 15*t^2 + 294 + 420*t + 402*t^2 + 180*t^3 + 54*t^4) 00139 * 162 + 220*t + 207*t^2 + 90*t^3 + 27*t^4 + t * (333 + 445*t + 417*t^2 + 180*t^3 + 54*t^4) 00140 * 162 + 220*t + 207*t^2 + 90*t^3 + 27*t^4 + 333*t + 445*t^2 + 417*t^3 + 180*t^4 + 54*t^5 00141 * 162 + 553*t + 652*t^2 + 507*t^3 + 207*t^4 + 54*t^5 00142 * 00143 */ 00144 float inputData[] = {7, 5, 3}; 00145 float expectedDataA[] = {3, 5}; 00146 float expectedDataB[] = {38, 95, 60, 27}; 00147 float expectedDataC[] = {162, 553, 652, 507, 207, 54}; 00148 tPolynomial<nMessageMock> inputPolynomial(inputData, sizeof(inputData)/sizeof(inputData[0])); 00149 tPolynomial<nMessageMock> expectedA(expectedDataA, sizeof(expectedDataA)/sizeof(expectedDataA[0])); 00150 tPolynomial<nMessageMock> expectedB(expectedDataB, sizeof(expectedDataB)/sizeof(expectedDataB[0])); 00151 tPolynomial<nMessageMock> expectedC(expectedDataC, sizeof(expectedDataC)/sizeof(expectedDataC[0])); 00152 00153 float tData[] = {0, 1}; 00154 tPolynomial<nMessageMock> t( tData, 2 ); 00155 00156 /* 00157 // Similar to B 00158 tPolynomial<nMessageMock> out2 = 00159 inputPolynomial*5 00160 + 3 00161 + t * ( 00162 inputPolynomial*9 00163 + 7 00164 ); 00165 00166 std::cout << std::endl; 00167 std::cout << "manually generated expected output for case B : " << std::endl; 00168 std::cout << out2.toString() << std::endl; 00169 std::cout << "marshaled output for case B : " << std::endl; 00170 std::cout << marshalerB.marshal(inputPolynomial).toString() << std::endl; 00171 */ 00172 00173 /* 00174 // Similar to C 00175 tPolynomial<nMessageMock> out3 = 00176 inputPolynomial*inputPolynomial*3 00177 + inputPolynomial*2 00178 + 1 00179 + t * ( 00180 inputPolynomial*inputPolynomial*6 00181 + inputPolynomial*5 00182 + 4 00183 ); 00184 00185 00186 std::cout << std::endl; 00187 std::cout << "manually generated expected output for case C : " << std::endl; 00188 std::cout << out3.toString() << std::endl; 00189 std::cout << "marshaled output for case C : " << std::endl; 00190 std::cout << marshalerC.marshal(inputPolynomial).toString() << std::endl; 00191 */ 00192 00193 CPPUNIT_ASSERT ( expectedA == marshalerA.marshal(inputPolynomial) ); 00194 CPPUNIT_ASSERT ( expectedB == marshalerB.marshal(inputPolynomial) ); 00195 CPPUNIT_ASSERT ( expectedC == marshalerC.marshal(inputPolynomial) ); 00196 tPolynomial<nMessageMock> tp3 = inputPolynomial.adaptToNewReferenceVarValue(4); 00197 00198 std::cout << std::endl; 00199 std::cout << tp3.toString() << std::endl; 00200 std::cout << marshalerB.toString() << std::endl; 00201 std::cout << expectedB.adaptToNewReferenceVarValue(4).toString() << std::endl; 00202 std::cout << marshalerB.marshal(tp3).toString() << std::endl; 00203 CPPUNIT_ASSERT ( expectedB.adaptToNewReferenceVarValue(4) == marshalerB.marshal(tp3) ); 00204 00205 }
void tPolynomialMarshalerTest::testMarshalingWithBase | ( | ) | [inline] |
The same logical input, transformed to 2 different reference value, and then marshalled should produce the same value at a given current value.
Definition at line 211 of file tPolynomialMarshalerTest.cpp.
References tPolynomial< T >::adaptToNewReferenceVarValue(), tPolynomialMarshaler< T >::marshal(), and marshalerB.
00212 { 00213 float inputData[] = {7, 5, 3}; 00214 tPolynomial<nMessageMock> inputPolynomialAt0(inputData, sizeof(inputData)/sizeof(inputData[0])); 00215 tPolynomial<nMessageMock> inputPolynomialAt3(inputPolynomialAt0.adaptToNewReferenceVarValue(3)); 00216 00217 tPolynomial<nMessageMock> marshaledResultAt0 = marshalerB.marshal(inputPolynomialAt0); 00218 tPolynomial<nMessageMock> marshaledResultAt3 = marshalerB.marshal(inputPolynomialAt3); 00219 00220 // CPPUNIT_ASSERT ( marshaledResultAt0 == marshaledResultAt3 ); 00221 std::cout << "at 0 : " << marshaledResultAt0(5) << " at 3 " << marshaledResultAt3(5) << std::endl; 00222 CPPUNIT_ASSERT ( marshaledResultAt0(5) == marshaledResultAt3(5) ); 00223 00224 }
Definition at line 9 of file tPolynomialMarshalerTest.cpp.
Referenced by setUp(), testConstructor(), testMarshaling(), and testParsing().
Definition at line 10 of file tPolynomialMarshalerTest.cpp.
Referenced by setUp(), testConstructor(), testMarshaling(), testMarshalingWithBase(), and testParsing().
Definition at line 11 of file tPolynomialMarshalerTest.cpp.
Referenced by setUp(), testConstructor(), testMarshaling(), and testParsing().
std::string tPolynomialMarshalerTest::dataInA [private] |
Definition at line 13 of file tPolynomialMarshalerTest.cpp.
Referenced by setUp(), testConstructor(), and testParsing().
std::string tPolynomialMarshalerTest::dataInB [private] |
Definition at line 14 of file tPolynomialMarshalerTest.cpp.
Referenced by setUp(), testConstructor(), and testParsing().
std::string tPolynomialMarshalerTest::dataInC [private] |
Definition at line 15 of file tPolynomialMarshalerTest.cpp.
Referenced by setUp(), testConstructor(), and testParsing().