dither 0.1.5-java → 0.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ /*
2
+ *
3
+ * Copyright (C) 2015 Jason Gowan
4
+ * All rights reserved.
5
+ *
6
+ * This software may be modified and distributed under the terms
7
+ * of the BSD license. See the LICENSE file for details.
8
+ */
9
+
10
+ #ifndef SIMPLE_CONSTRAINT_HANDLER_H_
11
+ #define SIMPLE_CONSTRAINT_HANDLER_H_
12
+
13
+ #include <vector>
14
+ #include <utility>
15
+ #include <algorithm>
16
+ #include "dither_types.h"
17
+ #include "base_constraint_handler.h"
18
+
19
+ namespace dither {
20
+
21
+ class SimpleConstraintHandler : public BaseConstraintHandler {
22
+ protected:
23
+ std::vector<std::vector<std::pair<std::size_t, dval>>> constraints;
24
+ std::vector<dval> params;
25
+ std::vector<dval> scratch;
26
+
27
+ inline bool violate_constraint(const dtest_case& test_case, const std::vector<std::pair<std::size_t, dval>>& constraint);
28
+ inline bool violate_constraints_(const dtest_case &test_case);
29
+
30
+ public:
31
+ SimpleConstraintHandler(std::vector<dval>& ranges, std::vector<std::vector<dval>>& pconstraints);
32
+ bool violate_constraints(const dtest_case &test_case);
33
+ bool violate_constraints(const std::vector<param> &test_case);
34
+ bool ground(dtest_case &test_case);
35
+ };
36
+ }
37
+
38
+ #endif // SIMPLE_CONSTRAINT_HANDLER_H_
39
+
data/lib/dither/api.rb ADDED
@@ -0,0 +1,21 @@
1
+
2
+ require 'ffi'
3
+
4
+ # Interface to the c++ api.
5
+ module Dither
6
+ module API
7
+ extend FFI::Library
8
+ LIB_DIR = File.expand_path('../..', __FILE__)
9
+ ffi_lib %W[#{LIB_DIR}/dither.so #{LIB_DIR}/dither.dll]
10
+
11
+ attach_function :dither_ipog_new, [:int], :pointer
12
+ attach_function :dither_ipog_add_parameter_int, [:pointer, :int, :pointer, :int], :void
13
+ attach_function :dither_ipog_run, [:pointer], :void
14
+ attach_function :dither_ipog_size, [:pointer], :int
15
+ attach_function :dither_ipog_display_raw_solution, [:pointer], :void
16
+ attach_function :dither_ipog_fill, [:pointer, :pointer], :void
17
+ attach_function :dither_ipog_add_constraint, [:pointer, :pointer, :int], :void
18
+ attach_function :dither_ipog_add_previously_tested, [:pointer, :pointer, :int], :void
19
+ # attach_function :dither_ipog_delete, [:pointer], :void
20
+ end
21
+ end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Dither
3
- VERSION = '0.1.5'
3
+ VERSION = '0.2.0'
4
4
  end
data/lib/dither.rb CHANGED
@@ -12,18 +12,73 @@ module Dither
12
12
  # deprecated
13
13
  def self.all_pairs(params, t = 2, opts = {})
14
14
  opts[:t] = t
15
- IPOG.new(params, opts).run
15
+ ipog(params, opts)
16
16
  end
17
17
 
18
18
  def self.ipog(params, opts = {})
19
19
  opts = DEFUALT_OPTS.dup.merge(opts)
20
- IPOG.new(params, opts).run
21
- end
20
+ t = opts[:t] || 2
21
+ if t < 2
22
+ raise Dither::Error,'t must be >= 2'
23
+ end
24
+ raise Dither::Error, 'param length must be > 1' if params.any? { |a| a.size <= 1 }
25
+ if t > params.size
26
+ raise Dither::Error, 't must be <= params.length'
27
+ end
22
28
 
23
- def self.mipog(params, t = 2, opts = {})
24
- raise Error, 'mipog does not support constraints' if opts.key?(:constraints)
25
- opts[:t] = t
26
- MIPOG.new(params, opts).run
29
+ pointer = Dither::API.dither_ipog_new(t)
30
+ c_params = (0..params.max { |a| a.size }.size).to_a
31
+ c_int_params = FFI::MemoryPointer.new(:int, c_params.size)
32
+ c_int_params.write_array_of_int(c_params)
33
+
34
+ params.each_with_index do |param, i|
35
+ Dither::API.dither_ipog_add_parameter_int(pointer, i, c_int_params, param.size)
36
+ end
37
+
38
+ if opts[:constraints]
39
+ constraint_scratch = FFI::MemoryPointer.new(:int, params.size)
40
+ opts[:constraints].each do |constraint|
41
+ arr = Array.new(params.size, -1)
42
+ constraint.each do |k, v|
43
+ if k >= params.size
44
+ raise Dither::Error, "Invalid constraint #{k} > #{params.size}"
45
+ end
46
+ if v >= params[k].size
47
+ raise Dither::Error, "Invalid constraint #{k} > #{params[k].size}"
48
+
49
+ end
50
+ arr[k] = v
51
+ end
52
+ constraint_scratch.write_array_of_int(arr)
53
+ Dither::API.dither_ipog_add_constraint(pointer, constraint_scratch, params.size)
54
+ end
55
+ end
56
+
57
+ if opts[:previously_tested]
58
+ tested_scratch = FFI::MemoryPointer.new(:int, params.size)
59
+ opts[:previously_tested].each do |test_case|
60
+ if test_case.size != params.size
61
+ raise Dither::Error
62
+ end
63
+ arr = Array.new(params.size)
64
+ (0...params.size).each do |i|
65
+ arr[i] = params[i].find_index(test_case[i])
66
+ end
67
+ tested_scratch.write_array_of_int(arr)
68
+ Dither::API.dither_ipog_add_previously_tested(pointer, tested_scratch, params.size)
69
+ end
70
+ end
71
+
72
+ Dither::API.dither_ipog_run(pointer)
73
+ result_size = Dither::API.dither_ipog_size(pointer)
74
+ solution = FFI::MemoryPointer.new(:int, params.size * result_size)
75
+ Dither::API.dither_ipog_fill(pointer, solution)
76
+
77
+ results = solution.read_array_of_int(params.size * result_size)
78
+ .enum_for(:each_slice, params.size)
79
+ .map do |test_case|
80
+ test_case.zip(params).map { |a, b| b[a] }
81
+ end
27
82
  end
28
83
 
29
84
  def self.aetg(params, opts = {})
@@ -34,12 +89,6 @@ module Dither
34
89
  class << self; alias_method :ateg, :aetg end
35
90
  end # Dither
36
91
 
37
- require 'dither/param'
38
- require 'dither/unbound_param'
39
- require 'dither/test_case'
40
- require 'dither/ipog_helper'
41
- require 'dither/ipog'
42
- require 'dither/mipog'
43
92
  require 'dither/chinese_postman_problem'
44
93
  require 'dither/aetg'
45
94
  require 'dither/aetg_pairwise'
@@ -48,7 +97,9 @@ require 'dither/graph'
48
97
  if RUBY_PLATFORM =~ /java/
49
98
  require 'java'
50
99
  require 'choco-solver-3.3.1-with-dependencies.jar'
51
- require 'dither-0.1.3.jar'
100
+ require 'dither-0.1.4.jar'
52
101
 
53
102
  require 'dither/java_ext/dither'
103
+ else
104
+ require 'dither/api'
54
105
  end
@@ -2,10 +2,6 @@ require File.expand_path('../../spec_helper.rb', __FILE__)
2
2
 
3
3
  describe Dither do
4
4
 
5
- it 'mipog does not support constraints' do
6
- expect { Dither.mipog([[1,1],[1,2]], 2, :constraints => []) }.to raise_error(Dither::Error, 'mipog does not support constraints')
7
- end
8
-
9
5
  it 't must be >= 2' do
10
6
  expect { Dither.ipog([], :t => 0) }.to raise_error(Dither::Error, 't must be >= 2')
11
7
  end
@@ -20,63 +16,15 @@ describe Dither do
20
16
 
21
17
  it 'can compute 2-way ipog using symbols' do
22
18
  params = [[:a, :b, :c], [:d, :e, :f], [:h, :i]]
23
- expect(Dither.ipog(params)).to eq([[:a, :d, :h],
24
- [:a, :e, :i],
25
- [:a, :f, :h],
26
- [:b, :d, :i],
27
- [:b, :e, :h],
28
- [:b, :f, :i],
29
- [:c, :d, :h],
30
- [:c, :e, :i],
31
- [:c, :f, :h]])
32
- end
33
-
34
- it 'can compute 3-way mipog' do
35
- params = [(0...2).to_a, (0...2).to_a, (0..3).to_a]
36
- expect(Dither.mipog(params, 3)).to eq([[0, 0, 0],
37
- [1, 0, 0],
38
- [0, 1, 0],
39
- [1, 1, 0],
40
- [0, 0, 1],
41
- [1, 0, 1],
42
- [0, 1, 1],
43
- [1, 1, 1],
44
- [0, 0, 2],
45
- [1, 0, 2],
46
- [0, 1, 2],
47
- [1, 1, 2],
48
- [0, 0, 3],
49
- [1, 0, 3],
50
- [0, 1, 3],
51
- [1, 1, 3],
52
- ])
53
- end
54
-
55
- it 'can compute 2-way mipog using symbols' do
56
- params = [[:a, :b, :c], [:d, :e, :f], [:h, :i]]
57
- expect(Dither.mipog(params).to_set).to eq([[:a, :d, :h],
58
- [:a, :e, :i],
59
- [:a, :f, :h],
60
- [:b, :d, :i],
61
- [:b, :e, :h],
62
- [:b, :f, :i],
63
- [:c, :d, :h],
64
- [:c, :e, :i],
65
- [:c, :f, :h]].to_set)
66
- end
67
-
68
- it 'can compute 2-way mipog' do
69
- params = [(0...2).to_a, (0..3).to_a]
70
- expect(Dither.mipog(params)).to eq([
71
- [0, 0],
72
- [1, 0],
73
- [0, 1],
74
- [1, 1],
75
- [0, 2],
76
- [1, 2],
77
- [0, 3],
78
- [1, 3],
79
- ])
19
+ expect(Dither.all_pairs(params)).to eq([[:c, :f, :h],
20
+ [:b, :f, :i],
21
+ [:a, :f, :h],
22
+ [:c, :e, :i],
23
+ [:b, :e, :h],
24
+ [:a, :e, :i],
25
+ [:c, :d, :h],
26
+ [:b, :d, :i],
27
+ [:a, :d, :h]])
80
28
  end
81
29
 
82
30
  it 'can compute 2-way ipog' do
@@ -90,7 +38,7 @@ describe Dither do
90
38
  [1, 2],
91
39
  [0, 3],
92
40
  [1, 3],
93
- ])
41
+ ].reverse)
94
42
  end
95
43
 
96
44
  it 'can compute 3-way ipog' do
@@ -115,55 +63,38 @@ describe Dither do
115
63
  end
116
64
 
117
65
  it 'can compute 3-way ipog with constraints' do
118
- params = [(0...2).to_a, (0...2).to_a, (0..3).to_a]
119
- expect(Dither.ipog(params, :t => 3,
66
+ params = [[:a, :b], (0...2).to_a, (0..3).to_a]
67
+ results = Dither.ipog(params, :t => 3,
120
68
  :constraints => [
121
69
  {0 => 0,
122
70
  2 => 2},
123
71
  {0 => 0,
124
72
  1 => 1,
125
73
  2 => 0}],
126
- :previously_tested => [[0, 0, 0]]).to_set).to eq([
127
- [1, 0, 0],
128
- [1, 1, 0],
129
- [0, 0, 1],
130
- [1, 0, 1],
131
- [0, 1, 1],
132
- [1, 1, 1],
133
- [1, 0, 2],
134
- [1, 1, 2],
135
- [0, 0, 3],
136
- [1, 0, 3],
137
- [0, 1, 3],
138
- [1, 1, 3],
139
- ].to_set)
74
+ :previously_tested => [[:a, 0, 0]]
75
+ )
76
+ results.each do |result|
77
+ expect(result[0] == :a && result[1] == 1 && result[2] == 0).to be false
78
+ end
79
+ results.each do |result|
80
+ expect(result[0] == :a && result[1] == 2).to be false
81
+ end
82
+ results.each do |result|
83
+ expect(result[0] == :a && result[1] == 0 && result[2] == 0).to be false
84
+ end
140
85
  end
141
86
 
142
87
  it 'another 3-way ipog with constraints' do
143
88
  params = [(0...2).to_a, (0...2).to_a, (0...2).to_a, (0..3).to_a]
144
- expect(Dither.ipog(params, :t => 3,
89
+ results = Dither.ipog(params, :t => 3,
145
90
  :constraints => [
146
91
  {0 => 0,
147
92
  1 => 1,
148
93
  2 => 0}
149
- ]).to_set).to eq([[0, 0, 0, 0],
150
- [1, 1, 0, 0],
151
- [1, 0, 1, 0],
152
- [0, 1, 1, 0],
153
- [1, 0, 0, 1],
154
- [1, 1, 0, 1],
155
- [0, 0, 1, 1],
156
- [1, 1, 1, 1],
157
- [0, 0, 0, 2],
158
- [1, 1, 0, 2],
159
- [1, 0, 1, 2],
160
- [0, 1, 1, 2],
161
- [0, 0, 0, 3],
162
- [1, 1, 0, 3],
163
- [1, 0, 1, 3],
164
- [0, 1, 1, 3],
165
- [0, 0, 0, 1],
166
- [0, 1, 1, 1]].to_set)
94
+ ])
95
+ results.each do |result|
96
+ expect(result[0] == 0 && result[1] == 1 && result[2] == 0).to be false
97
+ end
167
98
  end
168
99
 
169
100
  it 'can run 2-way aetg' do
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dither
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
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-10-21 00:00:00.000000000 Z
11
+ date: 2015-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - ~>
16
+ - - "~>"
17
17
  - !ruby/object:Gem::Version
18
18
  version: '3.2'
19
19
  name: rspec
@@ -21,13 +21,13 @@ dependencies:
21
21
  type: :development
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
- - - ~>
30
+ - - "~>"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.9.2
33
33
  name: rake
@@ -35,13 +35,27 @@ dependencies:
35
35
  type: :development
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.9.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - '>='
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ name: rake-compiler
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
45
59
  - !ruby/object:Gem::Version
46
60
  version: '0'
47
61
  name: coveralls
@@ -49,7 +63,7 @@ dependencies:
49
63
  type: :development
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - '>='
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  description: Efficient test generation strategies
@@ -59,34 +73,40 @@ executables: []
59
73
  extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
- - .gitignore
63
- - .ruby-version
64
- - .travis.yml
76
+ - ".gitignore"
77
+ - ".ruby-version"
78
+ - ".travis.yml"
65
79
  - Gemfile
66
80
  - Gemfile.lock
67
81
  - LICENSE
68
82
  - README.md
69
83
  - Rakefile
70
84
  - dither.gemspec
85
+ - ext/dither/README.md
86
+ - ext/dither/base_constraint_handler.h
87
+ - ext/dither/combinations.h
88
+ - ext/dither/dither.cc
89
+ - ext/dither/dither.h
90
+ - ext/dither/dither_types.h
91
+ - ext/dither/extconf.rb
92
+ - ext/dither/ipog.cc
93
+ - ext/dither/ipog.h
94
+ - ext/dither/simple_constraint_handler.cc
95
+ - ext/dither/simple_constraint_handler.h
96
+ - lib/choco-solver-3.3.1-with-dependencies.jar
97
+ - lib/dither-0.1.4.jar
71
98
  - lib/dither.rb
72
99
  - lib/dither/aetg.rb
73
100
  - lib/dither/aetg_pairwise.rb
101
+ - lib/dither/api.rb
74
102
  - lib/dither/chinese_postman_problem.rb
75
103
  - lib/dither/graph.rb
76
- - lib/dither/ipog.rb
77
- - lib/dither/ipog_helper.rb
78
104
  - lib/dither/java_ext/dither.rb
79
- - lib/dither/mipog.rb
80
- - lib/dither/param.rb
81
- - lib/dither/test_case.rb
82
- - lib/dither/unbound_param.rb
83
105
  - lib/dither/version.rb
84
106
  - spec/dither/chinese_postman_problem_spec.rb
85
107
  - spec/dither/dither_spec.rb
86
108
  - spec/dither/graph_spec.rb
87
109
  - spec/spec_helper.rb
88
- - lib/dither-0.1.3.jar
89
- - lib/choco-solver-3.3.1-with-dependencies.jar
90
110
  homepage: https://github.com/jesg/dither
91
111
  licenses:
92
112
  - MIT
@@ -97,17 +117,17 @@ require_paths:
97
117
  - lib
98
118
  required_ruby_version: !ruby/object:Gem::Requirement
99
119
  requirements:
100
- - - '>='
120
+ - - ">="
101
121
  - !ruby/object:Gem::Version
102
122
  version: '0'
103
123
  required_rubygems_version: !ruby/object:Gem::Requirement
104
124
  requirements:
105
- - - '>='
125
+ - - ">="
106
126
  - !ruby/object:Gem::Version
107
127
  version: '0'
108
128
  requirements: []
109
129
  rubyforge_project: dither
110
- rubygems_version: 2.1.9
130
+ rubygems_version: 2.4.8
111
131
  signing_key:
112
132
  specification_version: 4
113
133
  summary: Collection of test generation strategies
data/lib/dither/ipog.rb DELETED
@@ -1,58 +0,0 @@
1
- # coding: utf-8
2
-
3
- module Dither
4
- class IPOG
5
- include IPOGHelper
6
-
7
- def run
8
- # add into test set a test for each combination of values
9
- # of the first t parameter
10
- test_set = comb
11
-
12
- (t...params.length).each do |i|
13
- # let pi
14
- # be the set of t-way combinations of values involving
15
- # parameter Pi and t -1 parameters among the first i – 1
16
- # parameters
17
- pi = comb_i(i)
18
-
19
- # horizontal extension for parameter i
20
- test_set.each do |test_case|
21
- cover = maximize_coverage(i, test_case, pi)
22
-
23
- if cover.nil?
24
- test_set.delete(test_case)
25
- else
26
- pi -= cover
27
- end
28
- end
29
-
30
- # vertical extension for parameter i
31
- pi.each do |a|
32
- if test_set.any? { |b| a.subset?(b) }
33
- pi.delete(a)
34
- else
35
-
36
- test_case = nil
37
- test_set.each do |b|
38
- test_case = b.merge_without_conflict(i, a) do |a|
39
- violates_constraints?(a)
40
- end
41
- break unless test_case.nil?
42
- end
43
-
44
- if test_case.nil?
45
- test_set << a.create_unbound(i)
46
- end
47
- pi.delete(a)
48
- end
49
- end
50
- end
51
-
52
- @test_set = test_set.map { |a| fill_unbound(a) }
53
- .delete_if(&:nil?)
54
- .to_a
55
- @test_set
56
- end
57
- end # IPOG
58
- end # Dither