pycellga.tests package

Submodules

pycellga.tests.conftest module

pycellga.tests.test_ackley module

pycellga.tests.test_ackley.test_ackley()[source]

Test the Ackley function implementation.

This test verifies the correctness of the Ackley function by evaluating it at several points and comparing the results to expected values.

The Ackley function is commonly used as a benchmark for optimization algorithms. It is a continuous function with multiple local minima and a single global minimum.

The test performs the following checks: 1. Evaluates the Ackley function at a set of given points. 2. Compares the computed values to expected results.

Parameters:

None

Raises:

AssertionError – If any of the computed values do not match the expected values.

pycellga.tests.test_arithmetic_crossover module

class pycellga.tests.test_arithmetic_crossover.MockProblem[source]

Bases: AbstractProblem

A mock problem class for testing purposes.

f(x: list) float[source]

A mock fitness function that simply sums the chromosome values.

Parameters:

x (list) – A list of float variables.

Returns:

The sum of the list values.

Return type:

float

pycellga.tests.test_arithmetic_crossover.setup_parents()[source]

Fixture for creating a pair of parent Individual instances.

Returns:

A list containing two parent individuals with predefined chromosomes and size.

Return type:

list

pycellga.tests.test_arithmetic_crossover.setup_problem()[source]

Fixture for creating a mock problem instance.

Returns:

An instance of the mock problem.

Return type:

MockProblem

pycellga.tests.test_arithmetic_crossover.test_arithmetic_crossover(setup_parents, setup_problem)[source]

Test the ArithmeticCrossover function implementation.

This test checks the arithmetic crossover on a pair of parent individuals by verifying the recombination operation and the integrity of the offspring chromosomes.

Parameters:
  • setup_parents (fixture) – The fixture providing the parent individuals.

  • setup_problem (fixture) – The fixture providing the mock problem instance.

pycellga.tests.test_bentcigar_function module

pycellga.tests.test_bentcigar_function.setup_bentcigar()[source]

Fixture for creating an instance of the Bentcigar problem.

Returns:

An instance of the Bentcigar problem.

Return type:

Bentcigar

pycellga.tests.test_bentcigar_function.test_bentcigar_function(setup_bentcigar)[source]

Test the Bentcigar function implementation.

This test checks the calculation of the Bentcigar function value for given lists of float variables. It uses predefined inputs and compares the outputs to the expected values.

Parameters:

setup_bentcigar (fixture) – The fixture providing the Bentcigar problem instance.

pycellga.tests.test_bit_flip_mutation module

pycellga.tests.test_bit_flip_mutation.test_bit_flip_mutation()[source]

Test the BitFlipMutation class for the Individual class on the OneMax problem.

This test verifies that the BitFlipMutation correctly mutates the chromosome of an Individual by flipping some bits and ensures that the mutation is applied correctly. The test checks that: 1. The chromosome is mutated. 2. The chromosome size remains unchanged. 3. The fitness value of the mutated individual is computed correctly.

The function uses a fixed random seed to ensure reproducibility of the results.

Notes

The test assumes that the BitFlipMutation class correctly implements bit flipping mutation and that the OneMax problem correctly evaluates the fitness of an individual.

The following assertions are made: - At least one bit in the chromosome is changed. - The size of the mutated individual’s chromosome matches the original size. - The fitness value of the mutated individual is calculated correctly.

Raises:

AssertionError – If any of the conditions for correctness are not met.

pycellga.tests.test_blxalpha_crossover module

class pycellga.tests.test_blxalpha_crossover.MockProblem[source]

Bases: AbstractProblem

A mock problem class for testing purposes.

f(x: list) float[source]

A mock fitness function that simply sums the chromosome values.

Parameters:

x (list) – A list of float variables.

Returns:

The sum of the list values.

Return type:

float

pycellga.tests.test_blxalpha_crossover.setup_parents()[source]

Fixture for creating a pair of parent Individual instances.

Returns:

A list containing two parent individuals with predefined chromosomes and size.

Return type:

list

pycellga.tests.test_blxalpha_crossover.setup_problem()[source]

Fixture for creating a mock problem instance.

Returns:

An instance of the mock problem.

Return type:

MockProblem

pycellga.tests.test_blxalpha_crossover.test_blxalpha_crossover(setup_parents, setup_problem)[source]

Test the BlxalphaCrossover function implementation.

This test checks the BLX-alpha crossover on a pair of parent individuals by verifying the recombination operation and the integrity of the offspring chromosomes.

Parameters:
  • setup_parents (fixture) – The fixture providing the parent individuals.

  • setup_problem (fixture) – The fixture providing the mock problem instance.

pycellga.tests.test_bohachevsky module

pycellga.tests.test_bohachevsky.test_bohachevsky()[source]

Test the Bohachevsky function implementation.

This test verifies the correctness of the Bohachevsky function by evaluating it at several points and comparing the results to expected values.

The Bohachevsky function is used as a benchmark for optimization algorithms. It has multiple local minima and is designed to test the performance of optimization algorithms.

The test performs the following checks: 1. Evaluates the Bohachevsky function at specific points. 2. Compares the computed values to the expected rounded results.

Parameters:

None

Raises:

AssertionError – If any of the computed values do not match the expected rounded values.

pycellga.tests.test_byte_mutation module

class pycellga.tests.test_byte_mutation.MockProblem[source]

Bases: AbstractProblem

A mock problem class for testing purposes.

f(x: list) float[source]

A mock fitness function that simply sums the chromosome values.

Parameters:

x (list) – A list of float variables.

Returns:

The sum of the list values.

Return type:

float

pycellga.tests.test_byte_mutation.setup_individual()[source]

Fixture for creating a sample Individual instance.

Returns:

An individual instance with a predefined chromosome and size.

Return type:

Individual

pycellga.tests.test_byte_mutation.setup_problem()[source]

Fixture for creating a mock problem instance.

Returns:

An instance of the mock problem.

Return type:

MockProblem

pycellga.tests.test_byte_mutation.test_byte_mutation(setup_individual, setup_problem)[source]

Test the ByteMutation function implementation.

This test checks the byte-wise mutation on an individual’s chromosome by verifying the mutation operation and the integrity of the chromosome.

Parameters:
  • setup_individual (fixture) – The fixture providing the sample individual.

  • setup_problem (fixture) – The fixture providing the mock problem instance.

pycellga.tests.test_byte_mutation_random module

class pycellga.tests.test_byte_mutation_random.MockProblem[source]

Bases: AbstractProblem

A mock problem class for testing purposes.

f(x: list) float[source]

A mock fitness function that simply sums the chromosome values.

Parameters:

x (list) – A list of float variables.

Returns:

The sum of the list values.

Return type:

float

pycellga.tests.test_byte_mutation_random.setup_individual()[source]

Fixture for creating a sample Individual instance.

Returns:

An individual instance with a predefined chromosome and size.

Return type:

Individual

pycellga.tests.test_byte_mutation_random.setup_problem()[source]

Fixture for creating a mock problem instance.

Returns:

An instance of the mock problem.

Return type:

MockProblem

pycellga.tests.test_byte_mutation_random.test_byte_mutation_random(setup_individual, setup_problem)[source]

Test the ByteMutationRandom function implementation.

This test checks the byte mutation on an individual’s chromosome by verifying the mutation operation and the integrity of the chromosome.

Parameters:
  • setup_individual (fixture) – The fixture providing the sample individual.

  • setup_problem (fixture) – The fixture providing the mock problem instance.

pycellga.tests.test_byte_one_point_crossover module

class pycellga.tests.test_byte_one_point_crossover.MockProblem[source]

Bases: AbstractProblem

A mock problem class for testing purposes.

f(x: list) float[source]

A mock fitness function that simply sums the chromosome values.

Parameters:

x (list) – A list of float variables.

Returns:

The sum of the list values.

Return type:

float

pycellga.tests.test_byte_one_point_crossover.setup_parents()[source]

Fixture for creating a pair of parent Individual instances.

Returns:

A list containing two parent individuals with predefined chromosomes and size.

Return type:

list

pycellga.tests.test_byte_one_point_crossover.setup_problem()[source]

Fixture for creating a mock problem instance.

Returns:

An instance of the mock problem.

Return type:

MockProblem

pycellga.tests.test_byte_one_point_crossover.test_byte_one_point_crossover(setup_parents, setup_problem)[source]

Test the ByteOnePointCrossover function implementation.

This test checks the byte-level one-point crossover on a pair of parent individuals by verifying the recombination operation and the integrity of the offspring chromosomes.

Parameters:
  • setup_parents (fixture) – The fixture providing the parent individuals.

  • setup_problem (fixture) – The fixture providing the mock problem instance.

pycellga.tests.test_byte_operators module

pycellga.tests.test_byte_operators.test_bits_to_float()[source]

Test the bits_to_float function.

pycellga.tests.test_byte_operators.test_bits_to_floats()[source]

Test the bits_to_floats function.

pycellga.tests.test_byte_operators.test_float_to_bits()[source]

Test the float_to_bits function.

pycellga.tests.test_byte_operators.test_floats_to_bits()[source]

Test the floats_to_bits function.

pycellga.tests.test_byte_uniform_crossover module

class pycellga.tests.test_byte_uniform_crossover.MockProblem[source]

Bases: AbstractProblem

A mock problem class for testing purposes.

f(x: list) float[source]

A mock fitness function that simply sums the chromosome values.

Parameters:

x (list) – A list of float variables.

Returns:

The sum of the list values.

Return type:

float

pycellga.tests.test_byte_uniform_crossover.setup_parents()[source]

Fixture for creating a pair of parent Individual instances.

Returns:

A list containing two parent individuals with predefined chromosomes and size.

Return type:

list

pycellga.tests.test_byte_uniform_crossover.setup_problem()[source]

Fixture for creating a mock problem instance.

Returns:

An instance of the mock problem.

Return type:

MockProblem

pycellga.tests.test_byte_uniform_crossover.test_byte_uniform_crossover(setup_parents, setup_problem)[source]

Test the ByteUniformCrossover function implementation.

This test checks the byte-level uniform crossover on a pair of parent individuals by verifying the recombination operation and the integrity of the offspring chromosomes.

Parameters:
  • setup_parents (fixture) – The fixture providing the parent individuals.

  • setup_problem (fixture) – The fixture providing the mock problem instance.

pycellga.tests.test_chichinadze_function module

pycellga.tests.test_chichinadze_function.setup_chichinadze()[source]

Fixture for creating an instance of the Chichinadze problem.

Returns:

An instance of the Chichinadze problem.

Return type:

Chichinadze

pycellga.tests.test_chichinadze_function.test_chichinadze_function(setup_chichinadze)[source]

Test the Chichinadze function implementation.

This test checks the calculation of the Chichinadze function value for given lists of float variables. It uses predefined inputs and compares the outputs to the expected values.

Parameters:

setup_chichinadze (fixture) – The fixture providing the Chichinadze problem instance.

pycellga.tests.test_compact_13 module

pycellga.tests.test_compact_13.test_compact_13()[source]

Test the Compact13 class for calculating neighbor positions in a grid.

This test verifies that the Compact13 class correctly calculates the positions of the 12 neighbors surrounding a given position in a grid. It ensures that: 1. The number of neighbors is always 12 for positions not on the boundary of the grid. 2. Positions on the boundary of the grid still correctly return 12 neighbors.

The test uses three different positions within the grid to validate the functionality of the Compact13 neighborhood calculation.

Notes

The Compact13 neighborhood considers all 12 surrounding cells in a 5x5 grid centered on a given position, excluding the cell itself. The grid is assumed to be toroidal, meaning that positions on the edges wrap around to the opposite edge.

The following assertions are made: - The number of calculated neighbor positions is 12 for various positions in the grid.

Raises:

AssertionError – If the number of calculated neighbor positions is not 12.

pycellga.tests.test_compact_21 module

pycellga.tests.test_compact_21.test_compact_21()[source]

Test the Compact21 class for calculating neighbor positions in a grid.

This test verifies that the Compact21 class correctly calculates the positions of the 20 neighbors surrounding a given position in a grid. It ensures that: 1. The number of neighbors is always 20 for positions not on the boundary of the grid. 2. Positions on the boundary of the grid still correctly return 20 neighbors.

The test uses three different positions within the grid to validate the functionality of the Compact21 neighborhood calculation.

Notes

The Compact21 neighborhood considers all 20 surrounding cells in a 5x5 grid centered on a given position, excluding the cell itself. The grid is assumed to be toroidal, meaning that positions on the edges wrap around to the opposite edge.

The following assertions are made: - The number of calculated neighbor positions is 20 for various positions in the grid.

Raises:

AssertionError – If the number of calculated neighbor positions is not 20.

pycellga.tests.test_compact_25 module

pycellga.tests.test_compact_25.test_compact_25()[source]

Test the Compact25 class for calculating neighbor positions in a grid.

This test verifies that the Compact25 class correctly calculates the positions of the 24 neighbors surrounding a given position in a grid. It ensures that: 1. The number of neighbors is always 24 for positions not on the boundary of the grid. 2. Positions on the boundary of the grid still correctly return 24 neighbors.

The test uses three different positions within the grid to validate the functionality of the Compact25 neighborhood calculation.

Notes

The Compact25 neighborhood considers all 24 surrounding cells in a 5x5 grid centered on a given position, excluding the cell itself. The grid is assumed to be toroidal, meaning that positions on the edges wrap around to the opposite edge.

The following assertions are made: - The number of calculated neighbor positions is 24 for various positions in the grid.

Raises:

AssertionError – If the number of calculated neighbor positions is not 24.

pycellga.tests.test_compact_9 module

pycellga.tests.test_compact_9.test_compact_9()[source]

Test the Compact9 class for calculating neighbor positions in a grid.

This test verifies that the Compact9 class correctly calculates the positions of the 8 neighbors surrounding a given position in a grid. It ensures that: 1. The number of neighbors is always 8 for positions not on the boundary of the grid. 2. Positions on the boundary of the grid still correctly return 8 neighbors.

The test uses three different positions within the grid to validate the functionality of the Compact9 neighborhood calculation.

Notes

The Compact9 neighborhood considers all 8 surrounding cells in a 3x3 grid centered on a given position. The grid is assumed to be toroidal, meaning that positions on the edges wrap around to the opposite edge.

The following assertions are made: - The number of calculated neighbor positions is 8 for various positions in the grid.

Raises:

AssertionError – If the number of calculated neighbor positions is not 8.

pycellga.tests.test_count_sat module

pycellga.tests.test_count_sat.test_count_sat()[source]

Test the CountSat function implementation.

This test verifies the calculation of the CountSat function value for specific binary input values.

The CountSat function evaluates the satisfaction of a set of binary clauses. This test ensures the function computes the correct results for specific test inputs, including cases where all variables are set to 1.

Examples

>>> test_count_sat()

pycellga.tests.test_dropwave_function module

pycellga.tests.test_dropwave_function.setup_dropwave()[source]

Fixture for creating an instance of the Dropwave problem.

Returns:

An instance of the Dropwave problem.

Return type:

Dropwave

pycellga.tests.test_dropwave_function.test_dropwave_function(setup_dropwave)[source]

Test the Dropwave function implementation.

This test checks the calculation of the Dropwave function value for given lists of float variables. It uses predefined inputs and compares the outputs to the expected values.

Parameters:

setup_dropwave (fixture) – The fixture providing the Dropwave problem instance.

pycellga.tests.test_ecc module

pycellga.tests.test_ecc.ecc_instance()[source]

Fixture for creating an instance of the Ecc class.

This fixture returns an instance of the Ecc class to be used in tests.

pycellga.tests.test_ecc.test_ecc(ecc_instance)[source]

Test the ECC function implementation.

This test checks the calculation of the ECC function value for a given list of binary variables. It uses predefined inputs and compares the outputs to expected values.

pycellga.tests.test_flat_crossover module

class pycellga.tests.test_flat_crossover.MockProblem[source]

Bases: AbstractProblem

A mock problem class for testing purposes.

f(x: list) float[source]

A mock fitness function that simply sums the chromosome values.

Parameters:

x (list) – A list of float variables.

Returns:

The sum of the list values.

Return type:

float

pycellga.tests.test_flat_crossover.setup_parents()[source]

Fixture for creating a pair of parent Individual instances.

Returns:

A list containing two parent individuals with predefined chromosomes and size.

Return type:

list

pycellga.tests.test_flat_crossover.setup_problem()[source]

Fixture for creating a mock problem instance.

Returns:

An instance of the mock problem.

Return type:

MockProblem

pycellga.tests.test_flat_crossover.test_flat_crossover(setup_parents, setup_problem)[source]

Test the FlatCrossover function implementation.

This test checks the flat crossover on a pair of parent individuals by verifying the recombination operation and the integrity of the offspring chromosomes.

Parameters:
  • setup_parents (fixture) – The fixture providing the parent individuals.

  • setup_problem (fixture) – The fixture providing the mock problem instance.

pycellga.tests.test_float_uniform_mutation module

class pycellga.tests.test_float_uniform_mutation.MockProblem[source]

Bases: AbstractProblem

A mock problem class for testing purposes.

f(x: list) float[source]

A mock fitness function that simply sums the chromosome values.

Parameters:

x (list) – A list of float variables.

Returns:

The sum of the list values.

Return type:

float

pycellga.tests.test_float_uniform_mutation.setup_individual()[source]

Fixture for creating a sample Individual instance.

Returns:

An individual instance with a predefined chromosome and size.

Return type:

Individual

pycellga.tests.test_float_uniform_mutation.setup_problem()[source]

Fixture for creating a mock problem instance.

Returns:

An instance of the mock problem.

Return type:

MockProblem

pycellga.tests.test_float_uniform_mutation.test_float_uniform_mutation(setup_individual, setup_problem)[source]

Test the FloatUniformMutation function implementation.

This test checks the uniform mutation on an individual’s chromosome by verifying the mutation operation and the integrity of the chromosome.

Parameters:
  • setup_individual (fixture) – The fixture providing the sample individual.

  • setup_problem (fixture) – The fixture providing the mock problem instance.

pycellga.tests.test_fms module

pycellga.tests.test_fms.fms_instance()[source]

Fixture for creating an instance of the Fms class.

This fixture returns an instance of the Fms class to be used in tests.

Returns:

An instance of the Fms class.

Return type:

Fms

pycellga.tests.test_fms.test_fms(fms_instance)[source]

Test the Fms function implementation.

This test checks the calculation of the FMS function value for a given list of binary variables. It uses a predefined input and compares the output to the expected value.

Parameters:

fms_instance (Fms) – An instance of the Fms class.

Notes

The test uses a randomly generated sample input chromosome of length 192 and checks if the function output is a float and non-negative. Additional checks with known values can be added for more thorough testing.

Assertions

  • The fitness value should be a float.

  • The fitness value should be non-negative, as it’s a sum of squares of differences.

Examples

>>> test_fms(fms_instance)

pycellga.tests.test_grid module

pycellga.tests.test_grid.test_grid()[source]

Test the Grid class implementation.

This test checks the functionality of the Grid class for creating a 2D grid. It verifies the type, length, and content of the generated grid.

The test performs the following steps: 1. Create an instance of the Grid class with a 5x5 grid. 2. Generate the 2D grid using the make_2d_grid method. 3. Verify that the result is a list. 4. Verify that the length of the list is 25 (5x5). 5. Verify that each element in the list is a tuple. 6. Verify the first and last elements of the list.

Raises:

AssertionError – If the result does not match the expected values.

pycellga.tests.test_griewank_function module

pycellga.tests.test_griewank_function.setup_griewank()[source]

Fixture for creating an instance of the Griewank problem.

Returns:

An instance of the Griewank problem.

Return type:

Griewank

pycellga.tests.test_griewank_function.test_griewank_function(setup_griewank)[source]

Test the Griewank function implementation.

This test checks the calculation of the Griewank function value for given lists of float variables. It uses predefined inputs and compares the outputs to the expected values.

Parameters:

setup_griewank (fixture) – The fixture providing the Griewank problem instance.

pycellga.tests.test_holzman_function module

pycellga.tests.test_holzman_function.setup_holzman()[source]

Fixture for creating an instance of the Holzman problem.

Returns:

An instance of the Holzman problem.

Return type:

Holzman

pycellga.tests.test_holzman_function.test_holzman_function(setup_holzman)[source]

Test the Holzman function implementation.

This test checks the calculation of the Holzman function value for given lists of float variables. It uses predefined inputs and compares the outputs to the expected values.

Parameters:

setup_holzman (fixture) – The fixture providing the Holzman problem instance.

pycellga.tests.test_individual module

pycellga.tests.test_individual.setup_individual()[source]

Fixture to provide an instance of the Individual class with different configurations.

pycellga.tests.test_individual.test_get_set_neighbors()[source]

Test getting and setting the list of neighbors for the individual.

pycellga.tests.test_individual.test_get_set_neighbors_positions()[source]

Test getting and setting the positions of the individual’s neighbors.

pycellga.tests.test_individual.test_illegal_genome_type()[source]

Test that an exception is raised when an illegal genome type is provided.

pycellga.tests.test_individual.test_individual_init()[source]

Test the initialization of the Individual class.

pycellga.tests.test_individual.test_randomize_binary()[source]

Test the randomization of the chromosome for a binary genome type.

pycellga.tests.test_individual.test_randomize_permutation()[source]

Test the randomization of the chromosome for a permutation genome type.

pycellga.tests.test_individual.test_randomize_real_valued()[source]

Test the randomization of the chromosome for a real-valued genome type.

pycellga.tests.test_insertion_mutation module

pycellga.tests.test_insertion_mutation.test_insertion_mutation()[source]

Test the InsertionMutation class for the Individual class on the TSP problem.

This test verifies that the InsertionMutation correctly mutates the chromosome of an Individual by inserting elements and ensures that the mutation is applied correctly. The test checks that: 1. The chromosome is mutated. 2. The chromosome size remains unchanged.

The function uses random permutation for the chromosome initialization.

Notes

The test assumes that the InsertionMutation class correctly implements insertion mutation and that the TSP problem correctly evaluates the fitness of an individual.

The following assertions are made: - At least one element in the chromosome is changed. - The size of the mutated individual’s chromosome matches the original size.

Raises:

AssertionError – If any of the conditions for correctness are not met.

pycellga.tests.test_levy_function module

pycellga.tests.test_levy_function.setup_levy()[source]

Fixture to provide an instance of the Levy problem.

pycellga.tests.test_levy_function.test_levy_function(setup_levy)[source]

Test the Levy function implementation.

This test checks the calculation of the Levy function value for given lists of float variables. It uses predefined inputs and compares the outputs to the expected values.

Parameters:

setup_levy (fixture) – The fixture providing the Levy problem instance.

pycellga.tests.test_linear_5 module

pycellga.tests.test_linear_5.test_linear_5()[source]

Test the Linear5 class for calculating neighbor positions in a grid.

This test verifies that the Linear5 class correctly calculates the positions of the 4 neighbors surrounding a given position in a grid. It ensures that: 1. The number of neighbors is always 4, which should include the positions

directly adjacent in the linear neighborhood.

The test uses three different positions within the grid to validate the functionality of the Linear5 neighborhood calculation.

Notes

The Linear5 neighborhood considers 4 neighboring cells aligned in a linear fashion (left, right, up, and down) in a 5x5 grid centered on a given position.

The following assertions are made: - The number of calculated neighbor positions is 4 for various positions in the grid.

Raises:

AssertionError – If the number of calculated neighbor positions is not 4.

pycellga.tests.test_linear_9 module

pycellga.tests.test_linear_9.test_linear_9()[source]

Test the Linear9 class for calculating neighbor positions in a grid.

This test verifies that the Linear9 class correctly calculates the positions of the 8 neighbors surrounding a given position in a grid. It ensures that: 1. The number of neighbors is always 8, which should include the positions

surrounding the given position in the linear neighborhood.

The test uses three different positions within the grid to validate the functionality of the Linear9 neighborhood calculation.

Notes

The Linear9 neighborhood considers 8 neighboring cells aligned in a linear fashion (left, right, up, down, and the diagonals) in a 5x5 grid centered on a given position.

The following assertions are made: - The number of calculated neighbor positions is 8 for various positions in the grid.

Raises:

AssertionError – If the number of calculated neighbor positions is not 8.

pycellga.tests.test_linear_crossover module

class pycellga.tests.test_linear_crossover.MockProblem[source]

Bases: AbstractProblem

A mock problem class for testing purposes.

f(x: list) float[source]

A mock fitness function that simply sums the chromosome values.

Parameters:

x (list) – A list of float variables.

Returns:

The sum of the list values.

Return type:

float

pycellga.tests.test_linear_crossover.setup_parents()[source]

Fixture for creating a pair of parent Individual instances.

Returns:

A list containing two parent individuals with predefined chromosomes and size.

Return type:

list

pycellga.tests.test_linear_crossover.setup_problem()[source]

Fixture for creating a mock problem instance.

Returns:

An instance of the mock problem.

Return type:

MockProblem

pycellga.tests.test_linear_crossover.test_linear_crossover(setup_parents, setup_problem)[source]

Test the LinearCrossover function implementation.

This test checks the linear crossover on a pair of parent individuals by verifying the recombination operation and the integrity of the offspring chromosomes.

Parameters:
  • setup_parents (fixture) – The fixture providing the parent individuals.

  • setup_problem (fixture) – The fixture providing the mock problem instance.

pycellga.tests.test_matyas_function module

pycellga.tests.test_matyas_function.setup_matyas()[source]

Fixture to provide an instance of the Matyas problem.

pycellga.tests.test_matyas_function.test_matyas_function(setup_matyas)[source]

Test the Matyas function implementation.

This test checks the calculation of the Matyas function value for given lists of float variables. It uses predefined inputs and compares the outputs to the expected values.

Parameters:

setup_matyas (fixture) – The fixture providing the Matyas problem instance.

pycellga.tests.test_maxcut100 module

pycellga.tests.test_maxcut100.maxcut_instance()[source]

Fixture for creating an instance of the Maxcut100 class.

This fixture returns an instance of the Maxcut100 class to be used in tests.

pycellga.tests.test_maxcut100.test_maxcut100()[source]

pycellga.tests.test_maxcut20_01 module

pycellga.tests.test_maxcut20_01.maxcut_instance()[source]

Fixture for creating an instance of the Maxcut20_01 class.

This fixture returns an instance of the Maxcut20_01 class to be used in tests.

pycellga.tests.test_maxcut20_01.test_maxcut20_01(maxcut_instance)[source]

Test the MAXCUT function implementation.

This test checks the calculation of the MAXCUT function value for a given list of binary variables. It uses predefined inputs and compares the outputs to expected values.

pycellga.tests.test_maxcut20_09 module

pycellga.tests.test_maxcut20_09.maxcut_instance()[source]

Fixture for creating an instance of the Maxcut20_09 class.

This fixture returns an instance of the Maxcut20_09 class to be used in tests.

pycellga.tests.test_maxcut20_09.test_maxcut20_09(maxcut_instance)[source]

Test the MAXCUT function implementation.

This test checks the calculation of the MAXCUT function value for a given list of binary variables. It uses predefined inputs and compares the outputs to expected values.

pycellga.tests.test_mmdp module

pycellga.tests.test_mmdp.mmdp_instance()[source]

Fixture for creating an instance of the Mmdp class.

This fixture returns an instance of the Mmdp class to be used in tests.

pycellga.tests.test_mmdp.test_mmdp_function(mmdp_instance)[source]

Test the Mmdp function implementation.

This test checks the calculation of the MMDP fitness value for given lists of binary variables. It uses predefined inputs and compares the outputs to the expected values.

pycellga.tests.test_one_max module

pycellga.tests.test_one_max.test_one_max()[source]

Test the OneMax function implementation.

This test verifies the calculation of the OneMax function value for specific binary input values.

The OneMax function evaluates the number of 1s in a binary list. This test ensures that the function computes the correct number of 1s for various test inputs.

Examples

>>> test_one_max()

pycellga.tests.test_one_point_crossover module

pycellga.tests.test_one_point_crossover.test_one_point_crossover()[source]

Test the OnePointCrossover class for generating offspring from two parents.

This test verifies that the OnePointCrossover class correctly performs one-point crossover between two parent individuals. It ensures that: 1. The offspring generated have the same chromosome size as the parents. 2. The chromosomes of the offspring contain only valid binary values (0 or 1).

The test performs the following checks: - Both offspring have the same chromosome size. - Each chromosome in the offspring is composed of binary values (0 or 1).

Raises:

AssertionError – If any of the conditions for the crossover operation are not met.

pycellga.tests.test_optimizer_alpha_cga module

class pycellga.tests.test_optimizer_alpha_cga.BinaryProblem[source]

Bases: object

Example problem class to be maximized for binary chromosomes.

This class implements the OneMax problem where the goal is to maximize the number of 1s in a binary string.

__init__()[source]
f(x)[source]

Compute the objective function value.

This method counts the number of 1s in the binary chromosome.

Parameters:

x (list or numpy.ndarray) – The input chromosome represented as a list or array of binary values (0s and 1s).

Returns:

The computed value, which is the count of 1s in the chromosome.

Return type:

int

class pycellga.tests.test_optimizer_alpha_cga.PermutationProblem(target: List[int])[source]

Bases: object

Example problem class to be minimized using a permutation-based approach.

This class implements a simple objective function that measures the sum of absolute differences between the chromosome and a target permutation.

__init__(target: List[int])[source]

Initialize the PermutationProblem with a target permutation.

Parameters:

target (list of int) – The target permutation that the algorithm aims to find.

f(x: List[int]) float[source]

Compute the objective function value.

This method implements the sum of absolute differences function.

Parameters:

x (list) – The input chromosome represented as a list of integers (permutation).

Returns:

The computed value of the function given the input x.

Return type:

float

test_optimizer_alpha_cga_permutation()[source]

Test alpha_cga on a permutation-based problem where the target is the identity permutation.

class pycellga.tests.test_optimizer_alpha_cga.RealProblem[source]

Bases: object

Example problem class to be minimized.

This class implements a simple sum of squares function with a global minimum value of 0, achieved when all elements of the chromosome are equal to 0.

__init__()[source]
f(x)[source]

Compute the objective function value.

This method implements the sum of squares function.

Parameters:

x (list or numpy.ndarray) – The input chromosome represented as a list or array of real values.

Returns:

The computed value of the function given the input x.

Return type:

float

pycellga.tests.test_optimizer_alpha_cga.test_optimizer_alpha_cga_binary()[source]

Test alpha_cga on a binary OneMax problem.

pycellga.tests.test_optimizer_alpha_cga.test_optimizer_alpha_cga_no_variation()[source]

Test alpha_cga with no crossover or mutation.

pycellga.tests.test_optimizer_alpha_cga.test_optimizer_alpha_cga_real()[source]

Test alpha_cga on a real-valued sum of squares problem.

pycellga.tests.test_optimizer_ccga module

class pycellga.tests.test_optimizer_ccga.BinaryProblem[source]

Bases: object

Example problem class to be maximized for binary chromosomes.

This class implements the OneMax problem where the goal is to maximize the number of 1s in a binary string.

__init__()[source]
f(x)[source]

Compute the objective function value.

This method counts the number of 1s in the binary chromosome.

Parameters:

x (list or numpy.ndarray) – The input chromosome represented as a list or array of binary values (0s and 1s).

Returns:

The computed value, which is the count of 1s in the chromosome.

Return type:

int

pycellga.tests.test_optimizer_ccga.test_optimizer_ccga_binary()[source]

Test ccga on a binary OneMax problem.

pycellga.tests.test_optimizer_cga module

class pycellga.tests.test_optimizer_cga.BinaryProblem[source]

Bases: object

Example problem class to be maximized for binary chromosomes.

This class implements the OneMax problem where the goal is to maximize the number of 1s in a binary string.

__init__()[source]
f(x)[source]

Compute the objective function value.

This method counts the number of 1s in the binary chromosome.

Parameters:

x (list or numpy.ndarray) – The input chromosome represented as a list or array of binary values (0s and 1s).

Returns:

The computed value, which is the count of 1s in the chromosome.

Return type:

int

class pycellga.tests.test_optimizer_cga.PermutationProblem(target: List[int])[source]

Bases: object

Example problem class to be minimized using a permutation-based approach.

This class implements a simple objective function that measures the sum of absolute differences between the chromosome and a target permutation.

__init__(target: List[int])[source]

Initialize the PermutationProblem with a target permutation.

Parameters:

target (list of int) – The target permutation that the algorithm aims to find.

f(x: List[int]) float[source]

Compute the objective function value.

This method implements the sum of absolute differences function.

Parameters:

x (list) – The input chromosome represented as a list of integers (permutation).

Returns:

The computed value of the function given the input x.

Return type:

float

test_optimizer_cga_permutation()[source]

Test CGA on a permutation-based problem where the target is the identity permutation.

class pycellga.tests.test_optimizer_cga.RealProblem[source]

Bases: object

Example problem class to be minimized.

This class implements a simple sum of squares function with a global minimum value of 0, achieved when all elements of the chromosome are equal to 0.

__init__()[source]
f(x)[source]

Compute the objective function value.

This method implements the sum of squares function.

Parameters:

x (list or numpy.ndarray) – The input chromosome represented as a list or array of real values.

Returns:

The computed value of the function given the input x.

Return type:

float

pycellga.tests.test_optimizer_cga.test_optimizer_cga_binary()[source]

Test CGA on a binary OneMax problem.

pycellga.tests.test_optimizer_cga.test_optimizer_cga_no_variation()[source]

Test CGA with no crossover or mutation.

pycellga.tests.test_optimizer_cga.test_optimizer_cga_real()[source]

Test CGA on a real-valued sum of squares problem.

pycellga.tests.test_optimizer_mccga module

class pycellga.tests.test_optimizer_mccga.RealProblem[source]

Bases: object

Example problem class to be minimized.

This class implements a simple sum of squares function with a global minimum value of 0, achieved when all elements of the chromosome are equal to 0.

__init__()[source]
f(x)[source]

Compute the objective function value.

This method implements the sum of squares function.

Parameters:

x (list or numpy.ndarray) – The input chromosome represented as a list or array of real values.

Returns:

The computed value of the function given the input x.

Return type:

float

pycellga.tests.test_optimizer_mccga.test_optimizer_mcccga_binary()[source]

Test mcccga on a binary OneMax problem.

pycellga.tests.test_optimizer_sync_cga module

class pycellga.tests.test_optimizer_sync_cga.BinaryProblem[source]

Bases: object

Example problem class to be maximized for binary chromosomes.

This class implements the OneMax problem where the goal is to maximize the number of 1s in a binary string.

__init__()[source]
f(x)[source]

Compute the objective function value.

This method counts the number of 1s in the binary chromosome.

Parameters:

x (list or numpy.ndarray) – The input chromosome represented as a list or array of binary values (0s and 1s).

Returns:

The computed value, which is the count of 1s in the chromosome.

Return type:

int

class pycellga.tests.test_optimizer_sync_cga.PermutationProblem(target: List[int])[source]

Bases: object

Example problem class to be minimized using a permutation-based approach.

This class implements a simple objective function that measures the sum of absolute differences between the chromosome and a target permutation.

__init__(target: List[int])[source]

Initialize the PermutationProblem with a target permutation.

Parameters:

target (list of int) – The target permutation that the algorithm aims to find.

f(x: List[int]) float[source]

Compute the objective function value.

This method implements the sum of absolute differences function.

Parameters:

x (list) – The input chromosome represented as a list of integers (permutation).

Returns:

The computed value of the function given the input x.

Return type:

float

test_optimizer_sync_cga_permutation()[source]

Test sync_cga on a permutation-based problem where the target is the identity permutation.

class pycellga.tests.test_optimizer_sync_cga.RealProblem[source]

Bases: object

Example problem class to be minimized.

This class implements a simple sum of squares function with a global minimum value of 0, achieved when all elements of the chromosome are equal to 0.

__init__()[source]
f(x)[source]

Compute the objective function value.

This method implements the sum of squares function.

Parameters:

x (list or numpy.ndarray) – The input chromosome represented as a list or array of real values.

Returns:

The computed value of the function given the input x.

Return type:

float

pycellga.tests.test_optimizer_sync_cga.test_optimizer_sync_cga_binary()[source]

Test sync_cga on a binary OneMax problem.

pycellga.tests.test_optimizer_sync_cga.test_optimizer_sync_cga_no_variation()[source]

Test sync_cga with no crossover or mutation.

pycellga.tests.test_optimizer_sync_cga.test_optimizer_sync_cga_real()[source]

Test sync_cga on a real-valued sum of squares problem.

pycellga.tests.test_peak module

pycellga.tests.test_peak.peak_instance()[source]

Fixture for creating an instance of the Peak class.

This fixture returns an instance of the Peak class to be used in tests.

pycellga.tests.test_peak.test_peak(peak_instance)[source]

Test the Peak function implementation.

This test checks the calculation of the Peak fitness value for given lists of binary variables. It uses predefined inputs and compares the outputs to the expected values.

pycellga.tests.test_pmx_crossover module

pycellga.tests.test_pmx_crossover.test_pmx_crossover()[source]

Test the PMXCrossover class for generating offspring from two permutation parents.

This test verifies that the PMXCrossover class correctly performs partially matched crossover (PMX) between two parent individuals. It ensures that: 1. The offspring generated have the same chromosome size as the parents.

The test performs the following checks: - Both offspring have the same chromosome size as the parents.

Raises:

AssertionError – If any of the conditions for the crossover operation are not met.

pycellga.tests.test_population module

class pycellga.tests.test_population.MockProblem[source]

Bases: AbstractProblem

A mock problem for testing purposes.

f(chromosome: List[float]) float[source]

Returns the sum of the chromosome as the fitness value.

f(chromosome: List[float]) float[source]

Evaluate the fitness of a given solution x.

Parameters:

x (list) – A list representing a candidate solution.

Returns:

The fitness value of the candidate solution.

Return type:

float

Raises:

NotImplementedError – If the method is not implemented by a subclass.

pycellga.tests.test_population.setup_population()[source]

Fixture for setting up a Population object.

Returns:

A population instance with a mock problem.

Return type:

Population

pycellga.tests.test_population.test_fitness_evaluation(setup_population)[source]

Test the fitness evaluation of the individuals.

Parameters:
  • setup_population (Population) – The population fixture.

  • Asserts

  • -------

  • performed. (True if the fitness evaluation is correctly)

pycellga.tests.test_population.test_initial_population_size(setup_population)[source]

Test the size of the initial population.

Parameters:
  • setup_population (Population) – The population fixture.

  • Asserts

  • -------

  • correct. (True if the size of the population is)

pycellga.tests.test_population.test_neighborhood_assignment(setup_population)[source]

Test the neighborhood assignment for the individuals.

Parameters:
  • setup_population (Population) – The population fixture.

  • Asserts

  • -------

  • assigned. (True if neighborhood positions are correctly)

pycellga.tests.test_pow_function module

class pycellga.tests.test_pow_function.Pow[source]

Bases: AbstractProblem

Pow function implementation for optimization problems.

The Pow function is widely used for testing optimization algorithms. The function is usually evaluated on the hypercube x_i ∈ [-5.0, 15.0].

None
f(x: list) float[source]

Calculates the Pow function value for a given list of variables.

Notes

-5.0 ≤ xi ≤ 15.0 Global minimum at f(5, 7, 9, 3, 2) = 0

f(x: list) float[source]

Calculate the Pow function value for a given list of variables.

Parameters:

x (list) – A list of float variables.

Returns:

The Pow function value.

Return type:

float

pycellga.tests.test_powell_function module

pycellga.tests.test_powell_function.setup_powell()[source]

Fixture to provide an instance of the Powell problem.

pycellga.tests.test_powell_function.test_powell_function(setup_powell)[source]

Test the Powell function implementation.

This test checks the calculation of the Powell function value for given lists of float variables. It uses predefined inputs and compares the outputs to the expected values.

Parameters:

setup_powell (fixture) – The fixture providing the Powell problem instance.

pycellga.tests.test_rastrigin module

pycellga.tests.test_rastrigin.test_rastrigin()[source]

Test the Rastrigin function implementation.

This test verifies the calculation of the Rastrigin function value for a given list of continuous variables. It compares the function output with known expected values.

Notes

The Rastrigin function is a well-known benchmark function used in optimization problems. It has a global minimum value of 0, which is achieved when all variables are 0.

Assertions

  • The function should return the correct values for predefined inputs.

  • The function should return 0 for an input list of all zeros.

Examples

>>> test_rastrigin()

pycellga.tests.test_rosenbrock module

pycellga.tests.test_rosenbrock.test_rosenbrock()[source]

Test the Rosenbrock function implementation.

This test verifies the calculation of the Rosenbrock function value for a given list of continuous variables. It compares the function output with known expected values.

Notes

The Rosenbrock function, also known as the Rosenbrock’s valley or Rosenbrock’s banana function, is a common test problem for optimization algorithms. The global minimum is at (1, …, 1), where the function value is 0.

Assertions

  • The function should return the correct values for predefined inputs.

  • The function should return 0 for an input list of all ones.

Examples

>>> test_rosenbrock()

pycellga.tests.test_rothellipsoid_function module

pycellga.tests.test_rothellipsoid_function.setup_rothellipsoid()[source]

Fixture to provide an instance of the Rotated Hyper-Ellipsoid problem.

pycellga.tests.test_rothellipsoid_function.test_rothellipsoid_function(setup_rothellipsoid)[source]

Test the Rotated Hyper-Ellipsoid function implementation.

This test checks the calculation of the Rotated Hyper-Ellipsoid function value for given lists of float variables. It uses predefined inputs and compares the outputs to the expected values.

Parameters:

setup_rothellipsoid (fixture) – The fixture providing the Rotated Hyper-Ellipsoid problem instance.

pycellga.tests.test_roulette_wheel_selection module

pycellga.tests.test_roulette_wheel_selection.test_roulette_wheel_selection()[source]

Test the RouletteWheelSelection class implementation.

This test verifies the functionality of the RouletteWheelSelection for selecting parent individuals from a population. It ensures that the selected parents have valid attributes and different chromosomes and positions.

The test performs the following checks: 1. Each selected parent has the correct chromosome size and a non-None fitness value. 2. Each selected parent has valid types for neighbors_positions and position attributes. 3. The selected parents have different chromosomes and positions.

Raises:

AssertionError – If any of the conditions for the parent selection are not met.

pycellga.tests.test_schaffer2_function module

pycellga.tests.test_schaffer2_function.setup_schaffer2()[source]

Fixture to provide an instance of the Schaffer2 problem.

pycellga.tests.test_schaffer2_function.test_schaffer2_function(setup_schaffer2)[source]

Test the Modified Schaffer function #2 implementation.

This test checks the calculation of the Modified Schaffer function #2 value for given lists of float variables. It uses predefined inputs and compares the outputs to the expected values.

Parameters:

setup_schaffer2 (fixture) – The fixture providing the Schaffer2 problem instance.

pycellga.tests.test_schaffer_function module

pycellga.tests.test_schaffer_function.setup_schaffer()[source]

Fixture to provide an instance of the Schaffer problem.

pycellga.tests.test_schaffer_function.test_schaffer_function(setup_schaffer)[source]

Test the Modified Schaffer function #1 implementation.

This test checks the calculation of the Modified Schaffer function #1 value for given lists of float variables. It uses predefined inputs and compares the outputs to the expected values.

Parameters:

setup_schaffer (fixture) – The fixture providing the Schaffer problem instance.

pycellga.tests.test_schwefel module

pycellga.tests.test_schwefel.test_schwefel()[source]

Test the Schwefel function implementation.

This test verifies the functionality of the Schwefel function on a set of predefined input values.

The Schwefel function is used as a benchmark in optimization problems, and this test ensures that the function computes the expected results for given inputs.

It performs assertions to check: - The correctness of the function’s output for specific input values. - The proper rounding of the function’s output to three decimal places.

Notes

The Schwefel function is typically used to evaluate optimization algorithms, and the expected values for the test cases are specific to the known behavior of the function.

Examples

>>> test_schwefel()

pycellga.tests.test_shuffle_mutation module

pycellga.tests.test_shuffle_mutation.test_shuffle_mutation()[source]

Test the ShuffleMutation class for the Individual class on the TSP problem.

This test verifies that the ShuffleMutation correctly mutates the chromosome of an Individual by shuffling the elements. It ensures that: 1. The chromosome is mutated. 2. The chromosome size remains unchanged.

The function initializes the chromosome with a random permutation of integers from 1 to CHSIZE and applies the shuffle mutation.

Notes

The test assumes that the ShuffleMutation class correctly implements shuffle mutation and that the TSP problem correctly evaluates the fitness of an individual.

The following assertions are made: - At least one element in the chromosome is changed. - The size of the mutated individual’s chromosome matches the original size.

Raises:

AssertionError – If any of the conditions for correctness are not met.

pycellga.tests.test_sphere module

pycellga.tests.test_sphere.test_sphere()[source]

Test the Sphere function implementation.

This test checks the calculation of the Sphere function value for given input values.

The Sphere function is a common benchmark function in optimization, where the global minimum is at f(0, 0, …, 0) = 0. This test ensures that the function computes the correct results for specific input values and verifies that the function behaves as expected.

It performs assertions to validate: - The correctness of the function’s output for specific test inputs. - The rounding of the function’s output to three decimal places.

Examples

>>> test_sphere()

pycellga.tests.test_styblinskitang_function module

pycellga.tests.test_styblinskitang_function.setup_styblinski_tang()[source]

Fixture to provide an instance of the StyblinskiTang problem.

pycellga.tests.test_styblinskitang_function.test_styblinskitang_function(setup_styblinski_tang)[source]

Test the Styblinski-Tang function implementation.

This test checks the calculation of the Styblinski-Tang function value for given lists of float variables. It uses predefined inputs and compares the outputs to the expected values.

Parameters:

setup_styblinski_tang (fixture) – The fixture providing the StyblinskiTang problem instance.

pycellga.tests.test_sumofdifferentpowers_function module

pycellga.tests.test_sumofdifferentpowers_function.setup_sumofdifferentpowers()[source]

Fixture to create an instance of the Sumofdifferentpowers problem.

pycellga.tests.test_sumofdifferentpowers_function.test_sumofdifferentpowers_function(setup_sumofdifferentpowers)[source]

Test the Sum of Different Powers function implementation.

This test checks the calculation of the Sum of Different Powers function value for given lists of float variables. It uses predefined inputs and compares the outputs to the expected values.

Parameters:

setup_sumofdifferentpowers (fixture) – The fixture providing the Sumofdifferentpowers problem instance.

pycellga.tests.test_swap_mutation module

pycellga.tests.test_swap_mutation.test_swap_mutation()[source]

Test the SwapMutation class for the Individual class on the TSP problem.

This test verifies that the SwapMutation correctly mutates the chromosome of an Individual by swapping two elements. It ensures that: 1. The chromosome is mutated. 2. The chromosome size remains unchanged.

The function initializes the chromosome with a random permutation of integers from 1 to CHSIZE and applies the swap mutation.

Notes

The test assumes that the SwapMutation class correctly implements swap mutation and that the TSP problem correctly evaluates the fitness of an individual.

The following assertions are made: - At least one element in the chromosome is changed. - The size of the mutated individual’s chromosome matches the original size.

Raises:

AssertionError – If any of the conditions for correctness are not met.

pycellga.tests.test_threehumps_function module

pycellga.tests.test_threehumps_function.setup_threehumps()[source]

Fixture to provide the Threehumps problem instance.

pycellga.tests.test_threehumps_function.test_threehumps_function(setup_threehumps)[source]

Test the Three Hump Camel function implementation.

This test checks the calculation of the Three Hump Camel function value for given lists of float variables. It uses predefined inputs and compares the outputs to the expected values.

Parameters:

setup_threehumps (fixture) – The fixture providing the Threehumps problem instance.

pycellga.tests.test_tournament_selection module

pycellga.tests.test_tournament_selection.test_tournament_selection()[source]

Test the TournamentSelection class implementation.

This test verifies the functionality of the TournamentSelection for selecting parent individuals from a population. It ensures that the selected parents have valid attributes and different chromosomes and positions.

The test performs the following checks: 1. Each selected parent has the correct chromosome size and a non-None fitness value. 2. Each selected parent has valid types for neighbors_positions and position attributes. 3. The selected parents have different chromosomes and positions.

Parameters:

None

Raises:

AssertionError – If any of the conditions for the parent selection are not met.

pycellga.tests.test_tsp module

pycellga.tests.test_tsp.test_tsp()[source]

Test the Tsp function implementation.

This test verifies the calculation of the TSP (Traveling Salesman Problem) function value for different permutations of cities.

The TSP function evaluates the total distance for a given permutation of cities. This test checks if the function computes the correct distance for specific permutations generated using different random seeds.

Examples

>>> test_tsp()

pycellga.tests.test_two_opt_mutation module

pycellga.tests.test_two_opt_mutation.test_two_opt_mutation()[source]

Test the TwoOptMutation class for the Individual class on the TSP problem.

This test verifies that the TwoOptMutation correctly mutates the chromosome of an Individual by applying the 2-opt mutation technique. It ensures that: 1. The chromosome is mutated by swapping two edges in the permutation. 2. The chromosome size remains unchanged.

The function initializes the chromosome with a random permutation of integers from 1 to CHSIZE and applies the two-opt mutation.

Notes

The test assumes that the TwoOptMutation class correctly implements the 2-opt mutation and that the TSP problem correctly evaluates the fitness of an individual.

The following assertions are made: - At least one element in the chromosome is changed. - The size of the mutated individual’s chromosome matches the original size.

Raises:

AssertionError – If any of the conditions for correctness are not met.

pycellga.tests.test_two_point_crossover module

pycellga.tests.test_two_point_crossover.test_two_point_crossover()[source]

Test the TwoPointCrossover class implementation.

This test verifies the functionality of the TwoPointCrossover class for binary chromosomes. It ensures that the crossover operation produces valid offspring with the expected chromosome size.

The test performs the following checks: 1. Both offspring have the same chromosome size as the parents. 2. The chromosomes of the offspring contain only valid binary values (0 or 1).

Raises:

AssertionError – If any of the conditions for the crossover operation are not met.

pycellga.tests.test_unfair_average_crossover module

class pycellga.tests.test_unfair_average_crossover.MockProblem[source]

Bases: AbstractProblem

A mock problem class for testing purposes.

f(x: list) float[source]

A mock fitness function that simply sums the chromosome values.

Parameters:

x (list) – A list of float variables.

Returns:

The sum of the list values.

Return type:

float

pycellga.tests.test_unfair_average_crossover.setup_parents()[source]

Fixture for creating a pair of parent Individual instances.

Returns:

A list containing two parent individuals with predefined chromosomes and size.

Return type:

list

pycellga.tests.test_unfair_average_crossover.setup_problem()[source]

Fixture for creating a mock problem instance.

Returns:

An instance of the mock problem.

Return type:

MockProblem

pycellga.tests.test_unfair_average_crossover.test_unfair_average_crossover(setup_parents, setup_problem)[source]

Test the UnfairAvarageCrossover function implementation.

This test checks the unfair average crossover on a pair of parent individuals by verifying the recombination operation and the integrity of the offspring chromosomes.

Parameters:
  • setup_parents (fixture) – The fixture providing the parent individuals.

  • setup_problem (fixture) – The fixture providing the mock problem instance.

pycellga.tests.test_uniform_crossover module

pycellga.tests.test_uniform_crossover.test_uniform_crossover()[source]

Test the UniformCrossover class implementation.

This test verifies the functionality of the UniformCrossover class for binary chromosomes. It ensures that the crossover operation produces valid offspring with the expected chromosome size.

The test performs the following checks: 1. Both offspring have the same chromosome size as the parents. 2. The chromosomes of the offspring contain only valid binary values (0 or 1).

Raises:

AssertionError – If any of the conditions for the crossover operation are not met.

pycellga.tests.test_zakharov_function module

pycellga.tests.test_zakharov_function.test_zakharov_function()[source]

Test the Zakharov function implementation.

This test checks the calculation of the Zakharov function value for given lists of float variables. It uses predefined inputs and compares the outputs to the expected values.

pycellga.tests.test_zettle_function module

pycellga.tests.test_zettle_function.setup_zettle()[source]

Fixture to provide an instance of the Zettle problem.

pycellga.tests.test_zettle_function.test_zettle_function(setup_zettle)[source]

Test the Zettle function implementation.

This test checks the calculation of the Zettle function value for given lists of float variables. It uses predefined inputs and compares the outputs to the expected values.

Parameters:

setup_zettle (fixture) – The fixture providing the Zettle problem instance.

Module contents