Package com.peterhi.obsolete

Examples of com.peterhi.obsolete.Stream


  }
 
  @Test
  public void fReadLine_void() throws Exception {
    try {
      Stream stream = new Stream();
      stream.readLine();
      fail();
    } catch (EOFException ex) {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.readLine();
      fail();
    } catch (InsufficientBufferException ex) {
    }
   
    try {
      Stream stream = new Stream();
      stream.write("Hello World!\r".getBytes("ascii"));
      fail();
    } catch (InsufficientBufferException ex) {
    }
  }
View Full Code Here


  }
 
  @Test
  public void pReadUnsignedVarLong_void() throws Exception {
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
     
      int max = (int )(Math.pow(2, RT.INT62) * Byte.SIZE - 2);
     
      for (NumWithInfo nwi : genNumWithInfos(max)) {
        if (nwi.getBits() < max) {
          if (nwi.isOverflow() || nwi.isUnderflow()) {
            continue;
          }
        }
       
        stream.writeUnsignedVarLong(nwi.getNumber().longValue());
      }
     
      stream.writeBit(1);
     
      stream.readBit();
     
      for (NumWithInfo nwi : genNumWithInfos(max)) {
        if (nwi.getBits() < max) {
          if (nwi.isOverflow() || nwi.isUnderflow()) {
            continue;
          }
        }
       
        BigInteger mask = BigInteger.valueOf(2).pow(nwi.getVarLongBits(false)).subtract(BigInteger.ONE);
        BigInteger left = nwi.getNumber();
       
        BigInteger right = BigInteger.valueOf(stream.readUnsignedVarLong());
       
        left = left.and(mask);
        assertEquals(left, right);
      }
     
      assertEquals(1, stream.getData().readable());
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void fReadUnsignedVarLong_void() throws Exception {
    try {
      Stream stream = new Stream();
      stream.readUnsignedVarLong();
      fail();
    } catch (EOFException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.readUnsignedVarLong();
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(2);
      stream.readUnsignedVarLong();
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.writeBit(1);
      stream.write(1);
      stream.readUnsignedVarLong();
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void pReadBigInteger_void() throws Exception {
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
     
      for (NumWithInfo nwi : genNumWithInfos(128)) {
        stream.writeBigInteger(nwi.getNumber());
      }
     
      stream.writeBit(1);
      stream.readBit();
     
      for (NumWithInfo nwi : genNumWithInfos(128)) {
        assertEquals(nwi.getNumber(), stream.readBigInteger());
      }
     
      assertEquals(1, stream.getData().readable());
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void fReadBigInteger_void() throws Exception {
    try {
      Stream stream = new Stream();
      stream.readBigInteger();
      fail();
    } catch (EOFException ex) {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.readBigInteger();
      fail();
    } catch (InsufficientBufferException ex) {
    }
   
    try {
      Stream stream = new Stream();
      stream.getData().fill(1, 17);
      stream.readBigInteger();
      fail();
    } catch (InsufficientBufferException ex) {
    }
  }
View Full Code Here

  }
 
  @Test
  public void pReadBigInteger_int() throws Exception {
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
     
      for (NumWithInfo nwi : genNumWithInfos(128)) {
        stream.writeBigInteger(nwi.getNumber(), nwi.getNumber().bitLength() + 1);
      }
     
      stream.writeBit(1);
      stream.readBit();
     
      for (NumWithInfo nwi : genNumWithInfos(128)) {
        assertEquals(nwi.getNumber(), stream.readBigInteger(nwi.getNumber().bitLength() + 1));
      }
     
      assertEquals(BigInteger.ZERO, stream.readBigInteger(0));
     
      assertEquals(1, stream.getData().readable());
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void fReadBigInteger_int() throws Exception {
    try {
      Stream stream = new Stream();
      stream.readBigInteger(1);
      fail();
    } catch (EOFException ex) {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.readBigInteger(2);
      fail();
    } catch (InsufficientBufferException ex) {
    }
   
    try {
      Stream stream = new Stream();
      stream.getData().fill(1, 100);
      stream.readBigInteger(101);
      fail();
    } catch (InsufficientBufferException ex) {
    }
  }
View Full Code Here

  }
 
  @Test
  public void pReadFloat_void() throws Exception {
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
     
      for (float sample : sampleFloats()) {
        stream.writeFloat(sample);
      }
     
      stream.writeBit(1);
     
      stream.readBit();
     
      for (float sample : sampleFloats()) {
        assertEquals((double )sample, (double )stream.readFloat(), 0.00000001);
      }
     
      assertEquals(1, stream.getData().readable());
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void fReadFloat_void() throws Exception {
    try {
      Stream stream = new Stream();
      stream.readFloat();
      fail();
    } catch (EOFException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
      stream.readFloat();
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
   
    try {
      Stream stream = new Stream();
      stream.write(1);
      stream.write(1);
      stream.write(1);
      stream.readFloat();
      fail();
    } catch (InsufficientBufferException ex) {
    } finally {
    }
  }
View Full Code Here

  }
 
  @Test
  public void pReadDouble_void() throws Exception {
    try {
      Stream stream = new Stream();
      stream.writeBit(1);
     
      for (double sample : sampleDoubles()) {
        stream.writeDouble(sample);
      }
     
      stream.writeBit(1);
     
      stream.readBit();
     
      for (double sample : sampleDoubles()) {
        assertEquals(sample, stream.readDouble(), 0.00000001);
      }
     
      assertEquals(1, stream.getData().readable());
    } finally {
    }
  }
View Full Code Here

TOP

Related Classes of com.peterhi.obsolete.Stream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.