Skip to content

Commit

Permalink
Merge pull request #2149 from AllenInstitute/bugfix/2149-add_more_che…
Browse files Browse the repository at this point in the history
…cks_to_getsetintersection

Utils: Add additional checks to GetSetIntersection, GetSetDifference
  • Loading branch information
t-b authored Jun 17, 2024
2 parents 0c75283 + 7b726f7 commit 7477cee
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Packages/MIES/MIES_Utilities.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -3747,18 +3747,18 @@ threadsafe Function/WAVE GetSetUnion(WAVE wave1, WAVE wave2)
End

/// @brief Return a wave were all elements which are in both wave1 and wave2 have been removed from wave1
/// wave1 must be 1d, the returned wave is 1d.
///
/// @sa GetListDifference for string lists
threadsafe Function/WAVE GetSetDifference(wave1, wave2)
WAVE wave1
WAVE wave2
threadsafe Function/WAVE GetSetDifference(WAVE wave1, WAVE wave2)

variable isText, index

isText = (IsTextWave(wave1) && IsTextWave(wave2))

ASSERT_TS((IsFloatingPointWave(wave1) && IsFloatingPointWave(wave2)) || isText, "Non matching wave types (both float or both text).")
ASSERT_TS(WaveType(wave1) == WaveType(wave2), "Wave type mismatch")
ASSERT_TS(!DimSize(wave1, COLS), "input wave1 must be 1d")

WAVE/Z result

Expand Down Expand Up @@ -3841,6 +3841,7 @@ threadsafe Function/WAVE GetSetIntersection(WAVE wave1, WAVE wave2, [variable ge

ASSERT_TS((IsNumericWave(wave1) && IsNumericWave(wave2)) \
|| (IsTextWave(wave1) && IsTextWave(wave2)), "Invalid wave type")
ASSERT_TS(!DimSize(wave1, COLS) && !DimSize(wave2, COLS), "input waves must be 1d")

getIndices = ParamIsDefault(getIndices) ? 0 : !!getIndices

Expand Down
45 changes: 45 additions & 0 deletions Packages/tests/Basic/UTF_Utils.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,28 @@ Function GSD_ExpectsSameWaveType()
endtry
End

static Function GSD_Expects1dWave1()

Make/FREE/D/N=(1, 10) data1
Make/FREE/D data2

try
WAVE/Z matches = GetSetDifference(data1, data2)
FAIL()
catch
PASS()
endtry
End

static Function GSD_WorksWithNdWave2()

Make/FREE/D/N=5 data1 = p
Make/FREE/D/N=(1, 3) data2 = q

WAVE/Z matches = GetSetDifference(data1, data2)
CHECK_EQUAL_WAVES(matches, {3, 4}, mode = WAVE_DATA | DIMENSION_SIZES)
End

Function GSD_ExpectsFPWaveType()

Make/FREE/D data1
Expand Down Expand Up @@ -498,6 +520,29 @@ Function GSI_ExpectsSameWaveType()
endtry
End

static Function GSI_Expects1dWave()

Make/FREE/D/N=(1, 10) data1
Make/FREE/D data2

try
WAVE/Z matches = GetSetIntersection(data1, data2)
FAIL()
catch
PASS()
endtry

Make/FREE/D data1
Make/FREE/D/N=(1, 10) data2

try
WAVE/Z matches = GetSetIntersection(data1, data2)
FAIL()
catch
PASS()
endtry
End

Function GSI_Works()

Make/FREE data1 = {1, 2, 3, 4}
Expand Down

0 comments on commit 7477cee

Please sign in to comment.