Skip to content

Commit de6b75c

Browse files
committed
Tests: Add tests for SF operation preparefit and fit2
1 parent ad2ec7c commit de6b75c

2 files changed

Lines changed: 375 additions & 0 deletions

File tree

Packages/tests/Basic/UTF_SweepFormula_Operations.ipf

Lines changed: 362 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#pragma rtFunctionErrors = 1
44
#pragma ModuleName = UTF_SWEEPFORMULA_OPERATIONS
55

6+
static Constant IGOR_CURVEFIT_DEFAULT_LENGTH = 200
7+
68
// IUTF_TD_GENERATOR DataGenerators#TestOperationAPFrequency2Gen
79
static Function TestOperationAPFrequency2([WAVE wv])
810

@@ -4005,3 +4007,363 @@ static Function TestOperationxValues()
40054007

40064008
KillWaves/Z wv
40074009
End
4010+
4011+
static Function TestOperationPreparefit()
4012+
4013+
string str
4014+
string win, type
4015+
4016+
win = GetDataBrowserWithData()
4017+
4018+
str = "preparefit()"
4019+
WAVE/WAVE output = SFE_ExecuteFormula(str, win, useVariables = 0)
4020+
CHECK_WAVE(output, WAVE_WAVE)
4021+
CHECK_EQUAL_VAR(DimSize(output, ROWS), 6)
4022+
type = JWN_GetStringFromWaveNote(output, SF_META_DATATYPE)
4023+
CHECK_EQUAL_STR(type, SF_DATATYPE_PREPAREFIT)
4024+
4025+
WAVE/T fitArgs = output[%FITARGS]
4026+
CHECK_EQUAL_VAR(IsTextWave(fitArgs), 1)
4027+
CHECK_EQUAL_VAR(DimSize(fitArgs, ROWS), 4)
4028+
CHECK_EQUAL_STR(fitArgs[%HOLDSTR], "")
4029+
CHECK_EQUAL_STR(fitArgs[%FITFUNCNAME], SF_PREPAREFIT_NOFUNC)
4030+
CHECK_EQUAL_STR(fitArgs[%ERRORBARTYPE], SF_PREPAREFIT_ERRORBARTYPE_CONFIDENCE)
4031+
CHECK_EQUAL_STR(fitArgs[%ERRORBARSTYLE], SF_PREPAREFIT_ERRORBARSTYLE_SHADED)
4032+
4033+
CHECK_EQUAL_WAVES(output[%LENGTH], {SF_PREPAREFIT_LENGTH_DEFAULT}, mode = WAVE_DATA)
4034+
CHECK_EQUAL_WAVES(output[%CONFLEVEL], {SF_PREPAREFIT_CONFIDENCELEVEL_DEFAULT * PERCENT_TO_ONE}, mode = WAVE_DATA, tol = 1E-15)
4035+
CHECK_WAVE(output[%COEFS], NULL_WAVE)
4036+
CHECK_WAVE(output[%RANGE], NULL_WAVE)
4037+
CHECK_WAVE(output[%CONSTRAINTS], NULL_WAVE)
4038+
4039+
str = "preparefit(exp)"
4040+
WAVE/WAVE output = SFE_ExecuteFormula(str, win, useVariables = 0)
4041+
WAVE/T fitArgs = output[%FITARGS]
4042+
CHECK_EQUAL_STR(fitArgs[%FITFUNCNAME], "exp")
4043+
4044+
str = "preparefit(exp, 500)"
4045+
WAVE/WAVE output = SFE_ExecuteFormula(str, win, useVariables = 0)
4046+
WAVE wLength = output[%LENGTH]
4047+
CHECK_EQUAL_WAVES(wLength, {500}, mode = WAVE_DATA)
4048+
4049+
str = "preparefit(exp, 0, standard)"
4050+
WAVE/WAVE output = SFE_ExecuteFormula(str, win, useVariables = 0)
4051+
WAVE wLength = output[%LENGTH]
4052+
CHECK_EQUAL_WAVES(wLength, {NaN}, mode = WAVE_DATA)
4053+
WAVE/T fitArgs = output[%FITARGS]
4054+
CHECK_EQUAL_STR(fitArgs[%ERRORBARTYPE], SF_PREPAREFIT_ERRORBARTYPE_STANDARD)
4055+
4056+
str = "preparefit(exp, 500, conf)"
4057+
WAVE/WAVE output = SFE_ExecuteFormula(str, win, useVariables = 0)
4058+
WAVE/T fitArgs = output[%FITARGS]
4059+
CHECK_EQUAL_STR(fitArgs[%ERRORBARTYPE], SF_PREPAREFIT_ERRORBARTYPE_CONFIDENCE)
4060+
str = "preparefit(exp, 500, pred)"
4061+
WAVE/WAVE output = SFE_ExecuteFormula(str, win, useVariables = 0)
4062+
WAVE/T fitArgs = output[%FITARGS]
4063+
CHECK_EQUAL_STR(fitArgs[%ERRORBARTYPE], SF_PREPAREFIT_ERRORBARTYPE_PREDICTION)
4064+
4065+
str = "preparefit(exp, 500, pred, normal)"
4066+
WAVE/WAVE output = SFE_ExecuteFormula(str, win, useVariables = 0)
4067+
WAVE/T fitArgs = output[%FITARGS]
4068+
CHECK_EQUAL_STR(fitArgs[%ERRORBARSTYLE], SF_PREPAREFIT_ERRORBARSTYLE_NORMAL)
4069+
str = "preparefit(exp, 500, pred, shaded)"
4070+
WAVE/WAVE output = SFE_ExecuteFormula(str, win, useVariables = 0)
4071+
WAVE/T fitArgs = output[%FITARGS]
4072+
CHECK_EQUAL_STR(fitArgs[%ERRORBARSTYLE], SF_PREPAREFIT_ERRORBARSTYLE_SHADED)
4073+
4074+
str = "preparefit(exp, 500, pred, shaded, 3)"
4075+
WAVE/WAVE output = SFE_ExecuteFormula(str, win, useVariables = 0)
4076+
WAVE wConfLevel = output[%CONFLEVEL]
4077+
Make/FREE/D wConfLevelRef = {3 * PERCENT_TO_ONE}
4078+
CHECK_EQUAL_WAVES(wConfLevel, wConfLevelRef, mode = WAVE_DATA)
4079+
4080+
str = "preparefit(exp, 500, pred, shaded, 3, [1,2,3])"
4081+
WAVE/WAVE output = SFE_ExecuteFormula(str, win, useVariables = 0)
4082+
WAVE coefs = output[%COEFS]
4083+
CHECK_EQUAL_WAVES(coefs, {1, 2, 3}, mode = WAVE_DATA)
4084+
4085+
str = "preparefit(exp, 500, pred, shaded, 3, [1,2,3], XOX)"
4086+
WAVE/WAVE output = SFE_ExecuteFormula(str, win, useVariables = 0)
4087+
WAVE/T fitArgs = output[%FITARGS]
4088+
CHECK_EQUAL_STR(fitArgs[%HOLDSTR], "101")
4089+
4090+
str = "preparefit(exp, 500, pred, shaded, 3, [1,2,3], XOX, [1,10])"
4091+
WAVE/WAVE output = SFE_ExecuteFormula(str, win, useVariables = 0)
4092+
WAVE range = output[%RANGE]
4093+
CHECK_EQUAL_WAVES(range, {1, 10}, mode = WAVE_DATA)
4094+
4095+
str = "preparefit(exp, 500, pred, shaded, 3, [1,2,3], XOX, [1,10], [K1,K2])"
4096+
WAVE/WAVE output = SFE_ExecuteFormula(str, win, useVariables = 0)
4097+
WAVE/T constraints = output[%CONSTRAINTS]
4098+
CHECK_EQUAL_TEXTWAVES(constraints, {"K1", "K2"})
4099+
End
4100+
4101+
static Function TestOperationPreparefitFail()
4102+
4103+
string win, str
4104+
4105+
win = GetDataBrowserWithData()
4106+
4107+
str = "preparefit(nonExistingFitFunc)"
4108+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4109+
str = "preparefit(123)"
4110+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4111+
4112+
str = "preparefit(log, -1)"
4113+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4114+
str = "preparefit(log, abc)"
4115+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4116+
str = "preparefit(log, 0)"
4117+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4118+
str = "preparefit(log, 1)"
4119+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4120+
4121+
str = "preparefit(log, 200, unknown)"
4122+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4123+
str = "preparefit(log, 200, standard)"
4124+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4125+
str = "preparefit(log, 0, conf)"
4126+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4127+
str = "preparefit(log, 0, pred)"
4128+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4129+
4130+
str = "preparefit(log, 200, conf, unknown)"
4131+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4132+
4133+
str = "preparefit(log, 200, conf, shaded, -1)"
4134+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4135+
str = "preparefit(log, 200, conf, shaded, 101)"
4136+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4137+
4138+
// log requires 2 coefs
4139+
str = "preparefit(log, 200, conf, shaded, 85, 1)"
4140+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4141+
str = "preparefit(log, 200, conf, shaded, 85, [1,2,3])"
4142+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4143+
str = "preparefit(log, 200, conf, shaded, 85, [a,b,c])"
4144+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4145+
4146+
str = "preparefit(log, 200, conf, shaded, 85, [1,2], 1)"
4147+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4148+
str = "preparefit(log, 200, conf, shaded, 85, [1,2], AB)"
4149+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4150+
str = "preparefit(log, 200, conf, shaded, 85, [1,2], OOO)"
4151+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4152+
4153+
str = "preparefit(log, 200, conf, shaded, 85, [1,2], OO, 1)"
4154+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4155+
str = "preparefit(log, 200, conf, shaded, 85, [1,2], OO, [0])"
4156+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4157+
str = "preparefit(log, 200, conf, shaded, 85, [1,2], OO, [0, 0, 0])"
4158+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4159+
str = "preparefit(log, 200, conf, shaded, 85, [1,2], OO, [1, NaN])"
4160+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4161+
str = "preparefit(log, 200, conf, shaded, 85, [1,2], OO, [NaN, 1])"
4162+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4163+
str = "preparefit(log, 200, conf, shaded, 85, [1,2], OO, [2, 1])"
4164+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4165+
4166+
str = "preparefit(log, 200, conf, shaded, 85, [1,2], OO, [1, 10], 1)"
4167+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4168+
str = "preparefit(log, 200, conf, shaded, 85, [1,2], OO, [1, 10], [1, 2])"
4169+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4170+
4171+
str = "preparefit(log, 200, conf, shaded, 85, [1,2], OO, [1, 10], [K1, K2], obscureExtraArgument)"
4172+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4173+
End
4174+
4175+
// IUTF_TD_GENERATOR DataGenerators#IgorIntegratedFitFuncs
4176+
static Function TestOperationPreparefitFitFuncs([string str])
4177+
4178+
string win, code
4179+
4180+
win = GetDataBrowserWithData()
4181+
4182+
code = "preparefit(\"" + str + "\")"
4183+
SFE_ExecuteFormula(code, win, useVariables = 0)
4184+
End
4185+
4186+
static Function TestOperationFit2()
4187+
4188+
string str
4189+
string win, msg
4190+
variable val
4191+
4192+
win = GetDataBrowserWithData()
4193+
4194+
str = "fit2([1, 2, 3], preparefit())"
4195+
WAVE/Z output = SFE_ExecuteFormula(str, win, singleResult = 1, useVariables = 0)
4196+
CHECK_WAVE(output, NULL_WAVE)
4197+
4198+
str = "fit2([1, 5, 6], preparefit(line, 0 , standard))"
4199+
WAVE output = SFE_ExecuteFormula(str, win, singleResult = 1, useVariables = 0)
4200+
CHECK_WAVE(output, NUMERIC_WAVE)
4201+
CHECK_EQUAL_WAVES(output, {1.5, 4, 6.5}, mode = WAVE_DATA)
4202+
val = JWN_GetNumberFromWaveNote(output, SF_SERIALIZE + SF_META_FITERROR)
4203+
CHECK_EQUAL_VAR(val, 0)
4204+
val = JWN_GetNumberFromWaveNote(output, SF_SERIALIZE + SF_META_FITQUITREASON)
4205+
CHECK_EQUAL_VAR(val, 0)
4206+
val = JWN_GetNumberFromWaveNote(output, SF_SERIALIZE + SF_META_FITNUMITERS)
4207+
CHECK_EQUAL_VAR(val, 0)
4208+
msg = JWN_GetStringFromWaveNote(output, SF_SERIALIZE + SF_META_FITSTATUSMESSAGE)
4209+
CHECK_EQUAL_STR(msg, "Fit Ok.\rIterations run: 0")
4210+
msg = JWN_GetStringFromWaveNote(output, SF_SERIALIZE + SF_META_FITFUNC)
4211+
CHECK_EQUAL_STR(msg, "line")
4212+
WAVE coefs = JWN_GetNumericWaveFromWaveNote(output, SF_SERIALIZE + SF_META_FITCOEFS)
4213+
CHECK_EQUAL_WAVES(coefs, {1.5, 2.5}, mode = WAVE_DATA)
4214+
WAVE yResiduals = JWN_GetNumericWaveFromWaveNote(output, SF_SERIALIZE + SF_META_FITYRESIDUALS)
4215+
CHECK_EQUAL_WAVES(yResiduals, {-0.5, 1, -0.5}, mode = WAVE_DATA)
4216+
WAVE/Z xResiduals = JWN_GetNumericWaveFromWaveNote(output, SF_SERIALIZE + SF_META_FITXRESIDUALS)
4217+
CHECK_WAVE(xResiduals, NULL_WAVE)
4218+
WAVE yErrorsMinus = JWN_GetNumericWaveFromWaveNote(output, SF_META_ERRORBARYMINUS)
4219+
CHECK_EQUAL_WAVES(yErrorsMinus, {1.224744871391589, 1.224744871391589, 1.224744871391589}, mode = WAVE_DATA, tol = 1E-12)
4220+
WAVE yErrorsPlus = JWN_GetNumericWaveFromWaveNote(output, SF_META_ERRORBARYPLUS)
4221+
CHECK_EQUAL_WAVES(yErrorsPlus, {1.224744871391589, 1.224744871391589, 1.224744871391589}, mode = WAVE_DATA, tol = 1E-12)
4222+
val = JWN_GetNumberFromWaveNote(output, SF_SERIALIZE + SF_META_FITCHISQUARE)
4223+
CHECK_EQUAL_VAR(val, 1.5)
4224+
WAVE/Z wSigma = JWN_GetNumericWaveFromWaveNote(output, SF_SERIALIZE + SF_META_FITWSIGMA)
4225+
CHECK_EQUAL_WAVES(wSigma, {0.9128709291752769, 0.7071067811865476}, mode = WAVE_DATA, tol = 1E-12)
4226+
WAVE/Z mCovar = JWN_GetNumericWaveFromWaveNote(output, SF_SERIALIZE + SF_META_FITMCOVAR)
4227+
CHECK_WAVE(mCovar, NULL_WAVE)
4228+
WAVE/Z mFitConstraints = JWN_GetNumericWaveFromWaveNote(output, SF_SERIALIZE + SF_META_FITMFITCONSTRAINT)
4229+
CHECK_WAVE(mFitConstraints, NULL_WAVE)
4230+
WAVE/Z wFitConstraints = JWN_GetNumericWaveFromWaveNote(output, SF_SERIALIZE + SF_META_FITWFITCONSTRAINT)
4231+
CHECK_WAVE(wFitConstraints, NULL_WAVE)
4232+
WAVE/Z fitConstants = JWN_GetNumericWaveFromWaveNote(output, SF_SERIALIZE + SF_META_FITCONSTANT)
4233+
CHECK_WAVE(fitConstants, NULL_WAVE)
4234+
WAVE/Z wConfU = JWN_GetNumericWaveFromWaveNote(output, SF_SERIALIZE + SF_META_FITUCONFIDENCE)
4235+
CHECK_WAVE(wConfU, NUMERIC_WAVE)
4236+
CHECK_EQUAL_VAR(DimSize(wConfU, ROWS), IGOR_CURVEFIT_DEFAULT_LENGTH)
4237+
WAVE/Z wConfL = JWN_GetNumericWaveFromWaveNote(output, SF_SERIALIZE + SF_META_FITLCONFIDENCE)
4238+
CHECK_WAVE(wConfL, NUMERIC_WAVE)
4239+
CHECK_EQUAL_VAR(DimSize(wConfL, ROWS), IGOR_CURVEFIT_DEFAULT_LENGTH)
4240+
WAVE/Z wPredU = JWN_GetNumericWaveFromWaveNote(output, SF_SERIALIZE + SF_META_FITUPREDICTION)
4241+
CHECK_WAVE(wPredU, NUMERIC_WAVE)
4242+
CHECK_EQUAL_VAR(DimSize(wPredU, ROWS), IGOR_CURVEFIT_DEFAULT_LENGTH)
4243+
WAVE/Z wPredL = JWN_GetNumericWaveFromWaveNote(output, SF_SERIALIZE + SF_META_FITLPREDICTION)
4244+
CHECK_WAVE(wPredL, NUMERIC_WAVE)
4245+
CHECK_EQUAL_VAR(DimSize(wPredL, ROWS), IGOR_CURVEFIT_DEFAULT_LENGTH)
4246+
WAVE/Z wCoefConfInt = JWN_GetNumericWaveFromWaveNote(output, SF_SERIALIZE + SF_META_FITCOEFCONFINT)
4247+
CHECK_WAVE(wCoefConfInt, NUMERIC_WAVE)
4248+
CHECK_EQUAL_VAR(DimSize(wCoefConfInt, ROWS), 3)
4249+
WAVE/Z xWave = JWN_GetNumericWaveFromWaveNote(output, SF_META_XVALUES)
4250+
CHECK_EQUAL_WAVES(xWave, {0, 1, 2}, mode = WAVE_DATA)
4251+
WAVE/Z errorBarStyle = JWN_GetNumericWaveFromWaveNote(output, SF_META_ERRORBARSTYLE)
4252+
CHECK_WAVE(errorBarStyle, NUMERIC_WAVE)
4253+
4254+
// with X
4255+
str = "fit2([1, 5, 6], [4, 5, 6], preparefit(line, 0, standard))"
4256+
WAVE output = SFE_ExecuteFormula(str, win, singleResult = 1, useVariables = 0)
4257+
CHECK_EQUAL_WAVES(output, {1.5, 4, 6.5}, mode = WAVE_DATA)
4258+
WAVE/Z xWave = JWN_GetNumericWaveFromWaveNote(output, SF_META_XVALUES)
4259+
CHECK_EQUAL_WAVES(xWave, {4, 5, 6}, mode = WAVE_DATA)
4260+
4261+
// with default length
4262+
str = "fit2([1, 5, 6], [4, 5, 6], preparefit(line))"
4263+
WAVE output = SFE_ExecuteFormula(str, win, singleResult = 1, useVariables = 0)
4264+
CHECK_EQUAL_VAR(DimSize(output, ROWS), SF_PREPAREFIT_LENGTH_DEFAULT)
4265+
CHECK_EQUAL_VAR(output[0], 1.5)
4266+
CHECK_EQUAL_VAR(output[SF_PREPAREFIT_LENGTH_DEFAULT - 1], 6.5)
4267+
WAVE/Z xWave = JWN_GetNumericWaveFromWaveNote(output, SF_META_XVALUES)
4268+
CHECK_WAVE(xWave, NULL_WAVE)
4269+
WAVE yErrorsMinus = JWN_GetNumericWaveFromWaveNote(output, SF_META_ERRORBARYMINUS)
4270+
CHECK_WAVE(yErrorsMinus, NUMERIC_WAVE)
4271+
CHECK_EQUAL_VAR(DimSize(yErrorsMinus, ROWS), SF_PREPAREFIT_LENGTH_DEFAULT)
4272+
CHECK_EQUAL_VAR(yErrorsMinus[0], 3.802381071416012)
4273+
WAVE yErrorsPlus = JWN_GetNumericWaveFromWaveNote(output, SF_META_ERRORBARYPLUS)
4274+
CHECK_WAVE(yErrorsPlus, NUMERIC_WAVE)
4275+
CHECK_EQUAL_VAR(DimSize(yErrorsPlus, ROWS), SF_PREPAREFIT_LENGTH_DEFAULT)
4276+
CHECK_CLOSE_VAR(yErrorsPlus[0], 3.802381071416012)
4277+
End
4278+
4279+
static Function TestOperationFit2_ODR()
4280+
4281+
string str, wPath
4282+
string win
4283+
4284+
win = GetDataBrowserWithData()
4285+
4286+
Make/D data = {1, 5, 6}
4287+
Make/FREE/D errorB = {0.1, 0.1, 0.1}
4288+
JWN_SetWaveInWaveNote(data, SF_META_ERRORBARYMINUS, errorB)
4289+
JWN_SetWaveInWaveNote(data, SF_META_ERRORBARYPLUS, errorB)
4290+
JWN_SetWaveInWaveNote(data, SF_META_ERRORBARXMINUS, errorB)
4291+
JWN_SetWaveInWaveNote(data, SF_META_ERRORBARXPLUS, errorB)
4292+
wPath = GetWavesDataFolder(data, 2)
4293+
4294+
str = "fit2(wave(" + wPath + "), [4, 5, 6], preparefit(line))"
4295+
WAVE output = SFE_ExecuteFormula(str, win, singleResult = 1, useVariables = 0)
4296+
4297+
CHECK_EQUAL_VAR(DimSize(output, ROWS), SF_PREPAREFIT_LENGTH_DEFAULT)
4298+
CHECK_CLOSE_VAR(output[0], 1.2379534159593, tol = 5E-15)
4299+
CHECK_CLOSE_VAR(output[SF_PREPAREFIT_LENGTH_DEFAULT - 1], 6.762046584040696, tol = 5E-15)
4300+
WAVE/Z xWave = JWN_GetNumericWaveFromWaveNote(output, SF_META_XVALUES)
4301+
CHECK_WAVE(xWave, NULL_WAVE)
4302+
WAVE yErrorsMinus = JWN_GetNumericWaveFromWaveNote(output, SF_META_ERRORBARYMINUS)
4303+
CHECK_WAVE(yErrorsMinus, NUMERIC_WAVE)
4304+
CHECK_EQUAL_VAR(DimSize(yErrorsMinus, ROWS), SF_PREPAREFIT_LENGTH_DEFAULT)
4305+
CHECK_CLOSE_VAR(yErrorsMinus[0], 1.147218616615983, tol = 5E-15)
4306+
WAVE yErrorsPlus = JWN_GetNumericWaveFromWaveNote(output, SF_META_ERRORBARYPLUS)
4307+
CHECK_WAVE(yErrorsPlus, NUMERIC_WAVE)
4308+
CHECK_EQUAL_VAR(DimSize(yErrorsPlus, ROWS), SF_PREPAREFIT_LENGTH_DEFAULT)
4309+
CHECK_CLOSE_VAR(yErrorsPlus[0], 1.147218616615983, tol = 5E-15)
4310+
WAVE/Z xResiduals = JWN_GetNumericWaveFromWaveNote(output, SF_SERIALIZE + SF_META_FITXRESIDUALS)
4311+
CHECK_WAVE(xResiduals, NUMERIC_WAVE)
4312+
CHECK_EQUAL_VAR(DimSize(xResiduals, ROWS), 3)
4313+
4314+
str = "fit2(wave(" + wPath + "), [4, 5, 6], preparefit(line, 0, standard))"
4315+
WAVE output = SFE_ExecuteFormula(str, win, singleResult = 1, useVariables = 0)
4316+
WAVE/Z xWave = JWN_GetNumericWaveFromWaveNote(output, SF_META_XVALUES)
4317+
CHECK_WAVE(xWave, NUMERIC_WAVE)
4318+
CHECK_EQUAL_VAR(DimSize(xWave, ROWS), 3)
4319+
4320+
KillWaves/Z data
4321+
End
4322+
4323+
static Function TestOperationFit2Fail()
4324+
4325+
string str, wPath
4326+
string win
4327+
4328+
win = GetDataBrowserWithData()
4329+
4330+
str = "fit2()"
4331+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4332+
str = "fit2(1)"
4333+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4334+
str = "fit2(abc, preparefit())"
4335+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4336+
str = "fit2([1, 2, 3], abc, preparefit())"
4337+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4338+
str = "fit2([1, 2, 3], [1, 2, 3], 1)"
4339+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4340+
str = "fit2([1, 2, 3], [1, 2, 3], preparefit(), obscureAdditionalArgument)"
4341+
ExecuteSweepFormulaCode(win, str, expectFailure = 1)
4342+
End
4343+
4344+
static Function TestOperationFit2FitError()
4345+
4346+
string str
4347+
string win, msg
4348+
variable val
4349+
4350+
win = GetDataBrowserWithData()
4351+
4352+
str = "fit2([0, 0, 0], preparefit(exp))"
4353+
WAVE/Z output = SFE_ExecuteFormula(str, win, singleResult = 1, useVariables = 0)
4354+
CHECK_WAVE(output, NUMERIC_WAVE)
4355+
val = JWN_GetNumberFromWaveNote(output, SF_SERIALIZE + SF_META_FITERROR)
4356+
CHECK_EQUAL_VAR(val, 3)
4357+
msg = JWN_GetStringFromWaveNote(output, SF_SERIALIZE + SF_META_FITSTATUSMESSAGE)
4358+
CHECK_EQUAL_STR(msg, "Fit Error.\rSingular Matrix.\rchiSquare did not decrease in last 9 iterations.\rIterations run: 10")
4359+
4360+
CHECK_EQUAL_VAR(DimSize(output, ROWS), 0)
4361+
val = JWN_GetNumberFromWaveNote(output, SF_SERIALIZE + SF_META_FITQUITREASON)
4362+
CHECK_EQUAL_VAR(val, 3)
4363+
val = JWN_GetNumberFromWaveNote(output, SF_SERIALIZE + SF_META_FITNUMITERS)
4364+
CHECK_EQUAL_VAR(val, 10)
4365+
msg = JWN_GetStringFromWaveNote(output, SF_SERIALIZE + SF_META_FITFUNC)
4366+
CHECK_EQUAL_STR(msg, "exp")
4367+
WAVE/Z coefs = JWN_GetNumericWaveFromWaveNote(output, SF_SERIALIZE + SF_META_FITCOEFS)
4368+
CHECK_WAVE(coefs, NULL_WAVE)
4369+
End

Packages/tests/UTF_DataGenerators.ipf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,6 +2101,19 @@ static Function/WAVE ValidHashmapSizes()
21012101
return sizes
21022102
End
21032103

2104+
static Function/WAVE IgorIntegratedFitFuncs()
2105+
2106+
variable col
2107+
2108+
WAVE/T props = GetSFIgorFitProperties()
2109+
col = FindDimLabel(props, COLS, "FITFUNC")
2110+
Duplicate/FREE/RMD=[][col] props, fitFuncs
2111+
Redimension/N=(-1) fitFuncs
2112+
SetDimensionLabelsFromWaveContents(fitFuncs, cleanup = 1)
2113+
2114+
return fitFuncs
2115+
End
2116+
21042117
static Function/WAVE PermanentOrFree()
21052118

21062119
Make/FREE wv = {1, 0}

0 commit comments

Comments
 (0)