Changeset 78:ba2bc7ca2d65 in rrlib_localization


Ignore:
Timestamp:
11.01.2019 18:01:24 (6 days ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
14.08
Children:
79:d130ef868b2b, 80:b8a8e974d5d5
Phase:
public
Rebase:
34636261333538326635323165303738616161356663646363376566353339316362393966316161
Message:

Adds/restores planned unit test for streaming operators of position types

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/position.cpp

    r62 r78  
    199199  void Streaming() 
    200200  { 
    201 //    std::stringstream actual; 
    202 //    std::stringstream expected; 
    203 // 
    204 //    actual << tPosition2D<double>(1, 2); 
    205 //    expected << "(1, 2)"; 
    206 //    RRLIB_UNIT_TESTS_EQUALITY(expected.str(), actual.str()); 
    207 // 
    208 //    actual << tPosition3D<double>(math::tAngle<double, math::angle::Degree>(1), math::tAngle<double, math::angle::Degree>(2), math::tAngle<double, math::angle::Degree>(3)); 
    209 //    expected << "(1°, 2°, 3°)"; 
    210 //    RRLIB_UNIT_TESTS_EQUALITY(expected.str(), actual.str()); 
    211 // 
    212 //    tPosition2D<double> position_2d; 
    213 //    tPosition3D<double> position_3d; 
    214 //    std::stringstream source; 
    215 //    source.exceptions(std::istream::failbit); 
    216 //    RRLIB_UNIT_TESTS_EXCEPTION(source >> position_2d, std::ios_base::failure); 
    217 //    source.clear(); 
    218 //    RRLIB_UNIT_TESTS_EXCEPTION(source >> position_3d, std::ios_base::failure); 
    219 //    source.clear(); 
    220 //    source << "120°"; 
    221 //    source >> position_2d; 
    222 //    RRLIB_UNIT_TESTS_EQUALITY(tPosition2D<double>(math::tAngle<double, math::angle::Degree>(120)), position_2d); 
    223 //    source.clear(); 
    224 //    source << "(120)"; 
    225 //    RRLIB_UNIT_TESTS_EXCEPTION(source >> position_2d, std::ios_base::failure); 
    226 //    source.clear(); 
    227 //    source.str(""); 
    228 //    source << "(10°, 20°, 30°)"; 
    229 //    source >> position_3d; 
    230 //    RRLIB_UNIT_TESTS_EQUALITY(tPosition3D<double>(math::tAngle<double, math::angle::Degree>(10), math::tAngle<double, math::angle::Degree>(20), math::tAngle<double, math::angle::Degree>(30)), position_3d); 
    231 //    source.clear(); 
    232 //    source << "(120)"; 
    233 //    RRLIB_UNIT_TESTS_EXCEPTION(source >> position_3d, std::ios_base::failure); 
    234 // 
    235 //    source.clear(); 
    236 //    source.str(""); 
    237 //    source << "1°, 2°, ende"; 
    238 //    for (size_t i = 0; i < 2; ++i) 
    239 //    { 
    240 //      source >> position_2d; 
    241 //      math::tAngle<double, math::angle::Degree> degree(i + 1.0); 
    242 //      RRLIB_UNIT_TESTS_EQUALITY(tPosition2D<double>(degree), position_2d); 
    243 //      char delim; 
    244 //      source >> delim; 
    245 //    } 
    246 // 
    247 //    source.clear(); 
    248 //    source.str(""); 
    249 //    source << "(1°, 2°, 3°), (2°, 3°, 4°), ende"; 
    250 //    for (size_t i = 0; i < 2; ++i) 
    251 //    { 
    252 //      source >> position_3d; 
    253 //      math::tAngle<double, math::angle::Degree> degree_1(i + 1.0); 
    254 //      math::tAngle<double, math::angle::Degree> degree_2(i + 2.0); 
    255 //      math::tAngle<double, math::angle::Degree> degree_3(i + 3.0); 
    256 //      RRLIB_UNIT_TESTS_EQUALITY(tPosition3D<double>(degree_1, degree_2, degree_3), position_3d); 
    257 //      char delim; 
    258 //      source >> delim; 
    259 //    } 
    260 // 
    261 //    serialization::tMemoryBuffer memory_buffer; 
    262 //    serialization::tOutputStream output_stream(memory_buffer); 
    263 //    serialization::tInputStream input_stream(memory_buffer); 
    264 // 
    265 //    output_stream << tPosition2D<double>(math::tAngle<double, math::angle::Radian>(5 * M_PI_2)); 
    266 //    output_stream << tPosition2D<float>(math::tAngle<double, math::angle::Radian>(0)); 
    267 //    output_stream << tPosition3D<double>(math::tAngle<double, math::angle::Radian>(1), math::tAngle<double, math::angle::Radian>(2), math::tAngle<double, math::angle::Radian>(3)); 
    268 //    output_stream << tPosition3D<float>(math::tAngle<double, math::angle::Radian>(1.5), math::tAngle<double, math::angle::Radian>(2.5), math::tAngle<double, math::angle::Radian>(3.5)); 
    269 //    output_stream.Flush(); 
    270 // 
    271 //    input_stream >> position_2d; 
    272 //    RRLIB_UNIT_TESTS_EQUALITY(tPosition2D<double>(math::tAngle<double, math::angle::Radian>(M_PI_2)), position_2d); 
    273 //    input_stream >> position_2d; 
    274 //    RRLIB_UNIT_TESTS_EQUALITY(tPosition2D<double>(math::tAngle<double, math::angle::Radian>(0)), position_2d); 
    275 //    input_stream >> position_3d; 
    276 //    RRLIB_UNIT_TESTS_EQUALITY(tPosition3D<double>(math::tAngle<double, math::angle::Radian>(1), math::tAngle<double, math::angle::Radian>(2), math::tAngle<double, math::angle::Radian>(3)), position_3d); 
    277 //    input_stream >> position_3d; 
    278 //    RRLIB_UNIT_TESTS_ASSERT(IsEqual(tPosition3D<double>(math::tAngle<double, math::angle::Radian>(1.5), math::tAngle<double, math::angle::Radian>(2.5), math::tAngle<double, math::angle::Radian>(3.5)), position_3d, 1E-6)); 
     201    std::stringstream actual; 
     202    std::stringstream expected; 
     203 
     204    actual << tPosition2D<double>(1, 2); 
     205    expected << "(1 m, 2 m)"; 
     206    RRLIB_UNIT_TESTS_EQUALITY(expected.str(), actual.str()); 
     207 
     208    actual << tPosition3D<double>(1, 2, 3); 
     209    expected << "(1 m, 2 m, 3 m)"; 
     210    RRLIB_UNIT_TESTS_EQUALITY(expected.str(), actual.str()); 
     211 
     212    tPosition2D<double> position_2d; 
     213    tPosition3D<double> position_3d; 
     214    std::stringstream source; 
     215    source.exceptions(std::istream::failbit); 
     216    RRLIB_UNIT_TESTS_EXCEPTION(source >> position_2d, std::ios_base::failure); 
     217    source.clear(); 
     218    RRLIB_UNIT_TESTS_EXCEPTION(source >> position_3d, std::ios_base::failure); 
     219    source.clear(); 
     220    source << "(120 m, 150 m)"; 
     221    source >> position_2d; 
     222    RRLIB_UNIT_TESTS_EQUALITY(tPosition2D<double>(120, 150), position_2d); 
     223    source.clear(); 
     224    source << "(120 m)"; 
     225    RRLIB_UNIT_TESTS_EXCEPTION(source >> position_2d, std::ios_base::failure); 
     226    source.clear(); 
     227    source.str(""); 
     228    source << "(10 m, 20 m, 30 m)"; 
     229    source >> position_3d; 
     230    RRLIB_UNIT_TESTS_EQUALITY(tPosition3D<double>(10, 20, 30), position_3d); 
     231    source.clear(); 
     232    source << "(120 m)"; 
     233    RRLIB_UNIT_TESTS_EXCEPTION(source >> position_3d, std::ios_base::failure); 
     234 
     235    source.clear(); 
     236    source.str(""); 
     237    source << "(1 m, 3 m), (2 m, 4 m), ende"; 
     238    for (size_t i = 0; i < 2; ++i) 
     239    { 
     240      source >> position_2d; 
     241      RRLIB_UNIT_TESTS_EQUALITY(tPosition2D<double>(i + 1.0, i + 3.0), position_2d); 
     242      char delim; 
     243      source >> delim; 
     244    } 
     245 
     246    source.clear(); 
     247    source.str(""); 
     248    source << "(1 m, 2 m, 3 m), (2 m/s^2, 3 m/s^2, 4 m/s^2), ende"; 
     249    { 
     250      source >> position_3d; 
     251      RRLIB_UNIT_TESTS_EQUALITY(tPosition3D<double>(1.0, 2.0, 3.0), position_3d); 
     252      char delim; 
     253      source >> delim; 
     254    } 
     255    { 
     256      tAcceleration3D<> acceleration_3d; 
     257      source >> acceleration_3d; 
     258      RRLIB_UNIT_TESTS_EQUALITY(tAcceleration3D<double>(2.0, 3.0, 4.0), acceleration_3d); 
     259      char delim; 
     260      source >> delim; 
     261    } 
     262 
     263    serialization::tMemoryBuffer memory_buffer; 
     264    serialization::tOutputStream output_stream(memory_buffer); 
     265    serialization::tInputStream input_stream(memory_buffer); 
     266 
     267    output_stream << tPosition2D<double>(5, 7); 
     268    output_stream << tPosition2D<float>(1, -3); 
     269    output_stream << tPosition3D<double>(1, 2, 3); 
     270    output_stream << tPosition3D<float>(1.5, 2.5, 3.5); 
     271    output_stream.Flush(); 
     272 
     273    tPosition2D<float> position_2d_float; 
     274    tPosition3D<float> position_3d_float; 
     275 
     276    input_stream >> position_2d; 
     277    RRLIB_UNIT_TESTS_EQUALITY(tPosition2D<double>(5, 7), position_2d); 
     278    input_stream >> position_2d_float; 
     279    RRLIB_UNIT_TESTS_EQUALITY(tPosition2D<float>(1, -3), position_2d_float); 
     280    input_stream >> position_3d; 
     281    RRLIB_UNIT_TESTS_EQUALITY(tPosition3D<double>(1, 2, 3), position_3d); 
     282    input_stream >> position_3d_float; 
     283    RRLIB_UNIT_TESTS_ASSERT(IsEqual(tPosition3D<float>(1.5, 2.5, 3.5), position_3d_float, 1E-6)); 
    279284  } 
    280285 
Note: See TracChangeset for help on using the changeset viewer.