dither 0.0.11-java → 0.0.12-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e5528867e133a68bb9a429ae778153f59d7fa07
4
- data.tar.gz: 06470e7386b123b3a6642fb48761318ad9bfc0be
3
+ metadata.gz: ebd1c192f8d6b59c19a05e69fca456794c19dd7f
4
+ data.tar.gz: 2d31494b532b2050bd1fa8662f7882080a8f5202
5
5
  SHA512:
6
- metadata.gz: 70072c1bcfe0006bb632bf33542e700c8dd1036c2946b3d8bed6f4f752d1feffdbbf850a45eae283ab0651019c10b4ca03551f72741a6e9fe8dd8ae90b210741
7
- data.tar.gz: 630cc4a6cef209358550c04242a82093ddf7729de981ccd3eeb942b8b144286da4c20a4bebe31c07dc2fada801b21e2327fd8b8f59d8b881ac59e097cba0ab9c
6
+ metadata.gz: beca214f99e4581f1aa285dff9bbf037078d6ef83035a15f254af6f69ef9a3971c9ad00cc6aab65dd973d075b1e78f100ddf98012860358224ccc6a204752cdd
7
+ data.tar.gz: b37a58fe3bb90490f3d15e5823640f6454156eff35e543f2f3863ef75a6cc979521df14c53b46157205e2c9b8f0ed7c3d82362d025ce0d5078cd9ea8df4e5bd8
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,14 +1,14 @@
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
5
  platform: java
6
6
  authors:
7
7
  - Jason Gowan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-14 00:00:00.000000000 Z
11
+ date: 2015-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -70,6 +70,8 @@ files:
70
70
  - dither.gemspec
71
71
  - lib/dither.jar
72
72
  - lib/dither.rb
73
+ - lib/dither/ateg.rb
74
+ - lib/dither/ateg_pairwise.rb
73
75
  - lib/dither/chinese_postman_problem.rb
74
76
  - lib/dither/ipog.rb
75
77
  - lib/dither/ipog_helper.rb