package BinaryTreeLevelOrderTraversal;


import org.junit.Test;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

public class BinaryTreeLevelOrderTraversalSolutionTest {

    private BinaryTreeLevelOrderTraversalSolution solution = new BinaryTreeLevelOrderTraversalSolution();

    @Test
    public void nullInput() {
        List<List<Integer>> result = solution.levelOrder(null);

        assertThat(result).isEmpty();
    }

    @Test
    public void singleNodeInput() {
        TreeNode root = new TreeNode(1);
        List<List<Integer>> result = solution.levelOrder(root);

        assertThat(result).hasSize(1);
        assertThat(result.get(0)).containsExactly(1);
    }

    @Test
    public void twoNodesInput() {
        TreeNode root = new TreeNode(1);
        root.right = new TreeNode(2);

        List<List<Integer>> result = solution.levelOrder(root);

        assertThat(result).hasSize(2);
        assertThat(result.get(0)).containsExactly(1);
        assertThat(result.get(1)).containsExactly(2);
    }

    @Test
    public void threeNodesInput() {
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.right = new TreeNode(3);

        List<List<Integer>> result = solution.levelOrder(root);

        assertThat(result).hasSize(2);
        assertThat(result.get(0)).containsExactly(1);
        assertThat(result.get(1)).containsExactly(2, 3);
    }

    @Test
    public void fiveNodesInput() {
        TreeNode root = new TreeNode(3);
        root.left = new TreeNode(9);
        TreeNode rightTree = new TreeNode(20);
        rightTree.left = new TreeNode(15);
        rightTree.right = new TreeNode(7);
        root.right = rightTree;

        List<List<Integer>> result = solution.levelOrder(root);

        assertThat(result).hasSize(3);
        assertThat(result.get(0)).containsExactly(3);
        assertThat(result.get(1)).containsExactly(9, 20);
        assertThat(result.get(2)).containsExactly(15, 7);
    }
}