planout 0.1.1 → 0.1.2

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: de6ac7ac834d56d050fdc5d7a354f963e7fbef99
4
- data.tar.gz: 5a28a98c04bf3560be6d2ce89662f083ed249ba5
3
+ metadata.gz: b0ceb7515e0ea00593e38d727421d25b9a8309f6
4
+ data.tar.gz: 1ed211f8d2caf59c732165cfa83b9a1fd38eaa21
5
5
  SHA512:
6
- metadata.gz: 41b8aac76573def514e18e6676af436340f9f86a7e9cfb2c7295c46e8a10620a8ed53ffed8b883503de7eb84d391d96917cb437145bc4351e185da56d015a1df
7
- data.tar.gz: c2b98270f2d422568adc7d12b3c6fad917a36c0ef744a3aa7312fa2c71acc0a1c6ee006a2cc33d8bfdbd510d6ff52d0891186cd0e7a8ed0fb9163b4d3738d870
6
+ metadata.gz: 790a6c990f7cee32972682b3ad9ea7dc305211ec4080b3952e5d91b2f4481f387b9a5a50e06e5207cad4f82db646bc739483b6102c76a1713f355a8d3ad5f30a
7
+ data.tar.gz: 3516ce0449d787b7deaf66e15faae2631ca0856f6f346e3293be30bb45f07759b3d4deced2c9e5a4daf3d3658560b1584afc71a75a8a46b1f47ed0a9a3d4f4b4
@@ -57,18 +57,19 @@ module PlanOut
57
57
 
58
58
  return [] if choices.length() == 0
59
59
 
60
- cum_weights = choices.zip(weights)
60
+ cum_weights = Array.new(weights.length)
61
61
  cum_sum = 0.0
62
62
 
63
- cum_weights.each do |choice, weight|
63
+ weights.each_with_index do |weight, index|
64
64
  cum_sum += weight
65
- cum_weights[choice] = cum_sum
65
+ cum_weights[index] = cum_sum
66
66
  end
67
67
 
68
68
  stop_value = get_uniform(0.0, cum_sum)
69
69
 
70
- cum_weights.each do |choice, cum_weight|
71
- choice if stop_value <= cum_weight
70
+ i = 0
71
+ cum_weights.each_with_index do |cum_weight, index|
72
+ return choices[index] if stop_value <= cum_weight
72
73
  end
73
74
  end
74
75
  end
@@ -81,4 +82,4 @@ module PlanOut
81
82
  choices[rand_index]
82
83
  end
83
84
  end
84
- end
85
+ end
@@ -1,3 +1,3 @@
1
1
  module PlanOut
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -3,14 +3,24 @@ require_relative '../test_helper'
3
3
  module PlanOut
4
4
  class OperatorTest < Minitest::Test
5
5
  def setup
6
- @operator = Operator.new({ foo: 'bar' })
7
- @op_simple = OpSimple.new({ bar: 'qux' })
6
+ @a = Assignment.new('mtsalt')
8
7
  end
9
8
 
10
9
  def test_execute
11
- a = Assignment.new('mtsalt')
12
- assert_equal('mtsalt', @operator.execute(a))
13
- assert_equal(-1, @op_simple.execute(a))
10
+ operator = Operator.new({ foo: 'bar' })
11
+ op_simple = OpSimple.new({ bar: 'qux' })
12
+ assert_equal('mtsalt', operator.execute(@a))
13
+ assert_equal(-1, op_simple.execute(@a))
14
+ end
15
+
16
+ def test_weighted_choice
17
+ weighted = WeightedChoice.new({
18
+ choices: ["c1", "c2", "c1"],
19
+ weights: [20, 40, 60],
20
+ unit: 42,
21
+ salt:'x'
22
+ })
23
+ assert_equal("c2", weighted.execute(@a))
14
24
  end
15
25
  end
16
- end
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: planout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eytan Bakshy
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-03 00:00:00.000000000 Z
12
+ date: 2015-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler