Testing and Test-Driven Development

Testing and Test-Driven Development#

Let’s write a function implementing the game “rock - paper - scissors”. Inputs are two strings which can either be "rock", "paper", or "scissors". Outputs should reflect the outcome of the game.

We’ll do this in a test-driven way: We first invent and implement a few tests which would ensure the software works as intended. Only after this is done, we implement the actual function.

Software under test#

Here’s a prototype:

def rock_paper_scissor(player_one_plays=None, player_two_plays=None):
    # your code here
    return "player one wins"

Test cases#

Think about possible test cases which would ensure the (still to be implemented) software does what we want it to do. List a few thoughts here:

Tests#

Now, let’s implement these test cases. Here’s a prototye for the test function and its invocation:

def test_rps():
    assert True
test_rps()

Implementing the actual software#

Now that we have a few test cases, let’s work on the software we intend to write.

def rock_paper_scissor(player_one_plays=None, player_two_plays=None):
    # your code here
    return "player one wins"
test_rps()