Hey!
I am trying to generate unique ids however I am having some troubles with it. I have tried adding a list to which ids have already been generated and then discard any that matches. questionIdGenOptions.alreadyGeneratedQuestions is an array of strings. Utils.Contains is a function which returns true if the given array contains the corresponding string otherwise false.
func QuestionIdGen(questionIdGenOptions *QuestionIdGenOptions) gopter.Gen{
if questionIdGenOptions != nil && questionIdGenOptions.alreadyGeneratedQuestions == nil {
var newAlreadyGeneratedQuestions = []string{}
questionIdGenOptions.alreadyGeneratedQuestions = &newAlreadyGeneratedQuestions
}
pgen := gen.PtrOf(gen.AnyString())
if questionIdGenOptions != nil {
pgen = pgen.SuchThat(
func(generatedId *string) bool {
//Some characters look the same however their bytes are not i.e. it is therefore unique.
if questionIdGenOptions.GenUniqueId != nil && *questionIdGenOptions.GenUniqueId == true && (generatedId == nil || Utils.Contains(*questionIdGenOptions.alreadyGeneratedQuestions, *generatedId)) {
return false
}
newAlreadyGeneratedQuestions := append(*questionIdGenOptions.alreadyGeneratedQuestions, *generatedId)
questionIdGenOptions.alreadyGeneratedQuestions = &newAlreadyGeneratedQuestions
return true
})
}
return pgen
}
However atm. with this if statement, the wrapper generator which uses this function fails to generate anything... And I am unsure why almost like something internal error is happening. If I remove it everything works fine except the ids are not unique. Is there another way of doing it or?
Hey!
I am trying to generate unique ids however I am having some troubles with it. I have tried adding a list to which ids have already been generated and then discard any that matches.
questionIdGenOptions.alreadyGeneratedQuestionsis an array of strings.Utils.Containsis a function which returns true if the given array contains the corresponding string otherwise false.However atm. with this if statement, the wrapper generator which uses this function fails to generate anything... And I am unsure why almost like something internal error is happening. If I remove it everything works fine except the ids are not unique. Is there another way of doing it or?