mirror of
https://github.com/chylex/Brotli-Builder.git
synced 2025-04-13 00:15:42 +02:00
Fix BitStream.Add causing every 63rd bit to be zero w/ new unit tests
This commit is contained in:
parent
95b7f5448e
commit
235f3684a3
@ -54,20 +54,16 @@ namespace BrotliLib.IO{
|
||||
/// </summary>
|
||||
/// <param name="bytes">Input byte array segment.</param>
|
||||
public BitStream(byte[] bytes) : this(){
|
||||
int index = 0;
|
||||
|
||||
foreach(byte value in bytes){
|
||||
int offset = index % BytesPerEntry;
|
||||
int offset = Length & BitEntryMask;
|
||||
|
||||
if (offset == 0 && index > 0){
|
||||
if (offset == 0 && Length > 0){
|
||||
this.entryCollection.Add(0UL);
|
||||
}
|
||||
|
||||
this.entryCollection[LastEntryIndex] |= (ulong)value << (ByteSize * offset);
|
||||
++index;
|
||||
this.entryCollection[LastEntryIndex] |= (ulong)value << offset;
|
||||
Length += ByteSize;
|
||||
}
|
||||
|
||||
this.Length = ByteSize * index;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -97,9 +93,8 @@ namespace BrotliLib.IO{
|
||||
public void Add(bool bit){
|
||||
int offset = Length & BitEntryMask;
|
||||
|
||||
if (offset == BitEntryMask){
|
||||
if (offset == 0 && Length > 0){
|
||||
entryCollection.Add(0UL);
|
||||
offset -= BitEntrySize;
|
||||
}
|
||||
|
||||
if (bit){
|
||||
|
@ -105,12 +105,21 @@ module Mutability =
|
||||
[<InlineData("10", true, false)>]
|
||||
[<InlineData("11110000", true, true, true, true, false, false, false, false)>]
|
||||
[<InlineData("11110000111100001", true, true, true, true, false, false, false, false, true, true, true, true, false, false, false, false, true)>]
|
||||
let ``appending to empty stream yields correct text representation`` (expected: string, [<ParamArray>] values: bool array) =
|
||||
let ``appending few bits to empty stream yields correct text representation`` (expected: string, [<ParamArray>] values: bool array) =
|
||||
let stream = BitStream()
|
||||
Array.iter (stream.Add) <| values
|
||||
|
||||
Assert.Equal(expected, stream.ToString())
|
||||
|
||||
[<Fact>]
|
||||
let ``appending many bits to empty stream yields correct text representation`` () =
|
||||
let stream = BitStream()
|
||||
|
||||
for _ in 0..256 do
|
||||
stream.Add(true)
|
||||
|
||||
Assert.Equal(String.replicate 257 "1", stream.ToString())
|
||||
|
||||
[<Theory>]
|
||||
[<InlineData("", "")>]
|
||||
[<InlineData("0", "")>]
|
||||
|
Loading…
Reference in New Issue
Block a user