Cutesy and poison

Some time ago I wrote couple simple BDD-tests for combat. Today while cleaning up some test code I moved two poison related tests over to BDD side. It was nice to see that quite lot of what I had written for previous tests could be reused for new ones. I only had to create code for poison specific things.

Below is the code. First test is testing that poison actually damages character. Second one is for testing that poison can kill character and dead don’t hang around in the game world.

def test_poison_causes_damage(self):
    """
    Test that triggered poison will damage character
    """
    Pete = strong(Adventurer())

    affect(Pete, with_(weak_poison()))

    assert_that(Pete, has_less_hit_points())

def test_character_can_die_from_poisoning(self):
    """
    Test that character with less than 1 hit points is removed from play
    """
    Uglak = weak(Goblin())
    room = Level()
    place(Uglak, middle_of(room))

    affect(Uglak, with_(potent_poison()))

    assert_that(Uglak, is_dead())
    assert_that(Uglak, is_not_in(room))

Poor Uglak bites the dust again and Pete continues adventuring.

I probably need to soon start thinking on how to structure code in cutesy (BDD-oriented DSL for pyherc). Currently all the code is in a single file, but eventually I have to start splitting it up. I’m undecided still, if I want to do imports from top level of cutesy package, or from individual modules. Both have their advantages. Top level is nice, because I can move around code inside cutesy without breaking anything. Individual modules is nice, because then I can have identical functions, with different meaning.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s