Answer the question
In order to leave comments, you need to log in
Algorithm for generating permutations while preserving the order of elements in groups
Hello! I ran into a problem that I can not compose the algorithm I need, so I turn to you.
The situation is this. There is a very tricky data structure, there are three operations:
Answer the question
In order to leave comments, you need to log in
If I understand you correctly, you can use the generator of all permutations with repetitions on the following set:
Number of elements = number of records being tested (3 in your example)
Number of repetitions of each element = 3 (add, change, delete).
And then just for each repetition of the element (there are three of them), from left to right, put down “create” “change” “delete”.
But there is a problem here - you cannot test the "create" "delete" chains - for this you need to generate a bunch of possible permutations.
In general, firstly, you are testing only correct behavior in this way, without checking what will happen with erroneous calls.
Second - IMHO (based on the information provided), your approach is not entirely correct, you need to break the code into modules and test everything with only one element, and write tests for the fact that if there are several elements, there are no overlaps (i.e. working with they are conducted independently).
And for testing “create” / “delete”, you need to add a random number with a probability of 1/2, depending on the value of which, either use “set” or throw out the second of the occurrences altogether.
Cool puzzle :) It looks like you gave an example of a context-sensitive language (if you take it in a general way). There will be a lot of combinations. If I'm not mistaken (k*n)!/ (k!)^n where n is the number of groups, k is the number of elements in each group. For example, for three groups with three elements <c1, s1, d1>, <c2,s2,d2> <c3, s3, d3> there will be 9!/3!3!3 combinations! = 1680.0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question