dither 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e6663991d2d97eeed8b4ab2c42ce24e1c191aa05
4
+ data.tar.gz: 5a6f9d1128e72e2891a03f4651a95a3497730cf7
5
+ SHA512:
6
+ metadata.gz: 89ae91395e9fb79d6590acc667c86e667f76e9643d1a47f96752451c0c2eb36e8ffe3b3a9ab82c25b03cf0a43b067bf95cf9b597c4c7e98a129c7acdbacbc687
7
+ data.tar.gz: 2733499b976c74b037ef5653cca1e729be2e1ddd8f21fc318ab66fec6fe89392169553dfa27b8c7343074dd7f55b554d0aa3b25ab44c4c7ed2d68ced55e05056
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.0
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-19mode
5
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dither (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (0.9.6)
11
+ rspec (3.2.0)
12
+ rspec-core (~> 3.2.0)
13
+ rspec-expectations (~> 3.2.0)
14
+ rspec-mocks (~> 3.2.0)
15
+ rspec-core (3.2.1)
16
+ rspec-support (~> 3.2.0)
17
+ rspec-expectations (3.2.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.2.0)
20
+ rspec-mocks (3.2.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.2.0)
23
+ rspec-support (3.2.2)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ dither!
30
+ rake (~> 0.9.2)
31
+ rspec (~> 3.2)
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jason Gowan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Dither
2
+ Collection of combinatorial test generation strategies.
3
+
4
+ # Usage
5
+
6
+ Use 2-Way IPOG
7
+ ```ruby
8
+ require 'dither'
9
+
10
+ results = Dither.all_pairs([[true, false],
11
+ [:cat, :dog, :mouse],
12
+ (0...3).to_a])
13
+
14
+ results.each { |a| puts "#{a}" }
15
+
16
+ # output
17
+ [true, :cat, 0]
18
+ [true, :dog, 1]
19
+ [true, :mouse, 2]
20
+ [false, :cat, 0]
21
+ [false, :dog, 1]
22
+ [false, :mouse, 2]
23
+ [true, :cat, 0]
24
+ [true, :dog, 1]
25
+ [true, :mouse, 2]
26
+ ```
27
+
28
+ Use 3-Way IPOG
29
+ ```ruby
30
+ require 'dither'
31
+
32
+ results = Dither.all_pairs([[true, false],
33
+ [true, false],
34
+ [:cat, :dog, :mouse],
35
+ (0...5).to_a], 3)
36
+
37
+ results.each { |a| puts "#{a}" }
38
+
39
+ # output
40
+ [true, true, :cat, 0]
41
+ ...
42
+ ```
43
+
44
+ # Note on Patches/Pull Requests
45
+
46
+ * Fork the project.
47
+ * Make your feature addition or bug fix.
48
+ * Add tests for it. This is important so I don't break it in a
49
+ future version unintentionally.
50
+ * Commit, do not mess with rakefile, version, or history.
51
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
52
+ * Send me a pull request. Bonus points for topic branches
53
+
54
+ # Copyright
55
+ Copyright (c) 2015 Jason Gowan See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
data/dither.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "dither/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "dither"
6
+ s.version = Dither::VERSION
7
+ s.licenses = ['MIT']
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Jason Gowan"]
10
+ s.email = ["gowanjason@gmail.com"]
11
+ s.homepage = "https://github.com/jesg/dither"
12
+ s.summary = %q{Collection of test generation strategies}
13
+ s.description = %q{Efficient test generation strategies}
14
+
15
+ s.rubyforge_project = "dither"
16
+
17
+ s.add_development_dependency "rspec", "~> 3.2"
18
+ s.add_development_dependency "rake", "~> 0.9.2"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ end
@@ -0,0 +1,105 @@
1
+
2
+ module Dither
3
+ class IPOG
4
+ attr_reader :params, :t, :prng
5
+ private :params, :t, :prng
6
+
7
+ def initialize(params, t)
8
+ @params = params
9
+ @t = t
10
+ @prng = Random.new
11
+ raise 't must be >= 2' if t < 2
12
+ raise 't must be <= params.length' if t > params.length
13
+ params.each do |param|
14
+ raise 'param length must be > 1' if param.length < 2
15
+ end
16
+ end
17
+
18
+ def run
19
+ ts = comb((0...t))
20
+ (t...params.length).each do |i|
21
+ ts = ts.zip(params[i].cycle).map { |a| a[0] << Param.new(i, a[1]) }
22
+
23
+ comb_i(i).each do |a|
24
+ in_ts = ts.any? { |test| a.subset?(test) }
25
+
26
+ next if in_ts
27
+ existing_test = false
28
+ ts.select { |c| c.length <= i }
29
+ .each do |b|
30
+
31
+ unbound = find_unbound(a, b)
32
+
33
+ if unbound
34
+ unbound.each { |c| b << c }
35
+ existing_test = true
36
+ break
37
+ end
38
+ end
39
+
40
+ ts << a unless existing_test
41
+ end
42
+ end
43
+
44
+ ts.map { |a| fill_unbound(a) }
45
+ end
46
+
47
+ def comb(range)
48
+ range.to_a.combination(t).to_a.inject([]) do |result, a|
49
+ result + a[1..-1]
50
+ .inject((0...params[a[0]].length).map { |b| Param.new(0, b) }) { |p, i| p.product((0...params[i].length).to_a.map { |b| Param.new(i, b) }) }
51
+ .map(&:flatten)
52
+ .map(&:to_set)
53
+ end
54
+ end
55
+
56
+ def comb_i(param_i)
57
+ values = (0...param_i).to_a.combination((t-1)).to_a
58
+ values.each do |a|
59
+ a << param_i
60
+ end
61
+ result = []
62
+ values.each do |a|
63
+ result += a[1..-1]
64
+ .inject((0...params[a[0]].length).map { |b| Param.new(0, b) }) { |p, i| p.product((0...params[i].length).to_a.map { |b| Param.new(i, b) }) }
65
+ .map(&:flatten)
66
+ .map(&:to_set)
67
+ end
68
+ result
69
+ end
70
+
71
+ private
72
+
73
+ def fill_unbound(data)
74
+ arr = Array.new(params.length)
75
+ data.each do |param|
76
+ arr[param.i] = params[param.i][param.j]
77
+ end
78
+
79
+ arr.each_with_index do |e, i|
80
+ arr[i] = params[i][prng.rand(0...params[i].length)] if e.nil?
81
+ end
82
+ arr
83
+ end
84
+
85
+ def find_unbound(param_array, stuff)
86
+ data = {}
87
+ stuff.each do |param|
88
+ data[param.i] = param.j
89
+ end
90
+
91
+ unbound = []
92
+ param_array.each do |param|
93
+ case data[param.i]
94
+ when param.j
95
+ when nil
96
+ unbound << param
97
+ else
98
+ unbound = nil
99
+ break
100
+ end
101
+ end
102
+ unbound
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,4 @@
1
+
2
+ module Dither
3
+ Param = Struct.new(:i, :j)
4
+ end
@@ -0,0 +1,4 @@
1
+
2
+ module Dither
3
+ VERSION = '0.0.1'
4
+ end
data/lib/dither.rb ADDED
@@ -0,0 +1,12 @@
1
+
2
+ require 'set'
3
+
4
+ module Dither
5
+
6
+ def self.all_pairs(params, t = 2)
7
+ IPOG.new(params, t).run
8
+ end
9
+ end
10
+
11
+ require 'dither/param'
12
+ require 'dither/ipog'
@@ -0,0 +1,65 @@
1
+ require File.expand_path('../../spec_helper.rb', __FILE__)
2
+
3
+ describe Dither do
4
+
5
+ it 't must be >= 2' do
6
+ expect { Dither.all_pairs([], 0) }.to raise_error('t must be >= 2')
7
+ end
8
+
9
+ it 't must be <= params.length' do
10
+ expect { Dither.all_pairs((0...3).to_a, 4) }.to raise_error('t must be <= params.length')
11
+ end
12
+
13
+ it 'param length must be > 1' do
14
+ expect { Dither.all_pairs([[], []], 2) }.to raise_error('param length must be > 1')
15
+ end
16
+
17
+ it 'can compute 2-way ipog' do
18
+ params = [(0...2).to_a, (0..3).to_a]
19
+ expect(Dither.all_pairs(params)).to eq([
20
+ [0, 0],
21
+ [0, 1],
22
+ [0, 2],
23
+ [0, 3],
24
+ [1, 0],
25
+ [1, 1],
26
+ [1, 2],
27
+ [1, 3],
28
+ ])
29
+ end
30
+
31
+ it 'can compute 3-way ipog' do
32
+ params = [(0...2).to_a, (0...2).to_a, (0..3).to_a]
33
+ expect(Dither.all_pairs(params, 3)).to eq([[0, 0, 0],
34
+ [0, 0, 1],
35
+ [0, 0, 2],
36
+ [0, 0, 3],
37
+ [0, 1, 0],
38
+ [0, 1, 1],
39
+ [0, 1, 2],
40
+ [0, 1, 3],
41
+ [1, 0, 0],
42
+ [1, 0, 1],
43
+ [1, 0, 2],
44
+ [1, 0, 3],
45
+ [1, 1, 0],
46
+ [1, 1, 1],
47
+ [1, 1, 2],
48
+ [1, 1, 3]])
49
+ results = Dither.all_pairs([[true, false],
50
+ [true, false],
51
+ [:cat, :dog, :mouse],
52
+ (0...5).to_a], 3)
53
+ puts
54
+ results.each { |a| puts "#{a}" }
55
+ [true, :cat, 0]
56
+ [true, :dog, 1]
57
+ [true, :mouse, 2]
58
+ [false, :cat, 0]
59
+ [false, :dog, 1]
60
+ [false, :mouse, 2]
61
+ [true, :cat, 0]
62
+ [true, :dog, 1]
63
+ [true, :mouse, 2]
64
+ end
65
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib")
2
+ require 'dither'
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dither
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jason Gowan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ~>
17
+ - !ruby/object:Gem::Version
18
+ version: '3.2'
19
+ name: rspec
20
+ prerelease: false
21
+ type: :development
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.2
33
+ name: rake
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.2
41
+ description: Efficient test generation strategies
42
+ email:
43
+ - gowanjason@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .ruby-version
50
+ - .travis.yml
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE
54
+ - README.md
55
+ - Rakefile
56
+ - dither.gemspec
57
+ - lib/dither.rb
58
+ - lib/dither/ipog.rb
59
+ - lib/dither/param.rb
60
+ - lib/dither/version.rb
61
+ - spec/dither/dither_spec.rb
62
+ - spec/spec_helper.rb
63
+ homepage: https://github.com/jesg/dither
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project: dither
83
+ rubygems_version: 2.4.5
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Collection of test generation strategies
87
+ test_files:
88
+ - spec/dither/dither_spec.rb
89
+ - spec/spec_helper.rb