[Clam-devel] Re: Some steps to take on your own

David García Garzón dgarcia at iua.upf.edu
Wed Jun 11 05:03:33 PDT 2008


Proceed the same way with the ContiguousSegmentation

* Proceed with the same steps and patch points than ContiguousSegmentation
** Make the test red
** Greenify
** Refactor
* You may have also bugs in there, send me a mail if so.

* After that you should have the same content on both classes, as we rely on 
the virtual function FillArray, so we'll do a refactoring in two steps:
** Choose one implementation (ie. Discontinuous) and move it to the base 
class, (no StoreOn in Discontinuous now). all test passing, commit
** Remove the remaining implementation in Contiguous, all test passing, commit



On Dimecres 11 Juny 2008, JunJun wrote:
> > 1. Implement the testStoreOn() test method. The code could be something
> > like that:
> >
> > #include "XMLTestHelper.hxx"
> > ....
> >
> >       void testStoreOn()
> >        {
> >            const double onsets[] = {90,100,110};
> >            ContiguousSegmentation segmentation(200, onsets, onsets+3);
> >
> >            std::ostringstream stream;
> >            XMLStorage::Dump(segmentation, "Segmentation", stream);
> >
> >            CLAMTEST_ASSERT_XML_EQUAL(
> >                "<Segmentation size="3">90 100 110</Segmentation>"
> >                , stream.str());
> >        }
> >
> > Notice that this would be the output we are outputing now for such
> > segmentation as we are doing now.
> > Do the needed changes to compile and to make it fail (by doing nothing in
> > StoreOn)
>
> Done. It fails.
>
> > 2. We should make it green by building in StoreOn an array, filling it in
> > with the method we did the other day, and delegating onto the array store
> > on.
> >
> > ContinuousSegmentation::StoreOn(Storage & storage) const
> > {
> > CLAM::Array array;
> > fillArray(array);
> > array.StoreOn(storage);
> > }
> >
> > In order to be able to use the fillArray method in StoreOn which is a
> > const method, you should define fillArray method also as a constant one:
> > void fillArray(DataArray & array) const  <- this const
> > The constness should be changed at onece in the base class and in the
> > derived classes.
> >
> > After doing that you will see that the test is not as green as we should
> > expect. We catched an error!! What's happening there?
> >
> > Reply with copy to the list or at irc.
>
> Yes, we catch the error displayed as  below:
> ************************************************************************
> * . CLAMTest::ContiguousSegmentationTest::testStoreOn
> *
> *This application has requested the Runtime to terminate it in an unusual
> way. *Please contact the application's support team for more information. *
> *..........................................................................
>......................... *
> *..........................terminate called after throwing an instance of
> 'CLAM::ErrAssertionFailed' *  what():  Array::operator[]: Index out of
> range
> *This may happen if you forgot to call SetSize(...) in your code.
> *This is now needed. Just calling Resize() is not enough any more
> **************************************************************************
> Then I checked the code and caught a bug in ContiguousSegmentation:
>   void fillArray(DataArray& segmentation) const
>   {
>    unsigned nSegments= _onsets.size();
>    segmentation.Resize(nSegments-1);
>    segmentation.SetSize(nSegments-1);
>    for(unsigned i=1; i<nSegments; i++)
>     segmentation[i]=_onsets[i];      //Bug!! it should be
> "segmentation[i-1]=_onsets[i]; " }
> which is not introduced by me who just did a copy&paste job :-)
> I've fixed that and the test is GREEN now:
>
> ...........................................................................
>..................................................
>
>
> OK (125 tests)
>
>
> Cool!
> What's the next?
>
> > David.



-- 
David García Garzón
(Work) dgarcia at iua dot upf anotherdot es
http://www.iua.upf.edu/~dgarcia
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.clam-project.org/pipermail/clam-devel-clam-project.org/attachments/20080611/8682c632/attachment.sig>


More information about the clam-devel mailing list