コード例 #1
0
        public static void BasicTests()
        {
            using (CreateTimer("ZeroBuffers"))
            {
                var bytes = BFast.WriteBFastToBytes(ZeroBuffers);
                TestBFastBytes(bytes);
                var tmp = BFast.ReadBFast(bytes).ToArray();
                Assert.AreEqual(0, tmp.Length);
            }
            using (CreateTimer("Ten1MBBuffers"))
            {
                var bytes = BFast.WriteBFastToBytes(Ten1MBBuffers);
                TestBFastBytes(bytes);
                var tmp = BFast.ReadBFast(bytes).ToArray();
                Assert.AreEqual(10, tmp.Length);
                Assert.AreEqual(tmp.Select(x => x.Name).ToArray(), Enumerable.Range(0, 10).Select(x => x.ToString()).ToArray());
                Assert.AreEqual(tmp.Select(x => (int)x.NumBytes()).ToArray(), Enumerable.Repeat(Mb, 10).ToArray());

                for (var i = 0; i < 10; ++i)
                {
                    Assert.AreEqual(Ten1MBBuffers[i].Item2, tmp[i].ToBytes(), $"Buffer {i} are different");
                }
            }
            using (CreateTimer("OneGBBuffer"))
            {
                //Enumerable.Range(0, Gb).Select(i => (double)i).ToArray()
                var bytes = BFast.WriteBFastToBytes(One1GBBuffer);
                TestBFastBytes(bytes);
                var tmp = BFast.ReadBFast(bytes).ToArray();
                Assert.AreEqual(1, tmp.Length);
                Assert.AreEqual(tmp.Select(x => x.Name).ToArray(), new[] { "0" });
                Assert.AreEqual(tmp.Select(x => x.NumBytes()).ToArray(), Enumerable.Repeat((long)Gb, 1).ToArray());
            }
        }
コード例 #2
0
        public static void ValidateBFast(byte[] buffer, BFastBuilder srcBuilder)
        {
            var bfast = BFast.ReadBFast(buffer).ToArray();

            var names      = srcBuilder.BufferNames().ToArray();
            var sizes      = srcBuilder.BufferSizes().ToArray();
            var numBuffers = names.Count();

            // We should have the same number of buffers
            AssertEquals(bfast.Length, numBuffers);
            for (var i = 0; i < numBuffers; i++)
            {
                // Of equal size
                AssertEquals(bfast[i].Name, names[i]);
                AssertEquals(bfast[i].Data.Length, sizes[i]);
                // And they might be sub-buffers
                if (srcBuilder.Children[i].Item2 is BFastBuilder childBuilder)
                {
                    ValidateBFast(bfast[i].ToBytes(), childBuilder);
                }
            }
        }