This is a Chinese character string: “Bank card test”

I asked for his initials,

Expected, “yhkcs”

Actually, “yhqcs”

Yes, it contains one polyphonic word: card

Say ka or qia

 

My requirement becomes: I’m going to take all of its possible acronyms and put them in a big list.

Using a third-party Pinyin library, I managed to get a two-dimensional array of their initials, each element being a one-word alphabetic list:

“Test” = [[‘y’],[‘h’],[‘q’,’k’],[‘c’],[‘s’]]

The end result of this should be:

[‘yhqcs’,’yhkcs’] is of length 2

 

Of course, replace it with a polyphonic one:

[‘c’,’z’],[‘q’,’k’],[‘c’]]

Expected Results:

The length of [‘ CQC ‘,’ CKC ‘,’ ZQC ‘,’ ZKC ‘] is 4

 

The final total number of elements is the product of the lengths of each sublist.

 

Of course, there are more complicated ones:

[[‘a’,’b’,’c’,’d’],[‘e’,’f’,’g’],[‘h’,’i’]]

The expected length of the large list should be 4*3*2 = 24

 

So how to achieve the above requirements with the code?

I think I’m the only one who wrote this:

from allpairspy import AllPairsold = [['a','b','c','d'],['e','f','g'],['h','i']]ready = []for pairs in AllPairs(old[:2]):    ready.append(''.join(pairs))for i in range(2, len(old)):  new_r= []  for pairs in AllPairs([ready, old[i]]):    new_r.append(''.join(pairs))    ready=new_r
print(ready)print(len(ready))
Copy the code

Here are the results:

No problem at all.

 

Why did I come up with this solution?

Let me give you an idea. It’s very interesting

 

First of all, I think it’s cumbersome to just write the recursion. Efficiency doesn’t work, either. I just wonder if there’s a wild way out.

And then all of a sudden, this sub-list, one by one, is like a functional interface that we’re testing

An indefinite number of letters in a sublist are like the suboptions in these subboxes.

What do we do when we test this feature? The goal is to measure as many combinations as possible!

That is, only one drop-down box can be selected. I want to measure all kinds of combinations of boxes.

 

They clearly do not have any strong logical correlation, so we should prefer orthogonality in the black box use-case design approach!

 

Yes orthogonal, it can automatically generate a combination of situations, each combination is a final use case!

 

But!

 

The orthogonal algorithm was invented to avoid exhaustive testing, and my requirement this time is to exhaust all possible combinations.

So the orthogonal algorithm has to change a little bit, after all, this third party algorithm performance is very good, I use the performance is absolutely not wrong!

 

The basic principle of orthogonality is to ensure that any substate of any input condition occurs at the same time as any substate of the other input. So the number of combinations that you end up with with the orthogonal algorithm is going to be much smaller than the number of combinations.

 

Such as:

[[‘a’,’b’],[‘c’,’d’],[‘e’,’f’]]

The number of exhausted items should be: 2*2*2 = 8

And the number of orthogonal algorithms:

[‘a’, ‘c’, ‘e’]

[‘b’, ‘d’, ‘e’]

[‘b’, ‘c’, ‘f’]

[‘a’, ‘d’, ‘f’]

And finally 4, 4 of these you can see, any child of any two sublists has been present at the same time.

For example: A and F, yes.

D and E.

 

So the orthogonal algorithm is something that reduces the number of test cases we have, but still ensures full coverage.

 

But how do we apply it here so that it outputs all eight outcomes?

 

Very simple, when there are only two sublists, so there are only two inputs. So in this case, the result of the orthogonal algorithm is exactly the same as the exhaust result.

 

That is to say, I this demand may have four or more child list, but only as long as I use orthogonal algorithm to calculate the child list of the two end, then the end results as a list of new child, to go with another new child list to calculate the end, and then the results as a list of new child again, and the next is a list of calculating end, Until there are no more sublists, at which point the new sublist is the final result!

 

Did you see that it was a little confusing?

Let me illustrate:

And each time you add them up you end up with the final result. Safe, fast and accurate!

 

And then it becomes the final algorithm that I shared at the top.

Anyone interested can try it. Of course, I think I’m the only test that can save the country on such a curve.

 

Thanks first for coming up with this solution

  1. I am a great master of the test theory foundation: black box test case design method – orthogonal method
  2. Studied an orthogonal third-party Python function: AllpairSpy
  3. Years of brush leetcode practice SAO operation thinking

 

So guys, don’t talk about brushing Leetcode, writing algorithms doesn’t work for us anymore.

 

Don’t forget to like and share

If you are interested, you can add the wechat account qingwanjianhua to join the group

Add clubs: testerhome.com/wqrf

Follow the bloggers at wangzijia.blog.csdn.net/

Light up the project :github.com/Woqurefan/A…

Experience online address: http://47.97.77.125:8000/home/

Public number: test development dry goods