Algorithmix.UnitTest.NodeTest.IsValid C# (CSharp) Method

IsValid() private static method

private static IsValid ( INode parent ) : bool
parent INode
return bool
        private static bool IsValid(INode parent)
        {
            if (parent.Left() == null && parent.Right() == null)
            {
                return true;
            }
            else if (parent.Left() == null ^ parent.Right() == null)
            {
                throw new ArgumentException("Invalid INode - Must have left/right members or both must be null");
            }
            else
            {
                bool validLeft = parent.Left().Parent() == parent;
                bool validRight = parent.Right().Parent() == parent;
                if (validLeft && validRight)
                {
                    return IsValid(parent.Left()) && IsValid(parent.Right());
                }
                else
                {
                    return false;
                }
            }
        }