Esempio n. 1
0
 public void Test_BitFieldArray_Creation()
 {
     using (var bfa = new BitFieldArray())
     {
         Assert.Equal(0, bfa.NumBits);
         Assert.Equal(0, bfa.MemorySize());
     }
 }
Esempio n. 2
0
 public void Test_BitFieldArray_Initialise1()
 {
     using (var bfa = new BitFieldArray())
     {
         // Initialise with just a count of bits and records
         bfa.Initialise(10, 100);
         Assert.Equal(1000, bfa.NumBits);
         Assert.Equal(125, bfa.MemorySize()); // 125 bytes to store 1000 bits
     }
 }
Esempio n. 3
0
        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);
                }
            }
        }
Esempio n. 4
0
        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);
                }
            }
        }
Esempio n. 5
0
        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);
            }
        }
Esempio n. 6
0
        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);
            }
        }
Esempio n. 7
0
        public void Test_BitFieldArray_Initialise2()
        {
            using (var bfa = new BitFieldArray())
            {
                // Initialise with more than one field in a record

                BitFieldArrayRecordsDescriptor[] fieldsArray = new BitFieldArrayRecordsDescriptor[]
                {
                    new BitFieldArrayRecordsDescriptor {
                        BitsPerRecord = 10, NumRecords = 100
                    },
                    new BitFieldArrayRecordsDescriptor {
                        BitsPerRecord = 25, NumRecords = 500
                    }
                };

                bfa.Initialise(fieldsArray);

                Assert.Equal(13500, bfa.NumBits);
                Assert.Equal(1688, bfa.MemorySize()); // 1688 bytes to store 13500 bits
            }
        }
Esempio n. 8
0
        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);
            }
        }
Esempio n. 9
0
        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);
            }
        }