import { Chapter, _privates } from '../src/Chapter.js'

const { getNextBiggerNumber } = _privates

describe('Chapter', function() {
  const demoText =
    'Hello World. Foo bar baz. Lorem ipsum dolor sit. Worttrennungsalgorithmus.'

  it('Iterates through segments', function() {
    let chapter = new Chapter(demoText, 7)
    let i = 1
    while (chapter.next()) i++
    expect(i).toBe(13)
  })

  it('Iterates through words', function() {
    let chapter = new Chapter(demoText, 7)
    let i = 1
    while (chapter.nextWord()) i++
    expect(i).toBe(10)
  })

  it('Iterates through sentences', function() {
    let chapter = new Chapter(demoText)
    let i = 1
    while (chapter.nextSentence()) i++
    expect(i).toBe(4)
  })

  it('Iterators return null on finish', function() {
    let chapter = new Chapter(demoText, 7)
    let cur
    while ((cur = chapter.next())) {}
    expect(cur).toBe(null)
    while ((cur = chapter.prev())) {}
    expect(cur).toBe(null)
    while ((cur = chapter.nextWord())) {}
    expect(cur).toBe(null)
    while ((cur = chapter.prevWord())) {}
    expect(cur).toBe(null)
    while ((cur = chapter.nextSentence())) {}
    expect(cur).toBe(null)
    while ((cur = chapter.prevSentence())) {}
    expect(cur).toBe(null)
  })
})

describe('nextBiggerNumber', function() {
  it('Returns a the next bigger number', function() {
    expect(getNextBiggerNumber(5, [1, 4, 6])).toBe(6)
  })
})
