RegressionTests__CollectionTests.st
changeset 615 3a61700c6e88
parent 585 440a4221854e
child 639 a02e4406e10d
equal deleted inserted replaced
614:61a039961050 615:3a61700c6e88
   101     "Modified: / 04-07-2011 / 19:28:39 / cg"
   101     "Modified: / 04-07-2011 / 19:28:39 / cg"
   102 ! !
   102 ! !
   103 
   103 
   104 !CollectionTests methodsFor:'tests-general'!
   104 !CollectionTests methodsFor:'tests-general'!
   105 
   105 
   106 doTestGeneralCollectionOperationsIn:aClass
   106 doTestDictionaryLikeAddRemoveOperationsIn:aClass
   107     |coll|
   107     |coll|
   108 
   108 
   109     coll := aClass new.
   109     coll := aClass new.
   110 
   110 
   111     self assert: ( coll size == 0 ).
   111     self assert: ( coll size == 0 ).
   112     self assert: ( coll isEmpty ).
   112     self assert: ( coll isEmpty ).
   113     self assert: ( coll notEmpty not ).
   113     self assert: ( coll notEmpty not ).
   114     self assert: ( coll isEmptyOrNil ).
   114     self assert: ( coll isEmptyOrNil ).
   115     self assert: ( coll notEmptyOrNil not ).
   115     self assert: ( coll notEmptyOrNil not ).
   116 
   116 
       
   117     coll at:1 put:'one'.
       
   118 
       
   119     self assert: ( coll size == 1 ).
       
   120     self assert: ( coll isEmpty not).
       
   121     self assert: ( coll notEmpty ).
       
   122     self assert: ( coll isEmptyOrNil not ).
       
   123     self assert: ( coll notEmptyOrNil ).
       
   124 
       
   125     coll at:2 put:'two'.
       
   126 
       
   127     self assert: ( coll size == 2 ).
       
   128     self assert: ( coll isEmpty not).
       
   129     self assert: ( coll notEmpty ).
       
   130     self assert: ( coll isEmptyOrNil not ).
       
   131     self assert: ( coll notEmptyOrNil ).
       
   132 
       
   133     coll removeKey:2.
       
   134     self assert: ( coll size == 1 ).
       
   135     self assert: ( coll isEmpty not).
       
   136     self assert: ( coll notEmpty ).
       
   137     self assert: ( coll isEmptyOrNil not ).
       
   138     self assert: ( coll notEmptyOrNil ).
       
   139 
       
   140     coll removeKey:1.
       
   141     self assert: ( coll size == 0 ).
       
   142     self assert: ( coll isEmpty ).
       
   143     self assert: ( coll notEmpty not ).
       
   144     self assert: ( coll isEmptyOrNil ).
       
   145     self assert: ( coll notEmptyOrNil not ).
       
   146 
       
   147     "
       
   148      self basicNew doTestDictionaryLikeAddRemoveOperations
       
   149     "
       
   150 
       
   151     "Created: / 08-08-2011 / 16:01:14 / cg"
       
   152 !
       
   153 
       
   154 doTestGeneralAddRemoveOperationsIn:aClass
       
   155     |coll|
       
   156 
       
   157     coll := aClass new.
       
   158 
       
   159     self assert: ( coll size == 0 ).
       
   160     self assert: ( coll isEmpty ).
       
   161     self assert: ( coll notEmpty not ).
       
   162     self assert: ( coll isEmptyOrNil ).
       
   163     self assert: ( coll notEmptyOrNil not ).
       
   164 
       
   165     coll add:1.
       
   166 
       
   167     self assert: ( coll size == 1 ).
       
   168     self assert: ( coll isEmpty not).
       
   169     self assert: ( coll notEmpty ).
       
   170     self assert: ( coll isEmptyOrNil not ).
       
   171     self assert: ( coll notEmptyOrNil ).
       
   172 
       
   173     coll add:2.
       
   174 
       
   175     self assert: ( coll size == 2 ).
       
   176     self assert: ( coll isEmpty not).
       
   177     self assert: ( coll notEmpty ).
       
   178     self assert: ( coll isEmptyOrNil not ).
       
   179     self assert: ( coll notEmptyOrNil ).
       
   180 
       
   181     coll remove:2.
       
   182     self assert: ( coll size == 1 ).
       
   183     self assert: ( coll isEmpty not).
       
   184     self assert: ( coll notEmpty ).
       
   185     self assert: ( coll isEmptyOrNil not ).
       
   186     self assert: ( coll notEmptyOrNil ).
       
   187 
       
   188     coll remove:1.
       
   189     self assert: ( coll size == 0 ).
       
   190     self assert: ( coll isEmpty ).
       
   191     self assert: ( coll notEmpty not ).
       
   192     self assert: ( coll isEmptyOrNil ).
       
   193     self assert: ( coll notEmptyOrNil not ).
       
   194 
       
   195     "
       
   196      self basicNew testGeneralOperations
       
   197     "
       
   198 
       
   199     "Created: / 08-08-2011 / 16:00:06 / cg"
       
   200 !
       
   201 
       
   202 doTestGeneralCollectionOperationsIn:aClass
       
   203     |coll|
       
   204 
       
   205     coll := aClass new.
       
   206 
       
   207     self assert: ( coll size == 0 ).
       
   208     self assert: ( coll isEmpty ).
       
   209     self assert: ( coll notEmpty not ).
       
   210     self assert: ( coll isEmptyOrNil ).
       
   211     self assert: ( coll notEmptyOrNil not ).
       
   212 
   117     self should: [ coll first ] raise:Error.
   213     self should: [ coll first ] raise:Error.
   118     self should: [ coll last ] raise:Error.
   214     self should: [ coll last ] raise:Error.
   119     self should: [ (coll at:1) ] raise:Error.
   215     self should: [ (coll at:1) ] raise:Error.
   120 
   216 
   121     self assert: ( (coll includes:0) not ).
   217     self assert: ( (coll includes:0) not ).
   122 
   218 
   123     "
   219     "
   124      self basicNew testGeneralOperations
   220      self basicNew testGeneralOperations
   125     "
   221     "
       
   222 !
       
   223 
       
   224 testDictionaryLikeAddRemoveOperations
       
   225     |classes|
       
   226 
       
   227     classes := OrderedCollection new.
       
   228     classes 
       
   229         add:Dictionary;
       
   230         add:IdentityDictionary;
       
   231         add:OrderedDictionary;
       
   232         add:BTree.
       
   233 
       
   234     classes do:[:eachClass |
       
   235         self doTestDictionaryLikeAddRemoveOperationsIn:eachClass
       
   236     ].
       
   237 
       
   238     "
       
   239      self basicNew testDictionaryLikeAddRemoveOperations
       
   240     "
       
   241 
       
   242     "Created: / 08-08-2011 / 15:59:52 / cg"
       
   243 !
       
   244 
       
   245 testGeneralAddRemoveOperations
       
   246     |classes|
       
   247 
       
   248     classes := OrderedCollection new.
       
   249     classes 
       
   250         "/ add:RunArray;
       
   251         add:Bag;
       
   252         add:Set;
       
   253         add:IdentitySet;
       
   254         "/add:Dictionary;
       
   255         "/add:IdentityDictionary;
       
   256         add:OrderedCollection;
       
   257         add:SortedCollection;
       
   258         "/add:Queue;
       
   259         "/add:Stack;
       
   260         add:SortedCollection;
       
   261         "/add:OrderedDictionary;
       
   262         add:OrderedSet.
       
   263         "/add:BTree.
       
   264 
       
   265     classes do:[:eachClass |
       
   266         self doTestGeneralAddRemoveOperationsIn:eachClass
       
   267     ].
       
   268 
       
   269     "
       
   270      self basicNew testGeneralAddRemoveOperations
       
   271     "
       
   272 
       
   273     "Created: / 08-08-2011 / 15:59:02 / cg"
   126 !
   274 !
   127 
   275 
   128 testGeneralOperations
   276 testGeneralOperations
   129     |classes|
   277     |classes|
   130 
   278 
   140         add:SortedCollection;
   288         add:SortedCollection;
   141         add:Queue;
   289         add:Queue;
   142         add:Stack;
   290         add:Stack;
   143         add:SortedCollection;
   291         add:SortedCollection;
   144         add:OrderedDictionary;
   292         add:OrderedDictionary;
   145         add:OrderedSet.
   293         add:OrderedSet;
       
   294         add:BTree.
   146 
   295 
   147     classes do:[:eachClass |
   296     classes do:[:eachClass |
   148         self doTestGeneralCollectionOperationsIn:eachClass
   297         self doTestGeneralCollectionOperationsIn:eachClass
   149     ].
   298     ].
   150 
   299 
   151     "
   300     "
   152      self basicNew testGeneralOperations
   301      self basicNew testGeneralOperations
   153     "
   302     "
       
   303 
       
   304     "Modified: / 08-08-2011 / 15:53:16 / cg"
   154 ! !
   305 ! !
   155 
   306 
   156 !CollectionTests methodsFor:'tests-interval'!
   307 !CollectionTests methodsFor:'tests-interval'!
   157 
   308 
   158 testInterval01
   309 testInterval01