Tuesday, March 27, 2007

Effects

Functionality Testing
 I seem to be stuck, functionality speaking. I have a few things to clean up, but no major smells. This means I need to start making some messes. But I'm not sure how to proceed. Which means I need to create a new test.

Test
 Now that I have abilities that characters can use (with success or failure), I need effects. One basic effect is to increase a character's statistic. Something like TestReadingABookMakesLisaSmarter.

Responsibility
 Do I want objCharacter.UseAbility to implement the effects of that ablity? Or do I just want it to indicate whether it was successful (and then have another call to implement the effects)? For now, I'll have the method return a set of effects, and then call effect.Occur() or something.
 This vagueness is what got me stuck, and writing this test is helping me to proceed.

Ability
 Ok, so the ability object should have two collections - successEffects and failureEffects. I've written a bunch of code without and tests yet, so I'll implement this in steps:

1. Successful, no effects
3. Failure, no effects
2. Successful, 1 effect
4. Failure, 1 effect.

No effect
 So, My first test should be testReadingABookDoesNOTMakeLisaSmarter. Ok, I wrote the test, but also implemented it at the same time. I'm not letting the tests drive yet (as I know they are going to fail, so I skip that step). I've got to improve my habits here.
 New test - testReadingABookDoesNOTMakeHomerSmarter. Well, this one passes vacuously. Not so interesting.

Another effect
 Now, to implement my first effect. It should be as simple as possible - let's say returning a message to be displayed. Most effects will do this.
 I need to write a test first, and I need another effect. Something like testHittingThumbMakesHomerSayDoh. Writing test now.

Failure Unexpected
 Well, okay, I expected the test to fail, but I wasn't expecting a runtime error. Checking... Ah, I wrote the test wrong. Trying again. Ok, the test is failing for the expected reason now.

More Responsibility
 Who should set the success or failure effect? Should it be part of the canonical ablity? I think that's a good place to start. The canonical ability object (Ability Factory? ) should be able to produce ability objects (that, perhaps can be modified or tweaked). That seems like a good intermediate test. I could have the CanonicalAbility object return a test ability and make sure that it's debugPrint matches an expected value. This would also be a good place for AssertStringsMatch function. Ok, one thing at a time.

Little Detour
 Two additional sub-tests to prove that my AssertStringsMatch function works (it does). Yet again, tests written after code (I've got to stop doing that). Next, test the CanonicalAbility object returning function.

DebugPrint everywhere
 To do this, I've added debugPrint functions to abilities and effects. Along the way, I'm making some notes indicating where I need to shuffle things around. I still think that not using a database is making things more difficult at this point, so I may need to add that next.

Cleaning up
 At this point, I have one non-passing test. It will have to wait, as my time is up for now.

0 Comments:

Post a Comment

<< Home