Thursday, January 19, 2012

Big Lamentations Over PA1

So, a few days ago, I had the tree working beautifully.  Not everything had been tested thoroughly, but the requirements described in the assignment were verified and validated.  Children, siblings, recursion, and printing were working great, and I even managed to get all of the removal code working without a hitch.  From all that I could tell by the assignment description, it was finished.  Big happiness!

Then came the unit tests, which not only didn't match my interface, but also indicated that the design of my implementation was actually too good.  The unit tests actually required me to downgrade the quality of my design in order to make the tests pass.  It's painful, frustrating, and shameful.  I am not proud of some of the stupid things I've had to do just to get the tests to pass.  Big sadness.

There is one test that I cannot seem to pass no matter what.  There's a check in the unit tests to see if the root of a new tree is null.  Well, the assignment said that the root should not be removable, and my solution to this was to create a dummy root upon instantiation of the tree.  This way, the tree completely encapsulated the root and maintained complete control over it throughout its life.  The getRoot() function always returned the dummy root, which was always present and could not be deleted. No need to check for nulls and no worries about losing the entire tree in a memory leak.

I stand by the wisdom of this design as well as other aspects that I had to destroy for the sake of conformity.  But I can't find a way to make the unit tests pass because they expect the root to be null in a new tree.  If I make it null, then the whole thing crashes with access violations.  Big trouble.

What to do?  The assignment is officially past due and I'm stuck.  I think I just have to turn it in as-is.  I can't pull another all-nighter and still be able to perform at work tomorrow.  I've only had about eight hours of sleep in the last three days and I fear that it'll start to affect those who depend on me. Time to cut my losses, I think.  You can't win 'em all.

Perhaps tomorrow I'll start over on it and design it in the way the unit tests imply rather than the vague and incomplete specifications from the assignment write-up.  Better late than never, I suppose...even if the later version is worse than the earlier one.

Either that, or I'll start taking a look at PA2 and PA3, which I haven't even been able to read yet because I've been fighting with PA1.

Are we sure this is good experience for me?  Big skepticism.

No comments:

Post a Comment