This file contains unit tests for the compute_morans_i
function, which calculates Moran’s I statistic for spatial autocorrelation in a phylogenetic tree. The tests cover various scenarios, including single and multiple variables, custom weight matrices, and error handling.
This file references the following symbols:
cassiopeia.tl.compute_morans_i
: The function being tested, which calculates Moran’s I statistic.cassiopeia.data.CassiopeiaTree
: A class representing a phylogenetic tree.cassiopeia.mixins.AutocorrelationError
: An exception class for errors related to autocorrelation calculations.TestAutocorrelation
This class contains unit tests for the compute_morans_i
function. It sets up a basic tree structure and example data for testing.
This class does not take any inputs.
This class does not return any outputs. It uses the unittest
framework to run assertions and report test results.
The class defines several test methods, each testing a specific aspect of the compute_morans_i
function:
test_simple_moran_single_variable
: Tests the function with a single variable and compares the result to a known value.test_moran_bivariate
: Tests the function with multiple variables and compares the resulting correlation matrix to expected values.test_moran_custom_weights
: Tests the function with a user-provided weight matrix.test_moran_exceptions
: Tests various error conditions, such as invalid input data types and mismatched tree leaves.setUp
This method sets up the test environment by creating a basic tree structure and example data.
This method does not take any inputs.
This method does not explicitly return any outputs. It sets the self.basic_tree
and self.X
attributes, which are used by the test methods.
The test_moran_exceptions
method specifically tests for various error conditions that can occur in the compute_morans_i
function, such as:
X
argument.W
) that does not have the same leaves as the tree.These error conditions are handled by raising AutocorrelationError
exceptions with informative messages.
This file contains unit tests for the compute_morans_i
function, which calculates Moran’s I statistic for spatial autocorrelation in a phylogenetic tree. The tests cover various scenarios, including single and multiple variables, custom weight matrices, and error handling.
This file references the following symbols:
cassiopeia.tl.compute_morans_i
: The function being tested, which calculates Moran’s I statistic.cassiopeia.data.CassiopeiaTree
: A class representing a phylogenetic tree.cassiopeia.mixins.AutocorrelationError
: An exception class for errors related to autocorrelation calculations.TestAutocorrelation
This class contains unit tests for the compute_morans_i
function. It sets up a basic tree structure and example data for testing.
This class does not take any inputs.
This class does not return any outputs. It uses the unittest
framework to run assertions and report test results.
The class defines several test methods, each testing a specific aspect of the compute_morans_i
function:
test_simple_moran_single_variable
: Tests the function with a single variable and compares the result to a known value.test_moran_bivariate
: Tests the function with multiple variables and compares the resulting correlation matrix to expected values.test_moran_custom_weights
: Tests the function with a user-provided weight matrix.test_moran_exceptions
: Tests various error conditions, such as invalid input data types and mismatched tree leaves.setUp
This method sets up the test environment by creating a basic tree structure and example data.
This method does not take any inputs.
This method does not explicitly return any outputs. It sets the self.basic_tree
and self.X
attributes, which are used by the test methods.
The test_moran_exceptions
method specifically tests for various error conditions that can occur in the compute_morans_i
function, such as:
X
argument.W
) that does not have the same leaves as the tree.These error conditions are handled by raising AutocorrelationError
exceptions with informative messages.