monte_carlo 0.0.7 → 0.0.8

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: e982e4c691d1727d209a88dd129a31b9118b6e26
4
- data.tar.gz: 0fb0dba7ee9dcbad1c6c78faf14b4a370180326d
3
+ metadata.gz: 120ea6a35b01f39cc70e5d0b948c3a64df1bcd2b
4
+ data.tar.gz: 9c3316fbd6e1a5601a4fdd0421171e376e894a09
5
5
  SHA512:
6
- metadata.gz: 42aaa3bfb0fdf59aac78e3a810bb5f21083e4a2b30c1d3fb00e2155396cf37d18d0896e838a7002df93ff3e0d1cc63892dc2cdc270bf7f583ecec7f83c33d504
7
- data.tar.gz: c5038110cc5a7109caf001a33b8d35e22458431f370c94f4310d3535d1889a3ccbc4cdbe6c0a1055a7b338a3c73f47ac7422263b0d9ceb62a4ef4fbf7acc14ca
6
+ metadata.gz: c5867fd4db06e423585b8b572165d4395f9ff09e44cef2636c7c95d67bdcc43329d99f9d19f7953907277b7c4eb91d3fa45817afa7e43b2ba86bc44c8d67fb45
7
+ data.tar.gz: 256b2aed61720cd5286234f1659b3205c3b0abdd152e1e508a637cfec22f7fd32640769876c7cece8c06e823e12817ebb2007883292e91fcd0e55b96345bc8c7
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Assaf Gelber
1
+ Copyright (c) 2015 Assaf Gelber
2
2
 
3
3
  MIT License
4
4
 
@@ -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
@@ -2,6 +2,6 @@ module MonteCarlo
2
2
 
3
3
  # Current version
4
4
  # @return [String]
5
- VERSION = "0.0.7"
5
+ VERSION = "0.0.8"
6
6
 
7
7
  end
@@ -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 = -> { sample_value }
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.7
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: 2014-11-23 00:00:00.000000000 Z
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler