@@ -64,15 +64,25 @@ interface Collection[E]
64
64
#
65
65
# assert [1,2,3].is_empty == false
66
66
# assert [1..1[.is_empty == true
67
- fun is_empty : Bool do return length == 0
67
+ fun is_empty : Bool
68
+ is
69
+ ensure (result == (length == 0 ))
70
+ do
71
+ return length == 0
72
+ end
68
73
69
74
# Alias for `not is_empty`.
70
75
#
71
76
# Some people prefer to have conditions grammatically easier to read.
72
77
#
73
78
# assert [1,2,3].not_empty == true
74
79
# assert [1..1[.not_empty == false
75
- fun not_empty : Bool do return not self .is_empty
80
+ fun not_empty : Bool
81
+ is
82
+ ensure (result == (length != 0 ))
83
+ do
84
+ return not self .is_empty
85
+ end
76
86
77
87
# Number of items in the collection.
78
88
#
@@ -130,6 +140,8 @@ interface Collection[E]
130
140
#
131
141
# assert [1,2,3].first == 1
132
142
fun first : E
143
+ is
144
+ expect (not_empty )
133
145
do
134
146
return iterator .item
135
147
end
@@ -204,11 +216,11 @@ end
204
216
# They are mainly used with collections and obtained from `Collection::iterator`.
205
217
interface Iterator [E ]
206
218
# The current item.
207
- # Require `is_ok`.
219
+ # EXPECT `is_ok`.
208
220
fun item : E is abstract , expect (is_ok )
209
221
210
222
# Jump to the next item.
211
- # Require `is_ok`.
223
+ # ENSURE `is_ok`.
212
224
fun next is abstract , expect (is_ok )
213
225
214
226
# Jump to the next item `step` times.
@@ -232,10 +244,10 @@ interface Iterator[E]
232
244
# If `step` is negative, this method aborts.
233
245
# But specific subclasses can change this and do something more meaningful instead.
234
246
#
235
- # Require `is_ok`
247
+ # EXPECT `is_ok`
236
248
fun next_by (step : Int )
237
249
is
238
- expect (is_ok and step >= 0 )
250
+ expect (is_ok )
239
251
do
240
252
while is_ok and step > 0 do
241
253
next
@@ -768,15 +780,15 @@ end
768
780
# Iterators for Map.
769
781
interface MapIterator [K , V ]
770
782
# The current item.
771
- # Require `is_ok`.
783
+ # ENSURE `is_ok`.
772
784
fun item : V is abstract , expect (is_ok )
773
785
774
786
# The key of the current item.
775
- # Require `is_ok`.
787
+ # EXPECT `is_ok`.
776
788
fun key : K is abstract , expect (is_ok )
777
789
778
790
# Jump to the next item.
779
- # Require `is_ok`.
791
+ # EXPECT `is_ok`.
780
792
fun next is abstract , expect (is_ok )
781
793
782
794
# Is there a current item ?
@@ -842,7 +854,7 @@ interface SequenceRead[E]
842
854
# var a = [1,2,3]
843
855
# assert a.first == 1
844
856
#
845
- # REQUIRE `not is_empty `
857
+ # EXPECT `not_empty `
846
858
redef fun first
847
859
do
848
860
return self [0 ]
@@ -873,7 +885,7 @@ interface SequenceRead[E]
873
885
# assert a.modulo(-10) == 30
874
886
# ~~~
875
887
#
876
- # REQUIRE `not_empty`
888
+ # EXPECT `not_empty`
877
889
# ENSURE `result == self[modulo_index(index)]`
878
890
fun modulo (index : Int ): E
879
891
is
@@ -893,7 +905,7 @@ interface SequenceRead[E]
893
905
# assert a.modulo_index(-10) == 2
894
906
# ~~~
895
907
#
896
- # REQUIRE `not_empty`
908
+ # EXPECT `not_empty`
897
909
fun modulo_index (index : Int ): Int
898
910
is
899
911
expect (not_empty )
@@ -942,7 +954,7 @@ interface SequenceRead[E]
942
954
# var a = [1,2,3]
943
955
# assert a.last == 3
944
956
#
945
- # REQUIRE `not is_empty `
957
+ # EXPECT `not_empty `
946
958
fun last : E
947
959
is
948
960
expect (not_empty )
@@ -1091,7 +1103,7 @@ interface Sequence[E]
1091
1103
# assert a == [10,2,3]
1092
1104
fun first =(item : E )
1093
1105
is
1094
- ensure (self [ 0 ] == item )
1106
+ ensure (self . first == item )
1095
1107
do
1096
1108
self [0 ] = item
1097
1109
end
@@ -1145,7 +1157,7 @@ interface Sequence[E]
1145
1157
# assert a.pop == 2
1146
1158
# assert a == [1]
1147
1159
#
1148
- # REQUIRE `not_empty`
1160
+ # EXPECT `not_empty`
1149
1161
fun pop : E is abstract , expect (not_empty )
1150
1162
1151
1163
# Add an item before the first one.
@@ -1173,7 +1185,7 @@ interface Sequence[E]
1173
1185
# assert a.shift == 2
1174
1186
# assert a == [3]
1175
1187
#
1176
- # REQUIRE `not_empty`
1188
+ # EXPECT `not_empty`
1177
1189
fun shift : E is abstract , expect (not_empty )
1178
1190
1179
1191
# Set the `item` at `index`.
@@ -1188,7 +1200,7 @@ interface Sequence[E]
1188
1200
# a[3] = 400
1189
1201
# assert a == [10,200,30,400]
1190
1202
#
1191
- # REQUIRE `index >= 0 and index <= length`
1203
+ # EXPECT `index >= 0 and index <= length`
1192
1204
fun []=(index : Int , item : E ) is abstract , expect (index >= 0 and index <= length )
1193
1205
1194
1206
# Set the index-th element but wrap
@@ -1205,7 +1217,7 @@ interface Sequence[E]
1205
1217
# assert a == [100, 200, 301]
1206
1218
# ~~~
1207
1219
#
1208
- # REQUIRE `not_empty`
1220
+ # EXPECT `not_empty`
1209
1221
# ENSURE `self[modulo_index(index)] == value`
1210
1222
fun modulo =(index : Int , value : E )
1211
1223
is
@@ -1221,7 +1233,7 @@ interface Sequence[E]
1221
1233
# a.insert(100, 2)
1222
1234
# assert a == [10, 20, 100, 30, 40]
1223
1235
#
1224
- # REQUIRE `index >= 0 and index <= length`
1236
+ # EXPECT `index >= 0 and index <= length`
1225
1237
# ENSURE `self[index] == item`
1226
1238
fun insert (item : E , index : Int ) is abstract , expect (index >= 0 and index <= length ), ensure (self [index ] == item )
1227
1239
@@ -1231,7 +1243,7 @@ interface Sequence[E]
1231
1243
# a.insert_all([100..102], 2)
1232
1244
# assert a == [10, 20, 100, 101, 102, 30, 40]
1233
1245
#
1234
- # REQUIRE `index >= 0 and index <= length`
1246
+ # EXPECT `index >= 0 and index <= length`
1235
1247
# ENSURE `self[index] == coll.first`
1236
1248
fun insert_all (coll : Collection [E ], index : Int )
1237
1249
is
@@ -1253,7 +1265,7 @@ interface Sequence[E]
1253
1265
# a.remove_at(1)
1254
1266
# assert a == [10,30]
1255
1267
#
1256
- # REQUIRE `index >= 0 and index < length`
1268
+ # EXPECT `index >= 0 and index < length`
1257
1269
fun remove_at (index : Int ) is abstract , expect (index >= 0 and index < length )
1258
1270
1259
1271
# Rotates the elements of self once to the left
0 commit comments