LCOV - code coverage report
Current view: top level - src/pairinteraction/ket - utils.py (source / functions) Hit Total Coverage
Test: coverage.info Lines: 13 18 72.2 %
Date: 2026-08-14 15:26:44 Functions: 2 2 100.0 %

          Line data    Source code
       1             : # SPDX-FileCopyrightText: 2026 PairInteraction Developers
       2             : # SPDX-License-Identifier: LGPL-3.0-or-later
       3           1 : from __future__ import annotations
       4             : 
       5           1 : import logging
       6             : 
       7           1 : logger = logging.getLogger(__name__)
       8             : 
       9           1 : QUANTUM_NUMBER_L_LABELS = ("S", "P", "D", "F", "G", "H")
      10             : 
      11             : 
      12           1 : def format_half_integer(value: float) -> str:
      13             :     """Format an integer or half-integer quantum number as e.g. "1" or "1/2"."""
      14           1 :     if value == round(value):
      15           1 :         return f"{value:.0f}"
      16           1 :     if 2 * value == round(2 * value):
      17           1 :         return f"{2 * value:.0f}/2"
      18           0 :     logger.warning("Value %.5f is not an integer or half-integer.", value)
      19           0 :     return f"{value:.1f}"
      20             : 
      21             : 
      22           1 : def get_l_label(l: float) -> str:
      23             :     """Get the label for an integer quantum number l."""
      24           1 :     if l == round(l):
      25           1 :         if l < len(QUANTUM_NUMBER_L_LABELS):
      26           1 :             return QUANTUM_NUMBER_L_LABELS[round(l)]
      27           0 :         return f"{round(l):d}"
      28           0 :     logger.warning("Value of l %.5f is not an integer.", l)
      29           0 :     return f"{l:.1f}"

Generated by: LCOV version 1.16