Skip to content

Commit 5ea1ab9

Browse files
committed
Fix couple test failures and crappy whitespace
1 parent 0c0c0de commit 5ea1ab9

23 files changed

+931
-925
lines changed

cbuffer.js

+320-320
Large diffs are not rendered by default.

package.json

+34-32
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
{
2-
"name" : "CBuffer",
3-
"version" : "2.1.0",
4-
"description" : "Circular Buffer JavaScript implementation",
5-
"homepage" : "https://github.com/trevnorris/cbuffer",
6-
"main" : "./cbuffer.js",
7-
"author" : {
8-
"name" : "Trevor Norris",
9-
"email" : "[email protected]",
10-
"url" : "http://trevorjnorris.com"
11-
},
12-
"license": "MIT",
13-
"licenses" : [{
14-
"type" : "MIT",
15-
"url" : "http://www.opensource.org/licenses/mit-license.php"
16-
}],
17-
"keywords": [
18-
"circular buffer",
19-
"ring",
20-
"circular",
21-
"buffer",
22-
"data structure"
23-
],
24-
"devDependencies" : {
25-
"vows" : "latest"
26-
},
27-
"scripts" : {
28-
"test" : "vows"
29-
},
30-
"repository" : {
31-
"type" : "git",
32-
"url" : "https://github.com/trevnorris/cbuffer.git"
33-
}
2+
"name": "CBuffer",
3+
"version": "2.1.0",
4+
"description": "Circular Buffer JavaScript implementation",
5+
"homepage": "https://github.com/trevnorris/cbuffer",
6+
"main": "./cbuffer.js",
7+
"author": {
8+
"name": "Trevor Norris",
9+
"email": "[email protected]",
10+
"url": "http://trevorjnorris.com"
11+
},
12+
"license": "MIT",
13+
"licenses": [
14+
{
15+
"type": "MIT",
16+
"url": "http://www.opensource.org/licenses/mit-license.php"
17+
}
18+
],
19+
"keywords": [
20+
"circular buffer",
21+
"ring",
22+
"circular",
23+
"buffer",
24+
"data structure"
25+
],
26+
"devDependencies": {
27+
"vows": "latest"
28+
},
29+
"scripts": {
30+
"test": "vows"
31+
},
32+
"repository": {
33+
"type": "git",
34+
"url": "https://github.com/trevnorris/cbuffer.git"
35+
}
3436
}

test/accessor/indexOf-test.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
var vows = require('vows'),
2-
assert = require('assert')
3-
suite = vows.describe('CBuffer');
1+
var vows = require('vows');
2+
var assert = require('assert');
3+
var suite = vows.describe('indexOf');
44

55
require('../env');
66

77
suite.addBatch({
8-
'indexOf' : {
9-
'topic' : function () {
10-
return CBuffer;
11-
},
12-
'find item' : function (CBuffer) {
13-
assert.equal(CBuffer(1, 2, 3).indexOf(2), 1);
14-
assert.equal(CBuffer('a', 'b', 'c').indexOf('c'), 2);
15-
assert.equal(CBuffer(1, 2, 3).indexOf('1'), -1);
16-
assert.equal(CBuffer(1, 2, 3).indexOf(4), -1);
17-
}
18-
}
8+
'indexOf' : {
9+
'topic' : function () {
10+
return CBuffer;
11+
},
12+
'find item' : function (CBuffer) {
13+
assert.equal(CBuffer(1, 2, 3).indexOf(2), 1);
14+
assert.equal(CBuffer('a', 'b', 'c').indexOf('c'), 2);
15+
assert.equal(CBuffer(1, 2, 3).indexOf('1'), -1);
16+
assert.equal(CBuffer(1, 2, 3).indexOf(4), -1);
17+
}
18+
}
1919
});
2020

2121
suite.export(module);

test/accessor/lastIndexOf-test.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
var vows = require('vows'),
2-
assert = require('assert')
3-
suite = vows.describe('CBuffer');
1+
var vows = require('vows');
2+
var assert = require('assert');
3+
var suite = vows.describe('lastIndexOf');
44

55
require('../env');
66

77
suite.addBatch({
8-
'lastIndexOf' : {
9-
'topic' : function () {
10-
return CBuffer;
11-
},
12-
'find item' : function (CBuffer) {
13-
assert.equal(CBuffer(1, 2, 3).lastIndexOf(2), 1);
14-
assert.equal(CBuffer('a', 'b', 'c').lastIndexOf('c'), 2);
15-
assert.equal(CBuffer(1, 2, 3).lastIndexOf('1'), -1);
16-
assert.equal(CBuffer(1, 2, 3).lastIndexOf(4), -1);
17-
}
18-
}
8+
'lastIndexOf' : {
9+
'topic' : function () {
10+
return CBuffer;
11+
},
12+
'find item' : function (CBuffer) {
13+
assert.equal(CBuffer(1, 2, 3).lastIndexOf(2), 1);
14+
assert.equal(CBuffer('a', 'b', 'c').lastIndexOf('c'), 2);
15+
assert.equal(CBuffer(1, 2, 3).lastIndexOf('1'), -1);
16+
assert.equal(CBuffer(1, 2, 3).lastIndexOf(4), -1);
17+
}
18+
}
1919
});
2020

2121
suite.export(module);

test/accessor/sortedIndex-test.js

+91-91
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,102 @@
1-
var vows = require('vows'),
2-
assert = require('assert'),
3-
suite = vows.describe('CBuffer');
1+
var vows = require('vows');
2+
var assert = require('assert');
3+
var suite = vows.describe('sortedIndex');
44

55
require('../env');
66

77
suite.addBatch({
8-
'sortedIndex': {
9-
'works with simple sorted case': {
10-
topic: function() {
11-
return CBuffer(1, 3, 5, 7, 11);
12-
},
13-
'no iterator provided': function(buffer) {
14-
assert.equal(buffer.sortedIndex(-1), 0);
15-
assert.equal(buffer.sortedIndex(1.5), 1);
16-
},
17-
'returns index of existing items': function(buffer) {
18-
assert.equal(buffer.sortedIndex(1), 0);
19-
assert.equal(buffer.sortedIndex(5), 2);
20-
assert.equal(buffer.sortedIndex(11), 4);
21-
},
22-
'around the corner': function(buffer) {
23-
assert.equal(buffer.sortedIndex(-1), 0);
24-
assert.equal(buffer.sortedIndex(12), 4);
25-
},
26-
'takes an iterator': function() {
27-
var buffer = CBuffer(7, 5, 11, 3, 1);
28-
function iter(a, b) {
29-
return Math.abs(a - 8) - Math.abs(b - 8);
30-
}
31-
assert.equal(buffer.sortedIndex(6, iter), 1);
32-
},
8+
'sortedIndex': {
9+
'works with simple sorted case': {
10+
topic: function() {
11+
return CBuffer(1, 3, 5, 7, 11);
12+
},
13+
'no iterator provided': function(buffer) {
14+
assert.equal(buffer.sortedIndex(-1), 0);
15+
assert.equal(buffer.sortedIndex(1.5), 1);
16+
},
17+
'returns index of existing items': function(buffer) {
18+
assert.equal(buffer.sortedIndex(1), 0);
19+
assert.equal(buffer.sortedIndex(5), 2);
20+
assert.equal(buffer.sortedIndex(11), 4);
21+
},
22+
'around the corner': function(buffer) {
23+
assert.equal(buffer.sortedIndex(-1), 0);
24+
assert.equal(buffer.sortedIndex(12), 4);
25+
},
26+
'takes an iterator': function() {
27+
var buffer = CBuffer(7, 5, 11, 3, 1);
28+
function iter(a, b) {
29+
return Math.abs(a - 8) - Math.abs(b - 8);
30+
}
31+
assert.equal(buffer.sortedIndex(6, iter), 1);
32+
},
3333

34-
'non-full circular buffer': {
35-
topic: function() {
36-
var buffer = CBuffer(20);
37-
buffer.push(1, 2, 3, 4, 5, 6, 7, 8);
38-
return buffer;
39-
},
40-
'works with partially complete buffers': function(buffer) {
41-
assert.equal(buffer.sortedIndex(3), 2);
42-
assert.equal(buffer.sortedIndex(8), 7);
43-
},
44-
'can determine postion in a fixed length buffer': function(buffer) {
45-
assert.equal(buffer.sortedIndex(0), 0);
46-
assert.equal(buffer.sortedIndex(1), 0);
47-
assert.equal(buffer.sortedIndex(3), 2);
48-
assert.equal(buffer.sortedIndex(10), 8);
49-
}
50-
},
34+
'non-full circular buffer': {
35+
topic: function() {
36+
var buffer = CBuffer(20);
37+
buffer.push(1, 2, 3, 4, 5, 6, 7, 8);
38+
return buffer;
39+
},
40+
'works with partially complete buffers': function(buffer) {
41+
assert.equal(buffer.sortedIndex(3), 2);
42+
assert.equal(buffer.sortedIndex(8), 7);
43+
},
44+
'can determine postion in a fixed length buffer': function(buffer) {
45+
assert.equal(buffer.sortedIndex(0), 0);
46+
assert.equal(buffer.sortedIndex(1), 0);
47+
assert.equal(buffer.sortedIndex(3), 2);
48+
assert.equal(buffer.sortedIndex(10), 8);
49+
}
50+
},
5151

52-
'supports classic repeative item case': {
53-
topic: function() {
54-
return CBuffer(0, 0, 0, 1, 1, 1, 1, 1, 1, 3);
55-
},
56-
'supports repative item': function(buffer) {
57-
assert.equal(buffer.sortedIndex(2), 9);
58-
}
59-
}
60-
},
52+
'supports classic repeative item case': {
53+
topic: function() {
54+
return CBuffer(0, 0, 0, 1, 1, 1, 1, 1, 1, 3);
55+
},
56+
'supports repative item': function(buffer) {
57+
assert.equal(buffer.sortedIndex(2), 9);
58+
}
59+
}
60+
},
6161

62-
'handles circular cases': {
63-
'mid circular case': {
64-
topic: function() {
65-
var buffer = CBuffer(-1, 0, 1, 3, 5);
66-
buffer.push(7, 9);
67-
return buffer;
68-
},
69-
'simple circular buffer': function(buffer) {
70-
assert.equal(buffer.sortedIndex(0), 0);
71-
assert.equal(buffer.sortedIndex(2), 1);
72-
assert.equal(buffer.sortedIndex(4), 2);
73-
assert.equal(buffer.sortedIndex(7), 3);
74-
assert.equal(buffer.sortedIndex(8), 4);
75-
assert.equal(buffer.sortedIndex(10), 4);
76-
},
77-
'circular buffer on the pivot': function(buffer) {
78-
assert.equal(buffer.sortedIndex(4.999), 2);
79-
assert.equal(buffer.sortedIndex(5), 2);
80-
assert.equal(buffer.sortedIndex(6), 3);
81-
},
82-
'returns index of existing item': function(buffer) {
83-
assert.equal(buffer.sortedIndex(7), 3);
84-
}
85-
},
62+
'handles circular cases': {
63+
'mid circular case': {
64+
topic: function() {
65+
var buffer = CBuffer(-1, 0, 1, 3, 5);
66+
buffer.push(7, 9);
67+
return buffer;
68+
},
69+
'simple circular buffer': function(buffer) {
70+
assert.equal(buffer.sortedIndex(0), 0);
71+
assert.equal(buffer.sortedIndex(2), 1);
72+
assert.equal(buffer.sortedIndex(4), 2);
73+
assert.equal(buffer.sortedIndex(7), 3);
74+
assert.equal(buffer.sortedIndex(8), 4);
75+
assert.equal(buffer.sortedIndex(10), 4);
76+
},
77+
'circular buffer on the pivot': function(buffer) {
78+
assert.equal(buffer.sortedIndex(4.999), 2);
79+
assert.equal(buffer.sortedIndex(5), 2);
80+
assert.equal(buffer.sortedIndex(6), 3);
81+
},
82+
'returns index of existing item': function(buffer) {
83+
assert.equal(buffer.sortedIndex(7), 3);
84+
}
85+
},
8686

87-
'almost sorted data cases (1 item out of place)': {
88-
topic: function() {
89-
var buffer = CBuffer(-3, -1, 0, 1, 3, 5, 7);
90-
buffer.push(7, 9, 11, 13, 15, 17);
91-
return buffer;
92-
},
93-
'single item out of place': function(buffer) {
94-
assert.equal(buffer.sortedIndex(0), 0);
95-
assert.equal(buffer.sortedIndex(17), 6);
96-
}
97-
}
98-
}
99-
}
87+
'almost sorted data cases (1 item out of place)': {
88+
topic: function() {
89+
var buffer = CBuffer(-3, -1, 0, 1, 3, 5, 7);
90+
buffer.push(7, 9, 11, 13, 15, 17);
91+
return buffer;
92+
},
93+
'single item out of place': function(buffer) {
94+
assert.equal(buffer.sortedIndex(0), 0);
95+
assert.equal(buffer.sortedIndex(17), 6);
96+
}
97+
}
98+
}
99+
}
100100
});
101101

102102
suite.export(module);

0 commit comments

Comments
 (0)