1
1
package qsim
2
2
3
3
import (
4
- "fmt"
5
4
"testing"
6
5
)
7
6
@@ -14,15 +13,15 @@ func TestQueueAppend(t *testing.T) {
14
13
15
14
for i := 0 ; i < 20 ; i ++ {
16
15
j = NewJob (0 )
17
- j .Attrs ["i" ] = fmt . Sprintf ( "%d" , i )
16
+ j .IntAttrs ["i" ] = i
18
17
q .Append (j )
19
18
}
20
19
21
- if q .Jobs [0 ].Attrs ["i" ] != "0" {
20
+ if q .Jobs [0 ].IntAttrs ["i" ] != 0 {
22
21
t .Log ("Zeroeth element not found at index 0" )
23
22
t .Fail ()
24
23
}
25
- if q .Jobs [19 ].Attrs ["i" ] != "19" {
24
+ if q .Jobs [19 ].IntAttrs ["i" ] != 19 {
26
25
t .Log ("Nineteenth element not found at index 19" )
27
26
t .Fail ()
28
27
}
@@ -40,15 +39,15 @@ func TestQueueShift(t *testing.T) {
40
39
q = NewQueue ()
41
40
42
41
j0 = NewJob (0 )
43
- j0 .Attrs ["i" ] = "0"
42
+ j0 .IntAttrs ["i" ] = 0
44
43
q .Append (j0 )
45
44
46
45
j1 = NewJob (0 )
47
- j1 .Attrs ["i" ] = "1"
46
+ j1 .IntAttrs ["i" ] = 1
48
47
q .Append (j1 )
49
48
50
49
j , nrem = q .Shift ()
51
- if j .Attrs ["i" ] != "0" {
50
+ if j .IntAttrs ["i" ] != 0 {
52
51
t .Log ("Zeroeth element was not the first to be shifted" )
53
52
t .Fail ()
54
53
}
@@ -58,7 +57,7 @@ func TestQueueShift(t *testing.T) {
58
57
}
59
58
60
59
j , nrem = q .Shift ()
61
- if j .Attrs ["i" ] != "1" {
60
+ if j .IntAttrs ["i" ] != 1 {
62
61
t .Log ("Last element was not the last to be shifted" )
63
62
t .Fail ()
64
63
}
@@ -81,18 +80,18 @@ func TestQueueBeforeAppend(t *testing.T) {
81
80
var j * Job
82
81
q = NewQueue ()
83
82
84
- var counter string
83
+ var counter int
85
84
var qLen int
86
85
cb := func (q * Queue , j * Job ) {
87
- counter = j .Attrs ["i" ]
86
+ counter = j .IntAttrs ["i" ]
88
87
qLen = len (q .Jobs )
89
88
}
90
89
q .BeforeAppend (cb )
91
90
92
91
j = NewJob (0 )
93
- j .Attrs ["i" ] = "0"
92
+ j .IntAttrs ["i" ] = 0
94
93
q .Append (j )
95
- if counter != "0" {
94
+ if counter != 0 {
96
95
t .Log ("Expected BeforeAppend callback to set counter=0" )
97
96
t .Fail ()
98
97
}
@@ -102,9 +101,9 @@ func TestQueueBeforeAppend(t *testing.T) {
102
101
}
103
102
104
103
j = NewJob (0 )
105
- j .Attrs ["i" ] = "1"
104
+ j .IntAttrs ["i" ] = 1
106
105
q .Append (j )
107
- if counter != "1" {
106
+ if counter != 1 {
108
107
t .Log ("Expected BeforeAppend callback to set counter=1" )
109
108
t .Fail ()
110
109
}
@@ -121,18 +120,18 @@ func TestQueueAfterAppend(t *testing.T) {
121
120
var j * Job
122
121
q = NewQueue ()
123
122
124
- var counter string
123
+ var counter int
125
124
var qLen int
126
125
cb := func (q * Queue , j * Job ) {
127
- counter = j .Attrs ["i" ]
126
+ counter = j .IntAttrs ["i" ]
128
127
qLen = len (q .Jobs )
129
128
}
130
129
q .AfterAppend (cb )
131
130
132
131
j = NewJob (0 )
133
- j .Attrs ["i" ] = "0"
132
+ j .IntAttrs ["i" ] = 0
134
133
q .Append (j )
135
- if counter != "0" {
134
+ if counter != 0 {
136
135
t .Log ("Expected AfterAppend callback to set counter=0" )
137
136
t .Fail ()
138
137
}
@@ -142,9 +141,9 @@ func TestQueueAfterAppend(t *testing.T) {
142
141
}
143
142
144
143
j = NewJob (0 )
145
- j .Attrs ["i" ] = "1"
144
+ j .IntAttrs ["i" ] = 1
146
145
q .Append (j )
147
- if counter != "1" {
146
+ if counter != 1 {
148
147
t .Log ("Expected AfterAppend callback to set counter=1" )
149
148
t .Fail ()
150
149
}
@@ -161,27 +160,27 @@ func TestQueueBeforeShift(t *testing.T) {
161
160
var j * Job
162
161
q = NewQueue ()
163
162
164
- var counter string
163
+ var counter int
165
164
var qLen int
166
165
cb := func (q * Queue , j * Job ) {
167
166
if j != nil {
168
- counter = j .Attrs ["i" ]
167
+ counter = j .IntAttrs ["i" ]
169
168
} else {
170
- counter = "queue_was_empty"
169
+ counter = - 1
171
170
}
172
171
qLen = len (q .Jobs )
173
172
}
174
173
q .BeforeShift (cb )
175
174
176
175
j = NewJob (0 )
177
- j .Attrs ["i" ] = "0"
176
+ j .IntAttrs ["i" ] = 0
178
177
q .Append (j )
179
178
j = NewJob (0 )
180
- j .Attrs ["i" ] = "1"
179
+ j .IntAttrs ["i" ] = 1
181
180
q .Append (j )
182
181
183
182
q .Shift ()
184
- if counter != "0" {
183
+ if counter != 0 {
185
184
t .Log ("Expected BeforeShift callback to set counter=0" )
186
185
t .Fail ()
187
186
}
@@ -191,7 +190,7 @@ func TestQueueBeforeShift(t *testing.T) {
191
190
}
192
191
193
192
q .Shift ()
194
- if counter != "1" {
193
+ if counter != 1 {
195
194
t .Log ("Expected BeforeShift callback to set counter=1" )
196
195
t .Fail ()
197
196
}
@@ -201,8 +200,8 @@ func TestQueueBeforeShift(t *testing.T) {
201
200
}
202
201
203
202
q .Shift ()
204
- if counter != "queue_was_empty" {
205
- t .Log ("Expected BeforeShift callback to set counter=queue_was_empty " )
203
+ if counter != - 1 {
204
+ t .Log ("Expected BeforeShift callback to set counter=-1 " )
206
205
t .Fail ()
207
206
}
208
207
if qLen != 0 {
@@ -218,27 +217,27 @@ func TestQueueAfterShift(t *testing.T) {
218
217
var j * Job
219
218
q = NewQueue ()
220
219
221
- var counter string
220
+ var counter int
222
221
var qLen int
223
222
cb := func (q * Queue , j * Job ) {
224
223
if j != nil {
225
- counter = j .Attrs ["i" ]
224
+ counter = j .IntAttrs ["i" ]
226
225
} else {
227
- counter = "queue_was_empty"
226
+ counter = - 1
228
227
}
229
228
qLen = len (q .Jobs )
230
229
}
231
230
q .AfterShift (cb )
232
231
233
232
j = NewJob (0 )
234
- j .Attrs ["i" ] = "0"
233
+ j .IntAttrs ["i" ] = 0
235
234
q .Append (j )
236
235
j = NewJob (0 )
237
- j .Attrs ["i" ] = "1"
236
+ j .IntAttrs ["i" ] = 1
238
237
q .Append (j )
239
238
240
239
q .Shift ()
241
- if counter != "0" {
240
+ if counter != 0 {
242
241
t .Log ("Expected AfterShift callback to set counter=0" )
243
242
t .Fail ()
244
243
}
@@ -248,7 +247,7 @@ func TestQueueAfterShift(t *testing.T) {
248
247
}
249
248
250
249
q .Shift ()
251
- if counter != "1" {
250
+ if counter != 1 {
252
251
t .Log ("Expected AfterShift callback to set counter=1" )
253
252
t .Fail ()
254
253
}
@@ -258,8 +257,8 @@ func TestQueueAfterShift(t *testing.T) {
258
257
}
259
258
260
259
q .Shift ()
261
- if counter != "queue_was_empty" {
262
- t .Log ("Expected AfterShift callback to set counter=queue_was_empty " )
260
+ if counter != - 1 {
261
+ t .Log ("Expected AfterShift callback to set counter=-1 " )
263
262
t .Fail ()
264
263
}
265
264
if qLen != 0 {
0 commit comments