FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode-cli/test/test_queue.js at master · DanielChuDC/leetcode-cli · GitHub
DanielChuDC
/
leetcode-cli
Public
forked from
skygragon/leetcode-cli
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode-cli
/
test
/
test_queue.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
58 lines (46 loc) · 1.11 KB
Breadcrumbs
leetcode-cli
/
test
/
test_queue.js
Copy path
File metadata and controls
58 lines (46 loc) · 1.11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
'use strict'
;
const
assert
=
require
(
'chai'
)
.
assert
;
const
rewire
=
require
(
'rewire'
)
;
describe
(
'queue'
,
function
(
)
{
let
Queue
;
beforeEach
(
function
(
)
{
Queue
=
rewire
(
'../lib/queue'
)
;
}
)
;
it
(
'should ok'
,
function
(
done
)
{
function
doTask
(
x
,
q
,
cb
)
{
++
q
.
ctx
.
n
;
q
.
ctx
.
sum
+=
x
;
return
cb
(
)
;
}
const
ctx
=
{
n
:
0
,
sum
:
0
}
;
const
q
=
new
Queue
(
[
]
,
ctx
,
doTask
)
;
q
.
addTask
(
1
)
;
q
.
addTask
(
2
)
;
q
.
addTasks
(
[
3
,
4
,
5
]
)
;
q
.
run
(
5
,
function
(
e
,
ctx
)
{
assert
.
notExists
(
e
)
;
assert
.
equal
(
ctx
.
n
,
5
)
;
assert
.
equal
(
ctx
.
sum
,
15
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'should ok in sequence'
,
function
(
done
)
{
const
config
=
{
network
:
{
}
}
;
Queue
.
__set__
(
'config'
,
config
)
;
function
doTask
(
x
,
q
,
cb
)
{
if
(
!
q
.
ctx
.
list
)
q
.
ctx
.
list
=
[
]
;
q
.
ctx
.
list
.
push
(
x
)
;
return
cb
(
)
;
}
const
q
=
new
Queue
(
null
,
null
,
doTask
)
;
q
.
addTask
(
1
)
;
q
.
addTasks
(
[
2
,
3
]
)
;
q
.
addTasks
(
[
4
]
)
;
q
.
addTask
(
5
)
;
q
.
run
(
null
,
function
(
e
,
ctx
)
{
assert
.
notExists
(
e
)
;
assert
.
deepEqual
(
ctx
.
list
,
[
1
,
2
,
3
,
4
,
5
]
)
;
done
(
)
;
}
)
;
}
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL