> ## Documentation Index
> Fetch the complete documentation index at: https://demo.agenticlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# topology_test.py

## High-level description

This file contains a test suite for the topology functions in the `cassiopeia/tools/topology.py` module. It tests various functions related to tree topology, including expansion probabilities, cophenetic correlation, and simple coalescent probability calculations.

## Code Structure

The main class `TestTopology` inherits from `unittest.TestCase` and contains several test methods. The `setUp` method creates a sample tree and character matrix for use in the tests. Each test method focuses on a specific functionality of the topology module.

## Symbols

### TestTopology

#### Description

A test class that inherits from `unittest.TestCase` and contains multiple test methods for the topology functions.

#### Internal Logic

1. Sets up a sample tree and character matrix in the `setUp` method.
2. Implements various test methods to check different aspects of the topology functions.

### test\_simple\_choose\_function

#### Description

Tests the `nCk` function from the topology module.

#### Internal Logic

1. Checks if `nCk(10, 2)` returns the expected value of 45.
2. Verifies that `nCk(5, 7)` raises a `CassiopeiaError`.

### test\_simple\_coalescent\_probability

#### Description

Tests the `simple_coalescent_probability` function from the topology module.

#### Internal Logic

1. Calculates the coalescent probability for given parameters and compares it to an expected value.
2. Verifies that invalid input raises a `CassiopeiaError`.

### test\_expansion\_probability

#### Description

Tests the `compute_expansion_pvalues` function from the topology module.

#### Internal Logic

1. Calls `compute_expansion_pvalues` with different parameters.
2. Compares the resulting expansion probabilities with expected values for each node in the tree.

### test\_expansion\_probability\_variable\_depths

#### Description

Tests the `compute_expansion_pvalues` function with variable depths.

#### Internal Logic

1. Calls `compute_expansion_pvalues` with a minimum depth parameter.
2. Verifies the resulting expansion probabilities against expected values.

### test\_expansion\_probability\_copy\_tree

#### Description

Tests the `compute_expansion_pvalues` function with the copy option.

#### Internal Logic

1. Calls `compute_expansion_pvalues` with the copy option set to True.
2. Verifies that the original tree is not modified and the new tree has the expected probabilities.

### test\_cophenetic\_correlation\_perfect

#### Description

Tests the `compute_cophenetic_correlation` function with a perfect correlation scenario.

#### Internal Logic

1. Creates a custom dissimilarity map.
2. Calls `compute_cophenetic_correlation` and verifies that it returns a perfect correlation (1.0).
3. Tests the function with a custom weight matrix.

### test\_cophenetic\_correlation\_default

#### Description

Tests the `compute_cophenetic_correlation` function with default parameters.

#### Internal Logic

1. Calls `compute_cophenetic_correlation` without custom parameters.
2. Verifies that the resulting correlation is close to an expected value.

## Dependencies

| Dependency | Purpose                                   |
| :--------- | :---------------------------------------- |
| unittest   | Provides the testing framework            |
| networkx   | Used for creating and manipulating graphs |
| numpy      | Used for numerical operations             |
| pandas     | Used for data manipulation and analysis   |
| cassiopeia | The main package being tested             |

## Error Handling

The test suite uses assertions to check for expected values and behaviors. It also tests for specific error cases, such as raising `CassiopeiaError` for invalid inputs.
