forked from rolling-scopes-school/doubly-linked-list
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Maksim Shastsel
committed
Jan 24, 2017
0 parents
commit f01b363
Showing
11 changed files
with
316 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.DS_Store | ||
node_modules | ||
app.bundle.js | ||
app.bundle.js.map | ||
npm-debug* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
### Doubly linked list task | ||
|
||
:warning: DO NOT FORK AND SUBMIT PRS TO THIS REPO :warning: | ||
|
||
### Prerequisites | ||
* Install [nodejs](https://nodejs.org/en/) (>= v6.9.4) | ||
* open bash in this folder | ||
* `npm install` | ||
|
||
### Run tests | ||
```sh | ||
npm test | ||
``` | ||
|
||
### Run in browser | ||
```sh | ||
npm start | ||
``` | ||
|
||
open http://localhost:8080 | ||
|
||
--- | ||
|
||
© [Shastel](https://github.com/Shastel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Document</title> | ||
<style> | ||
body { | ||
margin: 0; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<script src="./app.bundle.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const linkedList = require('./src/linked-list'); | ||
|
||
const h = new linkedList(); | ||
window.h = h; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "doubly-linked-list", | ||
"version": "1.0.0", | ||
"description": "", | ||
"scripts": { | ||
"test": "mocha -r ./test/setup-mocha.js", | ||
"start": "webpack-dev-server" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"mocha": "^3.0.2", | ||
"sinon": "^1.17.5", | ||
"sinon-chai": "^2.8.0", | ||
"webpack": "^1.13.1", | ||
"webpack-dev-server": "^1.14.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"LinkedList": { | ||
"weight": 100, | ||
"suitesWeights": { | ||
"#constructor": 5, | ||
"#append": 10, | ||
"#head": 5, | ||
"#tail": 5, | ||
"#clear": 5, | ||
"#at": 10, | ||
"#insertAt": 10, | ||
"#isEmpty": 5, | ||
"#deleteAt": 10, | ||
"#reverse": 15, | ||
"#isEmpty": 5, | ||
"#indexOf": 10, | ||
"chaining": 5 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const Node = require('./node'); | ||
|
||
class LinkedList { | ||
constructor() {} | ||
|
||
append(data) {} | ||
|
||
head() {} | ||
|
||
tail() {} | ||
|
||
at(index) {} | ||
|
||
insertAt(index, data) {} | ||
|
||
isEmpty() {} | ||
|
||
clear() {} | ||
|
||
deleteAt(index) {} | ||
|
||
reverse() {} | ||
|
||
indexOf(data) {} | ||
} | ||
|
||
module.exports = LinkedList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Node { | ||
constructor(data = null, prev = null, next = null) { | ||
this.data = data; | ||
this.prev = prev; | ||
this.next = next; | ||
} | ||
} | ||
|
||
module.exports = Node; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
const Node = require('../src/node'); | ||
const LinkedList = require('../src/linked-list'); | ||
|
||
describe('LinkedList', () => { | ||
describe('#constructor', () => { | ||
const list = new LinkedList(); | ||
|
||
it('assign 0 to this.length', () => { | ||
expect(list.length).to.equal(0); | ||
}) | ||
}); | ||
|
||
describe('#append', () => { | ||
it('should assign any nodes to this._head and this._tail if list is empty', () => { | ||
const data = 42; | ||
|
||
const list = new LinkedList(); | ||
|
||
list.append(data); | ||
|
||
expect(list._tail).to.be.an.instanceof(Node) | ||
expect(list._head).to.be.an.instanceof(Node) | ||
}); | ||
|
||
it('should add new data to the end of list', () => { | ||
const list = new LinkedList(); | ||
|
||
list.append(123); | ||
list.append(413); | ||
|
||
expect(list.length).to.equal(2); | ||
expect(list.tail()).to.equal(413); | ||
expect(list.head()).to.equal(123); | ||
}); | ||
|
||
}); | ||
describe('#head', () => { | ||
const list = new LinkedList(); | ||
it('should return data from the this.head', () => { | ||
const data = 13; | ||
|
||
list.append(data); | ||
|
||
expect(list.head()).to.equal(data) | ||
}); | ||
}); | ||
describe('#tail', () => { | ||
const list = new LinkedList(); | ||
it('should return data from the this.tail', () => { | ||
const data = 31; | ||
|
||
list.append(data); | ||
|
||
expect(list.tail()).to.equal(data) | ||
}); | ||
}); | ||
describe('#at', () => { | ||
it('should return Node.data by index', () => { | ||
const list = new LinkedList(); | ||
|
||
list.append(1); | ||
list.append(123); | ||
list.append(444); | ||
|
||
expect(list.at(0)).to.equal(1); | ||
expect(list.at(1)).to.equal(123); | ||
expect(list.at(2)).to.equal(444); | ||
|
||
}); | ||
}); | ||
describe('#insertAt', () => { | ||
it('should insert data by index', () => { | ||
const list = new LinkedList(); | ||
const data = 34; | ||
const position = 1; | ||
|
||
list.append(32); | ||
list.append(47); | ||
|
||
list.insertAt(position, data); | ||
|
||
expect(list.at(position)).to.equal(data); | ||
}); | ||
}); | ||
describe('#isEmpty', () => { | ||
it('should return true if list is empty', () => { | ||
const list = new LinkedList(); | ||
|
||
expect(list.isEmpty()).to.be.true; | ||
|
||
list.append(32); | ||
|
||
expect(list.isEmpty()).to.be.false; | ||
}); | ||
}); | ||
|
||
describe('#clear', () => { | ||
it('should clear the list', () => { | ||
const list = new LinkedList(); | ||
|
||
list.append(32); | ||
list.append(47); | ||
|
||
list.clear(); | ||
|
||
expect(list.head()).to.equal(null); | ||
expect(list.tail()).to.equal(null); | ||
expect(list.length).to.equal(0); | ||
}); | ||
}); | ||
describe('#deleteAt', () => { | ||
it('should delete element by index', () => { | ||
const list = new LinkedList(); | ||
|
||
list.append(1); | ||
list.append(2); | ||
list.append(3); | ||
list.append(4); | ||
list.append(5); | ||
|
||
list.deleteAt(2); | ||
|
||
expect(list.at(2)).to.equal(4); | ||
}); | ||
}); | ||
describe('#reverse', () => { | ||
it('should reverse the list', () => { | ||
const list = new LinkedList(); | ||
|
||
list.append(1); | ||
list.append(2); | ||
list.append(3); | ||
list.append(4); | ||
list.append(5); | ||
list.append(6); | ||
|
||
list.reverse(); | ||
|
||
expect(list.head()).to.equal(6); | ||
expect(list.tail()).to.equal(1); | ||
|
||
expect(list.at(1)).to.equal(5); | ||
expect(list.at(2)).to.equal(4); | ||
expect(list.at(3)).to.equal(3); | ||
expect(list.at(4)).to.equal(2); | ||
}); | ||
}); | ||
describe('#indexOf', () => { | ||
it('should return index of element if data is found', () => { | ||
const list = new LinkedList(); | ||
|
||
list.append(3); | ||
list.append(7); | ||
|
||
expect(list.indexOf(3)).to.equal(0); | ||
expect(list.indexOf(7)).to.equal(1); | ||
}); | ||
|
||
it('should return -1 if data not found', () => { | ||
const list = new LinkedList(); | ||
|
||
list.append(7); | ||
|
||
expect(list.indexOf(3)).to.equal(-1); | ||
}) | ||
}); | ||
describe('chaining', () => { | ||
it('append reverse deleteAt insertAt methods should be chainable', () => { | ||
const list = new LinkedList(); | ||
|
||
function fn() { | ||
list.append(4).reverse().deleteAt(0).clear().insertAt(0, 3); | ||
} | ||
|
||
expect(fn).to.not.throw(); | ||
}) | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const chai = require('chai'); | ||
const sinon = require('sinon'); | ||
const sinonChai = require('sinon-chai'); | ||
|
||
global.expect = chai.expect; | ||
global.sinon = sinon; | ||
chai.use(sinonChai); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
entry: { app: './index.js' }, | ||
output: { | ||
path: './', | ||
filename: 'app.bundle.js' | ||
}, | ||
devtool: 'source-map' | ||
}; |