assert-random 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{assert-random}
8
- s.version = "0.3.1"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Stewart Matheson"]
12
- s.date = %q{2010-08-03}
12
+ s.date = %q{2010-09-08}
13
13
  s.description = %q{This gem adds an assert random assertion that will allow the testing of random sequences. This is handy for game development and anyone working with random numbers with out a way of testing them.}
14
14
  s.email = %q{stew@rtmatheson.com}
15
15
  s.extra_rdoc_files = [
@@ -6,11 +6,12 @@ module AssertRandom
6
6
  def assert_random(options = {})
7
7
  _wrap_assertion do
8
8
  assert_block("assert needs to be called with a block.") { block_given? }
9
- configuration = { :tolerance => 1 }
10
- configuration.update(options) if options.is_a?(Hash)
9
+ configuration = { :tolerance => 1, :iterations => 10 }
10
+ configuration.merge!(options) if options.is_a?(Hash)
11
+ assert_block("No point running with an iteration count of 1") { !only_iterating_once? configuration[:iterations] }
11
12
 
12
13
  results = Array.new
13
- 10.times do
14
+ configuration[:iterations].times do
14
15
  results.push yield
15
16
  end
16
17
 
@@ -21,6 +22,10 @@ module AssertRandom
21
22
 
22
23
 
23
24
  private
25
+ def only_iterating_once?(iterations)
26
+ iterations <= 1
27
+ end
28
+
24
29
  def same_values?(results, tolerance)
25
30
  same_value_counter = 0
26
31
  results.each do
@@ -93,6 +93,7 @@ class TestAssertRandom < Test::Unit::TestCase
93
93
  end
94
94
  end
95
95
 
96
+
96
97
  def test_must_pass_block
97
98
  assert_raise Test::Unit::AssertionFailedError do
98
99
  assert_random
@@ -100,4 +101,29 @@ class TestAssertRandom < Test::Unit::TestCase
100
101
  end
101
102
 
102
103
 
104
+ def test_iteration_gets_passed
105
+ assert_nothing_raised do
106
+ assert_random :iterations => 5 do
107
+ rand(1000)
108
+ end
109
+ end
110
+ end
111
+
112
+
113
+ def test_iteration_and_tolerance_get_passed
114
+ assert_nothing_raised do
115
+ assert_random :iterations => 5, :tolerance => 10 do
116
+ rand(1000)
117
+ end
118
+ end
119
+ end
120
+
121
+ def test_can_not_iterate_once
122
+ assert_raise Test::Unit::AssertionFailedError do
123
+ assert_random :iterations => 1 do
124
+ rand(1000)
125
+ end
126
+ end
127
+ end
128
+
103
129
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assert-random
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stewart Matheson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-03 00:00:00 +01:00
18
+ date: 2010-09-08 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21