Skip to content
This repository has been archived by the owner on Oct 5, 2020. It is now read-only.

Commit

Permalink
Add test cases for empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
luludotdev committed Aug 14, 2018
1 parent 5cea922 commit 359d50b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,27 @@ const analyze = lines => {

let model = {}
for (let line of lines) {
try {
let tokens = line.split(' ')
let tokens = line.split(' ')

for (let i = 0; i < tokens.length; i++) {
let token = tokens[i]
let next = tokens[i + 1]
for (let i = 0; i < tokens.length; i++) {
let token = tokens[i]
let next = tokens[i + 1]

if (!next) {
token = token.replace('\n', '')
next = '\n'
}
if (!next) {
token = token.replace('\n', '')
next = '\n'
}

if (!model[token]) model[token] = { start: false, next: {} }
if (i === 0) model[token].start = true
if (!model[token]) model[token] = { start: false, next: {} }
if (i === 0) model[token].start = true

let count = model[token].count || 0
if (i === 0) count++
model[token].count = count
let count = model[token].count || 0
if (i === 0) count++
model[token].count = count

let nextCount = model[token].next[next] || 0
nextCount++
model[token].next[next] = nextCount
}
} catch (err) {
continue
let nextCount = model[token].next[next] || 0
nextCount++
model[token].next[next] = nextCount
}
}

Expand Down
16 changes: 16 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ describe('analyze()', () => {
expect(() => { analyze({ object: true }) }).to.throw(analyzeErrors.invalidInput)
})
})

describe('return types', () => {
it('should return an Object', () => {
expect(analyze(testInput)).to.be.an('object')
})
})

describe('handling empty lines', () => {
it('should not throw', () => {
expect(() => { analyze(['a b c', '', 'd e f']) }).to.not.throw()
})

it('should return an Object', () => {
expect(analyze(['a b c', '', 'd e f'])).to.be.an('object')
})
})
})

describe('generate()', () => {
Expand Down

0 comments on commit 359d50b

Please sign in to comment.