-
-
Notifications
You must be signed in to change notification settings - Fork 353
/
MCSortingTest.class.st
71 lines (64 loc) · 2.12 KB
/
MCSortingTest.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Class {
#name : #MCSortingTest,
#superclass : #TestCase,
#category : #'Monticello-Tests-Sorting'
}
{ #category : #testing }
MCSortingTest class >> isUnitTest [
^false
]
{ #category : #building }
MCSortingTest >> classNamed: aSymbol [
^ MCClassDefinition
name: aSymbol
superclassName: #Object
category: ''
instVarNames: #()
comment: ''
]
{ #category : #building }
MCSortingTest >> methodNamed: aSymbol class: className meta: aBoolean [
^ MCMethodDefinition
className: className
classIsMeta: aBoolean
selector: aSymbol
category: ''
timeStamp: ''
source: ''
]
{ #category : #actions }
MCSortingTest >> sortDefinitions: aCollection [
^ aCollection asSortedCollection asArray
]
{ #category : #building }
MCSortingTest >> sortKeyFor: aDefinition [
^ String streamContents:
[:s |
aDefinition description
do: [:ea | s nextPutAll: ea asString]
separatedBy: [s nextPut: $.]]
]
{ #category : #tests }
MCSortingTest >> testConsistentSorting [
| definitions shuffledAndSorted |
definitions := {(self methodNamed: #a class: #A meta: false) . (self methodNamed: #a class: #A meta: true).
(self methodNamed: #a class: #B meta: false) . (self methodNamed: #b class: #A meta: false) . (self methodNamed: #b class: #B meta: false).
(self classNamed: #A) . (self classNamed: #B)}.
shuffledAndSorted := (1 to: 100) collect: [ :ea | self sortDefinitions: definitions shuffled ].
self assert: shuffledAndSorted asSet size equals: 1
]
{ #category : #tests }
MCSortingTest >> testSortOrder [
| aA aAm aB bA bB A B cA bAm cAm |
aA := self methodNamed: #a class: #A meta: false.
bA := self methodNamed: #b class: #A meta: false.
cA := self methodNamed: #c class: #A meta: false.
aAm := self methodNamed: #a class: #A meta: true.
bAm := self methodNamed: #b class: #A meta: true.
cAm := self methodNamed: #c class: #A meta: true.
aB := self methodNamed: #a class: #B meta: false.
bB := self methodNamed: #b class: #B meta: false.
A := self classNamed: #A.
B := self classNamed: #B.
self assert: (self sortDefinitions: {aA . aAm . cAm . aB . bAm . bA . bB . A . cA . B}) equals: {A . aAm . bAm . cAm . aA . bA . cA . B . aB . bB}
]