cartesian 0.6.4 → 0.6.5

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.
File without changes
@@ -1,3 +1,10 @@
1
+ === 0.6.5 2012-04-13
2
+
3
+ * 1 bug fix:
4
+ * Iterable now properly handles nil and false elements.
5
+ Thanks for ryanberckmans for pointing out the wrong behaviour
6
+ (https://github.com/adrianomitre/cartesian/issues/4)
7
+
1
8
  === 0.6.4 2011-01-07
2
9
 
3
10
  * 1 minor enhancements:
data/Rakefile CHANGED
@@ -14,39 +14,39 @@ $hoe = Hoe.spec 'cartesian' do
14
14
  self.developer 'Adriano Mitre', 'adriano.mitre@gmail.com'
15
15
  self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
16
  self.rubyforge_name = self.name # TODO this is default value
17
- # self.extra_deps = [['activesupport','>= 2.0.2']]
17
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
18
18
 
19
19
  end
20
20
 
21
- require 'newgem/tasks'
21
+ require 'rubygems/package_task'
22
22
  Dir['tasks/**/*.rake'].each { |t| load t }
23
23
 
24
24
  # TODO - want other tests/tasks run by default? Add them to the list
25
25
  # remove_task :default
26
- # task :default => [:spec, :features]
27
-
28
- task :chdir do
29
- Dir.chdir File.dirname(File.expand_path(__FILE__))
30
- end
31
-
32
- task :render_docs => [:chdir] do
33
- system %q{ rm -rf doc/ }
34
- system %q{ rdoc README.rdoc lib/*.rb }
35
- end
36
-
37
- task :render_website => [:chdir, :render_docs] do |t|
38
- system %q{ script/txt2html website/index.txt website/template.html.erb > website/index.html }
39
- system %q{ rm -rf website/doc; cp -R doc website }
40
- end
41
-
42
- task :pre_release => [:manifest, :render_website] do
43
- unless `git diff Manifest.txt`.empty?
44
- puts
45
- puts " Manifest.txt was re-generated and there were changes."
46
- puts " Use 'git diff Manifest.txt' to inspect them."
47
- end
48
- puts
49
- puts " Do NOT forget to update History.txt (VERSION should have already be updated)."
50
- puts
51
- end
52
-
26
+ # task :default => [:spec, :features]
27
+
28
+ task :chdir do
29
+ Dir.chdir File.dirname(File.expand_path(__FILE__))
30
+ end
31
+
32
+ task :render_docs => [:chdir] do
33
+ system %q{ rm -rf doc/ }
34
+ system %q{ rdoc README.rdoc lib/*.rb }
35
+ end
36
+
37
+ task :render_website => [:chdir, :render_docs] do |t|
38
+ system %q{ script/txt2html website/index.txt website/template.html.erb > website/index.html }
39
+ system %q{ rm -rf website/doc; cp -R doc website }
40
+ end
41
+
42
+ task :pre_release => [:manifest, :render_website] do
43
+ unless `git diff Manifest.txt`.empty?
44
+ puts
45
+ puts " Manifest.txt was re-generated and there were changes."
46
+ puts " Use 'git diff Manifest.txt' to inspect them."
47
+ end
48
+ puts
49
+ puts " Do NOT forget to update History.txt (VERSION should have already be updated)."
50
+ puts
51
+ end
52
+
@@ -39,7 +39,7 @@ module Cartesian
39
39
  # Unfortunately, as of now, the version data must be replicated in ../cartesian.rb,
40
40
  # due to a mix of newgem versions, each requiring a different one. Not DRY :P
41
41
  #
42
- VERSION = "0.6.4"
42
+ VERSION = "0.6.5"
43
43
 
44
44
  # Produces the cartesian product of self and other.
45
45
  # The result is an array of pairs (i.e. two-element arrays).
@@ -179,7 +179,7 @@ module Cartesian
179
179
  m.module_eval("include Cartesian")
180
180
  end
181
181
  end
182
- JRuby.objectspace = prev_jruby_objectspace_state if RUBY_DESCRIPTION =~ /jruby/i
182
+ JRuby.objectspace = prev_jruby_objectspace_state if defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /jruby/i
183
183
 
184
184
  end
185
185
 
@@ -1,3 +1,9 @@
1
+ require 'iterable'
2
+
3
+ class Array
4
+ include Iterable
5
+ end
6
+
1
7
  class CartesianIterator
2
8
 
3
9
  def initialize(foo, bar)
@@ -20,7 +26,7 @@ class CartesianIterator
20
26
  alias == equal
21
27
 
22
28
  def product!(other)
23
- @lists << other.to_a.dup
29
+ @lists << Array(other).dup
24
30
  @tot_iter *= @lists[-1].size
25
31
  self
26
32
  end
@@ -28,7 +34,7 @@ class CartesianIterator
28
34
  alias x! product!
29
35
 
30
36
  def left_product!(other)
31
- @lists.unshift other.to_a.dup
37
+ @lists.unshift Array(other).dup
32
38
  @tot_iter *= @lists[-1].size
33
39
  self
34
40
  end
@@ -57,7 +63,8 @@ class CartesianIterator
57
63
  last_list_index = @lists.size-1
58
64
  n = last_list_index
59
65
  loop do
60
- if elems[n] = @lists[n].raw_next
66
+ if !@lists[n].done?
67
+ elems[n] = @lists[n].raw_next
61
68
  if RUBY_VERSION <= '1.9.1'; yield(*elems.map {|x| x }); else; yield(*elems); end # See previous comment.
62
69
  n = last_list_index
63
70
  next
@@ -73,27 +80,3 @@ class CartesianIterator
73
80
  include Enumerable
74
81
 
75
82
  end
76
-
77
- module Iterable
78
- def restart
79
- @next_index = -1
80
- true
81
- end
82
-
83
- def next
84
- restart unless defined? @next_index
85
- raw_next
86
- end
87
-
88
- def raw_next
89
- self[@next_index += 1]
90
- end
91
-
92
- def restart_and_raw_next
93
- self[@next_index = 0]
94
- end
95
- end
96
-
97
- class Array
98
- include Iterable
99
- end
@@ -1,29 +1,19 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
2
  require 'cartesian'
3
-
4
- class TestCartesianIterator < Test::Unit::TestCase
5
-
6
- def test_equal
7
- assert_equal [1].x([2]), [1].x([2])
8
- assert_not_equal [1].x([2]), [1].x([3])
9
- end
10
-
11
-
12
- def test_dup
13
- c = [1,2].x([3,4])
14
- d = c.dup
15
- e = d.x([5,6])
16
- assert_not_equal(e, c)
17
- assert_equal(c, d)
18
- end
19
-
20
- def test_iterator_next_and_restart
21
- foo = [1,2]
22
- assert_equal 1, foo.next
23
- assert_equal 2, foo.next
24
- assert_equal nil, foo.next
25
- foo.restart
26
- assert_equal 1, foo.next
27
- end
28
-
29
- end
3
+
4
+ class TestCartesianIterator < Test::Unit::TestCase
5
+
6
+ def test_equal
7
+ assert_equal [1].x([2]), [1].x([2])
8
+ assert_not_equal [1].x([2]), [1].x([3])
9
+ end
10
+
11
+ def test_dup
12
+ c = [1,2].x([3,4])
13
+ d = c.dup
14
+ e = d.x([5,6])
15
+ assert_not_equal(e, c)
16
+ assert_equal(c, d)
17
+ end
18
+
19
+ end
@@ -0,0 +1,46 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper.rb')
2
+ require 'iterable'
3
+
4
+ class TestIterable < Test::Unit::TestCase
5
+ def setup
6
+ @foo = [1, 2].extend Iterable
7
+ @bar = [nil, "a", :b].extend Iterable
8
+ @baz = Array.new(rand(100)) {|n| n % 2 == 0 ? n : (rand >= 0.5 ? nil : false) }
9
+ @baz.extend Iterable
10
+ end
11
+
12
+ def test_next
13
+ [@foo, @bar, @baz].each do |ary|
14
+ ary.each do |item|
15
+ assert_equal item, ary.next
16
+ end
17
+ end
18
+ end
19
+
20
+ def test_done
21
+ [@foo, @bar, @baz].each do |ary|
22
+ ary.size.times do
23
+ assert !ary.done?
24
+ assert_nothing_raised { ary.next }
25
+ end
26
+ assert ary.done?
27
+ assert_raise(RangeError) { ary.next }
28
+ end
29
+ end
30
+
31
+ def test_restart
32
+ [@foo, @bar, @baz].each do |ary|
33
+ assert_equal ary.first, ary.next
34
+ rand(ary.size-1).times { ary.next }
35
+ assert_equal ary.first, ary.restart.next
36
+ end
37
+ end
38
+
39
+ def test_extending_objects_from_other_classes
40
+ baz = 'baz'.extend Iterable
41
+ baz.size.times do |n|
42
+ assert_equal baz[n], baz.next
43
+ end
44
+ assert_raise(RangeError) { baz.next }
45
+ end
46
+ end
metadata CHANGED
@@ -1,54 +1,66 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cartesian
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 6
8
- - 4
9
- version: 0.6.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.5
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Adriano Mitre
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-01-07 00:00:00 -02:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: hoe
12
+ date: 2012-04-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.10'
22
+ type: :development
22
23
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.10'
30
+ - !ruby/object:Gem::Dependency
31
+ name: hoe
32
+ requirement: !ruby/object:Gem::Requirement
24
33
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 2
30
- - 8
31
- - 0
32
- version: 2.8.0
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.0'
33
38
  type: :development
34
- version_requirements: *id001
35
- description: |-
36
- Provides methods for the calculation of the cartesian producted between two
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.0'
46
+ description: ! 'Provides methods for the calculation of the cartesian producted between
47
+ two
48
+
37
49
  or more enumerable objects. Includes grid search optimization methods.
38
- It can also be easily and conveniently mixed in into any enumerable class.
39
- email:
50
+
51
+ It can also be easily and conveniently mixed in into any enumerable class.'
52
+ email:
40
53
  - adriano.mitre@gmail.com
41
54
  executables: []
42
-
43
55
  extensions: []
44
-
45
- extra_rdoc_files:
56
+ extra_rdoc_files:
46
57
  - History.txt
47
58
  - Manifest.txt
48
59
  - PostInstall.txt
60
+ - README.rdoc
49
61
  - Wishlist.txt
50
62
  - website/index.txt
51
- files:
63
+ files:
52
64
  - History.txt
53
65
  - Manifest.txt
54
66
  - PostInstall.txt
@@ -94,43 +106,40 @@ files:
94
106
  - website/javascripts/rounded_corners_lite.inc.js
95
107
  - website/stylesheets/screen.css
96
108
  - website/template.html.erb
97
- has_rdoc: true
109
+ - test/test_iterable.rb
110
+ - .gemtest
98
111
  homepage: http://adrianomitre.github.com/cartesian/website/index.html
99
112
  licenses: []
100
-
101
113
  post_install_message: PostInstall.txt
102
- rdoc_options:
114
+ rdoc_options:
103
115
  - --main
104
116
  - README.rdoc
105
- require_paths:
117
+ require_paths:
106
118
  - lib
107
- required_ruby_version: !ruby/object:Gem::Requirement
119
+ required_ruby_version: !ruby/object:Gem::Requirement
108
120
  none: false
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- segments:
113
- - 0
114
- version: "0"
115
- required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
126
  none: false
117
- requirements:
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- segments:
121
- - 0
122
- version: "0"
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
123
131
  requirements: []
124
-
125
132
  rubyforge_project: cartesian
126
- rubygems_version: 1.3.7
133
+ rubygems_version: 1.8.21
127
134
  signing_key:
128
135
  specification_version: 3
129
- summary: Provides methods for the calculation of the cartesian producted between two or more enumerable objects
130
- test_files:
131
- - test/test_helper.rb
132
- - test/test_extensions.rb
136
+ summary: Provides methods for the calculation of the cartesian producted between two
137
+ or more enumerable objects
138
+ test_files:
133
139
  - test/test_suite.rb
134
- - test/test_cartesian_iterator.rb
135
- - test/test_cartesian.rb
140
+ - test/test_iterable.rb
136
141
  - test/test_grid_search.rb
142
+ - test/test_cartesian.rb
143
+ - test/test_extensions.rb
144
+ - test/test_helper.rb
145
+ - test/test_cartesian_iterator.rb