Skip to content

Commit 91d3de4

Browse files
🔍 test: Make tests pass.
1 parent 5a447e9 commit 91d3de4

File tree

14 files changed

+129
-124
lines changed

14 files changed

+129
-124
lines changed

test/src/undirected/offline/algo/eulerian/dup.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import test from 'ava';
22

3-
3+
import * as gn from '../../../../../../src' ;
44

55
var check = function(label, n, E, m){
66

7-
test('dup #' + label, function(assert){
7+
test('dup #' + label, t => {
88

99
var DGraph = gn.dense_graph_t();
1010
var SGraph = gn.sparse_graph_t();
@@ -54,9 +54,9 @@ var check = function(label, n, E, m){
5454

5555
i = m.length;
5656
while(i--){
57-
var u = m[i][0], w = m[i][1];
57+
const u = m[i][0], w = m[i][1];
5858
while(u !== w){
59-
var t = s[u][w];
59+
const t = s[u][w];
6060
++count[0][u][t];
6161
++count[0][t][u];
6262
u = t;
@@ -70,7 +70,7 @@ var check = function(label, n, E, m){
7070
});
7171

7272
t.deepEqual(count[1], count[0], 'check edge count');
73-
73+
7474

7575
});
7676

@@ -130,4 +130,4 @@ var I = [
130130

131131
for(var i = 0; i < I.length; ++i){
132132
check.apply(undefined, I[i]);
133-
}
133+
}

test/src/undirected/offline/algo/eulerian/eventour.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import test from 'ava';
22

3+
import * as gn from '../../../../../../src' ;
34

45
var check = function(label, n, x, E, _E){
56

67
if (_E === undefined) _E = [];
78

8-
test('eventour #' + label, function(assert){
9+
test('eventour #' + label, t => {
910

1011
var Graph = gn.sparse_graph_t();
1112

@@ -52,7 +53,7 @@ var check = function(label, n, x, E, _E){
5253
edges.forEach(function(e){
5354
free.push(e.free);
5455
});
55-
56+
5657
t.deepEqual(free, gn.sqmat(1, E.length, false), 'check free');
5758

5859

@@ -63,7 +64,7 @@ var check = function(label, n, x, E, _E){
6364
}
6465

6566

66-
67+
6768

6869
});
6970

@@ -165,7 +166,7 @@ var I = [
165166
],
166167

167168
[
168-
'disconected 2 + 0-1 * 4 + 0-8 * 2',
169+
'disconnected 2 + 0-1 * 4 + 0-8 * 2',
169170
11,
170171
0,
171172
[
@@ -198,4 +199,4 @@ var I = [
198199

199200
for(var i = 0; i < I.length; ++i){
200201
check.apply(undefined, I[i]);
201-
}
202+
}

test/src/undirected/offline/algo/eulerian/oddgraph.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import test from 'ava';
22

3+
import * as gn from '../../../../../../src' ;
34

45
var check = function(label, n, E){
56

6-
test('oddgraph #' + label, function(assert){
7+
test('oddgraph #' + label, t => {
78

89
var Graph = gn.dense_graph_t();
910

@@ -112,4 +113,4 @@ var I = [
112113

113114
for(var i = 0; i < I.length; ++i){
114115
check.apply(undefined, I[i]);
115-
}
116+
}

test/src/undirected/offline/algo/eulerian/simplegraph.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import test from 'ava';
2+
3+
import * as gn from '../../../../../../src' ;
4+
25
var check = function(name, order, E){
36

47

5-
test("simplegraph #" + name, function(assert){
8+
test("simplegraph #" + name, function(t){
69

710

811
var SGraph = gn.sparse_graph_t();
@@ -27,10 +30,10 @@ var check = function(name, order, E){
2730
g.eadd(V[e[0]], V[e[1]], e[2]);
2831
}
2932

30-
33+
3134

3235
var d = gn.sqmat(2, order, Infinity);
33-
36+
3437
simplegraph(g, order, d, h);
3538

3639

@@ -134,4 +137,4 @@ var I = [
134137

135138
for(var i = 0; i < I.length; ++i){
136139
check.apply(undefined, I[i]);
137-
}
140+
}
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,116 @@
1-
import test from 'ava';
1+
import test from 'ava' ;
22

3-
var check = function(key, alg, callback){
4-
test(key, function(assert){
5-
callback(alg, assert);
6-
});
7-
};
3+
import * as gn from '../../../../../../src' ;
84

5+
function macro ( t , alg , callback ) {
6+
callback(alg, t);
7+
}
98

10-
var tests = {
9+
const tests = {
1110

12-
test10_empty : function(alg){
11+
test10_empty : (alg,t) => {
1312
// empty input graph
1413
t.deepEqual(alg([]), []);
1514
},
16-
test11_singleedge : function(alg){
15+
test11_singleedge : (alg,t) => {
1716
// single edge
1817
t.deepEqual(alg([ [0,1,1] ]), [1, 0]);
1918
},
2019

21-
test12 : function(alg){
20+
test12 : (alg,t) => {
2221
t.deepEqual(alg([ [1,2,10], [2,3,11] ]), [ -1, -1, 3, 2 ]);
2322
},
2423

25-
test13 : function(alg){
24+
test13 : (alg,t) => {
2625
t.deepEqual(alg([ [1,2,5], [2,3,11], [3,4,5] ]), [ -1, -1, 3, 2, -1 ]);
2726
},
2827

29-
test14_maxcard : function(alg){
28+
test14_maxcard : (alg,t) => {
3029
// maximum cardinality
3130
t.deepEqual(alg([ [1,2,5], [2,3,11], [3,4,5] ], true), [ -1, 2, 1, 4, 3 ]);
3231
},
3332

34-
test15_float : function(alg){
33+
test15_float : (alg,t) => {
3534
// floating point weigths
3635
t.deepEqual(alg([ [1,2,Math.PI], [2,3,Math.E], [1,3,3.0], [1,4,Math.sqrt(2.0)] ]), [ -1, 4, 3, 2, 1 ]);
3736
},
3837

39-
test16_negative : function(alg){
38+
test16_negative : (alg,t) => {
4039
// negative weights
4140
t.deepEqual(alg([ [1,2,2], [1,3,-2], [2,3,1], [2,4,-1], [3,4,-6] ], false), [ -1, 2, 1, -1, -1 ]);
4241
t.deepEqual(alg([ [1,2,2], [1,3,-2], [2,3,1], [2,4,-1], [3,4,-6] ], true), [ -1, 3, 4, 1, 2 ]);
4342
},
4443

45-
test20_sblossom : function(alg){
44+
test20_sblossom : (alg,t) => {
4645
// create S-blossom and use it for augmentation
4746
t.deepEqual(alg([ [1,2,8], [1,3,9], [2,3,10], [3,4,7] ]), [ -1, 2, 1, 4, 3 ]);
4847
t.deepEqual(alg([ [1,2,8], [1,3,9], [2,3,10], [3,4,7], [1,6,5], [4,5,6] ]), [ -1, 6, 3, 2, 5, 4, 1 ]);
4948
},
5049

51-
test21_tblossom : function(alg){
50+
test21_tblossom : (alg,t) => {
5251
// create S-blossom, relabel as T-blossom, use for augmentation
5352
t.deepEqual(alg([ [1,2,9], [1,3,8], [2,3,10], [1,4,5], [4,5,4], [1,6,3] ]), [ -1, 6, 3, 2, 5, 4, 1 ]);
5453
t.deepEqual(alg([ [1,2,9], [1,3,8], [2,3,10], [1,4,5], [4,5,3], [1,6,4] ]), [ -1, 6, 3, 2, 5, 4, 1 ]);
5554
t.deepEqual(alg([ [1,2,9], [1,3,8], [2,3,10], [1,4,5], [4,5,3], [3,6,4] ]), [ -1, 2, 1, 6, 5, 4, 3 ]);
5655
},
5756

58-
test22_s_nest : function(alg){
57+
test22_s_nest : (alg,t) => {
5958
// create nested S-blossom, use for augmentation
6059
t.deepEqual(alg([ [1,2,9], [1,3,9], [2,3,10], [2,4,8], [3,5,8], [4,5,10], [5,6,6] ]), [ -1, 3, 4, 1, 2, 6, 5 ]);
6160
},
6261

63-
test23_s_relabel_nest : function(alg){
62+
test23_s_relabel_nest : (alg,t) => {
6463
// create S-blossom, relabel as S, include in nested S-blossom
6564
t.deepEqual(alg([ [1,2,10], [1,7,10], [2,3,12], [3,4,20], [3,5,20], [4,5,25], [5,6,10], [6,7,10], [7,8,8] ]), [ -1, 2, 1, 4, 3, 6, 5, 8, 7 ]);
6665
},
6766

68-
test24_s_nest_expand : function(alg){
67+
test24_s_nest_expand : (alg,t) => {
6968
// create nested S-blossom, augment, expand recursively
7069
t.deepEqual(alg([ [1,2,8], [1,3,8], [2,3,10], [2,4,12], [3,5,12], [4,5,14], [4,6,12], [5,7,12], [6,7,14], [7,8,12] ]), [ -1, 2, 1, 5, 6, 3, 4, 8, 7 ]);
7170
},
7271

73-
test25_s_t_expand : function(alg){
72+
test25_s_t_expand : (alg,t) => {
7473
// create S-blossom, relabel as T, expand
7574
t.deepEqual(alg([ [1,2,23], [1,5,22], [1,6,15], [2,3,25], [3,4,22], [4,5,25], [4,8,14], [5,7,13] ]), [ -1, 6, 3, 2, 8, 7, 1, 5, 4 ]);
7675
},
7776

78-
test26_s_nest_t_expand : function(alg){
77+
test26_s_nest_t_expand : (alg,t) => {
7978
// create nested S-blossom, relabel as T, expand
8079
t.deepEqual(alg([ [1,2,19], [1,3,20], [1,8,8], [2,3,25], [2,4,18], [3,5,18], [4,5,13], [4,7,7], [5,6,7] ]), [ -1, 8, 3, 2, 7, 6, 5, 4, 1 ]);
8180
},
8281

83-
test30_tnasty_expand : function(alg){
82+
test30_tnasty_expand : (alg,t) => {
8483
// create blossom, relabel as T in more than one way, expand, augment
8584
t.deepEqual(alg([ [1,2,45], [1,5,45], [2,3,50], [3,4,45], [4,5,50], [1,6,30], [3,9,35], [4,8,35], [5,7,26], [9,10,5] ]), [ -1, 6, 3, 2, 8, 7, 1, 5, 4, 10, 9 ]);
8685
},
8786

88-
test31_tnasty2_expand : function(alg){
87+
test31_tnasty2_expand : (alg,t) => {
8988
// again but slightly different
9089
t.deepEqual(alg([ [1,2,45], [1,5,45], [2,3,50], [3,4,45], [4,5,50], [1,6,30], [3,9,35], [4,8,26], [5,7,40], [9,10,5] ]), [ -1, 6, 3, 2, 8, 7, 1, 5, 4, 10, 9 ]);
9190
},
9291

93-
test32_t_expand_leastslack : function(alg){
92+
test32_t_expand_leastslack : (alg,t) => {
9493
// create blossom, relabel as T, expand such that a new least-slack S-to-free edge is produced, augment
9594
t.deepEqual(alg([ [1,2,45], [1,5,45], [2,3,50], [3,4,45], [4,5,50], [1,6,30], [3,9,35], [4,8,28], [5,7,26], [9,10,5] ]), [ -1, 6, 3, 2, 8, 7, 1, 5, 4, 10, 9 ]);
9695
},
9796

98-
test33_nest_tnasty_expand : function(alg){
97+
test33_nest_tnasty_expand : (alg,t) => {
9998
// create nested blossom, relabel as T in more than one way, expand outer blossom such that inner blossom ends up on an augmenting path
10099
t.deepEqual(alg([ [1,2,45], [1,7,45], [2,3,50], [3,4,45], [4,5,95], [4,6,94], [5,6,94], [6,7,50], [1,8,30], [3,11,35], [5,9,36], [7,10,26], [11,12,5] ]), [ -1, 8, 3, 2, 6, 9, 4, 10, 1, 5, 7, 12, 11 ]);
101100
},
102101

103-
test34_nest_relabel_expand : function(alg){
102+
test34_nest_relabel_expand : (alg,t) => {
104103
// create nested S-blossom, relabel as S, expand recursively
105104
t.deepEqual(alg([ [1,2,40], [1,3,40], [2,3,60], [2,4,55], [3,5,55], [4,5,50], [1,8,15], [5,7,30], [7,6,10], [8,10,10], [4,9,30] ]), [ -1, 2, 1, 5, 9, 3, 7, 6, 10, 4, 8 ]);
106105
}
107106
};
108107

109-
var alg = [
110-
gn.wblossom_n3_t(true, true, true),
108+
const alg = [
109+
gn.wblossom_n3_t(false, true, true),
111110
gn.wblossom_n3_t(false, false, false),
112111
gn.wblossom_n3_t()
113112
];
114113

115-
116-
for(var i = 0; i < alg.length; ++i){
117-
for(var key in tests)
118-
check(key, alg[i], tests[key]);
119-
}
114+
for(let i = 0; i < alg.length; ++i)
115+
for(const key in tests)
116+
test(`${key} ${i}`, macro, alg[i], tests[key]);

test/src/undirected/offline/algo/sp/dijkstra.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import test from 'ava';
22

3-
4-
import binomialheap from "@aureooms/js-binomial-heap" ;
3+
import { BinomialHeap , BinomialTreeWithParent } from "@aureooms/js-binomial-heap" ;
54
import functools from "@aureooms/js-functools" ;
65

6+
import * as gn from '../../../../../../src' ;
7+
78
function one ( label, n, s, edges, prev, dist ) {
89

910
test( "dijkstra #" + label, t => {
1011

11-
var Graph, PriorityQueue;
1212
var g, i, v, e, j, p, d, used, ref, left, predicate;
1313

14-
PriorityQueue = binomialheap.BinomialHeap( binomialheap.BinomialTreeWithParent );
14+
const PriorityQueue = BinomialHeap( BinomialTreeWithParent );
1515

16-
Graph = gn.dense_graph_t();
16+
const Graph = gn.dense_graph_t();
1717

1818
g = new Graph();
1919
i = n;

test/src/undirected/offline/algo/sp/floyd.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import test from 'ava';
22

3-
4-
import binomialheap from "@aureooms/js-binomial-heap" ;
3+
import { BinomialHeap , BinomialTreeWithParent } from "@aureooms/js-binomial-heap" ;
54
import functools from "@aureooms/js-functools" ;
65

6+
import * as gn from '../../../../../../src' ;
7+
78
function one ( label, n, edges ) {
89

910
test( "floyd #" + label, t => {
@@ -12,11 +13,11 @@ test( "floyd #" + label, t => {
1213

1314
var d, g, i, v, e, j;
1415

15-
var Graph, PriorityQueue, amat, floyd;
16+
var amat, floyd;
1617

17-
PriorityQueue = binomialheap.BinomialHeap( binomialheap.BinomialTreeWithParent );
18+
const PriorityQueue = BinomialHeap( BinomialTreeWithParent );
1819

19-
Graph = gn.dense_graph_t();
20+
const Graph = gn.dense_graph_t();
2021

2122
amat = gn.amat_t();
2223

@@ -60,7 +61,7 @@ test( "floyd #" + label, t => {
6061

6162
dist[i][i] = Infinity;
6263

63-
g.eitr( [i], function ( _, _, w ) {
64+
g.eitr( [i], function ( _1, _2, w ) {
6465
dist[i][i] = Math.min( dist[i][i], w * 2 );
6566
});
6667

test/src/undirected/offline/algo/sp/sptreedfs.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import test from 'ava';
22

3-
4-
import binomialheap from "@aureooms/js-binomial-heap" ;
3+
import { BinomialHeap , BinomialTreeWithParent } from "@aureooms/js-binomial-heap" ;
54
import functools from "@aureooms/js-functools" ;
65

6+
import * as gn from '../../../../../../src' ;
7+
78
function one ( label, n, edges ) {
89

910
test( "sptreedfs #" + label, t => {
@@ -12,11 +13,11 @@ test( "sptreedfs #" + label, t => {
1213

1314
var next, successors, d;
1415

15-
var Graph, PriorityQueue, amat, floyd, sptreedfs;
16+
var amat, floyd, sptreedfs;
1617

17-
PriorityQueue = binomialheap.BinomialHeap( binomialheap.BinomialTreeWithParent );
18+
const PriorityQueue = BinomialHeap( BinomialTreeWithParent );
1819

19-
Graph = gn.dense_graph_t();
20+
const Graph = gn.dense_graph_t();
2021

2122
amat = gn.amat_t();
2223

0 commit comments

Comments
 (0)