You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
funcQuestionIdGen(questionIdGenOptions*QuestionIdGenOptions) gopter.Gen{
ifquestionIdGenOptions!=nil&&questionIdGenOptions.alreadyGeneratedQuestions==nil {
varnewAlreadyGeneratedQuestions= []string{}
questionIdGenOptions.alreadyGeneratedQuestions=&newAlreadyGeneratedQuestions
}
pgen:=gen.PtrOf(gen.AnyString())
ifquestionIdGenOptions!=nil {
pgen=pgen.SuchThat(
func(generatedId*string) bool {
//Some characters look the same however their bytes are not i.e. it is therefore unique.ifquestionIdGenOptions.GenUniqueId!=nil&&*questionIdGenOptions.GenUniqueId==true&& (generatedId==nil||Utils.Contains(*questionIdGenOptions.alreadyGeneratedQuestions, *generatedId)) {
returnfalse
}
newAlreadyGeneratedQuestions:=append(*questionIdGenOptions.alreadyGeneratedQuestions, *generatedId)
questionIdGenOptions.alreadyGeneratedQuestions=&newAlreadyGeneratedQuestionsreturntrue
})
}
returnpgen
}
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?
The text was updated successfully, but these errors were encountered:
jonaslagoni
changed the title
Generating unique ids
Generating unique values
Nov 2, 2020
Soo I test simply give up after (fixed any underlying problems), however the usecase are still relevant, do you want any functionality which can do this in a reproducing manner? Or should I find external libraries for this?
Sorry for the long wait ... (I guess the situation is kind of messed up all around the world).
Obviously you are doing a sort of stateful testing, i.e. the function under test is not a pure-function since the outcome depends on the previous calls to it. As a rule of thumb one should use command-based tests for this kind of situation.
Maybe there is a somewhat "simple" example that could be added to the library reflecting a use-case like this.
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.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?
The text was updated successfully, but these errors were encountered: