Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 187 additions & 0 deletions spec/linkedList.js
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', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be consistant in spacing

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')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing

Choose a reason for hiding this comment

The 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')

})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to include a test for the -1 case as well.

})

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()

Choose a reason for hiding this comment

The 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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two &&'s are not necessary.


})
})
})

Choose a reason for hiding this comment

The 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.

29 changes: 29 additions & 0 deletions spec/node.js
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}))
})
})
})
})
28 changes: 28 additions & 0 deletions spec/queue.js
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')
})
49 changes: 49 additions & 0 deletions spec/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,64 @@ describe('Stack', () => {
'use strict'

it('exists', () => {

expect(Stack).to.be.a('function')
})

context('push()', () => {

it('pushes an element to the top of the stack.', () => {
const myStack = new Stack()

expect(() => myStack.push('foo'))
.to.alter(() => myStack.length(), { from: 0, to: 1 })
})
})

context('pop()', () => {
const myStack = new Stack()
myStack.push('indica')
myStack.push('sativa')
myStack.push('alcohol')
myStack.pop()

it('removes the top element from stack', () =>{

expect(myStack.size).to.equal(2)
})
})

context('peek()', () => {
const myStack = new Stack()
myStack.push('indica')
myStack.push('sativa')
myStack.peek()

it('pushes an element', () => {

expect(myStack.top.data).to.equal('sativa')
})
})

context('isEmpty', () => {
const myStack = new Stack()

it('Returns true if stack is empty', () => {

expect(myStack.isEmpty()).to.equal(true)
})
})

context('length()', () => {
const myStack = new Stack()
myStack.push('indica')
myStack.push('sativa')
myStack.length()

it('Returns the number of nodes/size of stack', () => {

expect(myStack.length()).to.equal(2)
})
})

})
Loading