HelloWorld package

Submodules

HelloWorld.challenge module

This is the HelloWorld challenge to teach the usage of the library by a minimal example.

This challenge takes a number and a word and composes a new word based on the input.

The class fully focuses on the “business logic” by overwriting just two methods of parent class <challenge.challenge.Challenge>:

  • <build>: This sets up the data model from the given input lines.
  • <calc>: This is the core algorithm of the challenge.

This design pattern is called the “Template Method Pattern”. While the parent class handles the common parts of the challenge flow, the child class just encapsulates what is special.

The two methods above is just the bare minimum to implement. For more complex challenges you will overwrite or extend other parts of the parent class.

Have a look into the parent class, especially into the <main> function, that controls the execution of the challenge. Also have a look into the parents <__init__> method to see what instance attributes are already prepared to serve the communication of the methods.

By the class attribute <sample> a small example of the possible input is given. This is recommended for every challenge. It is useful as input of unit tests or for the smoke tests with the -k option. For more extended input, in example from the given data files, this class attribute will be overwritten by injection of an instance attribute of the same name.

The optional class attribute <expect> the expected output for the given <sample> sets the expected output. This is typically used by unit tests.

Together <sample> and <expect> serve as documantation of the intention of the challenge.

class HelloWorld.challenge.HelloWorldChallenge[source]

Bases: challenges.challenge.Challenge

This is the HelloWorld Challenge class.

This challenge takes a word as input and a number at which position to split the word. It returns a new word composed of the switched parts with a blank in between and the total length of the new string.

build()[source]

Parse the input lines and set up the model.

calc()[source]

Swap head and tail of the model and store to result.

expect = '\n Hello World\n 11\n '

This is the expected output for the given sample.

It is used by unit tests, especially by the full integration test.

format()[source]
sample = '\n 5\n WorldHello\n '

This is a small exsample of the input. It can be overwritten by injection.

It is used by the –klass option of the challenge runner. It is also used by unit tests.

prompt> challenge HelloWorld/ –klass Hello World

HelloWorld.test module

class HelloWorld.test.HelloWorldTest(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]
test__init__()[source]
test_build()[source]
test_calc()[source]
test_format()[source]
test_full_integration()[source]

Module contents