Skip to content

Commit

Permalink
MIES_SweepFormula.ipf: Enhance mismatched waves message for basic mat…
Browse files Browse the repository at this point in the history
…h operations
  • Loading branch information
t-b committed Aug 19, 2024
1 parent 5583b7e commit ba7eb21
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
29 changes: 25 additions & 4 deletions Packages/MIES/MIES_SweepFormula.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -3268,6 +3268,27 @@ static Function/WAVE SF_OperationEpochsImpl(string graph, WAVE/T epochPatterns,
return output
End

static Function SF_AssertOnMismatchedWaves(WAVE data0, WAVE data1, string opShort)

string msg, size0Str, size1Str
variable ret

ret = EqualWaves(data0, data1, EQWAVES_DIMSIZE)

if(ret)
return NaN
endif

WAVE size0 = GetWaveDimensions(data0)
WAVE size1 = GetWaveDimensions(data1)

size0Str = NumericWaveToList(size0, ", ", trailSep = 0)
size1Str = NumericWaveToList(size1, ", ", trailSep = 0)
sprintf msg, "%s: wave size mismatch [%s] vs [%s]", opShort, size0Str, size1Str

SFH_ASSERT(ret, msg)
End

static Function/WAVE SF_OperationMinus(variable jsonId, string jsonPath, string graph)

WAVE output = SF_IndexOverDataSetsForPrimitiveOperation(jsonId, jsonpath, graph, SF_OPSHORT_MINUS)
Expand Down Expand Up @@ -3296,7 +3317,7 @@ static Function/WAVE SF_OperationMinusImplDataSets(WAVE/Z data0, WAVE/Z data1)
CopyScales data1, result
return result
endif
SFH_ASSERT(EqualWaves(data0, data1, EQWAVES_DIMSIZE), "minus: wave size mismatch")
SF_AssertOnMismatchedWaves(data0, data1, SF_OPSHORT_MINUS)

MatrixOp/FREE result = data0 - data1
CopyScales data0, result
Expand Down Expand Up @@ -3331,7 +3352,7 @@ static Function/WAVE SF_OperationPlusImplDataSets(WAVE/Z data0, WAVE/Z data1)
CopyScales data1, result
return result
endif
SFH_ASSERT(EqualWaves(data0, data1, EQWAVES_DIMSIZE), "plus: wave size mismatch")
SF_AssertOnMismatchedWaves(data0, data1, SF_OPSHORT_PLUS)

MatrixOp/FREE result = data0 + data1
CopyScales data0, result
Expand Down Expand Up @@ -3466,7 +3487,7 @@ static Function/WAVE SF_OperationDivImplDataSets(WAVE/Z data0, WAVE/Z data1)
CopyScales data1, result
return result
endif
SFH_ASSERT(EqualWaves(data0, data1, EQWAVES_DIMSIZE), "div: wave size mismatch")
SF_AssertOnMismatchedWaves(data0, data1, SF_OPSHORT_DIV)

MatrixOp/FREE result = data0 / data1
CopyScales data0, result
Expand Down Expand Up @@ -3501,7 +3522,7 @@ static Function/WAVE SF_OperationMultImplDataSets(WAVE/Z data0, WAVE/Z data1)
CopyScales data1, result
return result
endif
SFH_ASSERT(EqualWaves(data0, data1, EQWAVES_DIMSIZE), "mult: wave size mismatch")
SF_AssertOnMismatchedWaves(data0, data1, SF_OPSHORT_MULT)

MatrixOp/FREE result = data0 * data1
CopyScales data0, result
Expand Down
36 changes: 36 additions & 0 deletions Packages/tests/Basic/UTF_SweepFormula_Operations.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2411,3 +2411,39 @@ static Function TPWithModelCell()
Make/D/FREE ref = {17.3667394014963}
CHECK_EQUAL_WAVES(ref, results, mode = WAVE_DATA)
End

// IUTF_TD_GENERATOR DataGenerators#GetBasicMathOperations
static Function BasicMathMismatchedWaves([string str])

string code, win, opShort, error

win = GetDataBrowserWithData()

sprintf code, "[1, 2] %s [[1, 2]]", str
try
WAVE/WAVE output = SF_ExecuteFormula(code, win, useVariables = 0)
FAIL()
catch
CHECK_NO_RTE()
endtry

strswitch(str)
case "*":
opShort = "mult"
break
case "/":
opShort = "div"
break
case "+":
opShort = "plus"
break
case "-":
opShort = "minus"
break
default:
FAIL()
endswitch

error = ROStr(GetSweepFormulaParseErrorMessage())
CHECK_EQUAL_STR(error, opShort + ": wave size mismatch [2, 0, 0, 0] vs [1, 2, 0, 0]")
End
8 changes: 8 additions & 0 deletions Packages/tests/UTF_DataGenerators.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -868,3 +868,11 @@ static Function/WAVE GetDifferentGraphs()

return wv
End

static Function/WAVE GetBasicMathOperations()
Make/FREE/T op = {"+", "-", "*", "/"}

SetDimensionLabels(OP, "plus;minus;mult;div;", ROWS)

return op
End

0 comments on commit ba7eb21

Please sign in to comment.