from typing import Sequence
import difflib


def _validate_magics_with_black(before: Sequence[str], after: Sequence[str]) -> bool:
    """
    Validate the state of the notebook before and after running nbqa with black.

    Parameters
    ----------
    before
        Notebook contents before running nbqa with black
    after
        Notebook contents after running nbqa with black

    Returns
    -------
    bool
        True if validation succeeded else False
    """
    diff = difflib.unified_diff(before, after)
    result = "".join(i for i in diff if any([i.startswith("+ "), i.startswith("- ")]))
    expected = (
        '-    "def compute(operand1,operand2, bin_op):\\n",\n'
        '+    "def compute(operand1, operand2, bin_op):\\n",\n'
        '-    "compute(5,1, operator.add)"\n'
        '+    "compute(5, 1, operator.add)"\n'
        '-    "    ?str.splitlines"\n'
        '+    "str.splitlines?"\n'
        '-    "   %time randint(5,10)"\n'
        '+    "%time randint(5,10)"\n'
        '-    "result = str.split??"\n'
        '+    "str.split??"\n'
    )
    return result == expected