const TreeNode = require('../helpers/TreeNode')
const { insert } = require('../operations')
const {
  bfsInOrder,
  dfsInOrder,
  dfsPostOrder,
  dfsPreOrder
} = require('../traversals')

describe('Traversals', () => {
  const rootNode = new TreeNode(9)
  const nodes = [4, 17, 3, 6, 5, 7, 22, 20]
  nodes.forEach((node) => {
    insert(rootNode, node)
  })

  test('BFS', () => {
    expect(bfsInOrder(rootNode)).toEqual([9, 4, 17, 3, 6, 22, 5, 7, 20])
  })

  test('DFS - In Order', () => {
    expect(dfsInOrder(rootNode)).toEqual([3, 4, 5, 6, 7, 9, 17, 20, 22])
  })

  test('DFS - Pre Order', () => {
    expect(dfsPreOrder(rootNode)).toEqual([9, 4, 3, 6, 5, 7, 17, 22, 20])
  })

  test('DFS - Post Order', () => {
    expect(dfsPostOrder(rootNode)).toEqual([3, 5, 7, 6, 4, 20, 22, 17, 9])
  })
})
