This question evaluates understanding of binary tree traversal relationships, algorithmic reconstruction, input validation for malformed traversal arrays, and unit-test design, testing skills in tree data structures and array-based algorithms.

Given two arrays representing the preorder and inorder traversals of a binary tree with unique values, reconstruct the tree and return its root. Achieve O(n) time and O(n) extra space. Describe how you would detect and handle invalid inputs that cannot form a valid tree. Write unit tests covering typical, edge, and degenerate cases (e.g., empty tree, single node, skewed trees, mismatched arrays).