Sign in to follow this  
Endar

number of tests

Recommended Posts

Endar    668
I've written a dynamic array class for C++, and I just recently added an insert function. I'm just wondering how many tests I should put it through to test the insert function. Would you generally do a single test for each of the special cases and then one of the general case? This is what I ended up doing. I started the list off with 5 elements (integers, 0-4) and then inserted at the end, at the start and in the middle. Do you think that these tests would be enough considering that I have already tested the rest of the class and have confirmed it's correctness?

Share this post


Link to post
Share on other sites
SiCrane    11839
I'd also throw in a test with a class type to make sure that you aren't leaking memory or double deleting or similar non-kosherness.

Share this post


Link to post
Share on other sites
iMalc    2466
Do you have removal operations as well?
Don't forget to gracefully handle attempts to do stupid things such as pop_front with no items in the array.

[grin]!I think the best test is posting it on a message board and let 1000s of others pick holes in it![grin]

Share this post


Link to post
Share on other sites
Endar    668
All the other functions (push_back, erase, resize, etc) have been written and are working and I'm actually using it in my current project, a simple graphics engine.

It's just that I've always used push_back or just resized it and accessed the elements manually, because there's never been a need for anything else.

So, it was just on the insert function I was wondering about the number of tests.

Share this post


Link to post
Share on other sites
Enigma    1410
Quote:
Original post by Endar
I've written a dynamic array class for C++...

Everyone already knows that I'm going to post it and I'd hate to disappoint, so without further ado:

Why? What's wrong with std::vector?

Enigma

Share this post


Link to post
Share on other sites
Endar    668
Absolutely nothing.

There was a fairly good reason as to why I was using it early on that I can't remember as it is midnight here, but later on it just became ingrained with the rest of my code, and since it was all working, I couldn't really find a compelling reason to go and re-write a whole bunch of code for what seemed to be fairly negligible rewards.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this