@Test void shouldReverseUnevenCount() { // given Integer[] array = new Integer[] {0, 1, 2, 3, 4}; // when ArrayUtil.reverse( array ); // then assertArrayEquals( new Integer[] {4, 3, 2, 1, 0}, array ); }
@Test void shouldReverseEmptyArray() { // given Integer[] array = new Integer[] {}; // when ArrayUtil.reverse( array ); // then assertArrayEquals( new Integer[] {}, array ); } }
@Test void shouldReverseEvenCount() { // given Integer[] array = new Integer[] {0, 1, 2, 3, 4, 5}; // when ArrayUtil.reverse( array ); // then assertArrayEquals( new Integer[] {5, 4, 3, 2, 1, 0}, array ); }
private ThrowingFunction<LogPosition,TransactionCursor,IOException> log( int... transactionCounts ) throws IOException { long baseOffset = LogPosition.start( 0 ).getByteOffset(); @SuppressWarnings( "unchecked" ) ThrowingFunction<LogPosition,TransactionCursor,IOException> result = mock( ThrowingFunction.class ); AtomicLong txId = new AtomicLong( 0 ); CommittedTransactionRepresentation[][] logs = new CommittedTransactionRepresentation[transactionCounts.length][]; for ( int logVersion = 0; logVersion < transactionCounts.length; logVersion++ ) { logs[logVersion] = transactions( transactionCounts[logVersion], txId ); } when( result.apply( any( LogPosition.class ) ) ).thenAnswer( invocation -> { LogPosition position = invocation.getArgument( 0 ); if ( position == null ) { // A mockito issue when calling the "when" methods, I believe return null; } // For simplicity the offset means, in this test, the array offset CommittedTransactionRepresentation[] transactions = logs[toIntExact( position.getLogVersion() )]; CommittedTransactionRepresentation[] subset = copyOfRange( transactions, toIntExact( position.getByteOffset() - baseOffset ), transactions.length ); ArrayUtil.reverse( subset ); return given( subset ); } ); return result; }