Test Driven Development

Test Driven Developement (TDD) consist of defining test that would validate a desired functionality before to develop the functionality itself. After development, the test allows to validate that the functionality works but also that functionally matches the initial expectation.

Wikipedia is a good entrance point for going further in the concepts of TDD.

One of the simplest ways to develop tests in Python is to use pytest.

Pytest tool:

A test script has file-name starting with test_. Optionally it can be regrouped in a test directory. It is composed of test function starting with def test_ defining assert based test. For instance test_pytest.py:

def test_test():
    assert( True )

Then, Pytest can be used to run the tests:

# install
pip install pytest

# execute all your tests:
pytest

Test your players:

Test your games:

A minimal test bench built considering the gameHello tutorial:

"""
Test - hello.Engine
"""
import sys

sys.path.insert( 1, __file__.split('hackagames')[0] )
import hackagames.hackapy as hg
import gameHello.gameEngine as ge

def test_gameMethod():
    game= ge.GameConnect4()

    assert( type( game.initialize().asPod() ) is hg.Pod  )
    assert( type( game.playerHand(1).asPod() ) is hg.Pod )
    game.applyPlayerAction( 1, "test" )
    game.tic()
    assert( not game.isEnded() )
    assert( game.playerScore(1) == 0 )

def test_initialize():
    game= ge.GameConnect4()

    wakeUpPod= game.initialize().asPod()

    assert( str(wakeUpPod) == "hello:" )

    assert( wakeUpPod.family() == "hello" )
    assert( wakeUpPod.status() == "" )
    assert( wakeUpPod.integers() == [] )
    assert( wakeUpPod.values() == [] )
    assert( len( wakeUpPod.children() ) == 0 )

def test_playerHand():
    game= ge.GameConnect4()

    game.initialize().asPod()
    handPod= game.playerHand(1).asPod()

    assert( str(handPod) == 'hi: [0]' )

    assert( handPod.family() == "hi" )
    assert( handPod.status() == "" )
    assert( handPod.integers() == [0] )
    assert( handPod.values() == [] )
    assert( len( handPod.children() ) == 0 )

Then you have to adapt the test while you implement your game.