From: mzn Date: Thu, 20 Mar 2014 13:41:43 +0000 (+0000) Subject: Add tests. X-Git-Tag: BR_hydro_v1_0_1~36 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3c60d2bb98cf1eb21e57580898c10e1504c2a0cd;p=modules%2Fhydro.git Add tests. --- diff --git a/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.cxx b/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.cxx index b73e345b..720243bb 100644 --- a/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.cxx +++ b/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.cxx @@ -44,12 +44,274 @@ std::string test_HYDROGUI_ZLevelsModel::GetObjects( HYDROGUI_ZLevelsModel* theMo return anObjects; } +/** + Test move up algorithm. +*/ void test_HYDROGUI_ZLevelsModel::testMoveUp() { HYDROGUI_ZLevelsModel* aModel = new HYDROGUI_ZLevelsModel(); aModel->setObjects( CreateTestObjects( 6 ) ); + const HYDROGUI_ZLevelsModel::OpType anUp = HYDROGUI_ZLevelsModel::Up; + // 0. Check the initial state CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + // 1. [ *A ] / ALL OBJECTS + aModel->move( QList() << 0, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 2. [ *A, B ] / ALL OBJECTS + aModel->move( QList() << 0 << 1, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 3. [ *A, *C ] / ALL OBJECTS + aModel->move( QList() << 0 << 2, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 4. [ *A, F ] / ALL OBJECTS + aModel->move( QList() << 0 << 5, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 5. [ F ] X 6 times / ALL OBJECTS + aModel->move( QList() << 5, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, F, *E" ), GetObjects( aModel ) ); + aModel->move( QList() << 4, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, F, D, *E" ), GetObjects( aModel ) ); + aModel->move( QList() << 3, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, F, *C, D, *E" ), GetObjects( aModel ) ); + aModel->move( QList() << 2, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, F, B, *C, D, *E" ), GetObjects( aModel ) ); + aModel->move( QList() << 1, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, B, *C, D, *E" ), GetObjects( aModel ) ); + aModel->move( QList() << 0, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, B, *C, D, *E" ), GetObjects( aModel ) ); + + // 6. [ *A, B ] / ALL OBJECTS + aModel->move( QList() << 1 << 2, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, F, *C, D, *E" ), GetObjects( aModel ) ); + + // 7. [ B, *C, *E ] / ALL OBJECTS + aModel->move( QList() << 1 << 3 << 5, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *A, *C, F, *E, D" ), GetObjects( aModel ) ); + + // 8. [ *A, *C, F, *E, D ] / ALL OBJECTS + aModel->move( QList() << 1 << 2 << 3 << 4 << 5, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, F, *E, D, B" ), GetObjects( aModel ) ); + + // 9. [ *E ] / VISIBLE OBJECTS + aModel->move( QList() << 3, anUp, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, *E, *C, F, D, B" ), GetObjects( aModel ) ); + + // 10. [ *E, *C ] / VISIBLE OBJECTS + aModel->move( QList() << 1 << 2, anUp, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, *C, *A, F, D, B" ), GetObjects( aModel ) ); + + // 11. [ *A, F ] / ALL OBJECTS + aModel->move( QList() << 2 << 3, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, *A, F, *C, D, B" ), GetObjects( aModel ) ); + + // 12. [ *A, *C ] / VISIBLE OBJECTS + aModel->move( QList() << 1 << 3, anUp, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, *E, F, D, B" ), GetObjects( aModel ) ); + + // 13. [] / ALL OBJECTS + aModel->move( QList(), anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, *E, F, D, B"), GetObjects( aModel ) ); + + // 14. [ *A, *C, *E, F, D, B ] / ALL OBJECTS + aModel->move( QList() << 0 << 1 << 2 << 3 << 4 << 5, anUp, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, *C, *E, F, D, B"), GetObjects( aModel ) ); + + delete aModel; +} + +/** + Test move on top algorithm. +*/ +void test_HYDROGUI_ZLevelsModel::testMoveOnTop() +{ + HYDROGUI_ZLevelsModel* aModel = new HYDROGUI_ZLevelsModel(); + aModel->setObjects( CreateTestObjects( 6 ) ); + const HYDROGUI_ZLevelsModel::OpType aTop = HYDROGUI_ZLevelsModel::Top; + + // 0. Check the initial state + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 1. [ *A ] / ALL OBJECTS + aModel->move( QList() << 0, aTop, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 2. [ *A ] / VISIBLE OBJECTS + aModel->move( QList() << 0, aTop, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 3. [ F ] / ALL OBJECTS + aModel->move( QList() << 5, aTop, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *A, B, *C, D, *E" ), GetObjects( aModel ) ); + + // 4. [ *E ] / VISIBLE OBJECTS + aModel->move( QList() << 5, aTop, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, B, *C, D" ), GetObjects( aModel ) ); + + // 5. [ *E, F ] / ALL OBJECTS + aModel->move( QList() << 0 << 1, aTop, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, B, *C, D" ), GetObjects( aModel ) ); + + // 6. [ *E, *A ] / ALL OBJECTS + aModel->move( QList() << 0 << 2, aTop, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, *A, F, B, *C, D" ), GetObjects( aModel ) ); + + // 7. [ *A, F, *C ] / ALL OBJECTS + aModel->move( QList() << 1 << 2 << 4, aTop, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, F, *C, *E, B, D" ), GetObjects( aModel ) ); + + // 8. [ F, *C, *E, B, D ] / ALL OBJECTS + aModel->move( QList() << 1 << 2 << 3 << 4 << 5, aTop, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, *E, B, D, *A" ), GetObjects( aModel ) ); + + // 9. [] / ALL OBJECTS + aModel->move( QList(), aTop, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, *E, B, D, *A" ), GetObjects( aModel ) ); + + // 10. [*F, *C, *E, B, D, *A] / ALL OBJECTS + aModel->move( QList() << 0 << 1 << 2 << 3 << 4 << 5, aTop, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, *E, B, D, *A" ), GetObjects( aModel ) ); + + delete aModel; +} + +/** + Test move down algorithm. +*/ +void test_HYDROGUI_ZLevelsModel::testMoveDown() +{ + HYDROGUI_ZLevelsModel* aModel = new HYDROGUI_ZLevelsModel(); + aModel->setObjects( CreateTestObjects( 6 ) ); + const HYDROGUI_ZLevelsModel::OpType aDown = HYDROGUI_ZLevelsModel::Down; + + // 0. Check the initial state + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 1. [ F ] / ALL OBJECTS + aModel->move( QList() << 5, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 2. [ *E, F ] / ALL OBJECTS + aModel->move( QList() << 4 << 5, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 3. [ D, F ] / ALL OBJECTS + aModel->move( QList() << 3 << 5, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 4. [ *A, F ] / ALL OBJECTS + aModel->move( QList() << 0 << 5, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 5. [ *A ] X 6 times / ALL OBJECTS + aModel->move( QList() << 0, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *A, *C, D, *E, F" ), GetObjects( aModel ) ); + aModel->move( QList() << 1, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *A, D, *E, F" ), GetObjects( aModel ) ); + aModel->move( QList() << 2, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *A, *E, F" ), GetObjects( aModel ) ); + aModel->move( QList() << 3, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, *A, F" ), GetObjects( aModel ) ); + aModel->move( QList() << 4, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, F, *A" ), GetObjects( aModel ) ); + aModel->move( QList() << 5, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, F, *A" ), GetObjects( aModel ) ); + + // 6. [ *E, *F ] / ALL OBJECTS + aModel->move( QList() << 3 << 4, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *A, *E, F" ), GetObjects( aModel ) ); + + // 7. [ B, D, *E ] / ALL OBJECTS + aModel->move( QList() << 0 << 2 << 4, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*C, B, *A, D, F, *E" ), GetObjects( aModel ) ); + + // 8. [ *C, B, *A, D, F ] / ALL OBJECTS + aModel->move( QList() << 0 << 1 << 2 << 3 << 4, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, *C, B, *A, D, F" ), GetObjects( aModel ) ); + + // 9. [ *C ] / VISIBLE OBJECTS + aModel->move( QList() << 1, aDown, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, B, *A, *C, D, F" ), GetObjects( aModel ) ); + + // 10. [ *E, *A ] / VISIBLE OBJECTS + aModel->move( QList() << 0 << 2, aDown, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F" ), GetObjects( aModel ) ); + + // 11. [ *E, *A ] / VISIBLE OBJECTS + aModel->move( QList() << 2 << 3, aDown, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F" ), GetObjects( aModel ) ); + + // 12. [ *C, *E, *A ] / VISIBLE OBJECTS + aModel->move( QList() << 1 << 2 << 3, aDown, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F" ), GetObjects( aModel ) ); + + // 13. [] / ALL OBJECTS + aModel->move( QList(), aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F"), GetObjects( aModel ) ); + + // 14. [ B, *C, *E, *A, D, F ] / ALL OBJECTS + aModel->move( QList() << 0 << 1 << 2 << 3 << 4 << 5, aDown, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, *E, *A, D, F"), GetObjects( aModel ) ); + + delete aModel; +} + +/** + Test move on bottom algorithm. +*/ +void test_HYDROGUI_ZLevelsModel::testMoveOnBottom() +{ + HYDROGUI_ZLevelsModel* aModel = new HYDROGUI_ZLevelsModel(); + aModel->setObjects( CreateTestObjects( 6 ) ); + const HYDROGUI_ZLevelsModel::OpType aBottom = HYDROGUI_ZLevelsModel::Bottom; + + // 0. Check the initial state + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 1. [ F ] / ALL OBJECTS + aModel->move( QList() << 5, aBottom, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 2. [ F ] / VISIBLE OBJECTS + aModel->move( QList() << 5, aBottom, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "*A, B, *C, D, *E, F" ), GetObjects( aModel ) ); + + // 3. [ *A ] / ALL OBJECTS + aModel->move( QList() << 0, aBottom, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, *C, D, *E, F, *A" ), GetObjects( aModel ) ); + + // 4. [ *C ] / VISIBLE OBJECTS + aModel->move( QList() << 1, aBottom, true ); + CPPUNIT_ASSERT_EQUAL( std::string( "B, D, *E, F, *A, *C" ), GetObjects( aModel ) ); + + // 5. [ B, D ] / ALL OBJECTS + aModel->move( QList() << 0 << 1, aBottom, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, *C, B, D" ), GetObjects( aModel ) ); + + // 6. [ *C, *D ] / ALL OBJECTS + aModel->move( QList() << 3 << 5, aBottom, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "*E, F, *A, B, *C, D" ), GetObjects( aModel ) ); + + // 7. [ *E, *A, *C ] / ALL OBJECTS + aModel->move( QList() << 0 << 2 << 4, aBottom, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, B, D, *E, *A, *C" ), GetObjects( aModel ) ); + + // 8. [ B, D, *E, *A ] / ALL OBJECTS + aModel->move( QList() << 1 << 2 << 3 << 4 , aBottom, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, B, D, *E, *A" ), GetObjects( aModel ) ); + + // 9. [] / ALL OBJECTS + aModel->move( QList(), aBottom, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, B, D, *E, *A" ), GetObjects( aModel ) ); + + // 10. [F, *C, B, D, *E, *A] / ALL OBJECTS + aModel->move( QList() << 0 << 1 << 2 << 3 << 4 << 5, aBottom, false ); + CPPUNIT_ASSERT_EQUAL( std::string( "F, *C, B, D, *E, *A" ), GetObjects( aModel ) ); + delete aModel; } diff --git a/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.h b/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.h index 4dfcefdc..167b66ef 100644 --- a/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.h +++ b/src/HYDROGUI/test_HYDROGUI_ZLevelsModel.h @@ -5,14 +5,19 @@ class HYDROGUI_ZLevelsModel; class test_HYDROGUI_ZLevelsModel : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(test_HYDROGUI_ZLevelsModel); CPPUNIT_TEST(testMoveUp); + CPPUNIT_TEST(testMoveOnTop); + CPPUNIT_TEST(testMoveDown); + CPPUNIT_TEST(testMoveOnBottom); CPPUNIT_TEST_SUITE_END(); private: std::string GetObjects( HYDROGUI_ZLevelsModel* theModel ) const; public: - // checks move up void testMoveUp(); + void testMoveOnTop(); + void testMoveDown(); + void testMoveOnBottom(); }; CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROGUI_ZLevelsModel);