facets 2.0.2 → 2.0.3

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.
Files changed (114) hide show
  1. data/AUTHORS +3 -3
  2. data/README +6 -7
  3. data/lib/core/facets.rb +1 -46
  4. data/lib/core/facets/array.rb +3 -0
  5. data/lib/core/facets/array/indexable.rb +6 -1
  6. data/lib/core/facets/array/only.rb +20 -0
  7. data/lib/core/facets/dir/multiglob.rb +12 -1
  8. data/lib/core/facets/enumerable.rb +0 -1
  9. data/lib/core/facets/enumerable/collect.rb +1 -0
  10. data/lib/core/facets/enumerable/combination.rb +44 -90
  11. data/lib/core/facets/facets.rb +46 -0
  12. data/lib/core/facets/file/write.rb +46 -58
  13. data/lib/core/facets/hash.rb +2 -0
  14. data/lib/core/facets/hash/select.rb +14 -0
  15. data/lib/core/facets/integer/multiples.rb +12 -55
  16. data/lib/core/facets/kernel/val.rb +14 -0
  17. data/lib/core/facets/module/alias.rb +28 -9
  18. data/lib/core/facets/module/methods.rb +18 -0
  19. data/lib/core/facets/module/traits.rb +65 -70
  20. data/lib/core/facets/proc/compose.rb +15 -12
  21. data/lib/core/facets/stackable.rb +3 -2
  22. data/lib/core/facets/string/format.rb +4 -6
  23. data/lib/core/facets/string/tabs.rb +34 -0
  24. data/lib/core/facets/symbol.rb +1 -0
  25. data/lib/core/facets/symbol/succ.rb +1 -42
  26. data/lib/core/facets/symbol/to_proc.rb +34 -0
  27. data/lib/methods/facets/array/contains.rb +1 -0
  28. data/lib/methods/facets/facets/require_core.rb +1 -0
  29. data/lib/methods/facets/file/writelines.rb +1 -0
  30. data/lib/methods/facets/io/writelines.rb +1 -0
  31. data/lib/methods/facets/kernel/not_nil.rb +1 -0
  32. data/lib/methods/facets/module/conflict.rb +1 -0
  33. data/lib/methods/facets/module/instance_method_defined.rb +1 -0
  34. data/lib/methods/facets/module/module_method_defined.rb +1 -0
  35. data/lib/methods/facets/module/private_conflict.rb +1 -0
  36. data/lib/methods/facets/module/protected_conflict.rb +1 -0
  37. data/lib/methods/facets/module/public_conflict.rb +1 -0
  38. data/lib/methods/facets/string/expand_tabs.rb +1 -0
  39. data/lib/methods/facets/string/outdent.rb +1 -0
  40. data/lib/methods/facets/string/taballto.rb +1 -0
  41. data/lib/more/facets/arguments.rb +1 -1
  42. data/lib/more/facets/association.rb +0 -46
  43. data/lib/more/facets/autoarray.rb +0 -28
  44. data/lib/more/facets/command.rb +341 -8
  45. data/lib/more/facets/dictionary.rb +25 -131
  46. data/lib/more/facets/downloader.rb +1 -1
  47. data/lib/more/facets/infinity.rb +3 -3
  48. data/lib/more/facets/interval.rb +0 -161
  49. data/lib/more/facets/multiton.rb +16 -12
  50. data/lib/more/facets/namespace.rb +1 -1
  51. data/lib/more/facets/ostruct.rb +46 -10
  52. data/lib/more/facets/overload.rb +0 -51
  53. data/lib/more/facets/paramix.rb +0 -97
  54. data/lib/more/facets/pp_s.rb +30 -0
  55. data/lib/more/facets/progressbar.rb +18 -10
  56. data/lib/more/facets/prototype.rb +1 -40
  57. data/lib/more/facets/random.rb +1 -0
  58. data/lib/more/facets/rbsystem.rb +4 -1
  59. data/lib/more/facets/snapshot.rb +8 -1
  60. data/lib/more/facets/stylize.rb +2 -0
  61. data/meta/{project.yaml → facets-2.0.3.roll} +22 -14
  62. data/meta/manifest.txt +38 -8
  63. data/task/{config.yaml → config/general.yaml} +7 -2
  64. data/task/{rdoc.yaml → config/rdoc.yaml} +1 -1
  65. data/task/crosstest +309 -0
  66. data/task/isotest +293 -0
  67. data/task/loadtest +28 -0
  68. data/task/methods +4 -4
  69. data/task/prepare +5 -0
  70. data/task/publish +2 -2
  71. data/task/rdoc +1 -0
  72. data/task/syntax +29 -0
  73. data/task/test +0 -1
  74. data/task/testeach +42 -0
  75. data/task/testpairs +50 -0
  76. data/test/lib/rq.rb +15 -0
  77. data/test/unit/array/test_merge.rb +21 -43
  78. data/test/unit/array/test_only.rb +21 -0
  79. data/test/unit/enumerable/test_collect.rb +1 -21
  80. data/test/unit/enumerable/test_combination.rb +50 -44
  81. data/test/unit/file/test_topath.rb +48 -57
  82. data/test/unit/file/test_write.rb +82 -0
  83. data/test/unit/hash/test_select.rb +43 -0
  84. data/test/unit/integer/test_multiples.rb +28 -32
  85. data/test/unit/kernel/test_report.rb +9 -12
  86. data/test/unit/kernel/test_val.rb +50 -45
  87. data/test/unit/module/test_include.rb +56 -57
  88. data/test/unit/module/test_name.rb +42 -55
  89. data/test/unit/module/test_traits.rb +46 -47
  90. data/test/unit/string/test_filter.rb +19 -34
  91. data/test/unit/string/test_format.rb +87 -96
  92. data/test/unit/string/test_regesc.rb +18 -26
  93. data/test/unit/string/test_tabs.rb +226 -119
  94. data/test/unit/symbol/test_succ.rb +14 -23
  95. data/test/unit/symbol/test_to_proc.rb +41 -0
  96. data/test/unit/test_association.rb +38 -47
  97. data/test/unit/test_attributes.rb +24 -33
  98. data/test/unit/test_autoarray.rb +23 -32
  99. data/test/unit/test_command.rb +26 -0
  100. data/test/unit/test_dictionary.rb +123 -117
  101. data/test/unit/test_infinity.rb +41 -47
  102. data/test/unit/test_inheritor.rb +133 -142
  103. data/test/unit/test_interval.rb +129 -93
  104. data/test/unit/test_ostruct.rb +148 -101
  105. data/test/unit/test_overload.rb +8 -15
  106. data/test/unit/test_paramix.rb +67 -73
  107. data/test/unit/test_pp_s.rb +23 -0
  108. data/test/unit/test_prototype.rb +28 -38
  109. metadata +47 -11
  110. data/lib/core/facets/enumerable/instance_map.rb +0 -0
  111. data/lib/more/facets/command_options.rb +0 -328
  112. data/meta/version.txt +0 -1
  113. data/task/load +0 -39
  114. data/test/unit/test_command_options.rb +0 -29
@@ -1,30 +1,21 @@
1
- # _____ _
2
- # |_ _|__ ___| |_
3
- # | |/ _ \/ __| __|
4
- # | | __/\__ \ |
5
- # |_|\___||___/\__|
6
- #
7
- # for lib/facets/symbol/succ.rb
8
- #
9
- # Extracted Mon Sep 03 16:23:07 -0700 2007
10
- # w/ Test Extraction Ratchet
11
- #
1
+ # _____ _
2
+ # |_ _|__ ___| |_
3
+ # | |/ _ \/ __| __|
4
+ # | | __/\__ \ |
5
+ # |_|\___||___/\__|
6
+ #
12
7
 
13
- require 'facets/symbol/succ.rb'
8
+ require 'facets/symbol/succ.rb'
14
9
 
10
+ require 'test/unit'
15
11
 
12
+ class TestSymbol < Test::Unit::TestCase
16
13
 
17
- require 'test/unit'
18
-
19
- class TestSymbol < Test::Unit::TestCase
20
-
21
- def test_succ
22
- assert_equal( :b, :a.succ )
23
- assert_equal( :aab, :aaa.succ )
24
- assert_equal( :"2", :"1".succ )
25
- end
26
-
14
+ def test_succ
15
+ assert_equal( :b, :a.succ )
16
+ assert_equal( :aab, :aaa.succ )
17
+ assert_equal( :"2", :"1".succ )
27
18
  end
28
19
 
29
-
20
+ end
30
21
 
@@ -0,0 +1,41 @@
1
+ # _____ _
2
+ # |_ _|__ ___| |_
3
+ # | |/ _ \/ __| __|
4
+ # | | __/\__ \ |
5
+ # |_|\___||___/\__|
6
+ #
7
+ # for lib/facets/io/write.rb
8
+
9
+ require 'facets/symbol/to_proc.rb'
10
+ require 'test/unit'
11
+
12
+ class TestSymbolToProc < Test::Unit::TestCase
13
+
14
+ def test_to_proc
15
+ x = (1..10).inject(&:*)
16
+ assert_equal(3628800, x)
17
+
18
+ x = %w{foo bar qux}.map(&:reverse)
19
+ assert_equal(%w{oof rab xuq}, x)
20
+
21
+ x = [1, 2, nil, 3, nil].reject(&:nil?)
22
+ assert_equal([1, 2, 3], x)
23
+
24
+ x = %w{ruby and world}.sort_by(&:reverse)
25
+ assert_equal(%w{world and ruby}, x)
26
+ end
27
+
28
+ def test_to_proc_call
29
+ assert_instance_of(Proc, up = :upcase.to_proc )
30
+ assert_equal( "HELLO", up.call("hello") )
31
+ end
32
+
33
+ def test_to_proc_map
34
+ q = [[1,2,3], [4,5,6], [7,8,9]].map(&:reverse)
35
+ a = [[3, 2, 1], [6, 5, 4], [9, 8, 7]]
36
+ assert_equal( a, q )
37
+ end
38
+
39
+ end
40
+
41
+
@@ -1,53 +1,44 @@
1
- # _____ _
2
- # |_ _|__ ___| |_
3
- # | |/ _ \/ __| __|
4
- # | | __/\__ \ |
5
- # |_|\___||___/\__|
6
- #
7
- # for lib/facets/association.rb
8
- #
9
- # Extracted Mon Sep 03 16:23:07 -0700 2007
10
- # w/ Test Extraction Ratchet
11
- #
12
-
13
- require 'facets/association.rb'
14
-
15
-
16
-
17
- require 'test/unit'
18
-
19
- class TC01 < Test::Unit::TestCase
20
-
21
- def setup
22
- @complex_hierarchy = [
23
- 'parent' >> 'child',
24
- 'childless',
25
- 'another_parent' >> [
26
- 'subchildless',
27
- 'subparent' >> 'subchild'
28
- ]
1
+ # _____ _
2
+ # |_ _|__ ___| |_
3
+ # | |/ _ \/ __| __|
4
+ # | | __/\__ \ |
5
+ # |_|\___||___/\__|
6
+ #
7
+ # facets/association.rb
8
+
9
+ require 'facets/association.rb'
10
+
11
+ require 'test/unit'
12
+
13
+ class TC_Associations < Test::Unit::TestCase
14
+
15
+ def setup
16
+ @complex_hierarchy = [
17
+ 'parent' >> 'child',
18
+ 'childless',
19
+ 'another_parent' >> [
20
+ 'subchildless',
21
+ 'subparent' >> 'subchild'
29
22
  ]
30
- end
31
-
32
- def test_ohash
33
- k,v = [],[]
34
- ohash = [ 'A' >> '3', 'B' >> '2', 'C' >> '1' ]
35
- ohash.each { |e1,e2| k << e1 ; v << e2 }
36
- assert_equal( ['A','B','C'], k )
37
- assert_equal( ['3','2','1'], v )
38
- end
39
-
40
- def test_complex
41
- complex = [ 'Drop Menu' >> [ 'Button 1', 'Button 2', 'Button 3' ], 'Help' ]
42
- assert_equal( 'Drop Menu', complex[0].index )
43
- end
44
-
45
- def test_associations
46
- complex = [ :a >> :b, :a >> :c ]
47
- assert_equal( [ :b, :c ], :a.associations )
48
- end
23
+ ]
24
+ end
49
25
 
26
+ def test_ohash
27
+ k,v = [],[]
28
+ ohash = [ 'A' >> '3', 'B' >> '2', 'C' >> '1' ]
29
+ ohash.each { |e1,e2| k << e1 ; v << e2 }
30
+ assert_equal( ['A','B','C'], k )
31
+ assert_equal( ['3','2','1'], v )
50
32
  end
51
33
 
34
+ def test_complex
35
+ complex = [ 'Drop Menu' >> [ 'Button 1', 'Button 2', 'Button 3' ], 'Help' ]
36
+ assert_equal( 'Drop Menu', complex[0].index )
37
+ end
52
38
 
39
+ def test_associations
40
+ complex = [ :a >> :b, :a >> :c ]
41
+ assert_equal( [ :b, :c ], :a.associations )
42
+ end
53
43
 
44
+ end
@@ -1,41 +1,32 @@
1
- # _____ _
2
- # |_ _|__ ___| |_
3
- # | |/ _ \/ __| __|
4
- # | | __/\__ \ |
5
- # |_|\___||___/\__|
6
- #
7
- # for lib/facets/attributes.rb
8
- #
9
- # Extracted Mon Sep 03 16:23:08 -0700 2007
10
- # w/ Test Extraction Ratchet
11
- #
1
+ # _____ _
2
+ # |_ _|__ ___| |_
3
+ # | |/ _ \/ __| __|
4
+ # | | __/\__ \ |
5
+ # |_|\___||___/\__|
6
+ #
7
+ # facets/attributes.rb
12
8
 
13
- require 'facets/attributes.rb'
9
+ require 'facets/attributes.rb'
14
10
 
11
+ require 'test/unit'
15
12
 
16
-
17
- require 'test/unit'
18
-
19
- class TC01 < Test::Unit::TestCase
20
- class A
21
- attr_accessor :x, :cast=>"to_s"
22
- end
23
-
24
- def test_09_001
25
- a = A.new
26
- assert_equal( [:x], A.attributes )
27
- end
13
+ class TC_Attributes_Using_Attr < Test::Unit::TestCase
14
+ class A
15
+ attr :x, :cast=>"to_s"
28
16
  end
29
17
 
30
- class TC10 < Test::Unit::TestCase
31
- class A
32
- attr :x, :cast=>"to_s"
33
- end
34
-
35
- def test_10_001
36
- assert_equal( "to_s", A.ann(:x,:cast) )
37
- end
18
+ def test_01
19
+ assert_equal( "to_s", A.ann(:x,:cast) )
38
20
  end
21
+ end
39
22
 
23
+ class TC_Attributes_Using_Attr_Accessor < Test::Unit::TestCase
24
+ class A
25
+ attr_accessor :x, :cast=>"to_s"
26
+ end
40
27
 
41
-
28
+ def test_01
29
+ a = A.new
30
+ assert_equal( [:x], A.attributes )
31
+ end
32
+ end
@@ -1,34 +1,25 @@
1
- # _____ _
2
- # |_ _|__ ___| |_
3
- # | |/ _ \/ __| __|
4
- # | | __/\__ \ |
5
- # |_|\___||___/\__|
6
- #
7
- # for lib/facets/autoarray.rb
8
- #
9
- # Extracted Mon Sep 03 16:23:07 -0700 2007
10
- # w/ Test Extraction Ratchet
11
- #
12
-
13
- require 'facets/autoarray.rb'
14
-
15
-
16
-
17
- require 'test/unit'
18
-
19
- class TC_Autoarray
20
-
21
- def test_001
22
- a = Autoarray.new
23
- assert_equal( 12, a[1][2][3] = 12 )
24
- assert_equal( [nil, [nil, nil, [nil, nil, nil, 12]]], a )
25
- assert_equal( [], a[2][3][4] )
26
- assert_equal( [nil, [nil, nil, [nil, nil, nil, 12]]], a )
27
- assert_equal( "Negative", a[1][-2][1] = "Negative" )
28
- assert_equal( [nil, [nil, [nil, "Negative"], [nil, nil, nil, 12]]], a )
29
- end
30
-
1
+ # _____ _
2
+ # |_ _|__ ___| |_
3
+ # | |/ _ \/ __| __|
4
+ # | | __/\__ \ |
5
+ # |_|\___||___/\__|
6
+ #
7
+ # for facets/autoarray.rb
8
+
9
+ require 'facets/autoarray.rb'
10
+
11
+ require 'test/unit'
12
+
13
+ class TC_Autoarray
14
+
15
+ def test_001
16
+ a = Autoarray.new
17
+ assert_equal( 12, a[1][2][3] = 12 )
18
+ assert_equal( [nil, [nil, nil, [nil, nil, nil, 12]]], a )
19
+ assert_equal( [], a[2][3][4] )
20
+ assert_equal( [nil, [nil, nil, [nil, nil, nil, 12]]], a )
21
+ assert_equal( "Negative", a[1][-2][1] = "Negative" )
22
+ assert_equal( [nil, [nil, [nil, "Negative"], [nil, nil, nil, 12]]], a )
31
23
  end
32
24
 
33
-
34
-
25
+ end
@@ -258,3 +258,29 @@ class TestCommand < Test::Unit::TestCase
258
258
  end
259
259
 
260
260
  end
261
+
262
+
263
+ class TestCommandOptions < Test::Unit::TestCase
264
+
265
+ class MyOptions < Command::Options
266
+ attr_reader :a, :b
267
+ def a! ; @a = true ; end
268
+ def b=(x) ; @b = x ; end
269
+ end
270
+
271
+ def test_myoptions1
272
+ opts = MyOptions.parse("-a -b hi")
273
+ assert_equal( true, opts.a)
274
+ end
275
+
276
+ def test_myoptions2
277
+ opts = MyOptions.parse("-a -b hi")
278
+ assert_equal('hi', opts.b)
279
+ end
280
+
281
+ def test_usage
282
+ opts = MyOptions.parse("-a -b hi")
283
+ assert_equal('[-a] [-b value]', opts.usage)
284
+ end
285
+
286
+ end
@@ -1,122 +1,128 @@
1
- # _____ _
2
- # |_ _|__ ___| |_
3
- # | |/ _ \/ __| __|
4
- # | | __/\__ \ |
5
- # |_|\___||___/\__|
6
- #
7
- # for lib/facets/dictionary.rb
8
- #
9
- # Extracted Mon Sep 03 16:23:07 -0700 2007
10
- # w/ Test Extraction Ratchet
11
- #
12
-
13
- require 'facets/dictionary.rb'
14
-
15
-
16
-
17
- require 'test/unit'
18
-
19
- class TC_Dictionary < Test::Unit::TestCase
20
-
21
- def test_create
22
- hsh = Dictionary['z', 1, 'a', 2, 'c', 3]
23
- assert_equal( ['z','a','c'], hsh.keys )
24
- end
25
-
26
- def test_op_store
27
- hsh = Dictionary.new
28
- hsh['z'] = 1
29
- hsh['a'] = 2
30
- hsh['c'] = 3
31
- assert_equal( ['z','a','c'], hsh.keys )
32
- end
33
-
34
- def test_push
35
- hsh = Dictionary['a', 1, 'c', 2, 'z', 3]
36
- assert( hsh.push('end', 15) )
37
- assert_equal( 15, hsh['end'] )
38
- assert( ! hsh.push('end', 30) )
39
- assert( hsh.unshift('begin', 50) )
40
- assert_equal( 50, hsh['begin'] )
41
- assert( ! hsh.unshift('begin', 60) )
42
- assert_equal( ["begin", "a", "c", "z", "end"], hsh.keys )
43
- assert_equal( ["end", 15], hsh.pop )
44
- assert_equal( ["begin", "a", "c", "z"], hsh.keys )
45
- assert_equal( ["begin", 50], hsh.shift )
46
- end
47
-
48
- def test_insert
49
- # front
50
- h = Dictionary['a', 1, 'b', 2, 'c', 3]
51
- r = Dictionary['d', 4, 'a', 1, 'b', 2, 'c', 3]
52
- assert_equal( 4, h.insert(0,'d',4) )
53
- assert_equal( r, h )
54
- # back
55
- h = Dictionary['a', 1, 'b', 2, 'c', 3]
56
- r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
57
- assert_equal( 4, h.insert(-1,'d',4) )
58
- assert_equal( r, h )
59
- end
60
-
61
- def test_update
62
- # with other orderred hash
63
- h1 = Dictionary['a', 1, 'b', 2, 'c', 3]
64
- h2 = Dictionary['d', 4]
65
- r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
66
- assert_equal( r, h1.update(h2) )
67
- assert_equal( r, h1 )
68
- # with other hash
69
- h1 = Dictionary['a', 1, 'b', 2, 'c', 3]
70
- h2 = { 'd' => 4 }
71
- r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
72
- assert_equal( r, h1.update(h2) )
73
- assert_equal( r, h1 )
74
- end
75
-
76
- def test_merge
77
- # with other orderred hash
78
- h1 = Dictionary['a', 1, 'b', 2, 'c', 3]
79
- h2 = Dictionary['d', 4]
80
- r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
81
- assert_equal( r, h1.merge(h2) )
82
- # with other hash
83
- h1 = Dictionary['a', 1, 'b', 2, 'c', 3]
84
- h2 = { 'd' => 4 }
85
- r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
86
- assert_equal( r, h1.merge(h2) )
87
- end
88
-
89
- def test_order_by
90
- h1 = Dictionary['a', 3, 'b', 2, 'c', 1]
91
- h1.order_by{ |k,v| v }
92
- assert_equal( [1,2,3], h1.values )
93
- assert_equal( ['c','b','a'], h1.keys )
94
- end
95
-
96
- def test_op_store
97
- h1 = Dictionary[]
98
- h1[:a] = 1
99
- h1[:c] = 3
100
- assert_equal( [1,3], h1.values )
101
- h1[:b,1] = 2
102
- assert_equal( [1,2,3], h1.values )
103
- assert_equal( [:a,:b,:c], h1.keys )
104
- end
105
-
106
- def test_reverse!
107
- hsh = Dictionary['z', 1, 'a', 2, 'c', 3]
108
- hsh.reverse!
109
- assert_equal( ['c','a','z'], hsh.keys )
110
- end
111
-
112
- def test_enumerable
113
- h1 = Dictionary[]
114
- h1[:a] = "a"
115
- h1[:c] = "b"
116
- assert_equal( ["A","B"], h1.collect{|k,v| v.capitalize} )
117
- end
1
+ # _____ _
2
+ # |_ _|__ ___| |_
3
+ # | |/ _ \/ __| __|
4
+ # | | __/\__ \ |
5
+ # |_|\___||___/\__|
6
+ #
7
+ # for lib/facets/dictionary.rb
118
8
 
9
+ require 'facets/dictionary.rb'
10
+
11
+ require 'test/unit'
12
+
13
+ class TC_Dictionary < Test::Unit::TestCase
14
+
15
+ def test_create
16
+ d = Dictionary['z', 1, 'a', 2, 'c', 3]
17
+ assert_equal( ['z','a','c'], d.keys )
18
+ end
19
+
20
+ def test_op_store
21
+ d = Dictionary.new
22
+ d['z'] = 1
23
+ d['a'] = 2
24
+ d['c'] = 3
25
+ assert_equal( ['z','a','c'], d.keys )
26
+ end
27
+
28
+ def test_push
29
+ d = Dictionary['a', 1, 'c', 2, 'z', 3]
30
+ assert( d.push('end', 15) )
31
+ assert_equal( 15, d['end'] )
32
+ assert( ! d.push('end', 30) )
33
+ assert( d.unshift('begin', 50) )
34
+ assert_equal( 50, d['begin'] )
35
+ assert( ! d.unshift('begin', 60) )
36
+ assert_equal( ["begin", "a", "c", "z", "end"], d.keys )
37
+ assert_equal( ["end", 15], d.pop )
38
+ assert_equal( ["begin", "a", "c", "z"], d.keys )
39
+ assert_equal( ["begin", 50], d.shift )
40
+ end
41
+
42
+ def test_insert
43
+ # front
44
+ d = Dictionary['a', 1, 'b', 2, 'c', 3]
45
+ r = Dictionary['d', 4, 'a', 1, 'b', 2, 'c', 3]
46
+ assert_equal( 4, d.insert(0,'d',4) )
47
+ assert_equal( r, d )
48
+ # back
49
+ d = Dictionary['a', 1, 'b', 2, 'c', 3]
50
+ r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
51
+ assert_equal( 4, d.insert(-1,'d',4) )
52
+ assert_equal( r, d )
119
53
  end
120
54
 
55
+ def test_update
56
+ # with other orderred hash
57
+ d = Dictionary['a', 1, 'b', 2, 'c', 3]
58
+ c = Dictionary['d', 4]
59
+ r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
60
+ assert_equal( r, d.update(c) )
61
+ assert_equal( r, d )
62
+ # with other hash
63
+ d = Dictionary['a', 1, 'b', 2, 'c', 3]
64
+ c = { 'd' => 4 }
65
+ r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
66
+ assert_equal( r, d.update(c) )
67
+ assert_equal( r, d )
68
+ end
69
+
70
+ def test_merge
71
+ # with other orderred hash
72
+ d = Dictionary['a', 1, 'b', 2, 'c', 3]
73
+ c = Dictionary['d', 4]
74
+ r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
75
+ assert_equal( r, d.merge(c) )
76
+ # with other hash
77
+ d = Dictionary['a', 1, 'b', 2, 'c', 3]
78
+ c = { 'd' => 4 }
79
+ r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4]
80
+ assert_equal( r, d.merge(c) )
81
+ end
121
82
 
83
+ def test_order_by
84
+ d = Dictionary['a', 3, 'b', 2, 'c', 1]
85
+ d.order_by{ |k,v| v }
86
+ assert_equal( [1,2,3], d.values )
87
+ assert_equal( ['c','b','a'], d.keys )
88
+ end
89
+
90
+ def test_op_store
91
+ d = Dictionary[]
92
+ d[:a] = 1
93
+ d[:c] = 3
94
+ assert_equal( [1,3], d.values )
95
+ d[:b,1] = 2
96
+ assert_equal( [1,2,3], d.values )
97
+ assert_equal( [:a,:b,:c], d.keys )
98
+ end
99
+
100
+ def test_reverse!
101
+ d = Dictionary['z', 1, 'a', 2, 'c', 3]
102
+ d.reverse!
103
+ assert_equal( ['c','a','z'], d.keys )
104
+ end
105
+
106
+ def test_enumerable
107
+ d = Dictionary[]
108
+ d[:a] = "a"
109
+ d[:c] = "b"
110
+ assert_equal( ["A","B"], d.collect{|k,v| v.capitalize} )
111
+ end
112
+
113
+ def test_autohash
114
+ d = Dictionary.new{ |hash,key| hash[key] = 0 }
115
+ d[:a] = 0
116
+ d[:b] += 1
117
+ assert_equal([0, 1], d.values)
118
+ assert_equal([:a,:b], d.keys)
119
+ end
120
+
121
+ def test_dup_with_array_values
122
+ d = Dictionary.new
123
+ d.dup
124
+ d[:a]=['t',5]
125
+ assert_equal(d, d.dup)
126
+ end
127
+ end
122
128