planout 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/plan_out/op_random.rb +7 -6
- data/lib/plan_out/version.rb +1 -1
- data/test/plan_out/operator_test.rb +16 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0ceb7515e0ea00593e38d727421d25b9a8309f6
|
4
|
+
data.tar.gz: 1ed211f8d2caf59c732165cfa83b9a1fd38eaa21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 790a6c990f7cee32972682b3ad9ea7dc305211ec4080b3952e5d91b2f4481f387b9a5a50e06e5207cad4f82db646bc739483b6102c76a1713f355a8d3ad5f30a
|
7
|
+
data.tar.gz: 3516ce0449d787b7deaf66e15faae2631ca0856f6f346e3293be30bb45f07759b3d4deced2c9e5a4daf3d3658560b1584afc71a75a8a46b1f47ed0a9a3d4f4b4
|
data/lib/plan_out/op_random.rb
CHANGED
@@ -57,18 +57,19 @@ module PlanOut
|
|
57
57
|
|
58
58
|
return [] if choices.length() == 0
|
59
59
|
|
60
|
-
cum_weights =
|
60
|
+
cum_weights = Array.new(weights.length)
|
61
61
|
cum_sum = 0.0
|
62
62
|
|
63
|
-
|
63
|
+
weights.each_with_index do |weight, index|
|
64
64
|
cum_sum += weight
|
65
|
-
cum_weights[
|
65
|
+
cum_weights[index] = cum_sum
|
66
66
|
end
|
67
67
|
|
68
68
|
stop_value = get_uniform(0.0, cum_sum)
|
69
69
|
|
70
|
-
|
71
|
-
|
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
|
data/lib/plan_out/version.rb
CHANGED
@@ -3,14 +3,24 @@ require_relative '../test_helper'
|
|
3
3
|
module PlanOut
|
4
4
|
class OperatorTest < Minitest::Test
|
5
5
|
def setup
|
6
|
-
@
|
7
|
-
@op_simple = OpSimple.new({ bar: 'qux' })
|
6
|
+
@a = Assignment.new('mtsalt')
|
8
7
|
end
|
9
8
|
|
10
9
|
def test_execute
|
11
|
-
|
12
|
-
|
13
|
-
assert_equal(
|
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.
|
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-
|
12
|
+
date: 2015-10-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|