Exemplo n.º 1
0
        public void TestInsert_Small()
        {
            NcByteCollection instance = new NcByteCollection();

            byte[] initial  = NcTestUtils.RandomBytes(100);
            byte[] inserted = NcTestUtils.RandomBytes(50);
            instance.AddRange(initial);
            instance.InsertRange(10, inserted);

            Assert.IsTrue(instance.SequenceEqual(initial.Take(10).Concat(inserted).Concat(initial.Skip(10))));
        }
Exemplo n.º 2
0
        public void TestInsert_Start()
        {
            NcByteCollection instance = new NcByteCollection();

            byte[] initial  = NcTestUtils.RandomBytes(5 * 1024);
            byte[] inserted = NcTestUtils.RandomBytes(2 * 1024);
            instance.AddRange(initial);
            instance.InsertRange(0, inserted);

            Assert.IsTrue(instance.SequenceEqual(inserted.Concat(initial)));
        }
Exemplo n.º 3
0
        public void TestInsert_End()
        {
            NcByteCollection instance = new NcByteCollection();

            byte[] initial  = NcTestUtils.RandomBytes(5 * 1024);
            byte[] inserted = NcTestUtils.RandomBytes(2 * 1024);
            instance.AddRange(initial);
            instance.InsertRange(initial.Length - 1, inserted);

            Assert.IsTrue(instance.SequenceEqual(initial.Take(initial.Length - 1).Concat(inserted).Concat(initial.Skip(initial.Length - 1))));
        }
Exemplo n.º 4
0
        public void TestInsert_IEnumerable()
        {
            NcByteCollection instance = new NcByteCollection();

            byte[] initial  = NcTestUtils.RandomBytes(5 * 1024);
            byte[] inserted = NcTestUtils.RandomBytes(10 * 1024);
            instance.AddRange((IEnumerable <byte>)initial);
            instance.InsertRange(5120, (IEnumerable <byte>)inserted);

            Assert.IsTrue(instance.SequenceEqual(initial.Take(5120).Concat(inserted).Concat(initial.Skip(5120))));
        }
Exemplo n.º 5
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
        }