Skip to content

Commit 4e0a7d5

Browse files
committed
Merge pull request #48 from anaran/jscs-driven-fixes
Jscs driven fixes
2 parents c408965 + c6c88ca commit 4e0a7d5

File tree

3 files changed

+129
-128
lines changed

3 files changed

+129
-128
lines changed

test/algorithms/graph/topological_sort.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,37 @@ describe('Topological Sort', function () {
2929
it('should return a stack with the vertices ordered' +
3030
' considering the dependencies', function () {
3131

32-
var graph = new Graph();
33-
graph.addVertex('shirt');
34-
graph.addVertex('watch');
35-
graph.addVertex('socks');
36-
graph.addVertex('underwear');
37-
graph.addVertex('pants');
38-
graph.addVertex('belt');
39-
graph.addVertex('shoes');
40-
graph.addVertex('tie');
41-
graph.addVertex('jacket');
32+
var graph = new Graph();
33+
graph.addVertex('shirt');
34+
graph.addVertex('watch');
35+
graph.addVertex('socks');
36+
graph.addVertex('underwear');
37+
graph.addVertex('pants');
38+
graph.addVertex('belt');
39+
graph.addVertex('shoes');
40+
graph.addVertex('tie');
41+
graph.addVertex('jacket');
4242

43-
graph.addEdge('shirt', 'belt');
44-
graph.addEdge('shirt', 'tie');
45-
graph.addEdge('shirt', 'jacket');
43+
graph.addEdge('shirt', 'belt');
44+
graph.addEdge('shirt', 'tie');
45+
graph.addEdge('shirt', 'jacket');
4646

47-
graph.addEdge('socks', 'shoes');
47+
graph.addEdge('socks', 'shoes');
4848

49-
graph.addEdge('underwear', 'pants');
50-
graph.addEdge('underwear', 'shoes');
49+
graph.addEdge('underwear', 'pants');
50+
graph.addEdge('underwear', 'shoes');
5151

52-
graph.addEdge('pants', 'shoes');
53-
graph.addEdge('pants', 'belt');
52+
graph.addEdge('pants', 'shoes');
53+
graph.addEdge('pants', 'belt');
5454

55-
graph.addEdge('belt', 'jacket');
55+
graph.addEdge('belt', 'jacket');
5656

57-
graph.addEdge('tie', 'jacket');
57+
graph.addEdge('tie', 'jacket');
5858

59-
var stack = topologicalSort(graph);
60-
var a = [];
61-
while (!stack.isEmpty()) a.push(stack.pop());
62-
assert.deepEqual(a, ['underwear', 'pants', 'socks', 'shoes',
63-
'watch', 'shirt', 'tie', 'belt', 'jacket']);
64-
});
59+
var stack = topologicalSort(graph);
60+
var a = [];
61+
while (!stack.isEmpty()) a.push(stack.pop());
62+
assert.deepEqual(a, ['underwear', 'pants', 'socks', 'shoes',
63+
'watch', 'shirt', 'tie', 'belt', 'jacket']);
64+
});
6565
});

test/algorithms/string/knuth_morris_pratt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('Knuth-Morris-Pratt', function () {
4545
'org/wiki/Knuth-Morris-Pratt_algorithm';
4646
var pattern = 'https://en.wikipedia.org/wiki/Knuth-Morris-Pratt_al' +
4747
'gorithm';
48-
48+
4949
assert.equal(knuthMorrisPratt(text, pattern), 915);
5050

5151
pattern = '(https://en.wikipedia.org/wiki/Knuth-Morris-Pratt_algorithm';

test/data_structures/bst.js

Lines changed: 102 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -88,76 +88,76 @@ describe('Binary Search Tree', function () {
8888

8989

9090
it('should remove a leaf without altering anything else in ' +
91-
'the structure of the tree', function () {
91+
'the structure of the tree', function () {
9292

93-
bst.remove(0);
94-
/**
95-
* 4
96-
* 2 8
97-
* 1 3 5 10
98-
* 2.5 100
99-
*/
100-
var a = [];
101-
bfs(bst.root, callbackGenerator(a));
102-
assert.deepEqual(a, [4, 2, 8, 1, 3, 5, 10, 2.5, 100]);
103-
});
93+
bst.remove(0);
94+
/**
95+
* 4
96+
* 2 8
97+
* 1 3 5 10
98+
* 2.5 100
99+
*/
100+
var a = [];
101+
bfs(bst.root, callbackGenerator(a));
102+
assert.deepEqual(a, [4, 2, 8, 1, 3, 5, 10, 2.5, 100]);
103+
});
104104

105105
it('should remove an element with just one child and substitute ' +
106-
'it as the root of only subtree', function () {
106+
'it as the root of only subtree', function () {
107107

108-
bst.remove(10);
109-
/**
110-
* 4
111-
* 2 8
112-
* 1 3 5 100
113-
* 2.5
114-
*/
115-
var a = [];
116-
bfs(bst.root, callbackGenerator(a));
117-
assert.deepEqual(a, [4, 2, 8, 1, 3, 5, 100, 2.5]);
118-
});
108+
bst.remove(10);
109+
/**
110+
* 4
111+
* 2 8
112+
* 1 3 5 100
113+
* 2.5
114+
*/
115+
var a = [];
116+
bfs(bst.root, callbackGenerator(a));
117+
assert.deepEqual(a, [4, 2, 8, 1, 3, 5, 100, 2.5]);
118+
});
119119

120120
it('should substitute an element by the leftmost child in the right ' +
121-
'subtree and remove it as a leaf', function () {
122-
/**
123-
* 4
124-
* 2 8
125-
* 1 3 5 100
126-
* 2.5
127-
*/
128-
bst.remove(2);
129-
/**
130-
* 4
131-
* 2.5 8
132-
* 1 3 5 100
133-
*
134-
*/
135-
var a = [];
136-
bfs(bst.root, callbackGenerator(a));
137-
assert.deepEqual(a, [4, 2.5, 8, 1, 3, 5, 100]);
121+
'subtree and remove it as a leaf', function () {
122+
/**
123+
* 4
124+
* 2 8
125+
* 1 3 5 100
126+
* 2.5
127+
*/
128+
bst.remove(2);
129+
/**
130+
* 4
131+
* 2.5 8
132+
* 1 3 5 100
133+
*
134+
*/
135+
var a = [];
136+
bfs(bst.root, callbackGenerator(a));
137+
assert.deepEqual(a, [4, 2.5, 8, 1, 3, 5, 100]);
138138

139-
bst.remove(4);
140-
/**
141-
* 5
142-
* 2.5 8
143-
* 1 3 100
144-
*
145-
*/
146-
a = [];
147-
bfs(bst.root, callbackGenerator(a));
148-
assert.deepEqual(a, [5, 2.5, 8, 1, 3, 100]);
139+
bst.remove(4);
140+
/**
141+
* 5
142+
* 2.5 8
143+
* 1 3 100
144+
*
145+
*/
146+
a = [];
147+
bfs(bst.root, callbackGenerator(a));
148+
assert.deepEqual(a, [5, 2.5, 8, 1, 3, 100]);
149149

150-
bst.remove(2.5);
151-
/**
152-
* 5
153-
* 3 8
154-
* 1 100
155-
*
156-
*/
157-
a = [];
158-
bfs(bst.root, callbackGenerator(a));
159-
assert.deepEqual(a, [5, 3, 8, 1, 100]);
160-
});
150+
bst.remove(2.5);
151+
/**
152+
* 5
153+
* 3 8
154+
* 1 100
155+
*
156+
*/
157+
a = [];
158+
bfs(bst.root, callbackGenerator(a));
159+
assert.deepEqual(a, [5, 3, 8, 1, 100]);
160+
});
161161

162162
it('should always return the right root and size', function () {
163163
var bst = new BST();
@@ -194,14 +194,15 @@ describe('Binary Search Tree with custom comparator', function () {
194194
return a.length < b.length ? -1 : 1;
195195
};
196196

197-
it('should insert elements respecting the BST restrictions', function () {
198-
var bst = new BST(strLenCompare);
199-
bst.insert('banana');
200-
bst.insert('apple');
201-
bst.insert('pineapple');
202-
bst.insert('watermelon');
203-
assert.equal(bst.size, 4);
204-
});
197+
it(
198+
'should insert elements respecting the BST restrictions', function () {
199+
var bst = new BST(strLenCompare);
200+
bst.insert('banana');
201+
bst.insert('apple');
202+
bst.insert('pineapple');
203+
bst.insert('watermelon');
204+
assert.equal(bst.size, 4);
205+
});
205206

206207
it('should check if an element exists (in O(lg n))', function () {
207208
var bst = new BST(strLenCompare);
@@ -245,42 +246,42 @@ describe('Binary Search Tree with custom comparator', function () {
245246
});
246247

247248
it('should remove a leaf without altering anything else in ' +
248-
'the structure of the tree', function () {
249+
'the structure of the tree', function () {
249250

250-
bst.remove('watermelon');
251-
/**
252-
* 'banana'
253-
* 'apple' 'pineapple'
254-
* 'pear'
255-
*/
256-
var a = [];
257-
bfs(bst.root, callbackGenerator(a));
258-
assert.deepEqual(a, ['banana', 'apple', 'pineapple', 'pear']);
259-
});
251+
bst.remove('watermelon');
252+
/**
253+
* 'banana'
254+
* 'apple' 'pineapple'
255+
* 'pear'
256+
*/
257+
var a = [];
258+
bfs(bst.root, callbackGenerator(a));
259+
assert.deepEqual(a, ['banana', 'apple', 'pineapple', 'pear']);
260+
});
260261

261262
it('should remove an element with just one child and substitute ' +
262-
'it as the root of only subtree', function () {
263+
'it as the root of only subtree', function () {
263264

264-
bst.remove('apple');
265-
/**
266-
* 'banana'
267-
* 'pear' 'pineapple'
268-
*/
269-
var a = [];
270-
bfs(bst.root, callbackGenerator(a));
271-
assert.deepEqual(a, ['banana', 'pear', 'pineapple']);
272-
});
265+
bst.remove('apple');
266+
/**
267+
* 'banana'
268+
* 'pear' 'pineapple'
269+
*/
270+
var a = [];
271+
bfs(bst.root, callbackGenerator(a));
272+
assert.deepEqual(a, ['banana', 'pear', 'pineapple']);
273+
});
273274

274275
it('should substitute an element by the leftmost child in the right ' +
275-
'subtree and remove it as a leaf', function () {
276+
'subtree and remove it as a leaf', function () {
276277

277-
bst.remove('banana');
278-
/**
279-
* 'pineapple'
280-
* 'pear'
281-
*/
282-
var a = [];
283-
bfs(bst.root, callbackGenerator(a));
284-
assert.deepEqual(a, ['pineapple', 'pear']);
285-
});
278+
bst.remove('banana');
279+
/**
280+
* 'pineapple'
281+
* 'pear'
282+
*/
283+
var a = [];
284+
bfs(bst.root, callbackGenerator(a));
285+
assert.deepEqual(a, ['pineapple', 'pear']);
286+
});
286287
});

0 commit comments

Comments
 (0)