Repository navigation
Expand file tree
/
Copy pathshopping.spec.js
More file actions
139 lines (131 loc) · 2.51 KB
/
Copy pathshopping.spec.js
File metadata and controls
139 lines (131 loc) · 2.51 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
"use strict";
const assert = require("assert");
const Shopping = require("./shopping.js");
describe("Shortest path to all fish and home.", function() {
it("Should parse centres", function() {
const shopping = new Shopping();
const input = `5 5 5
1 1
4 15 23 3 455
1 3
1 4
1 5
1 2 10
1 3 10
1 4 10
1 5 30
2 4 10
3 5 10
4 5 10`;
const district = shopping.parseShoppingData(input);
assert.equal(5, district.centres.length);
assert.equal(4, district.centres[1].products.length);
assert.equal(4, district.centres[0].roads.length);
});
it("Cities should have correct number of roads.", function() {
const shopping = new Shopping();
const input = `5 6 5
1 1
1 2
1 3
1 4
1 5
1 2 10
1 3 10
2 4 10
3 5 10
4 5 10
5 1 10`;
const district = shopping.parseShoppingData(input);
assert.equal(3, district.centres[0].roads.length);
});
it("First city should have a road to 1,2.", function() {
const shopping = new Shopping();
const input = `5 6 5
1 1
1 2
1 3
1 4
1 5
1 2 10
1 3 10
2 4 10
3 5 10
4 5 10
5 1 10`;
const district = shopping.parseShoppingData(input);
assert.equal(1, district.centres[0].roads[0].end);
assert.equal(2, district.centres[0].roads[1].end);
});
it("Default distance to 5 should be 40.", function() {
const shopping = new Shopping();
const input = `5 5 5
1 1
1 2
1 3
1 4
1 5
1 2 10
1 3 10
2 4 10
3 5 10
4 5 10`;
const district = shopping.parseShoppingData(input);
const distance = shopping.visitAll(district, district.centres[0]);
assert.equal(20, distance);
});
it("Max distance should be 30.", function() {
const shopping = new Shopping();
const input = `5 5 5
1 1
1 2
1 3
1 4
1 5
1 2 10
1 3 10
2 4 10
3 5 10
4 5 10`;
const district = shopping.parseShoppingData(input);
const start = district.centres[0];
const node = {
id: start.id,
distance: 0,
nodes: []
};
node.nodes = shopping.graph(district, district.centres[0], 0, []);
shopping.print(node,0);
});
it("Max distance should be 3299.", function() {
const shopping = new Shopping();
const input = `8 9 5
3 2 4 5
0
2 1 2
0
0
2 3 4
1 5
1 1
7 4 150
3 6 166
7 1 602
1 3 932
4 3 959
1 5 269
4 1 644
2 1 745
8 5 834`;
const district = shopping.parseShoppingData(input);
const start = district.centres[0];
const node = {
id: start.id,
distance: 0,
nodes: []
};
node.nodes = shopping.graph(district, district.centres[0], 0, []);
// shopping.print(node,0);
// assert.equal(3299, maxDistance);
});
});