/
TCopyTest.trait.st
173 lines (141 loc) · 5.16 KB
/
TCopyTest.trait.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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
167
168
169
170
171
172
173
"
Tests whether a copied object contains the same elements than its source.
Note that the order is not garanteed -- see TEqualityTest for that.
"
Trait {
#name : #TCopyTest,
#category : #'Collections-Tests-Abstract'
}
{ #category : #requirements }
TCopyTest >> collectionNotIncluded [
" return a collection for wich each element is not included in 'nonEmpty' "
^ self explicitRequirement
]
{ #category : #requirements }
TCopyTest >> collectionWithElementsToRemove [
" return a collection of elements included in 'nonEmpty' "
^ self explicitRequirement
]
{ #category : #requirements }
TCopyTest >> elementToAdd [
" return an element of type 'nonEmpy' elements'type' not yet included in nonEmpty"
^ self explicitRequirement
]
{ #category : #requirements }
TCopyTest >> empty [
^ self explicitRequirement
]
{ #category : #requirements }
TCopyTest >> nonEmpty [
^ self explicitRequirement
]
{ #category : #'tests - fixture' }
TCopyTest >> test0CopyTest [
self empty.
self assertEmpty: self empty.
self nonEmpty.
self denyEmpty: self nonEmpty notEmpty.
self collectionWithElementsToRemove.
self denyEmpty: self collectionWithElementsToRemove notEmpty.
self collectionWithElementsToRemove do: [ :each | self assert: (self nonEmpty includes: each) ].
self elementToAdd.
self deny: (self nonEmpty includes: self elementToAdd).
self collectionNotIncluded do: [ :each | self deny: (self nonEmpty includes: each) ]
]
{ #category : #'tests - copy' }
TCopyTest >> testCopyEmptyWith [
| res anElement |
anElement := self elementToAdd.
res := self empty copyWith: anElement.
self assert: res size equals: (self empty size + 1).
self assert: (res includes: (anElement value))
]
{ #category : #'tests - copy' }
TCopyTest >> testCopyEmptyWithout [
| res |
res := self empty copyWithout: self elementToAdd.
self assert: res size equals: self empty size.
self deny: (res includes: self elementToAdd)
]
{ #category : #'tests - copy' }
TCopyTest >> testCopyEmptyWithoutAll [
| res |
res := self empty copyWithoutAll: self collectionWithElementsToRemove.
self assert: res size equals: self empty size.
self collectionWithElementsToRemove do: [ :each | self deny: (res includes: each) ]
]
{ #category : #'tests - copy' }
TCopyTest >> testCopyEquals [
"A copy should be equivalent to the things it's a copy of."
| copy |
copy := self nonEmpty copy.
self assert: copy equals: self nonEmpty
]
{ #category : #'tests - copy' }
TCopyTest >> testCopyNonEmptyWith [
| res anElement |
anElement := self elementToAdd .
res := self nonEmpty copyWith: anElement.
"Here we do not test the size since for a non empty set we would get a problem.
Then in addition copy is not about duplicate management. The element should
be in at the end."
self assert: (res includes: (anElement value)).
self nonEmpty do: [ :each | res includes: each ]
]
{ #category : #'tests - copy' }
TCopyTest >> testCopyNonEmptyWithout [
| res anElementOfTheCollection |
anElementOfTheCollection := self nonEmpty anyOne.
res := (self nonEmpty copyWithout: anElementOfTheCollection).
"here we do not test the size since for a non empty set we would get a problem.
Then in addition copy is not about duplicate management. The element should
be in at the end."
self deny: (res includes: anElementOfTheCollection).
self nonEmpty do:
[:each | (each = anElementOfTheCollection)
ifFalse: [self assert: (res includes: each)]]
]
{ #category : #'tests - copy' }
TCopyTest >> testCopyNonEmptyWithoutAll [
| res |
res := self nonEmpty copyWithoutAll: self collectionWithElementsToRemove.
"here we do not test the size since for a non empty set we would get a problem.
Then in addition copy is not about duplicate management. The element should
be in at the end."
self collectionWithElementsToRemove do: [ :each | self deny: (res includes: (each)) ].
self nonEmpty do:
[ :each |
(self collectionWithElementsToRemove includes: each) ifFalse: [ self assert: (res includes: each) ] ]
]
{ #category : #'tests - copy' }
TCopyTest >> testCopyNonEmptyWithoutAllNotIncluded [
| res |
res := self nonEmpty copyWithoutAll: self collectionNotIncluded.
"here we do not test the size since for a non empty set we would get a problem.
Then in addition copy is not about duplicate management. The element should
be in at the end."
self nonEmpty do: [ :each | self assert: (res includes: each) ]
]
{ #category : #'tests - copy' }
TCopyTest >> testCopyNonEmptyWithoutNotIncluded [
| res |
res := self nonEmpty copyWithout: self elementToAdd.
"here we do not test the size since for a non empty set we would get a problem.
Then in addition copy is not about duplicate management. The element should
be in at the end."
self nonEmpty do: [ :each | self assert: (res includes: each) ]
]
{ #category : #'tests - copy' }
TCopyTest >> testCopyNotSame [
"A copy of a collection should always be of the same class as the instance it copies"
| copy |
copy := self nonEmpty copy.
self deny: copy == self nonEmpty
]
{ #category : #'tests - copy' }
TCopyTest >> testCopySameClass [
"A copy of a collection should always be of the same class as the instance it copies"
| copy |
copy := self empty copy.
self assert: copy class == self empty class
]