--- a/RegressionTests__CollectionTests.st Wed Mar 07 13:19:22 2012 +0100
+++ b/RegressionTests__CollectionTests.st Wed Apr 11 21:52:30 2012 +0200
@@ -43,6 +43,21 @@
!CollectionTests methodsFor:'helpers'!
+checkSorted:aSortedCollection with:sortBlock against:anOriginalCollection
+ |first|
+
+ self assert:aSortedCollection size = anOriginalCollection size.
+
+ "is it sorted?"
+ first := true.
+ aSortedCollection inject:nil into:[:last :each|
+ first ifTrue:[first := false]
+ ifFalse:[self assert:(sortBlock value:last value:each)]. each].
+
+ "same elements as in original?"
+ self assert:(aSortedCollection asBag = anOriginalCollection asBag).
+!
+
collectedDoArgsOf:aCollection
|collectedDoArgs|
@@ -440,6 +455,42 @@
"
self new testOrderedCollection04_SortNilsInCollection
"
+!
+
+testOrderedCollection05_SortRandomCollection
+ |data sorted rg coData checkBlock|
+
+ checkBlock := [:a :b| a <= b].
+ rg := Random new.
+
+ #(1 4 11 2000 20011 200000) do:[:eachSize|
+ data := Array new:eachSize.
+ 1 to:data size do:[:i |
+ data at:i put:(rg nextIntegerBetween:1 and:100).
+ ].
+ sorted := data copy sort.
+ self checkSorted:sorted with:checkBlock against:data.
+ sorted := sorted sort.
+ self checkSorted:sorted with:checkBlock against:data.
+ sorted := sorted reverse sort.
+ self checkSorted:sorted with:checkBlock against:data.
+
+ coData := data copy.
+ sorted := data copy sortWith:coData.
+ self checkSorted:sorted with:checkBlock against:data.
+ self checkSorted:coData with:checkBlock against:data.
+
+ sorted := data copy sort:[:policy :a :b| a < b].
+ self checkSorted:sorted with:checkBlock against:data.
+
+ sorted := data copy sort:[:a :b| a < b].
+ self checkSorted:sorted with:checkBlock against:data.
+
+ coData := data copy.
+ sorted := data copy sort:[:a :b| a < b] with:coData.
+ self checkSorted:sorted with:checkBlock against:data.
+ self checkSorted:coData with:checkBlock against:data.
+ ].
! !
!CollectionTests methodsFor:'tests-orderedDictionary'!