webget_ramp 1.7.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data.tar.gz.sig +0 -0
  2. data/lib/webget_ramp.rb +227 -0
  3. data/lib/webget_ramp/active_record.rb +119 -0
  4. data/lib/webget_ramp/active_record/connection_adapters/abstract/schema_statements.rb +24 -0
  5. data/lib/webget_ramp/array.rb +369 -0
  6. data/lib/webget_ramp/csv.rb +52 -0
  7. data/lib/webget_ramp/date.rb +87 -0
  8. data/lib/webget_ramp/enumerable.rb +369 -0
  9. data/lib/webget_ramp/file.rb +13 -0
  10. data/lib/webget_ramp/hash.rb +195 -0
  11. data/lib/webget_ramp/integer.rb +20 -0
  12. data/lib/webget_ramp/io.rb +63 -0
  13. data/lib/webget_ramp/kernel.rb +34 -0
  14. data/lib/webget_ramp/math.rb +18 -0
  15. data/lib/webget_ramp/nil.rb +9 -0
  16. data/lib/webget_ramp/numeric.rb +94 -0
  17. data/lib/webget_ramp/object.rb +18 -0
  18. data/lib/webget_ramp/process.rb +153 -0
  19. data/lib/webget_ramp/string.rb +220 -0
  20. data/lib/webget_ramp/symbol.rb +10 -0
  21. data/lib/webget_ramp/time.rb +9 -0
  22. data/lib/webget_ramp/xml.rb +120 -0
  23. data/lib/webget_ramp/yaml.rb +32 -0
  24. data/test/webget_ramp/active_record/connection_adapters/abstract/schema_statements_test.rb +9 -0
  25. data/test/webget_ramp/active_record_test.rb +64 -0
  26. data/test/webget_ramp/array_test.rb +171 -0
  27. data/test/webget_ramp/csv_test.rb +18 -0
  28. data/test/webget_ramp/date_test.rb +60 -0
  29. data/test/webget_ramp/enumerable_test.rb +271 -0
  30. data/test/webget_ramp/file_test.rb +15 -0
  31. data/test/webget_ramp/hash_test.rb +105 -0
  32. data/test/webget_ramp/integer_test.rb +19 -0
  33. data/test/webget_ramp/io_test.rb +31 -0
  34. data/test/webget_ramp/io_test.txt +1 -0
  35. data/test/webget_ramp/kernel_test.rb +15 -0
  36. data/test/webget_ramp/math_test.rb +17 -0
  37. data/test/webget_ramp/nil_test.rb +11 -0
  38. data/test/webget_ramp/numeric_test.rb +28 -0
  39. data/test/webget_ramp/object_test.rb +12 -0
  40. data/test/webget_ramp/process_test.rb +24 -0
  41. data/test/webget_ramp/string_test.rb +125 -0
  42. data/test/webget_ramp/symbol_test.rb +26 -0
  43. data/test/webget_ramp/time_test.rb +12 -0
  44. data/test/webget_ramp/xml_test.rb +50 -0
  45. data/test/webget_ramp/xml_test_1.xml +5 -0
  46. data/test/webget_ramp/xml_test_2.xml +5 -0
  47. data/test/webget_ramp/yaml_test.rb +32 -0
  48. data/test/webget_ramp/yaml_test_1.yml +38 -0
  49. data/test/webget_ramp/yaml_test_2.yml +38 -0
  50. metadata +124 -0
  51. metadata.gz.sig +0 -0
@@ -0,0 +1,32 @@
1
+ require 'yaml'
2
+
3
+ module YAML
4
+
5
+ # Specify one or more directory patterns and pass each YAML file in the matching directories to a block.
6
+ #
7
+ # See [Dir#glob](http://www.ruby-doc.org/core/classes/Dir.html#M002347) for pattern details.
8
+ #
9
+ # ==Example
10
+ # YAML.load_dir('/tmp/*.yaml'){|yaml_document|
11
+ # #...whatever you want to do with each yaml document
12
+ # }
13
+ #
14
+ # ==Example to load documents in files ending in ".yaml" and ".yml"
15
+ # YAML.load_dir('/tmp/*.yaml','/tmp/*.yml','){|yaml_document|
16
+ # #...whatever you want to do with the yaml document
17
+ # }
18
+
19
+ def YAML.load_dir(*dirpaths)
20
+ dirpaths=[*dirpaths.flatten]
21
+ dirpaths.each do |dirpath|
22
+ Dir[dirpath].each do |filename|
23
+ File.open(filename) do |file|
24
+ YAML.load_documents(file) do |doc|
25
+ yield doc
26
+ end #load
27
+ end #file
28
+ end #dir
29
+ end #each
30
+ end #def
31
+
32
+ end
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+ require 'webget_ramp'
3
+
4
+ class SchemaStatementsTest < Test::Unit::TestCase
5
+
6
+ def test_placeholder
7
+ end
8
+
9
+ end
@@ -0,0 +1,64 @@
1
+ require 'test/unit'
2
+ require 'webget_ramp'
3
+ require 'active_record'
4
+
5
+ begin
6
+ require 'sqlite3'
7
+ rescue
8
+ # noop because sqlite may already be available,
9
+ # e.g. in JRuby on Ubuntu you can install it:
10
+ # apt-get install libsqlite3-ruby
11
+ end
12
+
13
+ begin
14
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
15
+ rescue
16
+ raise ""+
17
+ "ActiveRecord cannot establish connection to sqlite3 database memory.\n" +
18
+ "Please verify that you have the sqlite3 database installed for testing.\n" +
19
+ "To install it for Ruby typically do: sudo gem install sqlite3-ruby\n" +
20
+ "To install it for JRuby + Ubuntu do: sudo apt-get install libsqlite3-ruby"
21
+ end
22
+
23
+ ActiveRecord::Schema.define(:version => 1) do
24
+ create_table :foos do |t|
25
+ t.string :a
26
+ t.string :b
27
+ t.string :c
28
+ end
29
+ end
30
+
31
+ class Foo < ActiveRecord::Base
32
+ end
33
+
34
+ class ActiveRecordTest < Test::Unit::TestCase
35
+
36
+ def test_prelim_count
37
+ assert_equal(0,Foo.count)
38
+ end
39
+
40
+ def test_prelim_create
41
+ f=Foo.new
42
+ f.a='aa'
43
+ f.b='bb'
44
+ f.c='cc'
45
+ f.save
46
+ assert_equal(1,Foo.count)
47
+ end
48
+
49
+ def test_seed_with_create
50
+ n1=Foo.count
51
+ Foo.seed(:a,{:a=>'xxx',:b=>'yyy'})
52
+ n2=Foo.count
53
+ assert_equal(n1+1,n2)
54
+ end
55
+
56
+ def test_seed_with_update
57
+ n1=Foo.count
58
+ f1=Foo.find(:first)
59
+ Foo.seed(:a,{:a=>f1.a,:b=>'bbb'})
60
+ n2=Foo.count
61
+ assert_equal(n1,n2)
62
+ end
63
+
64
+ end
@@ -0,0 +1,171 @@
1
+ require 'test/unit'
2
+ require 'csv'
3
+ require 'webget_ramp'
4
+
5
+ class ArrayTest < Test::Unit::TestCase
6
+
7
+ def test_join
8
+ a=['a','b','c']
9
+ assert_equal('abc',a.join)
10
+ assert_equal('a*b*c',a.join('*'))
11
+ assert_equal('[a]*[b]*[c]',a.join('*','[',']'))
12
+ assert_equal('[a][b][c]',a.join('[',']'))
13
+ end
14
+
15
+ def test_size
16
+ assert_equal(false,[].size?)
17
+ assert_equal(true,[1].size?)
18
+ assert_equal(true,[1,2].size?)
19
+ assert_equal(true,[[]].size?)
20
+ end
21
+
22
+ def test_rotate
23
+ a=[1,2,3,4]
24
+ a.rotate!
25
+ assert_equal([2,3,4,1],a)
26
+ a.rotate!
27
+ assert_equal([3,4,1,2],a)
28
+ end
29
+
30
+ def test_choice
31
+ a=[1,2,3,4]
32
+ c=a.choice
33
+ assert_equal(Fixnum,c.class)
34
+ assert(a.include?(c))
35
+ end
36
+
37
+ def test_choices
38
+ a=[1,2,3,4]
39
+ c=a.choices(2)
40
+ assert_equal(2,c.size)
41
+ assert(a.include?(c[0]))
42
+ assert(a.include?(c[1]))
43
+ c=a.choices(3)
44
+ assert_equal(3,c.size)
45
+ assert(a.include?(c[0]))
46
+ assert(a.include?(c[1]))
47
+ assert(a.include?(c[2]))
48
+ end
49
+
50
+ def test_onto
51
+ foo=[:a,:b,:c]
52
+ goo=[:x,:y,:z]
53
+ assert_equal({:a=>:x, :b=>:y, :c=>:z},foo.onto(goo))
54
+ end
55
+
56
+ def test_slices
57
+ a=[1,2,3,4,5,6,7,8]
58
+ assert_equal([[1,2],[3,4],[5,6],[7,8]],a.slices(2))
59
+ assert_equal([[1,2,3,4],[5,6,7,8]], a.slices(4))
60
+ assert_equal([[1,2,3],[4,5,6],[7,8]],a.slices(3))
61
+ assert_equal([[1,2,3,4,5],[6,7,8]],a.slices(5))
62
+ end
63
+
64
+ def test_divvy_evenly_divisible
65
+ assert_equal([[1,2,3],[4,5]],[1,2,3,4,5].divvy(2),'division with equal slices')
66
+ assert_equal([[1,2,3],[4,5,6],[7]],[1,2,3,4,5,6,7].divvy(3),'division with remainer slice')
67
+ assert_equal([[1,2],[3,4],[5,6]],[1,2,3,4,5,6].divvy(4),'division with small numbers')
68
+ end
69
+
70
+ def test_union
71
+ a=[[2,3,4],[4,5,6],[6,7,8]]
72
+ assert_equal([2,3,4,5,6,7,8],a.union)
73
+ end
74
+
75
+ def test_intersect
76
+ a=[[2,3,4],[4,3,5],[3,4,7]]
77
+ assert_equal([3,4],a.intersect)
78
+ end
79
+
80
+ def test_shifted
81
+ a=['a','b','c']
82
+ assert_equal([ 'b','c'],a.shifted)
83
+ assert_equal(['a','b','c'],a.shifted(0))
84
+ assert_equal([ 'b','c'],a.shifted(1))
85
+ assert_equal([ 'c'],a.shifted(2))
86
+ assert_equal([ ],a.shifted(3))
87
+ assert_equal(nil ,a.shifted(4))
88
+ end
89
+
90
+ # test_cdr must be idential to test_shifted
91
+ # because cdr is an alias for shifted
92
+ def test_cdr
93
+ a=['a','b','c']
94
+ assert_equal([ 'b','c'],a.cdr)
95
+ assert_equal(['a','b','c'],a.cdr(0))
96
+ assert_equal([ 'b','c'],a.cdr(1))
97
+ assert_equal([ 'c'],a.cdr(2))
98
+ assert_equal([ ],a.cdr(3))
99
+ assert_equal(nil ,a.cdr(4))
100
+ end
101
+
102
+ # test_rest must be idential to test_shifted
103
+ # because rest is an alias for shifted
104
+ def test_rest
105
+ a=['a','b','c']
106
+ assert_equal([ 'b','c'],a.rest)
107
+ assert_equal(['a','b','c'],a.rest(0))
108
+ assert_equal([ 'b','c'],a.rest(1))
109
+ assert_equal([ 'c'],a.rest(2))
110
+ assert_equal([ ],a.rest(3))
111
+ assert_equal(nil ,a.rest(4))
112
+ end
113
+
114
+ def test_shifted_bang
115
+ a=['a','b','c']; a.shifted!; assert_equal([ 'b','c'],a)
116
+ a=['a','b','c']; a.shifted!(0); assert_equal(['a','b','c'],a)
117
+ a=['a','b','c']; a.shifted!(1); assert_equal([ 'b','c'],a)
118
+ a=['a','b','c']; a.shifted!(2); assert_equal([ 'c'],a)
119
+ a=['a','b','c']; a.shifted!(3); assert_equal([ ],a)
120
+ a=['a','b','c']; a.shifted!(4); assert_equal([ ],a)
121
+ end
122
+
123
+ # alias: test_cdr_bang must be identical to test_shifted_bang
124
+ def test_cdr_bang
125
+ a=['a','b','c']; a.cdr!; assert_equal([ 'b','c'],a)
126
+ a=['a','b','c']; a.cdr!(0); assert_equal(['a','b','c'],a)
127
+ a=['a','b','c']; a.cdr!(1); assert_equal([ 'b','c'],a)
128
+ a=['a','b','c']; a.cdr!(2); assert_equal([ 'c'],a)
129
+ a=['a','b','c']; a.cdr!(3); assert_equal([ ],a)
130
+ a=['a','b','c']; a.cdr!(4); assert_equal([ ],a)
131
+ end
132
+
133
+ # alias: test_rest_band must be identical to test_shifted_bang
134
+ def test_rest_bang
135
+ a=['a','b','c']; a.rest!; assert_equal([ 'b','c'],a)
136
+ a=['a','b','c']; a.rest!(0); assert_equal(['a','b','c'],a)
137
+ a=['a','b','c']; a.rest!(1); assert_equal([ 'b','c'],a)
138
+ a=['a','b','c']; a.rest!(2); assert_equal([ 'c'],a)
139
+ a=['a','b','c']; a.rest!(3); assert_equal([ ],a)
140
+ a=['a','b','c']; a.rest!(4); assert_equal([ ],a)
141
+ end
142
+
143
+ def test_car
144
+ a=['a','b','c']
145
+ assert_equal('a',a.car)
146
+ end
147
+
148
+ def test_to_csv_one_dimensional
149
+ a=["a","b","c"]
150
+ assert_equal("a,b,c\n",a.to_csv)
151
+ end
152
+
153
+ def test_to_csv_multi_dimensional
154
+ a=[["a","b","c"], ["d","e","f"],["g","h","i"]]
155
+ assert_equal("a,b,c\nd,e,f\ng,h,i\n",a.to_csv)
156
+ end
157
+
158
+ def test_to_tsv
159
+ a=[["a", "b"], ["c", "d"], ["e", "f"]]
160
+ assert_equal("a\tb\nc\td\ne\tf\n",a.to_tsv)
161
+ end
162
+
163
+ # alias: test_to_tdf must be identical to test_to_tsv
164
+ def test_to_tdf
165
+ a=[["a", "b"], ["c", "d"], ["e", "f"]]
166
+ assert_equal("a\tb\nc\td\ne\tf\n",a.to_tdf)
167
+ end
168
+
169
+ end
170
+
171
+
@@ -0,0 +1,18 @@
1
+ require 'test/unit'
2
+ require 'webget_ramp'
3
+
4
+ class CSVTest < Test::Unit::TestCase
5
+
6
+ def test_http_headers
7
+ h=CSV.http_headers
8
+ assert_equal('text/csv',h["Content-Type"])
9
+ assert_equal("attachment; filename=\"data.csv\"",h["Content-Disposition"])
10
+ end
11
+
12
+ def test_http_headers_with_filename
13
+ h=CSV.http_headers(:filename=>'foo')
14
+ assert_equal('text/csv',h["Content-Type"])
15
+ assert_equal("attachment; filename=\"foo\"",h["Content-Disposition"])
16
+ end
17
+
18
+ end
@@ -0,0 +1,60 @@
1
+ require 'test/unit'
2
+ require 'webget_ramp'
3
+
4
+ class DateTest < Test::Unit::TestCase
5
+
6
+
7
+ def test_weekday
8
+ # Start on Monday, January 1, 2007
9
+ assert( Date.new(2007,1,1).weekday?)
10
+ assert( Date.new(2007,1,2).weekday?)
11
+ assert( Date.new(2007,1,3).weekday?)
12
+ assert( Date.new(2007,1,4).weekday?)
13
+ assert( Date.new(2007,1,5).weekday?)
14
+ assert(!Date.new(2007,1,6).weekday?)
15
+ assert(!Date.new(2007,1,7).weekday?)
16
+ assert( Date.new(2007,1,8).weekday?)
17
+ end
18
+
19
+
20
+ def test_weekend
21
+ # Start on Monday, January 1, 2007
22
+ assert(!Date.new(2007,1,1).weekend?)
23
+ assert(!Date.new(2007,1,2).weekend?)
24
+ assert(!Date.new(2007,1,3).weekend?)
25
+ assert(!Date.new(2007,1,4).weekend?)
26
+ assert(!Date.new(2007,1,5).weekend?)
27
+ assert( Date.new(2007,1,6).weekend?)
28
+ assert( Date.new(2007,1,7).weekend?)
29
+ assert(!Date.new(2007,1,8).weekend?)
30
+ end
31
+
32
+
33
+ def test_to_sql
34
+ assert('2007-12-31',Date.new(2008,12,31))
35
+ end
36
+
37
+
38
+ # for test_age_years and test_age_days
39
+ BIRTHDATE = Date.new(1980,10,31)
40
+ VALENTINES = Date.new(2008,02,14)
41
+ HALLOWEEN = Date.new(2008,10,31)
42
+ NEW_YEARS_EVE = Date.new(2008,12,31)
43
+
44
+
45
+ def test_age_years
46
+ assert_equal(27,BIRTHDATE.age_years(VALENTINES), '< birthday')
47
+ assert_equal(28,BIRTHDATE.age_years(HALLOWEEN), '= birthday')
48
+ assert_equal(28,BIRTHDATE.age_years(NEW_YEARS_EVE), '> birthday')
49
+ end
50
+
51
+
52
+ def test_age_days
53
+ assert_equal( 9967,BIRTHDATE.age_days(VALENTINES), '< birthday')
54
+ assert_equal(10227,BIRTHDATE.age_days(HALLOWEEN), '= birthday')
55
+ assert_equal(10288,BIRTHDATE.age_days(NEW_YEARS_EVE), '> birthday')
56
+ end
57
+
58
+
59
+ end
60
+
@@ -0,0 +1,271 @@
1
+ require 'test/unit'
2
+ require 'webget_ramp'
3
+ require 'set'
4
+
5
+ class EnumerableTest < Test::Unit::TestCase
6
+
7
+ ITEMS = ['a','b','c']
8
+ MAPTEST = [123,"456"]
9
+ RGB = ["red","green","blue"]
10
+
11
+
12
+ ########################################################################
13
+ #
14
+ # typecast
15
+ #
16
+ ########################################################################
17
+
18
+
19
+ def test_to_h_with_unique_keys
20
+ a=[[:a,:b],[:c,:d],[:e,:f]]
21
+ assert_equal({:a=>:b, :c=>:d, :e=>:f}, a.to_h)
22
+ end
23
+
24
+ def test_to_h_with_duplicate_keys
25
+ a=[[:a,:b],[:a,:c],[:a,:d]]
26
+ assert_equal({:a=>[:b, :c, :d]}, a.to_h)
27
+ end
28
+
29
+ def test_index_by
30
+ assert_equal({3=>"red",4=>"blue",5=>"green"},RGB.index_by{|x| x.size})
31
+ end
32
+
33
+ def test_hash_by
34
+ assert_equal({3=>"Red",4=>"Blue",5=>"Green"},RGB.hash_by{|x| [x.size,x.titlecase]})
35
+ end
36
+
37
+
38
+ ########################################################################
39
+ #
40
+ # map
41
+ #
42
+ ########################################################################
43
+
44
+
45
+ class Mock #:nodoc: all
46
+ attr_accessor :id
47
+
48
+ def initialize(id)
49
+ @id=id
50
+ end
51
+
52
+ def to_a
53
+ [self]
54
+ end
55
+
56
+ end
57
+
58
+
59
+ A = Mock.new('a')
60
+ B = Mock.new('b')
61
+ C = Mock.new('c')
62
+
63
+
64
+ def test_map_id
65
+ assert_equal(['a','b','c'],[A,B,C].map_id)
66
+ end
67
+
68
+ def test_map_to_a
69
+ assert_equal([[123],["456"]],MAPTEST.to_set.map_to_a)
70
+ end
71
+
72
+ def test_map_to_f
73
+ assert_equal([123.0,456.0],MAPTEST.map_to_f)
74
+ end
75
+
76
+ def test_map_to_i
77
+ assert_equal([123,456],MAPTEST.map_to_i)
78
+ end
79
+
80
+ def test_map_to_s
81
+ assert_equal(["123","456"],MAPTEST.map_to_s)
82
+ end
83
+
84
+ def test_map_to_sym
85
+ assert_equal([:a,:b,:c],ITEMS.map_to_sym)
86
+ end
87
+
88
+
89
+ ########################################################################
90
+ #
91
+ # select
92
+ #
93
+ ########################################################################
94
+
95
+
96
+ def test_select_while
97
+ assert_equal([ ],ITEMS.select_while{|x| x < 'a' },'< a')
98
+ assert_equal(['a' ],ITEMS.select_while{|x| x < 'b' },'< b')
99
+ assert_equal(['a','b' ],ITEMS.select_while{|x| x < 'c' },'< c')
100
+ assert_equal(['a','b','c'],ITEMS.select_while{|x| x < 'd' },'< d')
101
+ assert_equal(['a','b','c'],ITEMS.select_while{|x| x < 'e' },'< e')
102
+ end
103
+
104
+
105
+ def test_select_until_condition
106
+ assert_equal([ ],ITEMS.select_until{|x| x == 'a' },'a')
107
+ assert_equal(['a' ],ITEMS.select_until{|x| x == 'b' },'b')
108
+ assert_equal(['a','b' ],ITEMS.select_until{|x| x == 'c' },'c')
109
+ assert_equal(['a','b','c'],ITEMS.select_until{|x| x == 'd' },'d')
110
+ assert_equal(['a','b','c'],ITEMS.select_until{|x| x == 'e' },'e')
111
+ end
112
+
113
+
114
+ def test_select_with_index
115
+ assert_equal([ ],ITEMS.select_with_index{|x,i| i < 0 },'i < 0')
116
+ assert_equal(['a' ],ITEMS.select_with_index{|x,i| i < 1 },'i < 1')
117
+ assert_equal(['a','b' ],ITEMS.select_with_index{|x,i| i < 2 },'i < 2')
118
+ assert_equal(['a','b','c'],ITEMS.select_with_index{|x,i| i < 3 },'i < 3')
119
+ assert_equal(['a','b','c'],ITEMS.select_with_index{|x,i| i < 4 },'i < 4')
120
+ end
121
+
122
+
123
+ ########################################################################
124
+ #
125
+ # bisect
126
+ #
127
+ ########################################################################
128
+
129
+ def test_bisect
130
+ assert_equal([[ ],['a','b','c']],ITEMS.bisect{|x| x < 'a' },'< a')
131
+ assert_equal([['a' ],[ 'b','c']],ITEMS.bisect{|x| x < 'b' },'< b')
132
+ assert_equal([['a','b' ],[ 'c']],ITEMS.bisect{|x| x < 'c' },'< c')
133
+ assert_equal([['a','b','c'],[ ]],ITEMS.bisect{|x| x < 'd' },'< d')
134
+ end
135
+
136
+
137
+ ########################################################################
138
+ #
139
+ # nitems
140
+ #
141
+ ########################################################################
142
+
143
+
144
+ def test_nitems_while
145
+ assert_equal(0,ITEMS.nitems_while{|x| x < 'a' },'< a')
146
+ assert_equal(1,ITEMS.nitems_while{|x| x < 'b' },'< b')
147
+ assert_equal(2,ITEMS.nitems_while{|x| x < 'c' },'< c')
148
+ assert_equal(3,ITEMS.nitems_while{|x| x < 'd' },'< d')
149
+ assert_equal(3,ITEMS.nitems_while{|x| x < 'e' },'< e')
150
+ end
151
+
152
+
153
+ def test_nitems_until
154
+ assert_equal(0,ITEMS.nitems_until{|x| x == 'a' },'a')
155
+ assert_equal(1,ITEMS.nitems_until{|x| x == 'b' },'b')
156
+ assert_equal(2,ITEMS.nitems_until{|x| x == 'c' },'c')
157
+ assert_equal(3,ITEMS.nitems_until{|x| x == 'd' },'d')
158
+ assert_equal(3,ITEMS.nitems_until{|x| x == 'e' },'e')
159
+ end
160
+
161
+
162
+ def test_nitems_with_index
163
+ assert_equal(0,ITEMS.nitems_with_index{|x,i| i < 0 },'i < 0')
164
+ assert_equal(1,ITEMS.nitems_with_index{|x,i| i < 1 },'i < 1')
165
+ assert_equal(2,ITEMS.nitems_with_index{|x,i| i < 2 },'i < 2')
166
+ assert_equal(3,ITEMS.nitems_with_index{|x,i| i < 3 },'i < 3')
167
+ assert_equal(3,ITEMS.nitems_with_index{|x,i| i < 4 },'i < 4')
168
+ end
169
+
170
+
171
+ ########################################################################
172
+ #
173
+ # strings
174
+ #
175
+ ########################################################################
176
+
177
+
178
+ def test_join_0
179
+ a=['a','b','c']
180
+ assert_equal("abc",a.join,"join()")
181
+ end
182
+
183
+ def test_join_1
184
+ a=['a','b','c']
185
+ assert_equal("a+b+c",a.join('+'),"join('+')")
186
+ end
187
+
188
+ def test_join_2
189
+ a=['a','b','c']
190
+ assert_equal("+a-+b-+c-",a.join("+","-"),"join('+','-')")
191
+ end
192
+
193
+
194
+ ########################################################################
195
+ #
196
+ # set math
197
+ #
198
+ ########################################################################
199
+
200
+ def test_intersect_true
201
+ assert_equal(true,['a','b'].intersect?(['b','c']))
202
+ end
203
+
204
+ def test_intersect_true_with_same
205
+ assert_equal(true,['a','b'].intersect?(['a','b']))
206
+ end
207
+
208
+ def test_intersect_false
209
+ assert_equal(false,['a','b'].intersect?(['c','d']))
210
+ end
211
+
212
+ def test_intersect_false_with_none
213
+ assert_equal(false,['a','b','c'].intersect?([]))
214
+ end
215
+
216
+ CARTESIAN_PRODUCT_EXPECT=[["a", "d", "g"],
217
+ ["a", "d", "h"],
218
+ ["a", "d", "i"],
219
+ ["a", "e", "g"],
220
+ ["a", "e", "h"],
221
+ ["a", "e", "i"],
222
+ ["a", "f", "g"],
223
+ ["a", "f", "h"],
224
+ ["a", "f", "i"],
225
+ ["b", "d", "g"],
226
+ ["b", "d", "h"],
227
+ ["b", "d", "i"],
228
+ ["b", "e", "g"],
229
+ ["b", "e", "h"],
230
+ ["b", "e", "i"],
231
+ ["b", "f", "g"],
232
+ ["b", "f", "h"],
233
+ ["b", "f", "i"],
234
+ ["c", "d", "g"],
235
+ ["c", "d", "h"],
236
+ ["c", "d", "i"],
237
+ ["c", "e", "g"],
238
+ ["c", "e", "h"],
239
+ ["c", "e", "i"],
240
+ ["c", "f", "g"],
241
+ ["c", "f", "h"],
242
+ ["c", "f", "i"]]
243
+
244
+ def test_cartesian_product_class_method
245
+ a1=['a','b','c']
246
+ a2=['d','e','f']
247
+ a3=['g','h','i']
248
+ actual=Enumerable.cartesian_product(a1,a2,a3)
249
+ assert_equal(CARTESIAN_PRODUCT_EXPECT,actual,'class method')
250
+ end
251
+
252
+ def test_cartesian_product_instance_method
253
+ a1=['a','b','c']
254
+ a2=['d','e','f']
255
+ a3=['g','h','i']
256
+ actual=a1.cartesian_product(a2,a3)
257
+ assert_equal(CARTESIAN_PRODUCT_EXPECT,actual,'instance method')
258
+ end
259
+
260
+ def test_power_set
261
+ a=['a','b','c']
262
+ expect=[[],['a'],['a','b'],['a','b','c'],['a','c'],['b'],['b','c'],['c']]
263
+ actual=a.power_set.sort
264
+ assert_equal(expect,actual)
265
+ end
266
+
267
+ end
268
+
269
+
270
+
271
+