LCOV - code coverage report
Current view: top level - src - ichiisot.c (source / functions) Coverage Total Hit
Test: InChI Unit Test Coverage Lines: 100.0 % 28 28
Test Date: 2026-10-14 12:14:55 Functions: 100.0 % 2 2
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 56.2 % 32 18

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * SPDX-License-Identifier: MIT
       3                 :             :  * Copyright (c) 2024 IUPAC and InChI Trust
       4                 :             :  */
       5                 :             : 
       6                 :             : #include "mode.h"
       7                 :             : #include "ichicomn.h"
       8                 :             : 
       9                 :             : #include "bcf_s.h"
      10                 :             : 
      11                 :             : /**********************************************************************************/
      12                 :         810 : AT_ISO_SORT_KEY make_iso_sort_key( int iso_atw_diff, int num_1H, int num_2H, int num_3H )
      13                 :             : {
      14                 :         810 :     AT_ISO_SORT_KEY iso_sort_key = 0, mult = 1;
      15                 :             : 
      16                 :         810 :     iso_sort_key += mult * num_1H;
      17                 :         810 :     mult *= AT_ISO_SORT_KEY_MULT;
      18                 :         810 :     iso_sort_key += mult * num_2H;
      19                 :         810 :     mult *= AT_ISO_SORT_KEY_MULT;
      20                 :         810 :     iso_sort_key += mult * num_3H;
      21                 :         810 :     mult *= AT_ISO_SORT_KEY_MULT;
      22                 :         810 :     iso_sort_key += mult * iso_atw_diff;
      23                 :             : 
      24                 :         810 :     return iso_sort_key;
      25                 :             : }
      26                 :             : 
      27                 :             : 
      28                 :             : 
      29                 :             : /****************************************************************************
      30                 :             :  Set sp_ATOM isotopic sort keys
      31                 :             : ****************************************************************************/
      32                 :         161 : int set_atom_iso_sort_keys( int num_at,
      33                 :             :                             sp_ATOM *at,
      34                 :             :                             T_GROUP_INFO* t_group_info,
      35                 :             :                             int *bHasIsotopicInTautomerGroups )
      36                 :             : {
      37                 :         161 :     int             i, num_isotopic = 0, bMergedTgroup;
      38                 :             :     AT_ISO_SORT_KEY iso_sort_key;
      39                 :         161 :     T_GROUP        *t_group =
      40                 :         161 :         ( t_group_info &&
      41         [ +  - ]:         161 :          t_group_info->t_group &&
      42   [ +  -  +  + ]:         322 :          t_group_info->num_t_groups > 0 ) ? t_group_info->t_group : NULL;
      43                 :             : 
      44         [ +  - ]:         161 :     if (bHasIsotopicInTautomerGroups)
      45                 :             :     {
      46                 :         161 :         *bHasIsotopicInTautomerGroups = 0;
      47                 :             :     }
      48         [ +  + ]:         971 :     for (i = 0; i < num_at; i++)
      49                 :             :     {
      50   [ +  -  -  +  :         810 :         bMergedTgroup = ( t_group_info && t_group_info->nIsotopicEndpointAtomNumber && ( at[i].cFlags & AT_FLAG_ISO_H_POINT ) );
                   -  - ]
      51   [ +  +  -  +  :         810 :         if (( !at[i].endpoint || !t_group ) && !bMergedTgroup)
                   +  - ]
      52                 :             :         {
      53                 :         782 :             iso_sort_key = make_iso_sort_key( at[i].iso_atw_diff, at[i].num_iso_H[0], at[i].num_iso_H[1], at[i].num_iso_H[2] );
      54                 :             :         }
      55                 :             :         else
      56                 :             :         {
      57                 :             :              /*  H isotopes go to the tautomer part of the CT (name) */
      58                 :             :              /*  if (at[i].endpoint && t_group) ... */
      59                 :          28 :             iso_sort_key = make_iso_sort_key( at[i].iso_atw_diff, 0, 0, 0 );
      60         [ +  - ]:          28 :             if (bHasIsotopicInTautomerGroups)
      61                 :             :             {
      62   [ +  -  +  -  :          28 :                 *bHasIsotopicInTautomerGroups += ( at[i].num_iso_H[0] || at[i].num_iso_H[1] || at[i].num_iso_H[2] || bMergedTgroup );
             +  -  -  + ]
      63                 :             :             }
      64                 :             :         }
      65                 :         810 :         at[i].iso_sort_key = iso_sort_key;
      66                 :         810 :         num_isotopic += ( iso_sort_key != 0 );
      67                 :             :     }
      68                 :             : 
      69                 :         161 :     return num_isotopic;
      70                 :             : }
      71                 :             : 
      72                 :             : 
      73                 :             : #ifdef NEVER
      74                 :             : 
      75                 :             : 
      76                 :             : /****************************************************************************/
      77                 :             : int unpack_iso_sort_key( AT_ISO_SORT_KEY iso_sort_key,
      78                 :             :                          S_CHAR *num_1H,
      79                 :             :                          S_CHAR *num_2H,
      80                 :             :                          S_CHAR *num_3H,
      81                 :             :                          S_CHAR *iso_atw_diff )
      82                 :             : {
      83                 :             :     int is_negative;
      84                 :             :     AT_ISO_SORT_KEY HOnlyAtwPart;
      85                 :             :     static const AT_ISO_SORT_KEY MultAtwDiff = AT_ISO_SORT_KEY_MULT*AT_ISO_SORT_KEY_MULT*AT_ISO_SORT_KEY_MULT;
      86                 :             :     if (!iso_sort_key)
      87                 :             :     {
      88                 :             :         *num_1H = *num_2H = *num_3H = *iso_atw_diff = 0;
      89                 :             :         return 0;
      90                 :             :     }
      91                 :             :     else
      92                 :             :     {
      93                 :             :         if (iso_sort_key < 0)
      94                 :             :         {
      95                 :             :             is_negative = 1;
      96                 :             :             iso_sort_key = -iso_sort_key;
      97                 :             :             HOnlyAtwPart = MultAtwDiff - iso_sort_key % MultAtwDiff;
      98                 :             :             iso_sort_key += HOnlyAtwPart;
      99                 :             :         }
     100                 :             :         else
     101                 :             :         {
     102                 :             :             is_negative = 0;
     103                 :             :             HOnlyAtwPart = iso_sort_key % MultAtwDiff;
     104                 :             :             iso_sort_key -= HOnlyAtwPart;
     105                 :             :         }
     106                 :             :     }
     107                 :             : 
     108                 :             :     iso_sort_key /= MultAtwDiff;
     109                 :             : 
     110                 :             :     *num_1H = (S_CHAR) ( HOnlyAtwPart % AT_ISO_SORT_KEY_MULT );
     111                 :             :     HOnlyAtwPart /= AT_ISO_SORT_KEY_MULT;
     112                 :             :     *num_2H = (S_CHAR) ( HOnlyAtwPart % AT_ISO_SORT_KEY_MULT );
     113                 :             :     HOnlyAtwPart /= AT_ISO_SORT_KEY_MULT;
     114                 :             :     *num_3H = (S_CHAR) ( HOnlyAtwPart % AT_ISO_SORT_KEY_MULT );
     115                 :             : 
     116                 :             :     *iso_atw_diff = (S_CHAR) ( is_negative ? -iso_sort_key : iso_sort_key );
     117                 :             : 
     118                 :             :     return 1;
     119                 :             : }
     120                 :             : #endif
        

Generated by: LCOV version 2.0-1