public void Test_BitFieldArray_MultiRecordMultiBitField_WithDescriptor() { using (var bfa = new BitFieldArray()) { BitFieldArrayRecordsDescriptor[] fieldsArray = new[] { new BitFieldArrayRecordsDescriptor() { BitsPerRecord = 11, NumRecords = 1000 }, }; bfa.Initialise(fieldsArray); Assert.Equal(11000, bfa.NumBits); Assert.Equal(172, bfa.NumStorageElements()); Assert.Equal(1375, bfa.MemorySize()); var descriptor = new EncodedBitFieldDescriptor(); AttributeValueRangeCalculator.CalculateAttributeValueRange(new long[] { 0, 2047 }, 0, 2, 0xffffffff, 0, false, ref descriptor); // Write a '1234' to the bfa bfa.StreamWriteStart(); try { for (int i = 0; i < 1000; i++) { bfa.StreamWrite(1234, descriptor); } } finally { bfa.StreamWriteEnd(); } // Read the value back again int bitAddress = 0; for (int i = 0; i < 1000; i++) { long readValue = bfa.ReadBitField(ref bitAddress, descriptor); Assert.Equal(1234, readValue); Assert.Equal(bitAddress, (i + 1) * 11); } } }
public void Test_BitFieldArray_MultiRecordMultiBitField_WithoutDescriptor() { using (var bfa = new BitFieldArray()) { BitFieldArrayRecordsDescriptor[] fieldsArray = new[] { new BitFieldArrayRecordsDescriptor() { BitsPerRecord = 11, NumRecords = 1000 }, }; bfa.Initialise(fieldsArray); Assert.Equal(11000, bfa.NumBits); Assert.Equal(172, bfa.NumStorageElements()); Assert.Equal(1375, bfa.MemorySize()); // Write a '1234' to the bfa bfa.StreamWriteStart(); try { for (int i = 0; i < 1000; i++) { bfa.StreamWrite(1234, 11); } } finally { bfa.StreamWriteEnd(); } // Read the value back again int bitAddress = 0; for (int i = 0; i < 1000; i++) { long readValue = bfa.ReadBitField(ref bitAddress, 11); Assert.Equal(1234, readValue); Assert.Equal(bitAddress, (i + 1) * 11); } } }
public void Test_BitFieldArray_SingleRecordSingleVariableSizeField_WithDescriptor (int bitsPerRecord, int numRecords, int minValue, int maxValue, int mask, long valueToWrite, int numStorageElements, int memorySize, int nativeNullValue, bool fieldIsNullable, int expectedNumValues) { using (var bfa = new BitFieldArray()) { BitFieldArrayRecordsDescriptor[] fieldsArray = new[] { new BitFieldArrayRecordsDescriptor { BitsPerRecord = bitsPerRecord, NumRecords = numRecords }, }; bfa.Initialise(fieldsArray); bitsPerRecord.Should().Be(bfa.NumBits); numStorageElements.Should().Be(bfa.NumStorageElements()); Assert.Equal((int)memorySize, bfa.MemorySize()); var descriptor = new EncodedBitFieldDescriptor(); AttributeValueRangeCalculator.CalculateAttributeValueRange(new long[] { minValue, maxValue }, 0, 2, mask, nativeNullValue, fieldIsNullable, ref descriptor); descriptor.RequiredBits.Should().Be((byte)bitsPerRecord); descriptor.NumValues.Should().Be(expectedNumValues); // Write a value to the bfa bfa.StreamWriteStart(); try { bfa.StreamWrite(valueToWrite, descriptor); } finally { bfa.StreamWriteEnd(); } // Read the value back again int bitAddress = 0; long readValue = bfa.ReadBitField(ref bitAddress, descriptor); valueToWrite.Should().Be(readValue); bitsPerRecord.Should().Be(bitAddress); } }
public void Test_BitFieldArray_SingleRecordSingleBitField_WithDescriptor() { using (var bfa = new BitFieldArray()) { BitFieldArrayRecordsDescriptor[] fieldsArray = new[] { new BitFieldArrayRecordsDescriptor { BitsPerRecord = 1, NumRecords = 1 }, }; bfa.Initialise(fieldsArray); Assert.Equal(1, bfa.NumBits); Assert.Equal(1, bfa.NumStorageElements()); Assert.Equal(1, bfa.MemorySize()); var descriptor = new EncodedBitFieldDescriptor(); AttributeValueRangeCalculator.CalculateAttributeValueRange(new long[] { 0, 1 }, 0, 2, 0xffffffff, 0, false, ref descriptor); // Write a '1' to the bfa bfa.StreamWriteStart(); try { bfa.StreamWrite(1, descriptor); } finally { bfa.StreamWriteEnd(); } // Read the value back again int bitAddress = 0; long readValue = bfa.ReadBitField(ref bitAddress, descriptor); Assert.Equal(1, readValue); Assert.Equal(1, bitAddress); } }
public void Test_BitFieldArray_SingleRecordSingleBitField_WithoutDescriptor() { using (var bfa = new BitFieldArray()) { BitFieldArrayRecordsDescriptor[] fieldsArray = new[] { new BitFieldArrayRecordsDescriptor() { BitsPerRecord = 1, NumRecords = 1 }, }; bfa.Initialise(fieldsArray); Assert.Equal(1, bfa.NumBits); Assert.Equal(1, bfa.NumStorageElements()); Assert.Equal(1, bfa.MemorySize()); // Write a '1' to the bfa bfa.StreamWriteStart(); try { bfa.StreamWrite(1, 1); } finally { bfa.StreamWriteEnd(); } // Read the value back again int bitAddress = 0; long readValue = bfa.ReadBitField(ref bitAddress, 1); Assert.Equal(1, readValue); Assert.Equal(1, bitAddress); } }
public void Test_BitFieldArray_SingleRecordSingleVariableSizeField_WithoutDescriptor (int bitsPerRecord, int numRecords, long valueToWrite, int numStorageElements, int memorySize) { using (var bfa = new BitFieldArray()) { BitFieldArrayRecordsDescriptor[] fieldsArray = new[] { new BitFieldArrayRecordsDescriptor { BitsPerRecord = bitsPerRecord, NumRecords = numRecords }, }; bfa.Initialise(fieldsArray); bitsPerRecord.Should().Be(bfa.NumBits); numStorageElements.Should().Be(bfa.NumStorageElements()); Assert.Equal((int)memorySize, bfa.MemorySize()); // Write a value to the bfa bfa.StreamWriteStart(); try { bfa.StreamWrite(valueToWrite, (int)bitsPerRecord); } finally { bfa.StreamWriteEnd(); } // Read the value back again int bitAddress = 0; long readValue = bfa.ReadBitField(ref bitAddress, (int)bitsPerRecord); valueToWrite.Should().Be(readValue); bitsPerRecord.Should().Be(bitAddress); } }