High-level description

This file contains unit tests for the CompleteBinarySimulator class, which is responsible for simulating complete binary trees. The tests verify the initialization of the simulator and the structure of the simulated tree, including its nodes, edges, and branch lengths.

Symbols

TestCompleteBinarySimulator

Description

This is a test class that inherits from unittest.TestCase. It contains two test methods to verify the functionality of the CompleteBinarySimulator class.

test_init

Description

This method tests the initialization of the CompleteBinarySimulator class.

Internal Logic

  1. It checks that the simulator raises a TreeSimulatorError when initialized without arguments.
  2. It verifies that the simulator raises an error when initialized with an invalid number of cells (not a power of 2).
  3. It ensures that the simulator raises an error when initialized with a depth of 0.
  4. It confirms that the simulator correctly calculates the depth when initialized with a valid number of cells.

test_simulate_tree

Description

This method tests the simulate_tree method of the CompleteBinarySimulator class.

Internal Logic

  1. It creates a simulator with a depth of 2 and simulates a tree.
  2. It verifies the correct set of nodes in the simulated tree.
  3. It checks the correct set of leaf nodes.
  4. It confirms the correct set of edges in the tree.
  5. It validates the branch lengths (times) for each node in the tree.

Dependencies

DependencyPurpose
numpyUsed for numerical operations (not explicitly used in the test file)
unittestProvides the testing framework
cassiopeia.mixinsImports the TreeSimulatorError exception
cassiopeia.simulatorImports the CompleteBinarySimulator class

Error Handling

The test cases check for proper error handling in the CompleteBinarySimulator class by asserting that TreeSimulatorError is raised under specific conditions.

References

  • CompleteBinarySimulator: The main class being tested, imported from cassiopeia.simulator.
  • TreeSimulatorError: An exception class used for error handling, imported from cassiopeia.mixins.

This test file ensures that the CompleteBinarySimulator class correctly initializes and generates complete binary trees with the expected structure and properties.