Skip to content

Commit

Permalink
SF: Add tests for new updated apfrequency operation
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHuth committed Mar 23, 2023
1 parent f575b9f commit d11549f
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 19 deletions.
149 changes: 130 additions & 19 deletions Packages/tests/Basic/UTF_SweepFormula.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,70 @@ static Function TestOperationFindLevel()
CHECK_EQUAL_STR(strRef, dataType)
End

Function/WAVE FakeSweepDataGeneratorAPF0(WAVE sweep, variable numChannels)

variable pnts = 9

Redimension/D/N=(pnts, numChannels) sweep
sweep[0][] = 10
sweep[1][] = 20
sweep[2][] = 30
sweep[3][] = 10
sweep[4][] = 20
sweep[5][] = 30
sweep[6][] = 10
sweep[7][] = 20
sweep[8][] = 30

return sweep
End

Function/WAVE FakeSweepDataGeneratorAPF1(WAVE sweep, variable numChannels)

variable pnts = 9

Redimension/D/N=(pnts, numChannels) sweep
sweep[0][] = 30
sweep[1][] = 10
sweep[2][] = 30
sweep[3][] = 10
sweep[4][] = 30
sweep[5][] = 10
sweep[6][] = 30
sweep[7][] = 10
sweep[8][] = 30

return sweep
End

// IUTF_TD_GENERATOR TestOperationAPFrequency2Gen
static Function TestOperationAPFrequency2([WAVE wv])

string win, device, formula
variable numResults

formula = note(wv)

[win, device] = CreateFakeDataBrowserWindow()

CreateFakeSweepData(win, device, sweepNo=0, sweepGen=FakeSweepDataGeneratorAPF0)
CreateFakeSweepData(win, device, sweepNo=1, sweepGen=FakeSweepDataGeneratorAPF1)

WAVE/WAVE outputRef = GetMultipleResults(formula, win)
numResults = DimSize(wv, ROWS)
CHECK_EQUAL_VAR(numResults, DimSize(outputRef, ROWS))
WAVE/WAVE results = wv

Make/FREE/N=(numResults) idxHelper
idxHelper = TestOperationAPFrequency2Checks(formula, results[p], outputRef[p])
End

static Function TestOperationAPFrequency2Checks(string formula, WAVE w1, WAVE w2)

INFO("Formula: %s", s0 = formula)
REQUIRE_EQUAL_WAVES(w1, w2, mode = WAVE_DATA, tol = 1E-12)
End

static Function TestOperationAPFrequency()

string str, strRef, dataType
Expand All @@ -1228,8 +1292,8 @@ static Function TestOperationAPFrequency()
PASS()
endtry

// but no more than three
str = "apfrequency([1], 0, 3, 4)"
// but no more than six
str = "apfrequency([1], 0, 0.5, freq, nonorm, time, 3)"
try
WAVE output = GetSingleResult(str, win)
FAIL()
Expand All @@ -1238,7 +1302,7 @@ static Function TestOperationAPFrequency()
endtry

// requires valid method
str = "apfrequency([1], 3)"
str = "apfrequency([1], 10)"
try
WAVE output = GetSingleResult(str, win)
FAIL()
Expand All @@ -1258,28 +1322,28 @@ static Function TestOperationAPFrequency()
Make/FREE/D output_ref = {3}
REQUIRE_EQUAL_WAVES(output, output_ref, mode = WAVE_DATA)

// works with 2D data and instantaneous
str = "apfrequency(setscale([[10, 5], [20, 40], [10, 5], [20, 30]], x, 0, 5, ms), 0, 15)"
WAVE output = GetSingleResult(str, win)
Make/FREE/D output_ref = {100, 100}
REQUIRE_EQUAL_WAVES(output, output_ref, mode = WAVE_DATA)

// works with instantaneous
str = "apfrequency(setscale([10, 20, 30, 10, 20, 30, 40, 10, 20], x, 0, 5, ms), 1, 15)"
WAVE output = GetSingleResult(str, win)
Make/FREE/D output_ref = {57.14285714285714}
REQUIRE_EQUAL_WAVES(output, output_ref, mode = WAVE_DATA)

// works with 2D data and instantaneous
str = "apfrequency(setscale([[10, 5], [20, 40], [10, 5], [20, 30]], x, 0, 5, ms), 1, 15)"
// works with instantaneous pair
str = "apfrequency(setscale([10, 20, 30, 10, 20, 30, 40, 10, 20], x, 0, 5, ms), 3, 15)"
WAVE output = GetSingleResult(str, win)
Make/FREE/D output_ref = {100 * 2 / 3, 50}
REQUIRE_EQUAL_WAVES(output, output_ref, mode = WAVE_DATA)
str = "apfrequency(setscale([10, 20, 30, 10, 20, 30, 40, 10, 20], x, 0, 5, ms), 3, 15,freq)"
WAVE output = GetSingleResult(str, win)
Make/FREE/D output_ref = {100, 94.59459459459457}
REQUIRE_EQUAL_WAVES(output, output_ref, mode = WAVE_DATA)

// x offset does not play any role
str = "apfrequency(setscale([[10, 5], [20, 40], [10, 5], [20, 30]], x, 0, 5, ms), 1, 15)"
// works with instantaneous pair time
str = "apfrequency(setscale([10, 20, 30, 10, 20, 30, 40, 10, 20], x, 0, 5, ms), 3, 15, time)"
WAVE output = GetSingleResult(str, win)
Make/FREE/D output_ref = {0.015, 0.02}
REQUIRE_EQUAL_WAVES(output, output_ref, mode = WAVE_DATA)
str = "apfrequency(setscale([10, 20, 30, 10, 20, 30, 40, 10, 20], x, 0, 5, ms), 3, 15, time, nonorm)"
WAVE output = GetSingleResult(str, win)
Make/FREE/D output_ref = {100, 94.59459459459457}
REQUIRE_EQUAL_WAVES(output, output_ref, mode = WAVE_DATA)

// returns 0 if nothing found for Full
Expand All @@ -1288,18 +1352,65 @@ static Function TestOperationAPFrequency()
Make/FREE/D output_ref = {0}
REQUIRE_EQUAL_WAVES(output, output_ref, mode = WAVE_DATA)

// returns 0 if nothing found for Instantaneous
// returns null wave if nothing found for Instantaneous
str = "apfrequency([10, 20, 30, 20], 1, 100)"
WAVE output = GetSingleResult(str, win)
Make/FREE/D output_ref = {0}
REQUIRE_EQUAL_WAVES(output, output_ref, mode = WAVE_DATA)
WAVE/Z output = GetSingleResult(str, win)
CHECK_WAVE(output, NULL_WAVE)

// returns null wave if nothing found for Instantaneous Pair
str = "apfrequency([10, 20, 30, 20], 3, 100)"
WAVE/Z output = GetSingleResult(str, win)
CHECK_WAVE(output, NULL_WAVE)

// returns null wave for single peak for Instantaneous Pair
str = "apfrequency([10, 20, 30, 20], 3, 25)"
WAVE/Z output = GetSingleResult(str, win)
CHECK_WAVE(output, NULL_WAVE)

// check meta data
str = "apfrequency([10, 20, 30, 20], 1, 100)"
WAVE/WAVE dataRef = GetMultipleResults(str, win)
dataType = JWN_GetStringFromWaveNote(dataRef, SF_META_DATATYPE)
strRef = SF_DATATYPE_APFREQUENCY
CHECK_EQUAL_STR(strRef, dataType)

// works with instantaneous pair time, norminsweepsmin
str = "apfrequency(setscale([10, 20, 30, 10, 20, 30, 40, 10, 20], x, 0, 5, ms), 3, 15, time, norminsweepsmin)"
WAVE output = GetSingleResult(str, win)
Make/FREE/D output_ref = {1, 0.02 / 0.015}
REQUIRE_EQUAL_WAVES(output, output_ref, mode = WAVE_DATA)

// works with instantaneous pair time, norminsweepsmax
str = "apfrequency(setscale([10, 20, 30, 10, 20, 30, 40, 10, 20], x, 0, 5, ms), 3, 15, time, norminsweepsmax)"
WAVE output = GetSingleResult(str, win)
Make/FREE/D output_ref = {0.015 / 0.02, 1}
REQUIRE_EQUAL_WAVES(output, output_ref, mode = WAVE_DATA)

// works with instantaneous pair time, norminsweepsavg
str = "apfrequency(setscale([10, 20, 30, 10, 20, 30, 40, 10, 20], x, 0, 5, ms), 3, 15, time, norminsweepsavg)"
WAVE output = GetSingleResult(str, win)
Make/FREE/D output_ref = {0.015 / 0.0175, 0.02 / 0.0175}
REQUIRE_EQUAL_WAVES(output, output_ref, mode = WAVE_DATA)

// works with instantaneous pair time, norminsweepsavg, time as x-axis
str = "apfrequency(setscale([10, 20, 30, 10, 20, 30, 40, 10, 20], x, 0, 5, ms), 3, 15, time, norminsweepsavg, time)"
WAVE/WAVE outputRef = GetMultipleResults(str, win)
Make/FREE/D output_ref = {2.5, 17.5}
for(data : outputRef)
WAVE/Z xValues = JWN_GetNumericWaveFromWaveNote(data, SF_META_XVALUES)
CHECK_WAVE(xValues, NUMERIC_WAVE)
CHECK_EQUAL_WAVES(xValues, output_Ref, mode = WAVE_DATA)
endfor

// works with instantaneous pair time, norminsweepsavg, count as x-axis
str = "apfrequency(setscale([10, 20, 30, 10, 20, 30, 40, 10, 20], x, 0, 5, ms), 3, 15, time, norminsweepsavg, count)"
WAVE/WAVE outputRef = GetMultipleResults(str, win)
Make/FREE/D/N=2 output_ref = p
for(data : outputRef)
WAVE/Z xValues = JWN_GetNumericWaveFromWaveNote(data, SF_META_XVALUES)
CHECK_WAVE(xValues, NUMERIC_WAVE)
CHECK_EQUAL_WAVES(xValues, output_Ref, mode = WAVE_DATA)
endfor
End

static Function TestOperationWave()
Expand Down
37 changes: 37 additions & 0 deletions Packages/tests/UTF_DataGenerators.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,40 @@ Function/WAVE NonExistingDevices()

return wv
End

Function/WAVE TestOperationAPFrequency2Gen()

variable m

Make/FREE/WAVE/N=3 wv

Make/FREE/WAVE/N=4 results
Make/FREE/D sweep0Result = {0.003 / 0.002, 0.003 / 0.002}
Make/FREE/D sweep1Result = {1, 1, 1}
results[0, 1] = sweep0Result
results[2, 3] = sweep1Result
note/K results, "apfrequency(data(cursors(A,B),select(channels(AD),[0,1],all)), 3, 15, time, normoversweepsmin)"
wv[0] = results
SetDimLabel ROWS, 0, normoversweepsmin, wv

Make/FREE/WAVE/N=4 results
Make/FREE/D sweep0Result = {1, 1}
Make/FREE/D sweep1Result = {0.002 / 0.003, 0.002 / 0.003, 0.002 / 0.003}
results[0, 1] = sweep0Result
results[2, 3] = sweep1Result
note/K results, "apfrequency(data(cursors(A,B),select(channels(AD),[0,1],all)), 3, 15, time, normoversweepsmax)"
wv[1] = results
SetDimLabel ROWS, 1, normoversweepsmax, wv

Make/FREE/WAVE/N=4 results
m = (2 * 0.003 + 3 * 0.002) / 5
Make/FREE/D sweep0Result = {0.003 / m, 0.003 / m}
Make/FREE/D sweep1Result = {0.002 / m, 0.002 / m, 0.002 / m}
results[0, 1] = sweep0Result
results[2, 3] = sweep1Result
note/K results, "apfrequency(data(cursors(A,B),select(channels(AD),[0,1],all)), 3, 15, time, normoversweepsavg)"
wv[2] = results
SetDimLabel ROWS, 2, normoversweepsavg, wv

return wv
End

0 comments on commit d11549f

Please sign in to comment.