statistical encoding
This commit is contained in:
parent
f8dee5b7d1
commit
ccf6641bad
41 changed files with 4543 additions and 1965 deletions
|
|
@ -1,8 +1,5 @@
|
|||
package btools.util;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -11,18 +8,46 @@ public class BitCoderContextTest
|
|||
@Test
|
||||
public void varBitsEncodeDecodeTest()
|
||||
{
|
||||
byte[] ab = new byte[4000];
|
||||
BitCoderContext ctx = new BitCoderContext( ab );
|
||||
for( int i=0; i<1000; i++ )
|
||||
{
|
||||
ctx.encodeVarBits( i );
|
||||
byte[] ab = new byte[4000];
|
||||
BitCoderContext ctx = new BitCoderContext( ab );
|
||||
for ( int i = 0; i < 1000; i++ )
|
||||
{
|
||||
ctx.encodeVarBits( i );
|
||||
}
|
||||
ctx = new BitCoderContext( ab );
|
||||
|
||||
for( int i=0; i<1000; i++ )
|
||||
{
|
||||
ctx = new BitCoderContext( ab );
|
||||
|
||||
for ( int i = 0; i < 1000; i++ )
|
||||
{
|
||||
int value = ctx.decodeVarBits();
|
||||
Assert.assertTrue( "distance value mismatch", value == i );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void boundedEncodeDecodeTest()
|
||||
{
|
||||
byte[] ab = new byte[581969];
|
||||
BitCoderContext ctx = new BitCoderContext( ab );
|
||||
for ( int max = 1; max < 1000; max++ )
|
||||
{
|
||||
for ( int val = 0; val <= max; val++ )
|
||||
{
|
||||
ctx.encodeBounded( max, val );
|
||||
}
|
||||
}
|
||||
|
||||
ctx = new BitCoderContext( ab );
|
||||
|
||||
for ( int max = 1; max < 1000; max++ )
|
||||
{
|
||||
for ( int val = 0; val <= max; val++ )
|
||||
{
|
||||
int valDecoded = ctx.decodeBounded( max );
|
||||
if ( valDecoded != val )
|
||||
{
|
||||
Assert.fail( "mismatch at max=" + max + " " + valDecoded + "<>" + val );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue