forked from jabbany/CommentCoreLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray_spec.coffee
More file actions
66 lines (55 loc) · 2.2 KB
/
Array_spec.coffee
File metadata and controls
66 lines (55 loc) · 2.2 KB
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
'use strict'
describe 'BinArray', ->
testAray = null
compare = (a, b)-> a - b
describe 'bsearch', ->
describe 'with empty array', ->
beforeEach -> testAray = []
it 'always returns 0', ->
expect(BinArray.bsearch(testAray, 2, compare)).toBe 0
expect(BinArray.bsearch(testAray, 0, compare)).toBe 0
describe 'with [1, 3, 5]', ->
beforeEach -> testAray = [1,3,5]
it 'search for 0', ->
expect(BinArray.bsearch(testAray, 0, compare)).toBe 0
it 'search for 1', ->
expect(BinArray.bsearch(testAray, 1, compare)).toBe 1
it 'search for 2', ->
expect(BinArray.bsearch(testAray, 2, compare)).toBe 1
it 'search for 3', ->
expect(BinArray.bsearch(testAray, 3, compare)).toBe 2
it 'search for 4', ->
expect(BinArray.bsearch(testAray, 4, compare)).toBe 2
it 'search for 5', ->
expect(BinArray.bsearch(testAray, 5, compare)).toBe 3
it 'search for 6', ->
expect(BinArray.bsearch(testAray, 6, compare)).toBe 3
describe 'binsert', ->
describe 'with empty array', ->
beforeEach -> testAray = []
it 'just insert to array', ->
expect(BinArray.binsert(testAray, 0, compare)).toBe 0
expect(testAray).toEqual [0]
describe 'with [1, 3, 5]', ->
beforeEach -> testAray = [1,3,5]
it 'insert 0', ->
expect(BinArray.binsert(testAray, 0, compare)).toBe 0
expect(testAray).toEqual [0,1,3,5]
it 'insert 1', ->
expect(BinArray.binsert(testAray, 1, compare)).toBe 1
expect(testAray).toEqual [1,1,3,5]
it 'insert 2', ->
expect(BinArray.binsert(testAray, 2, compare)).toBe 1
expect(testAray).toEqual [1,2,3,5]
it 'insert 3', ->
expect(BinArray.binsert(testAray, 3, compare)).toBe 2
expect(testAray).toEqual [1,3,3,5]
it 'insert 4', ->
expect(BinArray.binsert(testAray, 4, compare)).toBe 2
expect(testAray).toEqual [1,3,4,5]
it 'insert 5', ->
expect(BinArray.binsert(testAray, 5, compare)).toBe 3
expect(testAray).toEqual [1,3,5,5]
it 'insert 6', ->
expect(BinArray.binsert(testAray, 6, compare)).toBe 3
expect(testAray).toEqual [1,3,5,6]