dither 0.0.8-java → 0.0.9-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: eaa7339d133be5eb764dc4b8aa8d1504cfefd4fb
4
- data.tar.gz: dce4f5a332a553d1463da52cbf5feafae2579373
3
+ metadata.gz: f7b9a6a3077ab3312022ea6a5e4d1bc0bb66c597
4
+ data.tar.gz: 7de614370ed33a979147bc9249afa8cb4733f4fc
5
5
  SHA512:
6
- metadata.gz: 086c0fe7b98425443312ea641541684a700d3475a4928e2fb23e58322b0576952051abec719dc876a8205252ff51491d026600e12ce6f558d16192b622acaf6c
7
- data.tar.gz: 64763c24e5bebf57c82ad2e7d3e744392771986f765e262a6ef1dca950b9b757cce962f199203469337b7163a0691cd63a2aa3f342a7e0f4ecf47f2c0bf5b151
6
+ metadata.gz: 6a127e281dee369094061ff7511282ee5de76c212e762afac1d91784696b92cc2c0b24b8bfde4c0dd0a7a583c6b7858488670acc870bb3b8c12a5542e0820dee
7
+ data.tar.gz: 5bc538d91a0fc3d8ea851336bfd7abf3e98a3e84a3b0af1f159f3cd987d553a69f91a0982c2026fee4e3ea009a08d120ed66a916f012e46505ce1ffd592ce969
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: java
6
6
  authors:
7
7
  - Jason Gowan