测试目的
1-8通道取n个数组合,测试不同组合场景运行逻辑正确性
实现1:枚举法
1 def test_loadTips_TwoChannels():
2 """
3 1-8通道任意2通道组合扎取
4 """
5 # 方法一:枚举法
6 for a2 in range(1, 9):
7 for b2 in range(a2 + 1, 9):
8 load_tips({"Sequence": "Lane7TipsPos1", "Channels": [a2, b2], "IfIncrement": False})
9 unload_tips({"Sequence": "Lane7TipsPos1", "Channels": [a2, b2], "IfIncrement": True})
10 reload_sequence("Lane7TipsPos1")
11
12
13 test_loadTips_TwoChannels()
实现2:Python标准库itertools
1 def test_loadTips_ThreeChannel():
2 """
3 1-8通道任意3通道组合扎取
4 """
5 # 方法二:Python标准库itertools
6 channel_list = [1, 2, 3, 4, 5, 6, 7, 8]
7 for c in itertools.combinations(channel_list, 3):
8 threeChannel = map(int, c)
9 load_tips({"Sequence": "Lane1-TipSequence", "Channels": threeChannel, "IfIncrement": False})
10 unload_tips({"Sequence": "Lane1-TipSequence", "Channels": threeChannel, "IfIncrement": True})
11 reload_sequence("Lane1-TipSequence")
12
13
14 test_loadTips_ThreeChannel()
实现3:递归
1 # *****************************************case:1-8通道7通道组合扎取正确*****************************************
2 def test_loadTips_SevenChannel():
3 """
4 1-8通道7通道组合扎取
5 :return:
6 """
7 # 方法三:递归法 从8个数中取7个数,不重复的,共计28种组合
8 channel_list = [1, 2, 3, 4, 5, 6, 7, 8]
9
10 def combine(channel_list, l):
11 result = []
12 tmp = [0] * l
13 length = len(channel_list)
14
15 def next_num(li=0, ni=0):
16 if ni == l:
17 result.append(copy.copy(tmp))
18 return
19 for lj in range(li, length):
20 tmp[ni] = channel_list[lj]
21 next_num(lj + 1, ni + 1)
22
23 next_num()
24 return result
25
26 for channel in combine(channel_list, 7):
27 # print channel
28 load_tips({"Sequence": "Lane1-TipSequence", "Channels": channel, "IfIncrement": False})
29 unload_tips({"Sequence": "Lane1-TipSequence", "Channels": channel, "IfIncrement": True})
30 reload_sequence("Lane1-TipSequence")
31
32
33 test_loadTips_SevenChannel()