Class: TestKyaniteEnumerableStructure
- Defined in
- test/enumerable/test_structure.rb
Enumerable Additions
- Kyanite definitions
- Kyanite tests and examples
- Usage
-
require 'kyanite/enumerable/structure'
Instance Method Summary (collapse)
- - (Object) test_contentclass_mono
- - (Object) test_contentclass_multi
- - (Object) test_contentclass_set_and_hash
- - (Object) test_distribution_class
- - (Object) test_distribution_size
- - (Object) test_is_collection
Instance Method Details
- (Object) test_contentclass_mono
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'test/enumerable/test_structure.rb', line 94 def test_contentclass_mono test = [ :a, :b, :c ] assert_equal Symbol, test.contentclass assert_equal Symbol, test.contentclass( :precision => 1 ) assert_equal Symbol, test.contentclass( :precision => 2 ) assert_equal Symbol, test.contentclass( :precision => :all ) test = [ 1, 2, 3, 4 ] assert_equal Fixnum, test.contentclass assert_equal Fixnum, test.contentclass( :precision => 1 ) assert_equal Fixnum, test.contentclass( :precision => 2 ) assert_equal Fixnum, test.contentclass( :precision => :all ) test = [ 'i', 'ii' ] assert_equal String, test.contentclass assert_equal String, test.contentclass( :precision => 1 ) assert_equal String, test.contentclass( :precision => 2 ) assert_equal String, test.contentclass( :precision => :all ) end |
- (Object) test_contentclass_multi
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'test/enumerable/test_structure.rb', line 116 def test_contentclass_multi test = [ 1, 2, 3, 4.0 ] assert_equal Numeric, test.contentclass assert_equal Fixnum, test.contentclass( :precision => 1 ) assert_equal Numeric, test.contentclass( :precision => 2 ) assert_equal Numeric, test.contentclass( :precision => :all ) test = [ 1, 2, 3, 4.0, 5 ] assert_equal Fixnum, test.contentclass assert_equal Fixnum, test.contentclass( :precision => 1 ) assert_equal Fixnum, test.contentclass( :precision => 2 ) assert_equal Numeric, test.contentclass( :precision => :all ) test = [ nil, 1, 2, 3, 4.0, 5 ] assert_equal Fixnum, test.contentclass assert_equal Fixnum, test.contentclass( :precision => 1 ) assert_equal Fixnum, test.contentclass( :precision => 2 ) assert_equal Numeric, test.contentclass( :precision => :all ) test = [ 1, 2, 3, 4.0, 5, nil ] assert_equal Fixnum, test.contentclass assert_equal Fixnum, test.contentclass( :precision => 1 ) assert_equal Fixnum, test.contentclass( :precision => 2 ) assert_equal Numeric, test.contentclass( :precision => :all ) test = [ nil, 1, 2, 3, 4.0, 5 ] assert_equal Fixnum, test.contentclass assert_equal NilClass, test.contentclass( :precision => 1, :ignore_nil => false ) assert_equal Object, test.contentclass( :precision => 2, :ignore_nil => false ) assert_equal Object, test.contentclass( :precision => :all, :ignore_nil => false ) test = [ nil ] assert_equal nil, test.contentclass assert_equal nil, test.contentclass( :precision => 1 ) assert_equal nil, test.contentclass( :precision => 2 ) assert_equal nil, test.contentclass( :precision => :all ) test = [ ] assert_equal nil, test.contentclass assert_equal nil, test.contentclass( :precision => 1 ) assert_equal nil, test.contentclass( :precision => 2 ) assert_equal nil, test.contentclass( :precision => :all ) test = [ nil ] assert_equal NilClass, test.contentclass( :ignore_nil => false ) assert_equal NilClass, test.contentclass( :precision => 1, :ignore_nil => false ) assert_equal NilClass, test.contentclass( :precision => 2, :ignore_nil => false ) assert_equal NilClass, test.contentclass( :precision => :all, :ignore_nil => false ) end |
- (Object) test_contentclass_set_and_hash
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'test/enumerable/test_structure.rb', line 168 def test_contentclass_set_and_hash test = SortedSet.new([ 1, 2, 3, 4.0 ]) assert_equal Numeric, test.contentclass assert_equal Fixnum, test.contentclass( :precision => 1 ) assert_equal Numeric, test.contentclass( :precision => 2 ) assert_equal Numeric, test.contentclass( :precision => :all ) test = OrderedSet.new([ 1, 2, 3, 4.0 ]) assert_equal Numeric, test.contentclass assert_equal Fixnum, test.contentclass( :precision => 1 ) assert_equal Numeric, test.contentclass( :precision => 2 ) assert_equal Numeric, test.contentclass( :precision => :all ) test = Set.new([ 1, 2, 3, 4 ]) assert_equal Fixnum, test.contentclass assert_equal Fixnum, test.contentclass( :precision => 1 ) assert_equal Fixnum, test.contentclass( :precision => 2 ) assert_equal Fixnum, test.contentclass( :precision => :all ) test = {:b => 2, :a => 1, :c => 3} assert_equal Fixnum, test.contentclass assert_equal Fixnum, test.contentclass( :precision => 1 ) assert_equal Fixnum, test.contentclass( :precision => 2 ) assert_equal Fixnum, test.contentclass( :precision => :all ) test = Dictionary[ 'a', 1, 'b', 2, 'c', 3 ] assert_equal Fixnum, test.contentclass assert_equal Fixnum, test.contentclass( :precision => 1 ) assert_equal Fixnum, test.contentclass( :precision => 2 ) assert_equal Fixnum, test.contentclass( :precision => :all ) test = Dictionary[ 'a', 1, 'b', 2, 'c', 3.0 ] assert_equal Numeric, test.contentclass assert_equal Fixnum, test.contentclass( :precision => 1 ) assert_equal Numeric, test.contentclass( :precision => 2 ) assert_equal Numeric, test.contentclass( :precision => :all ) end |
- (Object) test_distribution_class
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'test/enumerable/test_structure.rb', line 75 def test_distribution_class test = [] test << [ :a, :b, :c ] test << [ 1, 2, 3, 4 ] test << [ 'i', 'ii' ] assert_equal [[Array, 3]], test.distribution(:class) test = [ :a, :b, :c ] assert_equal [[Symbol, 3]], test.distribution(:class) test = [] test << [ :a, :b, :c ] test << Set.new([ 1, 2, 3 ]) test << [ 'i', 'ii', nil ] assert_equal [[Array, 2], [Set, 1]], test.distribution(:class) end |
- (Object) test_distribution_size
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'test/enumerable/test_structure.rb', line 53 def test_distribution_size test = [] test << [ :a, :b, :c ] test << [ 1, 2, 3, 4 ] test << [ 'i', 'ii' ] expected = [[2, 1], [3, 1], [4, 1]] assert_equal expected, test.distribution test = [] test << [ :a, :b, :c ] test << [ 1, 2, 3 ] test << [ 'i', 'ii', nil ] assert_equal [[3, 3]], test.distribution test = [ :a, :bbbbbb, :c ] assert_equal [[1, 2], [6, 1]], test.distribution end |
- (Object) test_is_collection
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'test/enumerable/test_structure.rb', line 18 def test_is_collection # keine Collection assert ! 123.is_collection? assert ! (123.4).is_collection? assert ! (123.4).is_collection? assert ! (:hallo).is_collection? assert ! ''.is_collection? assert ! /123/.is_collection? assert ! Time.now.is_collection? assert ! nil.is_collection? assert ! true.is_collection? assert ! false.is_collection? assert ! Array.is_collection? assert ! (1..4).is_collection? # Range gilt NICHT als Collection # Collections assert [1,2,3].is_collection? assert [1].is_collection? assert [].is_collection? assert ['1','2','3'].is_collection? assert ({}).is_collection? assert ({:a => '1', :b => '2'}).is_collection? assert Dictionary[1,2,3,4].is_collection? Struct.new("Customer", :name, :adress) struct = Struct::Customer.new("Dave", "123 main") assert struct.is_collection? end |