Friday, 10 December 2010

Conditionals Mon Amour

The trouble is that while the function is executing, we don't know that the options being presented are correct, or that the branch being taken is the correct one.

We need to expand the test:

        assert_equal("Sulk", options[1].text)
        assert_equal("sulking", options[1].next)
        assert_equal("Complain", options[2].text)
        assert_equal("moaning", options[2].next)


They pass, so that bit's all right. We'll need to do another one where we  surpress an option in the middle of the list, just to make sure they aren't being truncated. But let's finish this one first.

So: at the moment, the choice has been displayed, but not evaluated. We need to queue some simulated user input, and then run the scene a bit further.

        stage:iq_insert(1)
        rc = narrator:play(stage)


I'm expecting it to cut before the transition to a new narrative. So:

        assert_true(rc)

No problem so far. Option 1 should be "Sulk". Let's see if the narrator is
pointing at the right narrative

        assert_equal("sulking", narrator.narrative.name)

That also passes. Let's play on

        --
        -- check the output
        --
        assert_equal("text", stage:oq(1).type)
        assert_equal("You pout", stage:oq(1).value)
        assert_equal("text", stage:oq(2).type)
        assert_equal("The door fails to open", stage:oq(2).value)

        --
        -- play it again - this will run the func and the jump
        --
        rc = narrator:play(stage)
        assert_true(rc)
        assert_true(narrator.userdata.sulk)
        assert_equal("in_the_room", narrator.narrative.name)


And all that passes. We're now back at the our start point. Let's take the "Complain" option this time...

No comments: