Module: Pairwise

Defined in:
lib/common/pairwise.rb

Overview

Pairwise (a.k.a. all-pairs) testing is an effective test case generation technique that

is based on the observation that most faults are caused by interactions of at most two factors.

Pairwise-generated test suites cover all combinations of two therefore are much

smaller than exhaustive ones yet still very effective in finding defects.

Based on jenny, burtleburtle.net/bob/math/jenny.html Thanks Bob Jenkins :)

Class Method Summary collapse

Class Method Details

.gen(*arrs) ⇒ Object

功能:

给定几个数组,按照pairwise算法,从中挑出最小的case集

参数解释:

  • *arrs 可以跟若干个数组参数

Example:

Example #1:

type_arr = %wLogical Single Span Stripe Mirror size_arr = %w100 500 5000 10000 40000 system_arr = %wFAT32 NTFS compression_arr = %woff

pair = Pairwise.gen(type_arr,size_arr,system_arr,compression_arr)

puts pair.size #=> 36 p pair #=> [[“Primary”, “5000”, “NTFS”, “off”], …]

pair.each do |type,size,system,compression| #=> 可以遍历 puts type,size,system,compression end



82
83
84
# File 'lib/common/pairwise.rb', line 82

def self.gen(*arrs)
	jenny(*arrs)
end

.generate(*arrs) ⇒ Object

与gen一样



87
88
89
# File 'lib/common/pairwise.rb', line 87

def self.generate(*arrs)
	jenny(*arrs)
end

.jenny(*arrs) ⇒ Object

给定几个数组,按照pairwise算法,从中挑出最小的case集借助jenny实现pairwise



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/common/pairwise.rb', line 22

def self.jenny(*arrs)
	raise "the number of arguments must > 1" unless arrs.size > 1 
	cmd = "jenny -n2"
	arrs.each do |arr|
		raise "argument[#{arr}] must be an Array!" unless arr.is_a?(Array) 
		raise "Array[#{arr}]'s size[#{arr.size}] must between in [2,51]" unless arr.size>1 and arr.size<52
		cmd << " #{arr.size}"
	end

	# 如果包含排除的组合列表
	if block_given?
		#TODO
	end

	# 开始执行jenny,并获取返回数据
	#p "cmd:#{cmd}"
	result = `#{cmd}`
	pair = []
	result.each_line do |line|
		line.strip!
		la = []
		index = 0
		line.split(" ").each do |str|
			if str[1].ord >= 97 and str[1].ord <=122
				la << arrs[index][str[1].ord-97]
			elsif str[1].ord >= 65 and str[1].ord <= 90
				la << arrs[index][str[1].ord-65+26]
			else
				raise "why you got this str[#{str}] ?"
			end
			index = index + 1
		end
		pair << la
	end
	return pair
end