[Clam-devel] Re: Some steps to take on your own
JunJun
wangjun at dsp.ac.cn
Tue Jun 10 22:02:46 PDT 2008
> 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.
>
More information about the clam-devel
mailing list