const TreeNode = require('../helpers/TreeNode')

const {
  find,
  findMax,
  findMin,
  height,
  insert,
  remove
} = require('../operations')

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

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

  test('Remove - the root node', () => {
    const rootNode = new TreeNode(9)

    const nodes = [4, 17, 3, 6, 5, 7, 22, 20]

    nodes.forEach((node) => {
      insert(rootNode, node)
    })

    remove(rootNode, 9)

    // expect(dfsPreOrder(rootNode)).toEqual([])
  })

  test('Remove - one leaf node', () => {
    const rootNode = new TreeNode(9)

    const nodes = [4, 17, 3, 6, 5, 7, 22, 20]

    nodes.forEach((node) => {
      insert(rootNode, node)
    })

    remove(rootNode, 5)

    expect(dfsInOrder(rootNode)).toEqual([3, 4, 6, 7, 9, 17, 20, 22])
  })

  test('Remove - root a node in between', () => {
    const rootNode = new TreeNode(9)

    const nodes = [4, 17, 3, 6, 5, 7, 22, 20]

    nodes.forEach((node) => {
      insert(rootNode, node)
    })

    remove(rootNode, 6)

    expect(dfsInOrder(rootNode)).toEqual([3, 4, 5, 7, 9, 17, 20, 22])
  })
})
