forked from bonzini/smalltalk
/
arrays.st
143 lines (116 loc) · 3.1 KB
/
arrays.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
"======================================================================
|
| Test the array routines
|
|
======================================================================"
"======================================================================
|
| Copyright (C) 1988, 1989, 1999 Free Software Foundation.
| Written by Steve Byrne
|
| This file is part of GNU Smalltalk.
|
| GNU Smalltalk is free software; you can redistribute it and/or modify it
| under the terms of the GNU General Public License as published by the Free
| Software Foundation; either version 2, or (at your option) any later version.
|
| GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
| FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
| details.
|
| You should have received a copy of the GNU General Public License along with
| GNU Smalltalk; see the file COPYING. If not, write to the Free Software
| Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
======================================================================"
!Object methodsFor: 'testing'!
arrayConstTest1
| a |
a := #(#foo #bar 'quem').
^a
!
arrayConstTest2
| a |
a := #(#foo #bar 'quem').
^a class
!
arrayConstTest3
| a |
a := #(#foo #bar 'quem').
^a size
!
arrayConstTest4
| a |
a := #(#foo (#a #sub #array) #bar 'quem' 3.4 1 $C #barn:yard:owl: #baz).
^a class
!
arrayConstSubscriptTest
| a |
a := #(#foo (#a #sub #array) #bar 'quem' 3.4 1 $C #barn:yard:owl: #baz).
^a at: self
!
arrayTrueFalseNilTest
| a |
a := #(true #true false #false nil #nil).
a do: [ :each | each class printNl ]
!
newArray1
| a |
a := Array new: 10.
^a class
!
newArray2
| a |
a := Array new: 10.
a at: self put: self.
^a at: self
! !
^nil arrayConstTest1!
^nil arrayConstTest2!
^nil arrayConstTest3!
^nil arrayConstTest4!
^1 arrayConstSubscriptTest!
^2 arrayConstSubscriptTest!
^3 arrayConstSubscriptTest!
^4 arrayConstSubscriptTest!
^5 arrayConstSubscriptTest!
^6 arrayConstSubscriptTest!
^7 arrayConstSubscriptTest!
^8 arrayConstSubscriptTest!
^9 arrayConstSubscriptTest!
^nil newArray1!
^1 newArray2!
^5 newArray2!
^10 newArray2!
^nil arrayTrueFalseNilTest!
^ByteArray with: -1!
^ByteArray with: 0!
^ByteArray with: 255!
^ByteArray with: 256!
^WordArray with: (-1 bitShift: 64)!
^WordArray with: -1!
^WordArray with: 0!
^WordArray with: 255!
^WordArray with: 256!
^WordArray with: (1 bitShift: 64)!
"-----------------"
"used to trigger a failure in the verifier"
^{{}} printString!
"-----------------"
"This test used to fail because #removeAtIndex: was not implemented
in SortedCollection."
| n4 n5 n6 n7 n8 n9 n10 n12 sc |
n4 := 4->2. n5 := 5->3. n6 := 6->3.
n7 := 7->2. n8 := 8->1. n9 := 9->8.
n10 := 10->8. n12 := 12->1.
sc := SortedCollection new: 10.
sc sortBlock: [ :a :b |
a value < b value
or: [ a value = b value and: [ a key <= b key ] ] ].
sc addAll: { n8. n12. n4. n7. n5. n6. n9. n10 }.
sc remove: n10.
sc remove: n8.
sc add: n8.
sc printNl!