> ## 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.

# supercellular_sampler_test.py

Here's a detailed documentation of the `test/simulator_tests/supercellular_sampler_test.py` file:

## High-level description

This file contains unit tests for the SupercellularSampler class, which is a subclass of LeafSubsampler. The tests verify the functionality of the SupercellularSampler, including its initialization, error handling, and leaf subsampling behavior.

## Code Structure

The main class `SupercellularSamplerTest` inherits from `unittest.TestCase` and contains several test methods. The `setUp` method initializes a test network and character matrix used in multiple tests.

## Symbols

### SupercellularSamplerTest

#### Description

A test class that contains unit tests for the SupercellularSampler class.

#### Internal Logic

The class sets up a test network and character matrix in the `setUp` method, which are used across multiple test cases.

### setUp

#### Description

Initializes the test environment by creating a test network and character matrix.

#### Internal Logic

* Creates a directed graph (`self.test_network`) representing a tree structure.
* Defines a character matrix (`self.character_matrix`) with sample data for testing.

### test\_bad\_parameters

#### Description

Tests the SupercellularSampler initialization with invalid parameters.

#### Internal Logic

* Attempts to create a SupercellularSampler with both ratio and number\_of\_merges specified, which should raise a LeafSubsamplerError.
* Attempts to create a SupercellularSampler with neither ratio nor number\_of\_merges specified, which should also raise a LeafSubsamplerError.

### test\_bad\_number\_of\_samples

#### Description

Tests the subsample\_leaves method with invalid inputs.

#### Internal Logic

* Creates a CassiopeiaTree with the test network and character matrix.
* Attempts to subsample leaves with invalid number\_of\_merges values (10, 0, and 2 for a tree without a character matrix), which should raise appropriate errors.

### test\_subsample\_balanced\_tree

#### Description

Tests the subsample\_leaves method with valid inputs and verifies the output.

#### Internal Logic

* Creates a CassiopeiaTree with the test network and character matrix.
* Subsamples leaves using SupercellularSampler with number\_of\_merges=2.
* Verifies the resulting character matrix and edges against expected values.
* Repeats the test with collapse\_duplicates=False and verifies the results.

## Dependencies

* unittest
* networkx
* numpy
* pandas
* cassiopeia.data.CassiopeiaTree
* cassiopeia.simulator.LeafSubsampler
* cassiopeia.simulator.SupercellularSampler
* cassiopeia.data.utilities

## Error Handling

The tests check for various error conditions, including:

* Incorrect initialization parameters for SupercellularSampler
* Invalid number of merges in subsample\_leaves method
* Attempting to subsample leaves on a tree without a character matrix

## TODOs

There are no explicit TODOs in this file.

This test file ensures that the SupercellularSampler class behaves correctly under various conditions and produces expected outputs when subsampling leaves from a CassiopeiaTree.
