package com.timepath.io;

import org.junit.Test;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.logging.Logger;

public class BitBufferTest {

    private static final Logger LOG = Logger.getLogger(BitBufferTest.class.getName());

    @Test
    public void testShift() {
        BitBuffer scramble = new BitBuffer(ByteBuffer.wrap(new byte[] {
                (byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE
        }));
        int shift = 1;
        scramble.position(0, shift);
        int first = scramble.getByte();
        scramble.position(0, shift);
        int second = scramble.getByte();
        assert first == second;
        LOG.info(first + " vs " + second);
        int number = 1;
        String expected = Long.toBinaryString(number);
        int bitLength = expected.length();
        for(int i = 0; i < ( 32 - bitLength ); i++) {
            int n = number << i;
            ByteBuffer b = ByteBuffer.allocate(4);
            b.order(ByteOrder.LITTLE_ENDIAN);
            b.putInt(n);
            b.flip();
            BitBuffer bb = new BitBuffer(b);
            bb.getBits(i);
            long bits = bb.getBits(bitLength);
            LOG.info(Long.toBinaryString(bits) + " == " + expected + " ?");
        }
        number = (int) ( Math.random() * Integer.MAX_VALUE );
        ByteBuffer b = ByteBuffer.allocate(4);
        b.order(ByteOrder.LITTLE_ENDIAN);
        b.putInt(number);
        b.flip();
        BitBuffer bb = new BitBuffer(b);
        String s1 = Integer.toBinaryString(number);
        String s2 = "";
        for(int i = 0; i < s1.length(); i++) {
            s2 = bb.getBits(1) + s2;
        }
        LOG.info(s1);
        LOG.info(s2);
    }
}

@@ -19,16 +19,41 @@
 th.io;%0A%0A
+import org.junit.Ignore;%0A
 import o
@@ -127,39 +127,52 @@
 er;%0A
+%0A
 import 
-java.util.logging.Logger
+static org.junit.Assert.assertEquals
 ;%0A%0Ap
@@ -208,101 +208,38 @@
     
-private static final Logger LOG = Logger.getLogger(BitBufferTest.class.getName());%0A%0A    @Test
+@Test%0A    @Ignore(%22Known bug%22)
 %0A   
@@ -259,13 +259,14 @@
 test
-Shift
+Jitter
 () %7B
@@ -614,68 +614,77 @@
 sert
- 
+Equals(
 first
- ==
+,
  second
+)
 ;%0A    
+%7D%0A%0A
     
-LOG.info(first + %22 vs %22 + second);
+@Test%0A    public void testShift() %7B
 %0A   
@@ -1164,25 +1164,39 @@
         
-LOG.info(
+assertEquals(expected, 
 Long.toB
@@ -1216,47 +1216,67 @@
 its)
- + %22 == %22 + expected + %22 ?%22);%0A        %7D
+);%0A        %7D%0A%0A    %7D%0A%0A    @Test%0A    public void testBits() %7B
 %0A   
@@ -1280,16 +1280,20 @@
         
+int 
 number =
@@ -1527,18 +1527,28 @@
  String 
-s1
+binaryString
  = Integ
@@ -1589,18 +1589,20 @@
  String 
-s2
+test
  = %22%22;%0A 
@@ -1627,18 +1627,28 @@
  0; i %3C 
-s1
+binaryString
 .length(
@@ -1669,18 +1669,20 @@
         
-s2
+test
  = bb.ge
@@ -1692,18 +1692,20 @@
 ts(1) + 
-s2
+test
 ;%0A      
@@ -1720,41 +1720,39 @@
     
-LOG.info(s1);%0A        LOG.info(s2
+assertEquals(binaryString, test
 );%0A 

Split tests, ignore known bug