Skip to content

Commit 2e5bcb7

Browse files
committed
Finalized OneLinkList. Improved the testing environment (functional).
1 parent af41ddb commit 2e5bcb7

File tree

5 files changed

+470
-292
lines changed

5 files changed

+470
-292
lines changed

JS Data Structures/Data Structs/OneLinkList.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ OneLinkList.prototype.AddToEnd = function(data) {
7474
*/
7575
OneLinkList.prototype.FindAt = function(position) {
7676
// Show error when trying to access position outside of list.
77-
if(this.count === 0 || position > this.count || position < 1) {
78-
throw new Err.DSException(Err.ListErr.NonExistant(OneLinkList.name), 101);
77+
if(this.count === 0) {
78+
throw new Err.DSException(Err.ListErr.EmptyList, 100);
7979
} else if(position % 1 != 0 || typeof position != Number.name.toLowerCase()) {
8080
throw new Err.DSException(Err.ListErr.InvalidPosition(), 102);
81+
} else if(position > this.count || position < 1) {
82+
throw new Err.DSException(Err.ListErr.NonExistant(OneLinkList.name), 101);
8183
}
8284

8385
// Sequentially search for item (1 -> last).
@@ -262,11 +264,6 @@ OneLinkList.prototype.PrintAll = function() {
262264
}
263265

264266
/**
265-
* All linked list exports.
267+
* All single linked list exports.
266268
*/
267-
module.exports = OneLinkList;
268-
269-
// Use below if exporting multiple items.
270-
// module.exports = {
271-
// OneLinkList: OneLinkList,
272-
// }
269+
module.exports = OneLinkList;

JS Data Structures/app.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
11
// app.js : Main entry point for the app.
22
const OneLinkList = require('./Data Structs/OneLinkList');
3-
const OneListTest = require('../tests/OneTest');
43
const TwoLinkList = require('./Data Structs/TwoLinkList');
4+
const test_OneList = require('./tests/Test_OneLinkList');
55

6-
// OneLinkList empty param test.
7-
if(OneListTest.EmptyParamTest(OneListTest.EmptyFinal)) {
8-
console.log('OneLinkList Empty Param test PASS.');
9-
} else {
10-
console.log('OneLinkList Empty Param test FAIL.');
11-
}
12-
// OneLinkList contains test.
13-
if(OneListTest.ContainsTest()) {
14-
console.log('OneLinkList Contains test PASS.');
15-
} else {
16-
console.log('OneLinkList Contains test PASS.');
17-
}
18-
// OneLinkList AddRemove test.
19-
if(OneListTest.AddRemoveTest()) {
20-
console.log('OneLinkList AddRemove test PASS.');
21-
} else {
22-
console.log('OneLinkList AddRemove test FAIL.');
23-
}
6+
// -- Test the OneLinkList --
7+
test_OneList.OverallOneLinkTest(true);
248

259

26-
// TwoLinkList
10+
// -- TwoLinkList --
2711
// var users2 = new TwoLinkList('one');
2812
// users2.AddToEnd('two');
2913
// users2.AddToEnd('three');

JS Data Structures/misc/Errors.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
// Errors.js - Contains all error messages the js data structures will use.
1+
// Errors.js : Contains all error messages the js data structures will use.
22

3+
/**
4+
* Data Structure error class.
5+
*/
6+
class DSException {
7+
/**
8+
* Creates a new data structure exception.
9+
* @param {String} message - Details why the error occured.
10+
* @param {Number} errCode - Numeric code to represent this error.
11+
*/
12+
constructor(message, errCode) {
13+
this.message = message;
14+
this.code = errCode;
15+
}
16+
}
317
/**
418
* Errors that may occur in lists.
519
*/
@@ -15,22 +29,8 @@ const ListErr = {
1529
},
1630
InvalidData: function() {
1731
return `No valid data was passed as an argument.`;
18-
}
19-
}
20-
21-
/**
22-
* Data Structure error class.
23-
*/
24-
class DSException {
25-
/**
26-
* Creates a new data structure exception.
27-
* @param {String} message - Details why the error occured.
28-
* @param {Number} errCode - Numeric code to represent this error.
29-
*/
30-
constructor(message, errCode) {
31-
this.message = message;
32-
this.code = errCode;
33-
}
32+
},
33+
EmptyList: `The linked list is empty.`,
3434
}
3535

3636
module.exports = {

0 commit comments

Comments
 (0)