Beispiel #1
0
        public void TestCompact()
        {
            NcByteCollection data = new NcByteCollection(NcTestUtils.RandomBytes(12 * 1024));

            data.RemoveRange(3 * 1024, 100);
            data.InsertRange(2 * 1024, NcTestUtils.RandomBytes(200));
            data.RemoveRange(5 * 1024, 5 * 1024);
            data.InsertRange(6 * 1024, NcTestUtils.RandomBytes(5 * 1024));
            data.RemoveRange(7 * 1024, 3 * 1024);
#if DEBUG
            long oldBytes = data.BlockLengthTotal;
            Console.WriteLine("Used bytes: {0}, Total bytes: {1}, Blocks: {2}", data.LongCount, data.BlockLengthTotal, data.BlockCount);
#endif
            byte[] snapshot = data.ToArray();
            data.Compact();
#if DEBUG
            Console.WriteLine("Used bytes: {0}, Total bytes: {1}, Blocks: {2}", data.LongCount, data.BlockLengthTotal, data.BlockCount);
#endif
            byte[] compacted = data.ToArray();
            Assert.IsTrue(snapshot.SequenceEqual(compacted));
#if DEBUG
            Assert.AreNotEqual(oldBytes, data.BlockLengthTotal);
#endif
        }