diff --git a/Packages/tests/Basic/UTF_SweepFormula.ipf b/Packages/tests/Basic/UTF_SweepFormula.ipf index 09424bbe28..3db2fd95c7 100644 --- a/Packages/tests/Basic/UTF_SweepFormula.ipf +++ b/Packages/tests/Basic/UTF_SweepFormula.ipf @@ -1212,6 +1212,62 @@ 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 + variable numResults + + [win, device] = CreateFakeDataBrowserWindow() + + CreateFakeSweepData(win, device, sweepNo=0, sweepGen=FakeSweepDataGeneratorAPF0) + CreateFakeSweepData(win, device, sweepNo=1, sweepGen=FakeSweepDataGeneratorAPF1) + + WAVE/WAVE outputRef = GetMultipleResults(note(wv), win) + numResults = DimSize(wv, ROWS) + CHECK_EQUAL_VAR(numResults, DimSize(outputRef, ROWS)) + Make/FREE/N=(numResults) idxHelper + + WAVE/WAVE results = wv + idxHelper = REQUIRE_EQUAL_WAVES(results[p], outputRef[p], mode = WAVE_DATA, tol = 1E-12) +End + static Function TestOperationAPFrequency() string str, strRef, dataType @@ -1228,8 +1284,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() @@ -1238,7 +1294,7 @@ static Function TestOperationAPFrequency() endtry // requires valid method - str = "apfrequency([1], 3)" + str = "apfrequency([1], 10)" try WAVE output = GetSingleResult(str, win) FAIL() @@ -1258,28 +1314,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 @@ -1288,11 +1344,20 @@ 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)" @@ -1300,6 +1365,44 @@ static Function TestOperationAPFrequency() 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() diff --git a/Packages/tests/UTF_DataGenerators.ipf b/Packages/tests/UTF_DataGenerators.ipf index 57674ec4c8..fba3adf4e2 100644 --- a/Packages/tests/UTF_DataGenerators.ipf +++ b/Packages/tests/UTF_DataGenerators.ipf @@ -218,3 +218,38 @@ 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/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 + + 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