### Question:
Node { public Node<T> split(long leftPartitionWidth) throws MalformedSpanException { if (leftPartitionWidth < 1) { throw new IllegalArgumentException("leftPartitionWidth must be greater than 0"); } if (!isLeaf()) { throw new MalformedSpanException("Can only split a leaf node"); } Node<T> parent = new Node<T>(leftPartitionWidth); StreamElementPartition<T> spans = (StreamElementPartition<T>) value.split(leftPartitionWidth); parent.left = new Node<T>(spans.getLeft()); parent.right = new Node<T>(spans.getRight()); parent.left.parent = parent; parent.right.parent = parent; if (parent.weight != leftPartitionWidth) { throw new IllegalStateException("node weight must equal variant position cutpoint"); } return parent; } Node(long weight);  Node(T value); long characterCount(); boolean isLeaf(); boolean isRightNode(); boolean isRoot(); Node<T> split(long leftPartitionWidth); @Override String toString(); public boolean isRed; public Node<T> left; public Node<T> parent; public Node<T> right; public String tag; final T value; public long weight; }### Answer:
@Test public void simpleSplit() throws Exception { Node<InvariantSpan> node = new Node<InvariantSpan>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> result = node.split(5); assertNotNull(result.left); assertNotNull(result.right); assertEquals(new InvariantSpan(1, 5, documentHash), result.left.value); assertEquals(new InvariantSpan(6, 5, documentHash), result.right.value); }
@Test public void split13() throws Exception { Node<InvariantSpan> result = getK().split(2); assertEquals(new InvariantSpan(300, 2, documentHash), result.left.value); assertEquals(new InvariantSpan(302, 2, documentHash), result.right.value); }
@Test(expected = MalformedSpanException.class) public void splitBranch() throws Exception { new Node<InvariantSpan>(10).split(5); }
@Test public void splitEdge() throws Exception { Node<InvariantSpan> result = getE().split(4); assertEquals(new InvariantSpan(100, 4, documentHash), result.left.value); assertEquals(new InvariantSpan(104, 2, documentHash), result.right.value); }
@Test public void splitF() throws Exception { Node<InvariantSpan> result = getF().split(2); assertEquals(new InvariantSpan(200, 2, documentHash), result.left.value); assertEquals(new InvariantSpan(202, 1, documentHash), result.right.value); }
@Test public void splitMinEdge() throws Exception { Node<InvariantSpan> result = getE().split(1); assertEquals(new InvariantSpan(100, 1, documentHash), result.left.value); assertEquals(new InvariantSpan(101, 5, documentHash), result.right.value); }
@Test(expected = IllegalArgumentException.class) public void splitNegative() throws Exception { Node<InvariantSpan> node = new Node<InvariantSpan>(new InvariantSpan(1, 10, documentHash)); node.split(-1); }