monte_carlo 0.0.7 → 0.0.8
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/LICENSE.txt +1 -1
- data/lib/monte_carlo/experiment.rb +10 -0
- data/lib/monte_carlo/version.rb +1 -1
- data/spec/lib/monte_carlo/experiment_spec.rb +40 -1
- 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: 120ea6a35b01f39cc70e5d0b948c3a64df1bcd2b
|
4
|
+
data.tar.gz: 9c3316fbd6e1a5601a4fdd0421171e376e894a09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5867fd4db06e423585b8b572165d4395f9ff09e44cef2636c7c95d67bdcc43329d99f9d19f7953907277b7c4eb91d3fa45817afa7e43b2ba86bc44c8d67fb45
|
7
|
+
data.tar.gz: 256b2aed61720cd5286234f1659b3205c3b0abdd152e1e508a637cfec22f7fd32640769876c7cece8c06e823e12817ebb2007883292e91fcd0e55b96345bc8c7
|
data/LICENSE.txt
CHANGED
@@ -53,9 +53,15 @@ module MonteCarlo
|
|
53
53
|
# @return [MonteCarlo::Experiment]
|
54
54
|
def initialize(times = DEFAULT_TIMES, &block)
|
55
55
|
@times = times
|
56
|
+
raise ArgumentError, "`times` must be a positive integer" unless valid_times?
|
56
57
|
MonteCarlo::ExperimentDSL.new(self).instance_eval(&block) if block_given?
|
57
58
|
end
|
58
59
|
|
60
|
+
def times=(times)
|
61
|
+
@times = times
|
62
|
+
raise ArgumentError, "`times` must be a positive integer" unless valid_times?
|
63
|
+
end
|
64
|
+
|
59
65
|
# Run the experiment
|
60
66
|
#
|
61
67
|
# @raise [MonteCarlo::Errors::NoSampleMethodError] if the experiment has no sample method set
|
@@ -93,5 +99,9 @@ module MonteCarlo
|
|
93
99
|
result
|
94
100
|
end
|
95
101
|
|
102
|
+
def valid_times?
|
103
|
+
@times.is_a?(Fixnum) && @times > 0
|
104
|
+
end
|
105
|
+
|
96
106
|
end
|
97
107
|
end
|
data/lib/monte_carlo/version.rb
CHANGED
@@ -4,15 +4,54 @@ describe MonteCarlo::Experiment do
|
|
4
4
|
|
5
5
|
let(:times) { 10 }
|
6
6
|
let(:sample_value) { 1 }
|
7
|
+
let(:sample_method) { -> { sample_value } }
|
7
8
|
let(:computation) { ->(sample) {sample * 2} }
|
8
9
|
let(:experiment) do
|
9
10
|
experiment = MonteCarlo::Experiment.new
|
10
11
|
experiment.times = times
|
11
|
-
experiment.sample_method =
|
12
|
+
experiment.sample_method = sample_method
|
12
13
|
experiment.computation = computation
|
13
14
|
experiment
|
14
15
|
end
|
15
16
|
|
17
|
+
describe :initialize do
|
18
|
+
shared_examples_for :raises_argument_error do
|
19
|
+
it 'should raise an ArgumentError' do
|
20
|
+
expect {
|
21
|
+
MonteCarlo::Experiment.new(times)
|
22
|
+
}.to raise_error ArgumentError
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when `times` is not a number' do
|
27
|
+
let(:times) { 'no good' }
|
28
|
+
it_behaves_like :raises_argument_error
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when `times` is negative' do
|
32
|
+
let(:times) { -1 }
|
33
|
+
it_behaves_like :raises_argument_error
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe :times= do
|
38
|
+
shared_examples_for :raises_argument_error do |times|
|
39
|
+
it 'should raise an ArgumentError' do
|
40
|
+
expect {
|
41
|
+
experiment.times = times
|
42
|
+
}.to raise_error ArgumentError
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when `times` is not a number' do
|
47
|
+
it_behaves_like :raises_argument_error, 'no good'
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'when `times` is negative' do
|
51
|
+
it_behaves_like :raises_argument_error, -1
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
16
55
|
describe :run do
|
17
56
|
it 'should raise a NoSampleMethodError if a sample method is not defined' do
|
18
57
|
experiment.sample_method = nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monte_carlo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Assaf Gelber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|