High-level description
This file contains unit tests for theCompleteBinarySimulator 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 fromunittest.TestCase. It contains two test methods to verify the functionality of the CompleteBinarySimulator class.
test_init
Description
This method tests the initialization of theCompleteBinarySimulator class.
Internal Logic
- It checks that the simulator raises a
TreeSimulatorErrorwhen initialized without arguments. - It verifies that the simulator raises an error when initialized with an invalid number of cells (not a power of 2).
- It ensures that the simulator raises an error when initialized with a depth of 0.
- It confirms that the simulator correctly calculates the depth when initialized with a valid number of cells.
test_simulate_tree
Description
This method tests thesimulate_tree method of the CompleteBinarySimulator class.
Internal Logic
- It creates a simulator with a depth of 2 and simulates a tree.
- It verifies the correct set of nodes in the simulated tree.
- It checks the correct set of leaf nodes.
- It confirms the correct set of edges in the tree.
- It validates the branch lengths (times) for each node in the tree.
Dependencies
| Dependency | Purpose |
|---|---|
| numpy | Used for numerical operations (not explicitly used in the test file) |
| unittest | Provides the testing framework |
| cassiopeia.mixins | Imports the TreeSimulatorError exception |
| cassiopeia.simulator | Imports the CompleteBinarySimulator class |
Error Handling
The test cases check for proper error handling in theCompleteBinarySimulator class by asserting that TreeSimulatorError is raised under specific conditions.
References
CompleteBinarySimulator: The main class being tested, imported fromcassiopeia.simulator.TreeSimulatorError: An exception class used for error handling, imported fromcassiopeia.mixins.
CompleteBinarySimulator class correctly initializes and generates complete binary trees with the expected structure and properties.