High-level description

This file contains unit tests for the LBIJungle fitness estimator in the cassiopeia.tools module. It tests the functionality of the LBIJungle class on a small tree to ensure that fitness estimates are calculated correctly and make sense based on the tree structure.

Code Structure

The file defines a single test class TestLBIJungle which inherits from unittest.TestCase. This class contains two test methods: test_small_tree and test_raises_error_if_leaf_name_startswith_underscore.

Symbols

TestLBIJungle

Description

A test class that contains unit tests for the LBIJungle fitness estimator.

Internal Logic

The class sets up test scenarios and asserts expected outcomes for the LBIJungle fitness estimator.

test_small_tree

Description

Tests the LBIJungle fitness estimator on a small, manually constructed tree to verify that the fitness estimates are sensible.

Internal Logic

  1. Constructs a small tree using networkx.
  2. Converts the networkx tree to a CassiopeiaTree.
  3. Sets node times for the tree.
  4. Creates an LBIJungle fitness estimator and applies it to the tree.
  5. Retrieves fitness estimates for all nodes except the root.
  6. Performs several assertions to check if the fitness estimates make sense based on the tree structure:
    • Compares fitness of internal nodes.
    • Checks equality of fitness for leaves with the same parent.
    • Compares fitness between different groups of leaves.
    • Verifies that parent nodes have higher fitness than their children.

test_raises_error_if_leaf_name_startswith_underscore

Description

Tests that the LBIJungle fitness estimator raises a FitnessEstimatorError when a leaf name starts with an underscore.

Internal Logic

  1. Constructs a small tree with a leaf name starting with an underscore.
  2. Converts the networkx tree to a CassiopeiaTree.
  3. Creates an LBIJungle fitness estimator.
  4. Asserts that applying the estimator to the tree raises a FitnessEstimatorError.

Dependencies

  • unittest: Python’s built-in unit testing framework
  • networkx: For creating and manipulating graph structures
  • cassiopeia.data.CassiopeiaTree: The tree data structure used in Cassiopeia
  • cassiopeia.tools.FitnessEstimatorError: Custom error for fitness estimation issues
  • cassiopeia.tools.LBIJungle: The fitness estimator being tested

Error Handling

The tests check for proper error handling when invalid input is provided (e.g., leaf names starting with underscores).

Performance Considerations

These are unit tests, so performance is not a primary concern. However, the tests use a small tree to ensure quick execution.