< Summary - Igor Pro Universal Testing Framework

Information
Class: procedures.igortest-utils-waves
Assembly: procedures
File(s): /builds/mirror/igortest/procedures/igortest-utils-waves.ipf
Tag: 74147b3
Line coverage
46%
Covered lines: 14
Uncovered lines: 16
Coverable lines: 30
Total lines: 83
Line coverage: 46.6%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
IUTF_Utils_Waves#RemoveDimLabel()100%2100%
IUTF_Utils_Waves#MoveDimLabel()50%2100%
IUTF_Utils_Waves#InPlaceShuffleText1D()100%40%

File(s)

/builds/mirror/igortest/procedures/igortest-utils-waves.ipf

#LineLine coverage
 1#pragma rtGlobals=3
 2#pragma TextEncoding="UTF-8"
 3#pragma rtFunctionErrors=1
 4#pragma version=1.10
 5#pragma ModuleName=IUTF_Utils_Waves
 6
 7#if (IgorVersion() >= 9.00)
 8static Constant RANDOM_NUMBER_GENERATOR = 3 // Xoshiro256
 9#else
 10static Constant RANDOM_NUMBER_GENERATOR = 2 // Merseene Twister
 11#endif
 12
 13/// @brief Search for the first occurrence of the specified dimension label and remove it. If the
 14/// label wasn't found nothing will be changed.
 15///
 16/// @param wv        The wave where the dimension label should be removed
 17/// @param dimension The dimension to search in
 18/// @param label     The label to remove
 32819static Function RemoveDimLabel(wv, dimension, label)
 20  WAVE     wv
 21  variable dimension
 22  string   label
 23
 32824  variable index = FindDimLabel(wv, dimension, label)
 32825  if(index != -2)
 29626    SetDimLabel dimension, index, $"", wv
 32827  endif
 32828End
 29
 30/// @brief Moves the specified dimension label to the new index and removes it from the old
 31/// position. If the same dimension label is used on more than one place it will only remove the
 32/// first one.
 33///
 34/// @param wv         The wave where the dimension label should be moved
 35/// @param dimension  The dimension to search in
 36/// @param label      The label to move
 37/// @param newIndex   The new index to move the label to
 38///
 39/// @return The old index of the dimension label. This return -2 if the dimension label was not
 40/// found and -1 if the whole column had the dimension label.
 15841static Function MoveDimLabel(wv, dimension, label, newIndex)
 42  WAVE wv
 43  variable dimension, newIndex
 44  string label
 45
 15846  variable oldIndex = FindDimLabel(wv, dimension, label)
 15847  if(oldIndex != -2)
 15848    SetDimLabel dimension, oldIndex, $"", wv
 15849  endif
 15850  SetDimLabel dimension, newIndex, $label, wv
 51
 15852  return oldIndex
 15853End
 54
 55/// @brief Shuffles the entries in the wave wv in a random order. It will always use the best PRNGs
 56/// for the current Igor version.
 57///
 58/// @param wv          a 1 dimension text wave that need to be shuffled
 59/// @param startIndex  (optional, default 0) The inclusive start index where the shuffle should
 60///                    start.
 61/// @param endIndex    (optional, default DimSize(wv, UTF_ROW)) The exclusive end index where the
 62///                    shuffle should stop. This is usefull for vectors.
 063static Function InPlaceShuffleText1D(wv, [startIndex, endIndex])
 64  WAVE/T wv
 65  variable startIndex, endIndex
 66
 067  variable i1, i2, halfRange
 068  string tmp
 69
 070  startIndex = ParamIsDefault(startIndex) ? 0 : startIndex
 071  endIndex   = ParamIsDefault(endIndex) ? DimSize(wv, UTF_ROW) : endIndex
 72
 073  // basic shuffle algorithm
 074  for(i1 = startIndex; i1 < endIndex - 1; i1 += 1)
 075    // getting second index
 076    halfRange = (endIndex - i1) * 0.5
 077    i2        = i1 + floor(halfRange + enoise(halfRange, RANDOM_NUMBER_GENERATOR))
 078    // triangle swap
 079    tmp    = wv[i1]
 080    wv[i1] = wv[i2]
 081    wv[i2] = tmp
 082  endfor
 083End