File tree 5 files changed +470
-292
lines changed 5 files changed +470
-292
lines changed Original file line number Diff line number Diff line change @@ -74,10 +74,12 @@ OneLinkList.prototype.AddToEnd = function(data) {
74
74
*/
75
75
OneLinkList . prototype . FindAt = function ( position ) {
76
76
// 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 ) ;
79
79
} else if ( position % 1 != 0 || typeof position != Number . name . toLowerCase ( ) ) {
80
80
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 ) ;
81
83
}
82
84
83
85
// Sequentially search for item (1 -> last).
@@ -262,11 +264,6 @@ OneLinkList.prototype.PrintAll = function() {
262
264
}
263
265
264
266
/**
265
- * All linked list exports.
267
+ * All single linked list exports.
266
268
*/
267
- module . exports = OneLinkList ;
268
-
269
- // Use below if exporting multiple items.
270
- // module.exports = {
271
- // OneLinkList: OneLinkList,
272
- // }
269
+ module . exports = OneLinkList ;
Original file line number Diff line number Diff line change 1
1
// app.js : Main entry point for the app.
2
2
const OneLinkList = require ( './Data Structs/OneLinkList' ) ;
3
- const OneListTest = require ( '../tests/OneTest' ) ;
4
3
const TwoLinkList = require ( './Data Structs/TwoLinkList' ) ;
4
+ const test_OneList = require ( './tests/Test_OneLinkList' ) ;
5
5
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 ) ;
24
8
25
9
26
- // TwoLinkList
10
+ // -- TwoLinkList --
27
11
// var users2 = new TwoLinkList('one');
28
12
// users2.AddToEnd('two');
29
13
// users2.AddToEnd('three');
Original file line number Diff line number Diff line change 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.
2
2
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
+ }
3
17
/**
4
18
* Errors that may occur in lists.
5
19
*/
@@ -15,22 +29,8 @@ const ListErr = {
15
29
} ,
16
30
InvalidData : function ( ) {
17
31
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.` ,
34
34
}
35
35
36
36
module . exports = {
You can’t perform that action at this time.
0 commit comments