public void Test_AttributeValueRangeCalculator_ZeroBitRange_Nullable() { EncodedBitFieldDescriptor descriptor = new EncodedBitFieldDescriptor(); AttributeValueRangeCalculator.CalculateAttributeValueRange(new long[] { 0, 0 }, 0, 2, 0xffffffff, 0, true, ref descriptor); Assert.Equal(0, descriptor.MinValue); Assert.Equal(0, descriptor.MaxValue); Assert.Equal(0, descriptor.RequiredBits); }
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_AttributeValueRangeCalculator_NullRangeHeights() { // Simulate a subgrid containing the same non-null elevation in every cell, expressed as a single vector long value = AttributeValueModifiers.ModifiedHeight(12345.678F); long[] values = Enumerable.Range(0, SubGridTreeConsts.SubGridTreeCellsPerSubGrid).Select(x => value).ToArray(); EncodedBitFieldDescriptor descriptor = new EncodedBitFieldDescriptor(); AttributeValueRangeCalculator.CalculateAttributeValueRange(values, 0, values.Length, 0xffffffff, 0x7fffffff, true, ref descriptor); Assert.Equal(descriptor.MinValue, value); Assert.Equal(descriptor.MaxValue, value); Assert.Equal(0, descriptor.RequiredBits); }
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_AttributeValueRangeCalculator_SingleBitRange_Nullable() { EncodedBitFieldDescriptor descriptor = new EncodedBitFieldDescriptor(); AttributeValueRangeCalculator.CalculateAttributeValueRange(new long[] { 0, 1 }, 0, 2, 0xffffffff, 5, true, ref descriptor); Assert.Equal(0, descriptor.MinValue); Assert.Equal(1, descriptor.MaxValue); Assert.False(descriptor.Nullable); Assert.Equal(5, descriptor.NativeNullValue); Assert.Equal(1, descriptor.RequiredBits); AttributeValueRangeCalculator.CalculateAttributeValueRange(new long[] { 0, 1, 5 }, 0, 3, 0xffffffff, 5, true, ref descriptor); Assert.Equal(0, descriptor.MinValue); Assert.Equal(2, descriptor.MaxValue); Assert.True(descriptor.Nullable); Assert.Equal(5, descriptor.NativeNullValue); Assert.Equal(2, descriptor.RequiredBits); }
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); } }