complete_binary_simulator_test.py
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
- It checks that the simulator raises a
TreeSimulatorError
when 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 the simulate_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 the CompleteBinarySimulator
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
.
This test file ensures that the CompleteBinarySimulator
class correctly initializes and generates complete binary trees with the expected structure and properties.