srtm30 utils
This commit is contained in:
parent
8c0b416aef
commit
91c463302e
5 changed files with 338 additions and 0 deletions
63
brouter-util/src/test/java/btools/util/MixCoderTest.java
Normal file
63
brouter-util/src/test/java/btools/util/MixCoderTest.java
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
package btools.util;
|
||||
|
||||
import java.util.Random;
|
||||
import java.io.*;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MixCoderTest
|
||||
{
|
||||
@Test
|
||||
public void mixEncodeDecodeTest() throws IOException
|
||||
{
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
MixCoderDataOutputStream mco = new MixCoderDataOutputStream( baos );
|
||||
MixCoderDataInputStream mci = null;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
Random rnd = new Random( 1234 );
|
||||
for( int i=0; i<1500; i++ )
|
||||
{
|
||||
checkEncodeDecode( rnd.nextInt( 3800 ), mco, mci );
|
||||
}
|
||||
for( int i=0; i<1500; i++ )
|
||||
{
|
||||
checkEncodeDecode( rnd.nextInt( 35 ), mco, mci );
|
||||
}
|
||||
for( int i=0; i<1500; i++ )
|
||||
{
|
||||
checkEncodeDecode( 0, mco, mci );
|
||||
}
|
||||
for( int i=0; i<1500; i++ )
|
||||
{
|
||||
checkEncodeDecode( 1000, mco, mci );
|
||||
}
|
||||
|
||||
if ( mco != null )
|
||||
{
|
||||
mco.close();
|
||||
mco = null;
|
||||
mci = new MixCoderDataInputStream( new ByteArrayInputStream( baos.toByteArray() ) );
|
||||
}
|
||||
else break;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkEncodeDecode( long v, MixCoderDataOutputStream mco, MixCoderDataInputStream mci ) throws IOException
|
||||
{
|
||||
if ( mco != null )
|
||||
{
|
||||
mco.writeMixed( v );
|
||||
}
|
||||
if ( mci != null )
|
||||
{
|
||||
long vv = mci.readMixed();
|
||||
if ( vv != v )
|
||||
{
|
||||
Assert.assertTrue( "value mismatch: v=" + v + " vv=" + vv, false );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue