tests.validation_test Module

This module contains all integration tests for the euler.solutions package. In particular, it will compute the solution for all currently solved problems, and where a known answer exists, it will be checked for correctness.

While this project will only include known answers for problems that have been correctly solved, i.e. have been successfully submitted to https://projecteuler.net/; this test harness will detect problems introduced by changes to the core lib Package.

Note

this module has been written to dynamically generate test cases for all solutions at run-time. This means that it does not need to be modified for any new solution included in the project.

The tests.validation_test.TestSolutions class is initially defined to be empty, however, the tests.validation_test.register_solutions() function will dynamically add member functions to that class. For each solution detected at run-time, a test case will be created and added to tests.validation_test.TestSolutions named test_problem_X, X is a three digit decimal number derived from the corresponding Project Euler problem number.

tests.validation_test – Validation of Implemented Solutions

class tests.validation_test.TestSolutions(methodName='runTest')

Bases: unittest.case.TestCase

Will contain all registered solutions once tests.validation_test.register_solutions() is invoked

test_problem_001()
test_problem_002()
test_problem_003()
test_problem_004()
test_problem_005()
test_problem_006()
test_problem_007()
test_problem_008()
test_problem_009()
test_problem_010()
test_problem_011()
test_problem_012()
test_problem_013()
test_problem_014()
test_problem_015()
test_problem_016()
test_problem_017()
test_problem_018()
test_problem_019()
test_problem_020()
test_problem_021()
test_problem_022()
test_problem_023()
test_problem_024()
test_problem_025()
test_problem_026()
test_problem_027()
test_problem_028()
test_problem_029()
test_problem_030()
test_problem_031()
test_problem_032()
test_problem_033()
test_problem_034()
test_problem_035()
test_problem_036()
test_problem_037()
test_problem_038()
test_problem_039()
test_problem_040()
test_problem_041()
test_problem_042()
test_problem_043()
test_problem_044()
test_problem_045()
test_problem_046()
test_problem_047()
test_problem_048()
test_problem_049()
test_problem_050()
tests.validation_test.make_failure(message)

Build a test that unconditionally fails, used to flag errors in dynamic test generation

Parameters:message (str) – the description of the error
Returns:a unit test function
tests.validation_test.make_tst_function(description, problem_number, solver, expected_answer)

Build a test that computes the answer to the given problem and checks its correctness

Parameters:
  • description (str) – a label to attach to this test case
  • problem_number (int) – the Project Euler problem number
  • solver (Callable[[None], Union[int, str]]) – the function that computes the answer
  • expected_answer (Union[int, str]) – the expected answer to this problem
Returns:

a unit test function

tests.validation_test.register_solutions()

Dynamically load and run each solution present, test the computed answers match expected answers

tests.validation_test.teardown_module(module)

The teardown (module) function is called when all tests in this module are complete

This function will collect and report on the results of all validation tests. That is, their correctness and their run-times. These reports are collated into ordered CSV files, each capturing up to 100 contiguous tests:

  • tests 1-100
  • tests 101-200
  • etc.

These CSVs will be picked up by other code to ultimately build the documented project. These CSVs will contribute to the tables of solutions and their respective run-times.

Parameters:module – the module under teardown (i.e. tests.validation_test)
Returns:None