/*-
 * Copyright (c) 2014 Mikolaj Izdebski
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.lbzip2.impl;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public abstract class AbstractBWTTest
{
    private final BWT bwt;

    public AbstractBWTTest( BWT bwt )
    {
        this.bwt = bwt;
    }

    @Test
    public void testTrivialTransformation()
    {
        int[] P = new int[] { 'M', 'I', 'S', 'S', 'I', 'S', 'S', 'I', 'P', 'P', 'I', 0 };

        int idx = bwt.transform( P, 11 );

        assertEquals( 'P', P[0] );
        assertEquals( 'S', P[1] );
        assertEquals( 'S', P[2] );
        assertEquals( 'M', P[3] );
        assertEquals( 'I', P[4] );
        assertEquals( 'P', P[5] );
        assertEquals( 'I', P[6] );
        assertEquals( 'S', P[7] );
        assertEquals( 'S', P[8] );
        assertEquals( 'I', P[9] );
        assertEquals( 'I', P[10] );

        assertEquals( 4, idx );
    }
}

@@ -1455,11 +1455,1000 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testFibonacciWords()%0A    %7B%0A        int%5B%5D f2 = new int%5B%5D %7B 'A' %7D;%0A        int%5B%5D f1 = new int%5B%5D %7B 'A', 'B' %7D;%0A%0A        int x2 = 0;%0A        int x1 = 1;%0A        int d = 0;%0A%0A        for ( int j = 2; j %3C= 20; j++ )%0A        %7B%0A            int%5B%5D f0 = new int%5Bf1.length + f2.length%5D;%0A            System.arraycopy( f1, 0, f0, 0, f1.length );%0A            System.arraycopy( f2, 0, f0, f1.length, f2.length );%0A%0A            int x0 = x2 + x1;%0A%0A            int%5B%5D P = new int%5Bf0.length + 1%5D;%0A            System.arraycopy( f0, 0, P, 0, f0.length );%0A            int idx = bwt.transform( P, f0.length );%0A            assertEquals( x0 + d, idx );%0A%0A            for ( int i = 0; i %3C f2.length; i++ )%0A                assertEquals( %22i=%22 + i, 'B', P%5Bi%5D );%0A            for ( int i = f2.length; i %3C f0.length; i++ )%0A                assertEquals( %22i=%22 + i, 'A', P%5Bi%5D );%0A%0A            f2 = f1;%0A            f1 = f0;%0A%0A            x2 = x1;%0A            x1 = x0;%0A            d %5E= -1;%0A        %7D%0A    %7D
 %0A%7D%0A

Implement BWT test based on Fibonacci words