dither 0.0.8 → 0.0.9

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: 271a9f006b9084c1217f28558119aec7a8d0f412
4
- data.tar.gz: 40f2427cfda6ba58f77f92f5fcab155a84dcf9a4
3
+ metadata.gz: 9574ed6c2c949edec919c9278fb913429c877e77
4
+ data.tar.gz: 801a8c1dfc56648d97d62b456037a1132e1b418b
5
5
  SHA512:
6
- metadata.gz: d5629757b14b9431935a9dc8042e5703e16ae5fd0c90eacfa49ffd3ff5c97ce66f06f42ab14dd4b095ec9a4463a8940e34018131d78f2a9dc76f81ff9774373a
7
- data.tar.gz: 59087c6e94f32b69dff2c9efd13763548e6ff8c8cb37fe83d26ba8c620bd08ad13fd8a31db6b5a480e7745c3f02ca1fe139421e5817ab53fc3a01b2a360bd1a0
6
+ metadata.gz: 63d2f2ab3792d6a711a96543328df659d84a43f83909d6a3f392f4ad77e00898a9d652fb8b36cf8c85c35e68d0de257f0f59bd22089c4ad1b0ea8c57da2e607b
7
+ data.tar.gz: 5e997a1f04704678feb68b925a85bc82d66dcb91818c2ec22aba056bf3bbd2bfdbb1f3fd05219fe8f90cf125d9ce59157e56fd566ddfb781a884167d9ea72aee
data/README.md CHANGED
@@ -7,9 +7,9 @@ Use 2-Way IPOG
7
7
  ```ruby
8
8
  require 'dither'
9
9
 
10
- results = Dither.all_pairs([[true, false],
11
- [:cat, :dog, :mouse],
12
- (0...3).to_a])
10
+ results = Dither.ipog([[true, false],
11
+ [:cat, :dog, :mouse],
12
+ (0...3).to_a])
13
13
 
14
14
  results.each { |a| puts "#{a}" }
15
15
 
@@ -29,10 +29,10 @@ Use 3-Way IPOG
29
29
  ```ruby
30
30
  require 'dither'
31
31
 
32
- results = Dither.all_pairs([[true, false],
33
- [true, false],
34
- [:cat, :dog, :mouse],
35
- (0...5).to_a], 3)
32
+ results = Dither.ipog([[true, false],
33
+ [true, false],
34
+ [:cat, :dog, :mouse],
35
+ (0...5).to_a], :t => 3)
36
36
 
37
37
  results.each { |a| puts "#{a}" }
38
38
 
@@ -5,17 +5,17 @@ module Dither
5
5
  attr_reader :params, :t, :constraints, :test_set, :orig_params, :unbound_param_pool
6
6
  private :params, :t, :constraints, :test_set, :orig_params, :unbound_param_pool
7
7
 
8
- def initialize(params, t, opts = {})
8
+ def initialize(params, opts = {})
9
9
  init_params(params)
10
- @t = t
10
+ @t = opts[:t]
11
11
  unless opts[:constraints].nil?
12
12
  @constraints = opts[:constraints].map(&:to_a)
13
13
  .map { |a| a.map { |b| @params[@map_to_orig_index.key(b[0])][b[1]] } }
14
14
  .map(&:to_set)
15
15
  end
16
16
 
17
- raise Dither::Error, 't must be >= 2' if t < 2
18
- raise Dither::Error, 't must be <= params.length' if t > params.length
17
+ raise Dither::Error, 't must be >= 2' if opts[:t] < 2
18
+ raise Dither::Error, 't must be <= params.length' if opts[:t] > params.length
19
19
  params.each do |param|
20
20
  raise Dither::Error, 'param length must be > 1' if param.length < 2
21
21
  end
@@ -1,10 +1,11 @@
1
1
 
2
2
  module Dither
3
3
 
4
- def self.all_pairs(params, t = 2, opts = {})
4
+ def self.ipog(params, opts = {})
5
+ opts = DEFUALT_OPTS.dup.merge(opts)
5
6
  constraints = constraints_to_java(params.length, opts[:constraints])
6
7
  com.github.jesg.dither.Dither.ipog(
7
- t.to_java(:int),
8
+ opts[:t].to_java(:int),
8
9
  params.map(&:to_java).to_java,
9
10
  constraints).to_a
10
11
  rescue com.github.jesg.dither.DitherError => e
@@ -20,7 +21,6 @@ module Dither
20
21
  new_constraint = Array.new(param_length)
21
22
  constraint.each do |k, v|
22
23
  new_constraint[k] = v
23
- puts "#{k} => #{v}"
24
24
  end
25
25
  result << new_constraint
26
26
  end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Dither
3
- VERSION = '0.0.8'
3
+ VERSION = '0.0.9'
4
4
  end
data/lib/dither.rb CHANGED
@@ -5,13 +5,25 @@ module Dither
5
5
 
6
6
  class Error < StandardError; end
7
7
 
8
+ DEFUALT_OPTS = {
9
+ :t => 2
10
+ }
11
+
12
+ # deprecated
8
13
  def self.all_pairs(params, t = 2, opts = {})
9
- IPOG.new(params, t, opts).run
14
+ opts[:t] = t
15
+ IPOG.new(params, opts).run
16
+ end
17
+
18
+ def self.ipog(params, opts = {})
19
+ opts = DEFUALT_OPTS.dup.merge(opts)
20
+ IPOG.new(params, opts).run
10
21
  end
11
22
 
12
23
  def self.mipog(params, t = 2, opts = {})
13
24
  raise Error, 'mipog does not support constraints' if opts.key?(:constraints)
14
- MIPOG.new(params, t, opts).run
25
+ opts[:t] = t
26
+ MIPOG.new(params, opts).run
15
27
  end
16
28
  end # Dither
17
29
 
@@ -7,20 +7,20 @@ describe Dither do
7
7
  end
8
8
 
9
9
  it 't must be >= 2' do
10
- expect { Dither.all_pairs([], 0) }.to raise_error(Dither::Error, 't must be >= 2')
10
+ expect { Dither.ipog([], :t => 0) }.to raise_error(Dither::Error, 't must be >= 2')
11
11
  end
12
12
 
13
13
  it 't must be <= params.length' do
14
- expect { Dither.all_pairs([(0...3).to_a], 4) }.to raise_error(Dither::Error,'t must be <= params.length')
14
+ expect { Dither.ipog([(0...3).to_a], :t => 4) }.to raise_error(Dither::Error,'t must be <= params.length')
15
15
  end
16
16
 
17
17
  it 'param length must be > 1' do
18
- expect { Dither.all_pairs([[], []], 2) }.to raise_error(Dither::Error,'param length must be > 1')
18
+ expect { Dither.ipog([[], []], :t => 2) }.to raise_error(Dither::Error,'param length must be > 1')
19
19
  end
20
20
 
21
21
  it 'can compute 2-way ipog using symbols' do
22
22
  params = [[:a, :b, :c], [:d, :e, :f], [:h, :i]]
23
- expect(Dither.all_pairs(params)).to eq([[:a, :d, :h],
23
+ expect(Dither.ipog(params)).to eq([[:a, :d, :h],
24
24
  [:a, :e, :i],
25
25
  [:a, :f, :h],
26
26
  [:b, :d, :i],
@@ -81,7 +81,7 @@ describe Dither do
81
81
 
82
82
  it 'can compute 2-way ipog' do
83
83
  params = [(0...2).to_a, (0..3).to_a]
84
- expect(Dither.all_pairs(params)).to eq([
84
+ expect(Dither.ipog(params)).to eq([
85
85
  [0, 0],
86
86
  [1, 0],
87
87
  [0, 1],
@@ -95,7 +95,7 @@ describe Dither do
95
95
 
96
96
  it 'can compute 3-way ipog' do
97
97
  params = [(0...2).to_a, (0...2).to_a, (0..3).to_a]
98
- expect(Dither.all_pairs(params, 3).to_set).to eq([[0, 0, 0],
98
+ expect(Dither.ipog(params, :t => 3).to_set).to eq([[0, 0, 0],
99
99
  [1, 0, 0],
100
100
  [0, 1, 0],
101
101
  [1, 1, 0],
@@ -116,7 +116,7 @@ describe Dither do
116
116
 
117
117
  it 'can compute 3-way ipog with constraints' do
118
118
  params = [(0...2).to_a, (0...2).to_a, (0..3).to_a]
119
- expect(Dither.all_pairs(params, 3,
119
+ expect(Dither.ipog(params, :t => 3,
120
120
  :constraints => [
121
121
  {0 => 0,
122
122
  2 => 2},
@@ -141,7 +141,7 @@ describe Dither do
141
141
 
142
142
  it 'another 3-way ipog with constraints' do
143
143
  params = [(0...2).to_a, (0...2).to_a, (0...2).to_a, (0..3).to_a]
144
- expect(Dither.all_pairs(params, 3,
144
+ expect(Dither.ipog(params, :t => 3,
145
145
  :constraints => [
146
146
  {0 => 0,
147
147
  1 => 1,
@@ -164,59 +164,5 @@ describe Dither do
164
164
  [0, 1, 1, 3],
165
165
  [0, 0, 0, 1],
166
166
  [0, 1, 1, 1]].to_set)
167
-
168
- # results = Dither.all_pairs([
169
- # (0...10).to_a,
170
- # (0...10).to_a,
171
- # (0...4).to_a,
172
- # (0...3).to_a,
173
- # (0...3).to_a,
174
- # (0...2).to_a,
175
- # (0...2).to_a,
176
- # (0...2).to_a,
177
- # (0...2).to_a,
178
- # (0...2).to_a,
179
- # (0...2).to_a,
180
- # (0...2).to_a,
181
- # ], 4)
182
-
183
- # results = Dither.all_pairs([
184
- # (0...4).to_a,
185
- # (0...4).to_a,
186
- # (0...4).to_a,
187
- # (0...4).to_a,
188
- # (0...4).to_a,
189
- # (0...3).to_a,
190
- # (0...3).to_a,
191
- # (0...3).to_a,
192
- # (0...3).to_a,
193
- # ], 2)
194
-
195
-
196
- results = Dither.all_pairs([
197
- (0...2).to_a, # user type
198
- (0...2).to_a, # exists?
199
- (0...2).to_a, # seats
200
- (0...2).to_a, # seats
201
- (0...3).to_a, # user region
202
- (0...3).to_a, # currency
203
- (0...3).to_a,
204
- (0...4).to_a, # payment
205
- (0...6).to_a, # delivery
206
- (0...6).to_a,
207
- ], 3)
208
-
209
- # mipog 2-way 36... ipog 36
210
- # mipog 3-way 156... ipog 151
211
- # mipog 4-way 592... ipog 511
212
-
213
- # results = Dither.all_pairs( [[1,2],
214
- # ['1','2'],
215
- # [1.0,2.0],
216
- # [true, false, 3]],3)
217
- require 'csv'
218
- results.each { |a| puts a.to_csv }
219
- puts results.count
220
-
221
167
  end
222
168
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dither
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Gowan