Powering buildings and unit testing

Published November 02, 2011
Advertisement
I've been working on adding a "power" system to the game. I'd say powering buildings is a pretty fundamental task in a modern city building game, but I never included it for some reason.

Well, now I am! Part of the reason is that all of the code for it is written in C# and so it provides an excellent task to really test the interop abilities with VB6. The other reason I like it is because the "power simulator" as I call it is very unit testable.

I'm a fan of unit testing -- in the last project I worked on with a friend we had a pretty extensive test suite and maintained ~70% code coverage, and we had the tests run by the build server we set up. Anyway, I do try and test the more "logical" parts of the game. This power system is a perfect example -- here are some of the scenarios you can test:
  • there should be unpowered buildings when the demand exceeds the supply
  • there could be excess power, but one of the power plants may not be connected. At which point, the buildings should not receive power.
  • all of the buildings adjacent to the power plant are powered
  • a building that is connected to a powered building is not considered powered (must be connected to power lines)
In addition, it's much easier to test this isolated than it is trying to try it out in the game. An even more important benefit is that it allowed me to write the simulation part while holding off on allowing the user to construct power lines. That's what will be coming next actually.. For the moment, there are just a bunch of unpowered buildings:

gallery_83239_305_172109.jpg

Here is what the unit test suite for the game currently looks like (keep in mind I just started extending it with C# a few weeks ago):

gallery_83239_305_15142.jpg
Previous Entry The Challenge
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement