High-level description

This file contains unit tests for the utility functions defined in cassiopeia/mixins/utilities.py. It tests the functionality of various utility functions related to handling ambiguous states in character matrices and finding duplicate groups.

Symbols

TestMixinUtilities

Description

This is a test class that inherits from unittest.TestCase. It contains several test methods to verify the functionality of utility functions from the cassiopeia.mixins.utilities module.

Internal Logic

The class defines three test methods:

  1. test_is_ambiguous_state: Tests the is_ambiguous_state function.
  2. test_unravel_states: Tests the unravel_ambiguous_states function.
  3. test_find_duplicated_character_states: Tests the find_duplicate_groups function.

test_is_ambiguous_state

Description

This method tests the is_ambiguous_state function from the utilities module.

Internal Logic

  • Asserts that (1, 2) is recognized as an ambiguous state.
  • Asserts that 1 is not recognized as an ambiguous state.

test_unravel_states

Description

This method tests the unravel_ambiguous_states function from the utilities module.

Internal Logic

  • Tests the function with an array containing both ambiguous and non-ambiguous states.
  • Tests the function with an array containing only non-ambiguous states.
  • Asserts that the output matches the expected unraveled list in both cases.

test_find_duplicated_character_states

Description

This method tests the find_duplicate_groups function from the utilities module.

Internal Logic

  • Creates a sample character matrix using pandas DataFrame.
  • Calls the find_duplicate_groups function on the character matrix.
  • Checks if the returned duplicate mappings contain the expected entries.
  • Verifies that the keys and values in the duplicate mappings match the expected groups.

Dependencies

DependencyPurpose
unittestProvides the testing framework
pandasUsed to create and manipulate the character matrix
cassiopeia.mixins.utilitiesModule containing the utility functions being tested

Error Handling

The test methods use assertions to verify the correctness of the utility functions. If any assertion fails, an AssertionError will be raised, indicating a test failure.

Notes

  • The test file uses the unittest framework, which is a standard Python testing library.
  • The tests cover various scenarios, including ambiguous states and duplicate character states in matrices.
  • The test_find_duplicated_character_states method uses a complex character matrix with ambiguous states to thoroughly test the find_duplicate_groups function.