kyanite 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/0 start all Tests.bat +23 -0
- data/History.txt +4 -0
- data/License.txt +21 -0
- data/Manifest.txt +88 -0
- data/PostInstall.txt +4 -0
- data/README.txt +48 -0
- data/Rakefile.rb +79 -0
- data/init.rb +2 -0
- data/lib/kyanite.rb +39 -0
- data/lib/kyanite/array.rb +5 -0
- data/lib/kyanite/array/array.rb +172 -0
- data/lib/kyanite/array/array2.rb +140 -0
- data/lib/kyanite/array/matrix2.rb +120 -0
- data/lib/kyanite/array_of_enumerables.rb +2 -0
- data/lib/kyanite/array_of_numerics.rb +2 -0
- data/lib/kyanite/array_of_strings.rb +2 -0
- data/lib/kyanite/basics.rb +60 -0
- data/lib/kyanite/dictionary.rb +116 -0
- data/lib/kyanite/enumerable.rb +7 -0
- data/lib/kyanite/enumerable/enumerable_enumerables.rb +70 -0
- data/lib/kyanite/enumerable/enumerable_numerics.rb +171 -0
- data/lib/kyanite/enumerable/enumerable_strings.rb +58 -0
- data/lib/kyanite/enumerable/structure.rb +170 -0
- data/lib/kyanite/general.rb +8 -0
- data/lib/kyanite/general/callerutils.rb +128 -0
- data/lib/kyanite/general/classutils.rb +246 -0
- data/lib/kyanite/general/kernel.rb +105 -0
- data/lib/kyanite/general/nil.rb +64 -0
- data/lib/kyanite/general/object.rb +86 -0
- data/lib/kyanite/general/true_false.rb +65 -0
- data/lib/kyanite/general/undoable.rb +24 -0
- data/lib/kyanite/hash.rb +170 -0
- data/lib/kyanite/matrix2.rb +2 -0
- data/lib/kyanite/nil.rb +3 -0
- data/lib/kyanite/numeric.rb +4 -0
- data/lib/kyanite/numeric/float.rb +26 -0
- data/lib/kyanite/numeric/integer.rb +34 -0
- data/lib/kyanite/numeric/numeric.rb +45 -0
- data/lib/kyanite/operation.rb +5 -0
- data/lib/kyanite/operation/call_tracker.rb +69 -0
- data/lib/kyanite/operation/rake.rb +101 -0
- data/lib/kyanite/operation/regexp.rb +23 -0
- data/lib/kyanite/operation/unit_test.rb +53 -0
- data/lib/kyanite/optimizer.rb +119 -0
- data/lib/kyanite/rake.rb +2 -0
- data/lib/kyanite/range.rb +54 -0
- data/lib/kyanite/set.rb +219 -0
- data/lib/kyanite/smart_load_path.rb +2 -0
- data/lib/kyanite/string.rb +13 -0
- data/lib/kyanite/string/cast.rb +104 -0
- data/lib/kyanite/string/chars.rb +184 -0
- data/lib/kyanite/string/chars_const.rb +190 -0
- data/lib/kyanite/string/diff.rb +78 -0
- data/lib/kyanite/string/div.rb +19 -0
- data/lib/kyanite/string/include.rb +43 -0
- data/lib/kyanite/string/list.rb +84 -0
- data/lib/kyanite/string/mgsub.rb +35 -0
- data/lib/kyanite/string/nested.rb +253 -0
- data/lib/kyanite/string/random.rb +69 -0
- data/lib/kyanite/string/split.rb +136 -0
- data/lib/kyanite/symbol.rb +19 -0
- data/lib/kyanite/tree.rb +99 -0
- data/lib/kyanite/undoable.rb +2 -0
- data/lib/kyanite/unit_test.rb +2 -0
- data/test/_start_all.rb +17 -0
- data/test/array/test_array.rb +106 -0
- data/test/array/test_matrix2.rb +162 -0
- data/test/enumerable/test_enumerable_enumerables.rb +46 -0
- data/test/enumerable/test_enumerable_numerics.rb +93 -0
- data/test/enumerable/test_enumerable_strings.rb +22 -0
- data/test/enumerable/test_structure.rb +220 -0
- data/test/general/test_classutils.rb +45 -0
- data/test/general/test_nil.rb +44 -0
- data/test/general/test_object.rb +49 -0
- data/test/general/test_true_false.rb +28 -0
- data/test/numeric/test_numeric_integer.rb +28 -0
- data/test/string/test_cast.rb +108 -0
- data/test/string/test_chars.rb +255 -0
- data/test/string/test_diff.rb +95 -0
- data/test/string/test_list.rb +141 -0
- data/test/string/test_nested.rb +361 -0
- data/test/string/test_split.rb +187 -0
- data/test/test_dictionary.rb +128 -0
- data/test/test_hash.rb +59 -0
- data/test/test_optimizer.rb +150 -0
- data/test/test_range.rb +41 -0
- data/test/test_set.rb +210 -0
- data/test/test_tree.rb +94 -0
- metadata +217 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
|
2
|
+
require 'kyanite/unit_test'
|
3
|
+
require 'kyanite/smart_load_path'; smart_load_path
|
4
|
+
require 'perception' if $0 == __FILE__
|
5
|
+
|
6
|
+
require 'kyanite/enumerable/enumerable_numerics'
|
7
|
+
|
8
|
+
class Array
|
9
|
+
include EnumerableNumerics
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
# Tests für EnumerableNumerics
|
14
|
+
#
|
15
|
+
class TestKyaniteEnumerableNumerics < UnitTest
|
16
|
+
|
17
|
+
|
18
|
+
def test_sum
|
19
|
+
assert_equal 2, [2].summation
|
20
|
+
assert_equal 4, [2,2].summation
|
21
|
+
assert_equal 6, [2,2,2].summation
|
22
|
+
assert_equal 8, [2,2,2,2].summation
|
23
|
+
assert_equal 8.5, [2,2,2,2,0.5].summation
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
def test_prd
|
29
|
+
assert_equal 2, [2].prd
|
30
|
+
assert_equal 6, [2,3].prd
|
31
|
+
assert_equal -12, [2,2,-3].prd
|
32
|
+
assert_equal 1, [0.5,0.5,2,2].prd
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def test_avg
|
37
|
+
a = [1,2,3,4,5,6,7,8,9]
|
38
|
+
assert_equal 5.0, a.average
|
39
|
+
|
40
|
+
assert_equal 2, [2].avg
|
41
|
+
assert_equal 2.5, [2,3].avg
|
42
|
+
assert_equal 2.5, [3,2].avg
|
43
|
+
assert_equal 0.33333333333333, [2,2,-3].avg
|
44
|
+
assert_equal 1.25, [0.5,0.5,2,2].avg
|
45
|
+
|
46
|
+
assert_equal 75, [ 50, 100 ].mean_arithmetric
|
47
|
+
assert_equal 66.6666666666667, [ 50, 100 ].mean_harmonic
|
48
|
+
assert_equal 70.7106781186548, [ 50, 100 ].mean_geometric
|
49
|
+
|
50
|
+
assert_equal 66.6666666666667, [ 100, 0, 100 ].mean_arithmetric
|
51
|
+
assert_equal 66.6666667, [ 100, 0.0000001, 100 ].mean_arithmetric
|
52
|
+
assert_equal 0.0, [ 100, 0, 100 ].mean_harmonic
|
53
|
+
assert_equal 2.999999994e-007, [ 100, 0.0000001, 100 ].mean_harmonic
|
54
|
+
assert_equal 0, [ 100, 0, 100 ].mean_geometric
|
55
|
+
assert_equal 0.1, [ 100, 0.0000001, 100 ].mean_geometric
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def test_mean_harmonic
|
60
|
+
assert_equal 66.6666666666667, [ 50, 100 ].mean_harmonic
|
61
|
+
assert_equal 0.0, [ 100, 0, 100 ].mean_harmonic
|
62
|
+
assert_equal 2.999999994e-007, [ 100, 0.0000001, 100 ].mean_harmonic
|
63
|
+
assert_equal 4, [ 1, -2 ].mean_harmonic # formal richtig, aber sinnlos
|
64
|
+
assert_equal -0.5, [ 1, -2 ].mean_harmonic(:allow_negative => true)
|
65
|
+
assert_equal -0.5, [ 1, 1, -2, -2 ].mean_harmonic(:allow_negative => true)
|
66
|
+
assert_equal -2, [ -2, -2 ].mean_harmonic(:allow_negative => true)
|
67
|
+
assert_equal 2, [ 2, 2 ].mean_harmonic(:allow_negative => true)
|
68
|
+
assert_equal 0, [ -2, 2 ].mean_harmonic(:allow_negative => true)
|
69
|
+
assert_equal 0, [ 2, -2 ].mean_harmonic(:allow_negative => true)
|
70
|
+
assert_equal 0.666666666666667, [ 2, 2, -2 ].mean_harmonic(:allow_negative => true)
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
def test_parallel
|
75
|
+
assert_equal 1, [1].parallel
|
76
|
+
assert_equal 0.5, [1,1].parallel
|
77
|
+
assert_equal 0.333333333333333, [1,1,1].parallel
|
78
|
+
assert_equal 0.25, [1,1,1,1].parallel
|
79
|
+
|
80
|
+
assert_equal 2, [2].parallel
|
81
|
+
assert_equal 1, [2,2].parallel
|
82
|
+
assert_equal 0.666666666666667, [2,2,2].parallel
|
83
|
+
assert_equal 0.5, [2,2,2,2].parallel
|
84
|
+
assert_equal 0.5, [2,2,1].parallel
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
end # class
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
require 'kyanite/unit_test'
|
3
|
+
require 'kyanite/smart_load_path'; smart_load_path
|
4
|
+
require 'perception' if $0 == __FILE__
|
5
|
+
|
6
|
+
require 'kyanite/enumerable/enumerable_strings'
|
7
|
+
|
8
|
+
class Array
|
9
|
+
include EnumerableStrings
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
# Tests für EnumerableStrings
|
14
|
+
#
|
15
|
+
class TestKyaniteEnumerableStrings < UnitTest
|
16
|
+
|
17
|
+
def test_palindrom_rumpf
|
18
|
+
test = ['lut', 'lutr', 'lutmi', 'lutmil', 'lutmila', 'lutrika', 'lutrik', 'lutri', 'lutr', 'lut']
|
19
|
+
assert_equal ['lutmi', 'lutmil', 'lutmila', 'lutrika', 'lutrik', 'lutri'], test.palindrom_rumpf
|
20
|
+
end
|
21
|
+
|
22
|
+
end # class
|
@@ -0,0 +1,220 @@
|
|
1
|
+
|
2
|
+
require 'kyanite/unit_test'
|
3
|
+
require 'kyanite/smart_load_path'; smart_load_path
|
4
|
+
require 'perception' if $0 == __FILE__
|
5
|
+
|
6
|
+
require 'kyanite/enumerable/structure'
|
7
|
+
require 'kyanite/dictionary'
|
8
|
+
require 'kyanite/set'
|
9
|
+
require 'kyanite/hash'
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
# Tests für Enumerable
|
14
|
+
#
|
15
|
+
class TestKyaniteEnumerableStructure < UnitTest
|
16
|
+
|
17
|
+
def test_is_collection
|
18
|
+
|
19
|
+
# keine Collection
|
20
|
+
assert ! 123.is_collection?
|
21
|
+
assert ! (123.4).is_collection?
|
22
|
+
assert ! (123.4).is_collection?
|
23
|
+
assert ! (:hallo).is_collection?
|
24
|
+
assert ! ''.is_collection?
|
25
|
+
assert ! /123/.is_collection?
|
26
|
+
assert ! Time.now.is_collection?
|
27
|
+
assert ! nil.is_collection?
|
28
|
+
assert ! true.is_collection?
|
29
|
+
assert ! false.is_collection?
|
30
|
+
assert ! Array.is_collection?
|
31
|
+
assert ! (1..4).is_collection? # Range gilt NICHT als Collection
|
32
|
+
|
33
|
+
# Collections
|
34
|
+
assert [1,2,3].is_collection?
|
35
|
+
assert [1].is_collection?
|
36
|
+
assert [].is_collection?
|
37
|
+
assert ['1','2','3'].is_collection?
|
38
|
+
assert ({}).is_collection?
|
39
|
+
assert ({:a => '1', :b => '2'}).is_collection?
|
40
|
+
assert Dictionary[1,2,3,4].is_collection?
|
41
|
+
|
42
|
+
Struct.new("Customer", :name, :adress)
|
43
|
+
struct = Struct::Customer.new("Dave", "123 main")
|
44
|
+
assert struct.is_collection?
|
45
|
+
|
46
|
+
end # test_is_collection?
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
def test_distribution_size
|
53
|
+
test = []
|
54
|
+
test << [ :a, :b, :c ]
|
55
|
+
test << [ 1, 2, 3, 4 ]
|
56
|
+
test << [ 'i', 'ii' ]
|
57
|
+
expected = [[2, 1],
|
58
|
+
[3, 1],
|
59
|
+
[4, 1]]
|
60
|
+
assert_equal expected, test.distribution
|
61
|
+
|
62
|
+
test = []
|
63
|
+
test << [ :a, :b, :c ]
|
64
|
+
test << [ 1, 2, 3 ]
|
65
|
+
test << [ 'i', 'ii', nil ]
|
66
|
+
assert_equal [[3, 3]], test.distribution
|
67
|
+
|
68
|
+
test = [ :a, :bbbbbb, :c ]
|
69
|
+
assert_equal [[1, 2], [6, 1]], test.distribution
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
def test_distribution_class
|
75
|
+
test = []
|
76
|
+
test << [ :a, :b, :c ]
|
77
|
+
test << [ 1, 2, 3, 4 ]
|
78
|
+
test << [ 'i', 'ii' ]
|
79
|
+
assert_equal [[Array, 3]], test.distribution(:class)
|
80
|
+
|
81
|
+
test = [ :a, :b, :c ]
|
82
|
+
assert_equal [[Symbol, 3]], test.distribution(:class)
|
83
|
+
|
84
|
+
test = []
|
85
|
+
test << [ :a, :b, :c ]
|
86
|
+
test << Set.new([ 1, 2, 3 ])
|
87
|
+
test << [ 'i', 'ii', nil ]
|
88
|
+
assert_equal [[Array, 2], [Set, 1]], test.distribution(:class)
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
def test_contentclass_mono
|
94
|
+
test = [ :a, :b, :c ]
|
95
|
+
assert_equal Symbol, test.contentclass
|
96
|
+
assert_equal Symbol, test.contentclass( :precision => 1 )
|
97
|
+
assert_equal Symbol, test.contentclass( :precision => 2 )
|
98
|
+
assert_equal Symbol, test.contentclass( :precision => :all )
|
99
|
+
|
100
|
+
test = [ 1, 2, 3, 4 ]
|
101
|
+
assert_equal Fixnum, test.contentclass
|
102
|
+
assert_equal Fixnum, test.contentclass( :precision => 1 )
|
103
|
+
assert_equal Fixnum, test.contentclass( :precision => 2 )
|
104
|
+
assert_equal Fixnum, test.contentclass( :precision => :all )
|
105
|
+
|
106
|
+
|
107
|
+
test = [ 'i', 'ii' ]
|
108
|
+
assert_equal String, test.contentclass
|
109
|
+
assert_equal String, test.contentclass( :precision => 1 )
|
110
|
+
assert_equal String, test.contentclass( :precision => 2 )
|
111
|
+
assert_equal String, test.contentclass( :precision => :all )
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
def test_contentclass_multi
|
116
|
+
test = [ 1, 2, 3, 4.0 ]
|
117
|
+
assert_equal Numeric, test.contentclass
|
118
|
+
assert_equal Fixnum, test.contentclass( :precision => 1 )
|
119
|
+
assert_equal Numeric, test.contentclass( :precision => 2 )
|
120
|
+
assert_equal Numeric, test.contentclass( :precision => :all )
|
121
|
+
|
122
|
+
test = [ 1, 2, 3, 4.0, 5 ]
|
123
|
+
assert_equal Fixnum, test.contentclass
|
124
|
+
assert_equal Fixnum, test.contentclass( :precision => 1 )
|
125
|
+
assert_equal Fixnum, test.contentclass( :precision => 2 )
|
126
|
+
assert_equal Numeric, test.contentclass( :precision => :all )
|
127
|
+
|
128
|
+
test = [ nil, 1, 2, 3, 4.0, 5 ]
|
129
|
+
assert_equal Fixnum, test.contentclass
|
130
|
+
assert_equal Fixnum, test.contentclass( :precision => 1 )
|
131
|
+
assert_equal Fixnum, test.contentclass( :precision => 2 )
|
132
|
+
assert_equal Numeric, test.contentclass( :precision => :all )
|
133
|
+
|
134
|
+
test = [ 1, 2, 3, 4.0, 5, nil ]
|
135
|
+
assert_equal Fixnum, test.contentclass
|
136
|
+
assert_equal Fixnum, test.contentclass( :precision => 1 )
|
137
|
+
assert_equal Fixnum, test.contentclass( :precision => 2 )
|
138
|
+
assert_equal Numeric, test.contentclass( :precision => :all )
|
139
|
+
|
140
|
+
test = [ nil, 1, 2, 3, 4.0, 5 ]
|
141
|
+
assert_equal Fixnum, test.contentclass
|
142
|
+
assert_equal NilClass, test.contentclass( :precision => 1, :ignore_nil => false )
|
143
|
+
assert_equal Object, test.contentclass( :precision => 2, :ignore_nil => false )
|
144
|
+
assert_equal Object, test.contentclass( :precision => :all, :ignore_nil => false )
|
145
|
+
|
146
|
+
|
147
|
+
test = [ nil ]
|
148
|
+
assert_equal nil, test.contentclass
|
149
|
+
assert_equal nil, test.contentclass( :precision => 1 )
|
150
|
+
assert_equal nil, test.contentclass( :precision => 2 )
|
151
|
+
assert_equal nil, test.contentclass( :precision => :all )
|
152
|
+
|
153
|
+
test = [ ]
|
154
|
+
assert_equal nil, test.contentclass
|
155
|
+
assert_equal nil, test.contentclass( :precision => 1 )
|
156
|
+
assert_equal nil, test.contentclass( :precision => 2 )
|
157
|
+
assert_equal nil, test.contentclass( :precision => :all )
|
158
|
+
|
159
|
+
test = [ nil ]
|
160
|
+
assert_equal NilClass, test.contentclass( :ignore_nil => false )
|
161
|
+
assert_equal NilClass, test.contentclass( :precision => 1, :ignore_nil => false )
|
162
|
+
assert_equal NilClass, test.contentclass( :precision => 2, :ignore_nil => false )
|
163
|
+
assert_equal NilClass, test.contentclass( :precision => :all, :ignore_nil => false )
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_contentclass_set_and_hash
|
168
|
+
test = SortedSet.new([ 1, 2, 3, 4.0 ])
|
169
|
+
assert_equal Numeric, test.contentclass
|
170
|
+
assert_equal Fixnum, test.contentclass( :precision => 1 )
|
171
|
+
assert_equal Numeric, test.contentclass( :precision => 2 )
|
172
|
+
assert_equal Numeric, test.contentclass( :precision => :all )
|
173
|
+
|
174
|
+
test = OrderedSet.new([ 1, 2, 3, 4.0 ])
|
175
|
+
assert_equal Numeric, test.contentclass
|
176
|
+
assert_equal Fixnum, test.contentclass( :precision => 1 )
|
177
|
+
assert_equal Numeric, test.contentclass( :precision => 2 )
|
178
|
+
assert_equal Numeric, test.contentclass( :precision => :all )
|
179
|
+
|
180
|
+
test = Set.new([ 1, 2, 3, 4 ])
|
181
|
+
assert_equal Fixnum, test.contentclass
|
182
|
+
assert_equal Fixnum, test.contentclass( :precision => 1 )
|
183
|
+
assert_equal Fixnum, test.contentclass( :precision => 2 )
|
184
|
+
assert_equal Fixnum, test.contentclass( :precision => :all )
|
185
|
+
|
186
|
+
test = {:b => 2, :a => 1, :c => 3}
|
187
|
+
assert_equal Fixnum, test.contentclass
|
188
|
+
assert_equal Fixnum, test.contentclass( :precision => 1 )
|
189
|
+
assert_equal Fixnum, test.contentclass( :precision => 2 )
|
190
|
+
assert_equal Fixnum, test.contentclass( :precision => :all )
|
191
|
+
|
192
|
+
test = Dictionary[ 'a', 1, 'b', 2, 'c', 3 ]
|
193
|
+
assert_equal Fixnum, test.contentclass
|
194
|
+
assert_equal Fixnum, test.contentclass( :precision => 1 )
|
195
|
+
assert_equal Fixnum, test.contentclass( :precision => 2 )
|
196
|
+
assert_equal Fixnum, test.contentclass( :precision => :all )
|
197
|
+
|
198
|
+
test = Dictionary[ 'a', 1, 'b', 2, 'c', 3.0 ]
|
199
|
+
assert_equal Numeric, test.contentclass
|
200
|
+
assert_equal Fixnum, test.contentclass( :precision => 1 )
|
201
|
+
assert_equal Numeric, test.contentclass( :precision => 2 )
|
202
|
+
assert_equal Numeric, test.contentclass( :precision => :all )
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
end # class
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
require 'kyanite/unit_test'
|
3
|
+
require 'kyanite/smart_load_path'; smart_load_path
|
4
|
+
require 'perception' if $0 == __FILE__
|
5
|
+
|
6
|
+
require 'kyanite/general/classutils'
|
7
|
+
|
8
|
+
class DummyClass1 # :nodoc:
|
9
|
+
end
|
10
|
+
module DummyModule # :nodoc:
|
11
|
+
class DummyClass2 # :nodoc:
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
class TestKyaniteClassutils < UnitTest
|
17
|
+
|
18
|
+
def test_to_class
|
19
|
+
assert_equal DummyClass1, 'DummyClass1'.to_class
|
20
|
+
assert_equal DummyClass1, 'dummy_class1'.to_class
|
21
|
+
assert_equal DummyClass1, :DummyClass1.to_class
|
22
|
+
assert_equal DummyClass1, :dummy_class1.to_class
|
23
|
+
assert_equal DummyClass1, DummyClass1.to_class
|
24
|
+
assert_equal DummyModule::DummyClass2, 'DummyModule::DummyClass2'.to_class
|
25
|
+
|
26
|
+
assert_equal nil, 'DummyClass2'.to_class
|
27
|
+
assert_equal nil, 'UserBlaBlubb'.to_class
|
28
|
+
assert_equal nil, 'user_bla_blubb'.to_class
|
29
|
+
assert_equal nil, nil.to_class
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def test_to_classname
|
34
|
+
assert_equal 'dummy_class1', 'DummyClass1'.to_classname
|
35
|
+
assert_equal 'dummy_class2', 'DummyModule::DummyClass2'.to_classname
|
36
|
+
|
37
|
+
assert_equal 'dummy_class1', DummyClass1.to_classname
|
38
|
+
assert_equal 'dummy_class2', DummyModule::DummyClass2.to_classname
|
39
|
+
|
40
|
+
assert_equal '', nil.to_classname
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
end # class
|
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
require 'kyanite/unit_test'
|
3
|
+
require 'kyanite/smart_load_path'; smart_load_path
|
4
|
+
require 'perception' if $0 == __FILE__
|
5
|
+
|
6
|
+
require 'kyanite/general/nil'
|
7
|
+
|
8
|
+
class TestKyaniteNil < UnitTest
|
9
|
+
|
10
|
+
def test_nil_patches
|
11
|
+
assert nil.empty?
|
12
|
+
|
13
|
+
assert ! nil.include?('g')
|
14
|
+
assert ! nil.include?(nil)
|
15
|
+
|
16
|
+
assert_nil nil.to_nil
|
17
|
+
assert_equal 0, nil.size
|
18
|
+
assert_equal 0, nil.length
|
19
|
+
|
20
|
+
assert_equal nil, nil + 42
|
21
|
+
assert_equal nil, nil + '42'
|
22
|
+
assert_equal '', nil.to_s
|
23
|
+
|
24
|
+
assert_nil nil[1]
|
25
|
+
assert_nil nil[1,2]
|
26
|
+
assert_nil nil[1][2]
|
27
|
+
assert_nil nil[1][2,3][4]
|
28
|
+
assert_nil nil[nil]
|
29
|
+
assert_nil nil[nil,nil]
|
30
|
+
assert_nil nil[nil][nil]
|
31
|
+
|
32
|
+
assert_equal 42, nil[1] = 42
|
33
|
+
assert_equal 42, nil[1,2] = 42
|
34
|
+
assert_equal 42, nil[1][2] = 42
|
35
|
+
assert_equal 42, nil[1][2,3][4] = 42
|
36
|
+
assert_equal 42, nil[nil] = 42
|
37
|
+
assert_equal 42, nil[nil,nil] = 42
|
38
|
+
assert_equal 42, nil[nil][nil] = 42
|
39
|
+
|
40
|
+
end # test_nil_patches
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
end # class
|
@@ -0,0 +1,49 @@
|
|
1
|
+
|
2
|
+
require 'kyanite/unit_test'
|
3
|
+
require 'kyanite/smart_load_path'; smart_load_path
|
4
|
+
require 'perception' if $0 == __FILE__
|
5
|
+
|
6
|
+
require 'kyanite/general/object'
|
7
|
+
|
8
|
+
|
9
|
+
class TestKyaniteObject < UnitTest
|
10
|
+
|
11
|
+
def test_is_numeric
|
12
|
+
assert 1.2345.is_numeric? #=> 1.2345
|
13
|
+
assert 12345678987654321.is_numeric? #=> 1.23456789876543e+16
|
14
|
+
assert 0.is_numeric? #=> 0.0
|
15
|
+
assert 0.0.is_numeric? #=> 0.0
|
16
|
+
assert ".001".is_numeric? #=> 0.001
|
17
|
+
assert 123435.12345.is_numeric? #=> 123435.12345
|
18
|
+
assert ! "123435.".is_numeric?
|
19
|
+
assert "1.50130937545297e+68".is_numeric? #=> 1.50130937545297e+68
|
20
|
+
assert ! "a".is_numeric?
|
21
|
+
assert ! "a42".is_numeric?
|
22
|
+
assert ! "42a".is_numeric?
|
23
|
+
assert 123.42.is_numeric? #=> 123.42
|
24
|
+
assert "1_2_3.42".is_numeric? #=> 123.42
|
25
|
+
assert ! "_1_2_3_.42_".is_numeric?
|
26
|
+
assert ! "__1__2_3_.42__".is_numeric?
|
27
|
+
assert ! nil.is_numeric?
|
28
|
+
assert ! true.is_numeric?
|
29
|
+
assert ! false.is_numeric?
|
30
|
+
assert ! [].is_numeric?
|
31
|
+
assert ! [1].is_numeric?
|
32
|
+
assert ! [1,2].is_numeric?
|
33
|
+
assert ! Fixnum.is_numeric?
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
def test_blank
|
39
|
+
#assert_equal true, ''.blank? # ok
|
40
|
+
# assert_equal false, nil.blank?
|
41
|
+
assert_equal false, 1.blank? # ok
|
42
|
+
assert_equal false, 'a'.blank? # ok
|
43
|
+
assert_equal false, true.blank? # ok
|
44
|
+
assert_equal false, false.blank? # ok
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
end # class
|