-
Notifications
You must be signed in to change notification settings - Fork 65
LinkedList src and spec file... Any input GREATLY APPRECIATED... Thanks in advance... #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| import chai, { expect } from 'chai' | ||
| import chaiChange from 'chai-change' | ||
| import LinkedList from '../src/linkedList' | ||
|
|
||
| chai.use(chaiChange) | ||
|
|
||
| describe('LinkedList', () => { | ||
|
|
||
|
|
||
| it('exists', () => { | ||
|
|
||
| expect(LinkedList).to.be.a('function') | ||
|
|
||
| }) | ||
|
|
||
| context('getHeadNode', () => { | ||
|
|
||
| it('returns head node', () => { | ||
| const linkedList = new LinkedList() | ||
| linkedList.insert('apple') | ||
| linkedList.insert('banana') | ||
|
|
||
| expect(linkedList.getHeadNode().data).to.equal('apple') | ||
|
|
||
| }) | ||
| }) | ||
|
|
||
| context('getTailNode', () => { | ||
|
|
||
| it('returns tail node', () => { | ||
| const linkedList = new LinkedList() | ||
| linkedList.insert('apple') | ||
| linkedList.insert('banana') | ||
|
|
||
| expect(linkedList.getTailNode().data).to.equal('banana') | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spacing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everywhere, I'm not going to comment them all. It almost doesn't matter which way you pick, just be maximum consistent before submitting PR |
||
| }) | ||
| }) | ||
|
|
||
| context('contains', () => { | ||
| const string = 'banana' | ||
| const linkedList = new LinkedList() | ||
| linkedList.insert('apple') | ||
| linkedList.insert('banana') | ||
|
|
||
| it('checks to see if node in list contains "bananas"', () => { | ||
|
|
||
| expect(linkedList.contains("banana")).to.equal(true) | ||
|
|
||
| }) | ||
| }) | ||
|
|
||
| context('find', () => { | ||
| const string = 'banana' | ||
| const linkedList = new LinkedList() | ||
| linkedList.insert('apple') | ||
| linkedList.insert('banana') | ||
|
|
||
| it('returns the first node with corresponding data or -1', () => { | ||
|
|
||
| expect(linkedList.find("banana").data).to.equal('banana') | ||
|
|
||
| }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to include a test for the |
||
| }) | ||
|
|
||
| context('insert', () => { | ||
| const linkedList = new LinkedList() | ||
| linkedList.insert('apple') | ||
| linkedList.insert('banana') | ||
|
|
||
| it.only('inserts node with data to tail of list', () => { | ||
|
|
||
| expect(linkedList.tail.data).to.equal("banana") | ||
|
|
||
| }) | ||
| }) | ||
|
|
||
| context('insertFirst', () => { | ||
| const linkedList = new LinkedList() | ||
| linkedList.insert('apple') | ||
| linkedList.insertFirst('banana') | ||
|
|
||
| it('inserts node with data at head of list', () => { | ||
|
|
||
| expect(linkedList.head.data).to.equal("banana") | ||
|
|
||
| }) | ||
| }) | ||
|
|
||
| context('insertBefore', (string, data) => { | ||
| const linkedList = new LinkedList() | ||
| linkedList.insert('banana') | ||
| linkedList.insertBefore('banana', 'apple') | ||
|
|
||
| it('inserts node containing "apple" before node containing "banana"', () => { | ||
|
|
||
| expect(linkedList.head.data).to.equal('apple') | ||
|
|
||
| }) | ||
| }) | ||
|
|
||
| context('insertAfter', () => { | ||
| const linkedList = new LinkedList() | ||
| linkedList.insert('banana') | ||
| linkedList.insert('twitter') | ||
| linkedList.insert('google') | ||
| linkedList.insert('netflix') | ||
| linkedList.insertAfter('banana', 'apple') | ||
|
|
||
|
|
||
| it('inserts node containing "bananas" after node containing "apples"', () => { | ||
|
|
||
| expect(linkedList.head.next.data).to.equal('apple') | ||
|
|
||
| }) | ||
| }) | ||
|
|
||
| context('remove', () => { | ||
| const linkedList = new LinkedList() | ||
| linkedList.insert('apple') | ||
| linkedList.insert('banana') | ||
| linkedList.remove() | ||
|
|
||
| it('removes the tail node from the list', () => { | ||
|
|
||
| expect(linkedList.tail.data).to.equal('apple') | ||
|
|
||
| }) | ||
| }) | ||
|
|
||
| context('removeFirst', () => { | ||
| const linkedList = new LinkedList() | ||
| linkedList.insert('apple') | ||
| linkedList.insert('banana') | ||
| linkedList.removeFirst() | ||
|
|
||
| it('removes the head element from list', () => { | ||
|
|
||
| expect(linkedList.head.data).to.equal('banana') | ||
| }) | ||
| }) | ||
|
|
||
| context('isEmpty', () => { | ||
| const linkedList = new LinkedList() | ||
| linkedList.isEmpty() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line (145) is not necessary |
||
|
|
||
|
|
||
|
|
||
| it('Determines if list is empty or not', () => { | ||
|
|
||
| expect(linkedList.isEmpty()).to.equal(true) | ||
|
|
||
|
|
||
| }) | ||
| }) | ||
|
|
||
| context('size', () => { | ||
|
|
||
| it('Determines the number of nodes in list', () => { | ||
| const linkedList = new LinkedList() | ||
| linkedList.insert('apple') | ||
| linkedList.insert('banana') | ||
| linkedList.insert('tree') | ||
| linkedList.insert('grapes') | ||
| linkedList.insert('fire') | ||
| expect(linkedList.size).to.equal(5) | ||
| }) | ||
| }) | ||
|
|
||
| context('clear', () => { | ||
| const linkedList = new LinkedList() | ||
| linkedList.insert('apple') | ||
| linkedList.insert('banana') | ||
| linkedList.insert('tree') | ||
| linkedList.insert('grapes') | ||
| linkedList.insert('fire') | ||
| linkedList.clear() | ||
|
|
||
| it('clears the list of all nodes/data', () => { | ||
|
|
||
| expect(linkedList.tail).to.equal(null) && | ||
| expect(linkedList.head).to.equal(null) && | ||
| expect(linkedList.size).to.equal(0) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The two |
||
|
|
||
| }) | ||
| }) | ||
| }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good job on these linked list tests! There are some blank lines which could be removed to make it look a little cleaner. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import chai, { expect } from 'chai' | ||
| import chaiChange from 'chai-change' | ||
| import Node from '../src/node' | ||
|
|
||
| chai.use(chaiChange) | ||
|
|
||
| describe('Node', () => { | ||
| 'use strict' | ||
|
|
||
| it('exists', () => { | ||
| expect(Node).to.be.a('function') | ||
| }) | ||
|
|
||
| context('setNext()', () => { | ||
| it('Changes the next node in queue and returns current node', () => { | ||
|
|
||
| const nodeA = new Node({data: "apple"}) | ||
| const nodeB = new Node({data: "banana"}) | ||
|
|
||
| expect(() => nodeA.setNext(nodeB)) | ||
| .to.alter(() => nodeA.next, { from: null, to: nodeB }) | ||
| }) | ||
| context('getNext()', () => { | ||
| it('returns the value of the next object in queue', () => { | ||
| expect(() => nodeA.getNext().to.equal({nodeB})) | ||
| }) | ||
| }) | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import chai, { expect } from 'chai' | ||
| import chaiChange from 'chai-change' | ||
| import Queue from '../src/queue' | ||
|
|
||
| chai.use(chaiChange) | ||
|
|
||
| describe('Queue', () => { | ||
|
|
||
| it('exists', () => { | ||
|
|
||
| expect(Queue).to.be.a('function') | ||
|
|
||
| }) | ||
|
|
||
| context('enqueue', () => { | ||
| const queue = new Queue() | ||
| queue.enqueue('dumbass') | ||
| queue.enqueue('Hella Weed') | ||
| queue.enqueue('Dummy Weed') | ||
|
|
||
| it('adds node containing string to the back of queue', () => { | ||
|
|
||
| expect(queue.size).to.equal(3) | ||
| }) | ||
| }) | ||
|
|
||
| context('dequeue') | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be consistant in spacing