dither 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,6 +4,7 @@ Collection of combinatorial test generation strategies.
4
4
  # Usage
5
5
 
6
6
  ## Pairwise Testing
7
+ IPOG (In-Parameter-Order-General) is an efficient deterministic alogrithm.
7
8
  ```ruby
8
9
  require 'dither'
9
10
 
@@ -32,6 +33,25 @@ Dither.ipog([[true, false],
32
33
 
33
34
  ```
34
35
 
36
+ ATEG non-deterministic alogrithm for pairwise testing.
37
+ ```ruby
38
+ require 'dither'
39
+
40
+ # 2-way
41
+ Dither.ateg([[true, false],
42
+ [:cat, :dog, :mouse],
43
+ (0...3).to_a])
44
+
45
+ # 3-way
46
+ Dither.ateg([[true, false],
47
+ [true, false],
48
+ [:cat, :dog, :mouse],
49
+ (0...5).to_a],
50
+ :t => 3,
51
+ :seed => 0 # set the seed on the random number generator
52
+ )
53
+ ```
54
+
35
55
  ## Graph Models (Experimental)
36
56
  ```ruby
37
57
  raw_graph = {
@@ -0,0 +1,15 @@
1
+
2
+ module Dither
3
+ module Ateg
4
+
5
+ def run
6
+ result = []
7
+ until stop?
8
+ generate
9
+ filter
10
+ result << best_fit
11
+ end
12
+ result
13
+ end
14
+ end # Ateg
15
+ end # Dither
@@ -0,0 +1,77 @@
1
+
2
+ module Dither
3
+ module Ateg
4
+ class Pairwise
5
+ include Ateg
6
+
7
+ attr_reader :scratch, :n, :random, :t, :params, :constraints, :pair_cache, :comb
8
+
9
+ Pair = Struct.new(:i, :j)
10
+
11
+ module Pairs
12
+
13
+ def in_test_case?(test_case)
14
+ self.all? { |pair| pair.j == test_case[pair.i] }
15
+ end
16
+
17
+ alias_method :orig_method_missing, :method_missing
18
+
19
+ def method_missing(method, *args, &block)
20
+ if method == :cached_hash
21
+ orig_hash = hash
22
+ self.class.define_method(:cached_hash) do
23
+ orig_hash
24
+ end
25
+ end
26
+ orig_method_missing(method, *args, &block)
27
+ end
28
+ end
29
+
30
+ def initialize(params, opts = {})
31
+
32
+ raise Dither::Error, 't must be >= 2' if opts[:t] < 2
33
+ raise Dither::Error, 't must be <= params.length' if opts[:t] > params.length
34
+ params.each do |param|
35
+ raise Dither::Error, 'param length must be > 1' if param.length < 2
36
+ end
37
+ @params = params
38
+ @n = 50
39
+ @scratch = Array.new(@n)
40
+ seed = opts[:seed] || Random.new.seed
41
+ @random = Random.new(seed)
42
+ @constraints = nil
43
+ @pair_cache = Array.new(params.length)
44
+ params.each_with_index do |param, i|
45
+ pair_cache[i] = (0...param.length).map { |j| Pair.new(i, j).freeze }
46
+ end
47
+ @comb = []
48
+ @t = opts[:t]
49
+ (0...params.length).to_a.combination(t).each do |a|
50
+ car, *cdr = a.map { |b| pair_cache[b] }
51
+ @comb.push(*car.product(*cdr).each { |b| b.extend(Pairs) })
52
+ end
53
+ end
54
+
55
+ def generate
56
+ (0...n).each do |i|
57
+ scratch[i] = params.map { |a| random.rand(a.length) }
58
+ end
59
+ end
60
+
61
+ def filter
62
+ return unless constraints
63
+ end
64
+
65
+ def best_fit
66
+ max, _ = scratch.map { |a| [a, comb.count { |b| b.in_test_case?(a) }] }
67
+ .max { |a, b| a[1] <=> b[1] }
68
+ comb.delete_if { |a| a.in_test_case?(max) }
69
+ max
70
+ end
71
+
72
+ def stop?
73
+ comb.empty?
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Dither
3
- VERSION = '0.0.11'
3
+ VERSION = '0.0.12'
4
4
  end
data/lib/dither.rb CHANGED
@@ -25,6 +25,11 @@ module Dither
25
25
  opts[:t] = t
26
26
  MIPOG.new(params, opts).run
27
27
  end
28
+
29
+ def self.ateg(params, opts = {})
30
+ opts = DEFUALT_OPTS.dup.merge(opts)
31
+ Ateg::Pairwise.new(params, opts).run
32
+ end
28
33
  end # Dither
29
34
 
30
35
  require 'dither/param'
@@ -34,6 +39,8 @@ require 'dither/ipog_helper'
34
39
  require 'dither/ipog'
35
40
  require 'dither/mipog'
36
41
  require 'dither/chinese_postman_problem'
42
+ require 'dither/ateg'
43
+ require 'dither/ateg_pairwise'
37
44
 
38
45
  if RUBY_PLATFORM =~ /java/
39
46
  require 'java'
@@ -165,4 +165,14 @@ describe Dither do
165
165
  [0, 0, 0, 1],
166
166
  [0, 1, 1, 1]].to_set)
167
167
  end
168
+
169
+ it 'can run 2-way ateg' do
170
+ params = [(0...2).to_a, (0...2).to_a, (0...2).to_a, (0..3).to_a]
171
+ Dither.ateg(params)
172
+ end
173
+
174
+ it 'can run 4-way ateg with seed' do
175
+ params = [(0...2).to_a, (0...2).to_a, (0...2).to_a, (0..3).to_a]
176
+ expect(Dither.ateg(params, :t => 4, :seed => 0).length).to eq 32
177
+ end
168
178
  end
metadata CHANGED
@@ -1,55 +1,62 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dither
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Jason Gowan
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-09-14 00:00:00.000000000 Z
12
+ date: 2015-09-18 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rspec
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - "~>"
19
+ - - ~>
18
20
  - !ruby/object:Gem::Version
19
21
  version: '3.2'
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - "~>"
27
+ - - ~>
25
28
  - !ruby/object:Gem::Version
26
29
  version: '3.2'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rake
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - "~>"
35
+ - - ~>
32
36
  - !ruby/object:Gem::Version
33
37
  version: 0.9.2
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - "~>"
43
+ - - ~>
39
44
  - !ruby/object:Gem::Version
40
45
  version: 0.9.2
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: coveralls
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - ">="
51
+ - - ! '>='
46
52
  - !ruby/object:Gem::Version
47
53
  version: '0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - ">="
59
+ - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  description: Efficient test generation strategies
@@ -59,9 +66,9 @@ executables: []
59
66
  extensions: []
60
67
  extra_rdoc_files: []
61
68
  files:
62
- - ".gitignore"
63
- - ".ruby-version"
64
- - ".travis.yml"
69
+ - .gitignore
70
+ - .ruby-version
71
+ - .travis.yml
65
72
  - Gemfile
66
73
  - Gemfile.lock
67
74
  - LICENSE
@@ -69,6 +76,8 @@ files:
69
76
  - Rakefile
70
77
  - dither.gemspec
71
78
  - lib/dither.rb
79
+ - lib/dither/ateg.rb
80
+ - lib/dither/ateg_pairwise.rb
72
81
  - lib/dither/chinese_postman_problem.rb
73
82
  - lib/dither/ipog.rb
74
83
  - lib/dither/ipog_helper.rb
@@ -84,26 +93,27 @@ files:
84
93
  homepage: https://github.com/jesg/dither
85
94
  licenses:
86
95
  - MIT
87
- metadata: {}
88
96
  post_install_message:
89
97
  rdoc_options: []
90
98
  require_paths:
91
99
  - lib
92
100
  required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
93
102
  requirements:
94
- - - ">="
103
+ - - ! '>='
95
104
  - !ruby/object:Gem::Version
96
105
  version: '0'
97
106
  required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
98
108
  requirements:
99
- - - ">="
109
+ - - ! '>='
100
110
  - !ruby/object:Gem::Version
101
111
  version: '0'
102
112
  requirements: []
103
113
  rubyforge_project: dither
104
- rubygems_version: 2.2.0
114
+ rubygems_version: 1.8.23.2
105
115
  signing_key:
106
- specification_version: 4
116
+ specification_version: 3
107
117
  summary: Collection of test generation strategies
108
118
  test_files:
109
119
  - spec/dither/chinese_postman_problem_spec.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: d7fbd5b281ba90ffd541192320abf17d31c8e345
4
- data.tar.gz: 08e49deed38f7d4e239f080c28341c023317d195
5
- SHA512:
6
- metadata.gz: a4f14b7801a1914321ea7dd02dd803dab97cc7c9ad1a0fc44658093ded0deec3defba34eae97fb4b0984f9c99eef4a94ad828e88e6f4d010ce67c9d31a139726
7
- data.tar.gz: fd023b9f6fd8d00ce0d776546ad807515f211283a5f8b62bf0cdc1b088ae2764d7f69773d2a6b96a5711164db3a92889bcd1eb89f9c7dc7c270e0ac88c8c4112