Menu

setUp problem pls check it out!!!

Help
ritesh
2002-12-27
2003-04-25
  • ritesh

    ritesh - 2002-12-27

    Hi
        I am tring to test some method of vector STL. I putting here entire code. Please some try it out. Please Tell me, why setUp is not failing?
    **************************************************
    #ifndef __TEST_H__
    #define __TEST_H__
    #include<vector>
    #include "cppunit/extensions/HelperMacros.h"
    using namespace std;
    typedef vector <char>charvect;
    class vect : public CppUnit::TestFixture
    {
      CPPUNIT_TEST_SUITE( vect );
      CPPUNIT_TEST( SizePushBackTest );
      CPPUNIT_TEST_SUITE_END();
    private:
        charvect v;

    public:
        void setUp();
        void SizePushBackTest ();

    };

    #endif
    **************************************************
    #include<cctype>
    #include"text1.h"

    void vect::setUp()
    {
        v.resize(5);
        for(int i=0;i<10;i++)
        {
            //push_back(i+'a');
            v[i]=i+'a';
        }

    }
    void vect::SizePushBackTest ()
    {
        CPPUNIT_ASSERT_EQUAL(char('f'),v[5]);
        int siz=v.size();
        CPPUNIT_ASSERT_EQUAL(5,siz);
        for( int i=0; i<v.size();i++)
        {
            CPPUNIT_ASSERT_EQUAL(char(i+'a'),v[i]);
        }
    }

    As initialy v size was zero. then i am resizing in the setup to 5. while assigning the value to v. It should fail setUp.
    I have tried this thing without the CPPUNIT.
    So here Cppunit is not fullfilling the purpose.

    - Regards

    Ritesh

     
    • Anonymous

      Anonymous - 2003-04-09

      The member function returns a reference to the element of the controlled sequence at position pos. If that position is invalid, the behavior is undefined.

      In another word, it does not have to fail!

       
      • Johan Nilsson

        Johan Nilsson - 2003-04-25

        "Xiaofeng Zhao" <xf10036@users.sourceforge.net> wrote in message
        news:162@37108.11795.sourceforge.net...
        >
        > The member function returns a reference to the element of the controlled
        sequence at position pos. If that position is invalid, the behavior is
        undefined.
        >

        The member function "at()" throws an exception if out of bounds. The array
        subscription operator "[]" has undefined behaviour under the same condition.

        // Johan

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.