Example #1
0
        public void TestClone()
        {
            NcByteCollection original = new NcByteCollection(NcTestUtils.RandomBytes(12 * 1024));
            NcByteCollection cloned   = original.Clone();

            Assert.IsTrue(original.SequenceEqual(cloned));
        }
Example #2
0
        public void TestSequenceEquals_False()
        {
            NcByteCollection b1 = new NcByteCollection(NcTestUtils.RandomBytes(30 * 1000));
            NcByteCollection b2 = new NcByteCollection(NcTestUtils.RandomBytes(30 * 1000));

            Assert.IsFalse(b1.SequenceEqual(b2));
        }
Example #3
0
        public void TestSequenceEquals_True()
        {
            byte[]           data = NcTestUtils.RandomBytes(30 * 1000);
            NcByteCollection b1   = new NcByteCollection(data, 4096);
            NcByteCollection b2   = new NcByteCollection(data, 3000);

            Assert.IsTrue(b1.SequenceEqual(b2));
        }
Example #4
0
        public void TestCopyFromStream_Small()
        {
            NcByteCollection b1 = new NcByteCollection(NcTestUtils.RandomBytes(30 * 1000));
            NcByteStream     b2 = new NcByteStream(NcTestUtils.RandomBytes(1000));

            b1.Copy(b2, 5000, 50);
            Assert.IsTrue(b1.Count == (30 * 1000));
            Assert.IsTrue(b1.SequenceEqual(b1.Take(5000).Concat(b2.Data.Take(50)).Concat(b1.Skip(5050))));
        }
Example #5
0
        public void TestAdd_IEnumerable()
        {
            NcByteCollection instance = new NcByteCollection();

            byte[] data = NcTestUtils.RandomBytes(100);
            instance.AddRange((IEnumerable <byte>)data);

            Assert.IsTrue(instance.SequenceEqual(data));
        }
Example #6
0
        public void TestAdd_Large()
        {
            NcByteCollection instance = new NcByteCollection();

            byte[] data = NcTestUtils.RandomBytes(17 * 1024);
            instance.AddRange(data);

            Assert.IsTrue(instance.SequenceEqual(data));
        }
Example #7
0
        public void TestCopyToStream()
        {
            NcByteCollection data = new NcByteCollection(NcTestUtils.RandomBytes(12 * 1024));
            MemoryStream     ms   = new MemoryStream();

            data.Copy(3 * 1024, ms, 5 * 1024);

            Assert.IsTrue(ms.ToArray().SequenceEqual(data.Skip(3 * 1024).Take(5 * 1024)));
        }
Example #8
0
        public void TestRemove_End()
        {
            NcByteCollection instance = new NcByteCollection();

            byte[] data = NcTestUtils.RandomBytes(12 * 1024);
            instance.AddRange(data);
            instance.RemoveRange(7 * 1024, 5 * 1024);

            Assert.IsTrue(instance.SequenceEqual(data.Take(7 * 1024)));
        }
Example #9
0
        public void TestRemove_1()
        {
            NcByteCollection instance = new NcByteCollection();

            byte[] data = NcTestUtils.RandomBytes(12 * 1024);
            instance.AddRange(data);
            instance.RemoveAt(3 * 1024);

            Assert.IsTrue(instance.SequenceEqual(data.Take(3 * 1024).Concat(data.Skip(3 * 1024 + 1))));
        }
Example #10
0
        public void TestRemove_Small()
        {
            NcByteCollection instance = new NcByteCollection();

            byte[] data = NcTestUtils.RandomBytes(100);
            instance.AddRange(data);
            instance.RemoveRange(10, 50);

            Assert.IsTrue(instance.SequenceEqual(data.Take(10).Concat(data.Skip(10 + 50))));
        }
Example #11
0
        public void TestCopyFromArray_Small()
        {
            NcByteCollection b1 = new NcByteCollection(NcTestUtils.RandomBytes(30 * 1000));

            byte[] b2 = NcTestUtils.RandomBytes(1000);

            b1.Copy(b2, 0, 5000, 50);
            Assert.IsTrue(b1.Count == (30 * 1000));
            Assert.IsTrue(b1.SequenceEqual(b1.Take(5000).Concat(b2.Take(50)).Concat(b1.Skip(5050))));
        }
Example #12
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)));
        }
Example #13
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))));
        }
Example #14
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))));
        }
Example #15
0
        public void TestStreamWrite()
        {
            NcByteCollection original = new NcByteCollection(NcTestUtils.RandomBytes(12 * 1024));
            NcByteStream     stream   = new NcByteStream(original);
            MemoryStream     ms       = new MemoryStream(NcTestUtils.RandomBytes(5 * 1024));

            stream.Seek(5 * 1024, SeekOrigin.Begin);
            ms.CopyTo(stream);

            Assert.IsTrue(original.Take(5 * 1024).Concat(ms.ToArray()).Concat(original.Skip(5 * 1024 + 5 * 1024)).SequenceEqual(stream.Data));
        }
Example #16
0
        public void TestInsert_1()
        {
            NcByteCollection instance = new NcByteCollection();

            byte[] initial  = NcTestUtils.RandomBytes(5 * 1024);
            byte[] inserted = new byte[] { 127 };
            instance.AddRange((IEnumerable <byte>)initial);
            instance.Insert(5120, inserted[0]);

            Assert.IsTrue(instance.SequenceEqual(initial.Take(5120).Concat(inserted).Concat(initial.Skip(5120))));
        }
Example #17
0
        public void TestStreamRead()
        {
            byte[]       data   = NcTestUtils.RandomBytes(12 * 1024);
            NcByteStream stream = new NcByteStream(data);
            MemoryStream ms     = new MemoryStream();

            stream.Seek(5 * 1024, SeekOrigin.Begin);
            stream.CopyTo(ms);

            Assert.IsTrue(ms.ToArray().SequenceEqual(data.Skip(5 * 1024)));
        }
Example #18
0
        public void TestBinarySerialization()
        {
            NcByteCollection original  = new NcByteCollection(NcTestUtils.RandomBytes(12 * 1024));
            BinaryFormatter  formatter = new BinaryFormatter();

            using (MemoryStream ms = new MemoryStream()) {
                formatter.Serialize(ms, original);
                ms.Position = 0;
                NcByteCollection deserialized = (NcByteCollection)formatter.Deserialize(ms);
                Assert.IsTrue(original.SequenceEqual(deserialized));
            }
        }
Example #19
0
        public void TestXmlSerialization()
        {
            NcByteCollection original = new NcByteCollection(NcTestUtils.RandomBytes(12 * 1024));
            XmlSerializer    xs       = new XmlSerializer(typeof(NcByteCollection));

            using (MemoryStream ms = new MemoryStream()) {
                xs.Serialize(ms, original);
                ms.Position = 0;
                NcByteCollection deserialized = (NcByteCollection)xs.Deserialize(ms);
                Assert.IsTrue(original.SequenceEqual(deserialized));
            }
        }
Example #20
0
        public void TestStreamSetLength()
        {
            int          declLength = 12 * 1024;
            NcByteStream stream     = new NcByteStream(NcTestUtils.RandomBytes(declLength));

            Assert.AreEqual(declLength, stream.Length);

            long lessLength = 5 * 1024;

            stream.SetLength(lessLength);
            Assert.AreEqual(lessLength, stream.Length);

            long moreLength = 10 * 1024;

            stream.SetLength(moreLength);
            Assert.AreEqual(moreLength, stream.Length);
        }
Example #21
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
        }