### Question:
PrimitiveArrays { public static long[] intersect( long[] left, long[] right ) { if ( left == null || right == null ) { return EMPTY_LONG_ARRAY; } assert isSortedSet( left ) && isSortedSet( right ); long uniqueCounts = countUnique( left, right ); if ( uniqueCounts == 0 ) { return right; } if ( right( uniqueCounts ) == right.length || left( uniqueCounts ) == left.length ) { return EMPTY_LONG_ARRAY; } long[] intersect = new long[left.length - left( uniqueCounts )]; int cursor = 0; int l = 0; int r = 0; while ( l < left.length && r < right.length ) { if ( left[l] == right[r] ) { intersect[cursor++] = left[l]; l++; r++; } else if ( left[l] < right[r] ) { l++; } else { r++; } } assert cursor == intersect.length; return intersect; } private  PrimitiveArrays(); static int[] union( int[] lhs, int[] rhs ); static long[] intersect( long[] left, long[] right ); static long[] symmetricDifference( long[] left, long[] right ); static boolean isSortedSet( int[] set ); static boolean isSortedSet( long[] set );  }### Answer:
@Test void intersect_shouldHandleNullInput() { assertThat( PrimitiveArrays.intersect( null, null ), equalTo( NO_LONGS ) ); assertThat( PrimitiveArrays.intersect( null, NO_LONGS ), equalTo( NO_LONGS ) ); assertThat( PrimitiveArrays.intersect( NO_LONGS, null ), equalTo( NO_LONGS ) ); assertThat( PrimitiveArrays.intersect( null, ONE_LONG ), equalTo( NO_LONGS ) ); assertThat( PrimitiveArrays.intersect( ONE_LONG, null ), equalTo( NO_LONGS ) ); }
@Test void intersect_shouldHandleNonIntersectingArrays() { assertThat( PrimitiveArrays.intersect( new long[]{1, 2, 3}, new long[]{4, 5, 6} ), equalTo( NO_LONGS ) ); assertThat( PrimitiveArrays.intersect( new long[]{14, 15, 16}, new long[]{1, 2, 3} ), equalTo( NO_LONGS ) ); }
@Test void intersect_shouldHandleIntersectingArrays() { assertThat( PrimitiveArrays.intersect( new long[]{1, 2, 3}, new long[]{3, 4, 5} ), isArray( 3 ) ); assertThat( PrimitiveArrays.intersect( new long[]{3, 4, 5}, new long[]{1, 2, 3, 4} ), isArray( 3, 4 ) ); }
@Test void intersect_shouldHandleComplexIntersectingArraysWithGaps() { assertThat( PrimitiveArrays.intersect( new long[]{4, 6, 9, 11, 12, 15}, new long[]{2, 3, 4, 7, 8, 9, 12, 16, 19} ), isArray( 4, 9, 12 ) ); assertThat( PrimitiveArrays.intersect( new long[]{2, 3, 4, 7, 8, 9, 12, 16, 19}, new long[]{4, 6, 9, 11, 12, 15} ), isArray( 4, 9, 12 ) ); }