public void MutationalEntryPeerStreamTest()
        {
            var config = new MutationConfig()
            {
                Description = "Test"
            };
            var entry = new MutationalEntry()
            {
                FuzzPercent     = new FromToValue <double>(100),
                ValidOffset     = new FromToValue <long>(0, long.MaxValue),
                MaxChanges      = new FromToValue <ushort>(50),
                FuzzPercentType = EFuzzingPercentType.PeerStream
            };

            // Config

            config.Mutations.Add(entry);
            entry.Changes.Add(new MutationalChange()
            {
                Weight           = 1,
                Append           = new MutationalFromTo(0x01),
                RemoveLength     = new FromToValue <ushort>(),
                AppendIterations = new FromToValue <ushort>(1)
            });

            // 100% / 50 changes

            var input = new ManualFuzzingInput(new byte[200]);

            using (var copy = new MemoryStream())
                using (var stream = new FuzzingStream(config, input.GetStream()))
                {
                    stream.CopyTo(copy, 200);
                    Assert.AreEqual(50, copy.ToArray().Count(u => u == 0x01));
                }

            // 0%

            entry.FuzzPercent = new FromToValue <double>(0);

            input = new ManualFuzzingInput(new byte[200]);
            using (var copy = new MemoryStream())
                using (var stream = new FuzzingStream(config, input.GetStream()))
                {
                    stream.CopyTo(copy, 200);
                    Assert.AreEqual(200, copy.ToArray().Count(u => u == 0x00));
                }

            // Only offset 5

            entry.FuzzPercent = new FromToValue <double>(100);
            entry.ValidOffset = new FromToValue <long>(5);
            entry.MaxChanges  = new FromToValue <ushort>(1);

            input = new ManualFuzzingInput(new byte[200]);
            using (var stream = new FuzzingStream(config, input.GetStream()))
            {
                for (long x = 0; x < 200; x++)
                {
                    var next = entry.Get(stream, x, 0);

                    if (x == 5)
                    {
                        Assert.IsNotNull(next);
                    }
                    else
                    {
                        Assert.IsNull(next);
                    }
                }
            }

            // Max changes 2

            entry.ValidOffset = new FromToValue <long>(0, long.MaxValue);
            entry.MaxChanges  = new FromToValue <ushort>(2);

            input = new ManualFuzzingInput(new byte[200]);
            using (var stream = new FuzzingStream(config, input.GetStream()))
            {
                stream.CopyTo(new MemoryStream(), 200);

                Assert.AreEqual(2, stream.Log.Length);
            }
        }
        public void MutationalEntryPeerByteTest()
        {
            var config = new MutationConfig()
            {
                Description = "Test"
            };
            var entry = new MutationalEntry()
            {
                FuzzPercent     = new FromToValue <double>(100),
                ValidOffset     = new FromToValue <long>(0, long.MaxValue),
                MaxChanges      = new FromToValue <ushort>(ushort.MaxValue),
                FuzzPercentType = EFuzzingPercentType.PeerByte
            };

            // Config

            config.Mutations.Add(entry);
            entry.Changes.Add(new MutationalChange()
            {
                Weight           = 5,
                Description      = "Add A",
                Append           = new MutationalFromTo((byte)'A'),
                RemoveLength     = new FromToValue <ushort>(1),
                AppendIterations = new FromToValue <ushort>(1)
            });
            entry.Changes.Add(new MutationalChange()
            {
                // Remmove
                Weight           = 1,
                Description      = "Remove",
                RemoveLength     = new FromToValue <ushort>(1),
                AppendIterations = new FromToValue <ushort>(1)
            });

            // 100%

            var input = new ManualFuzzingInput(new byte[200]);

            using (var stream = new FuzzingStream(config, input.GetStream()))
            {
                for (long x = 0; x < 200; x++)
                {
                    Assert.IsNotNull(entry.Get(stream, x, 0));
                }
            }

            // 0%

            entry.FuzzPercent = new FromToValue <double>(0);

            input = new ManualFuzzingInput(new byte[200]);
            using (var stream = new FuzzingStream(config, input.GetStream()))
            {
                for (long x = 0; x < 200; x++)
                {
                    Assert.IsNull(entry.Get(stream, x, 0));
                }
            }

            // Argument excepcion

            entry.FuzzPercentType = (EFuzzingPercentType)197;
            Assert.Throws <ArgumentException>(() => entry.Get(null, 0, 0));

            // Only offset 5

            entry.FuzzPercentType = EFuzzingPercentType.PeerByte;
            entry.FuzzPercent     = new FromToValue <double>(100);
            entry.ValidOffset     = new FromToValue <long>(5);

            input = new ManualFuzzingInput(new byte[100]);
            using (var stream = new FuzzingStream(config, input.GetStream()))
            {
                for (long x = 0; x < 100; x++)
                {
                    var next = entry.Get(stream, x, 0);

                    if (x == 5)
                    {
                        Assert.IsNotNull(next);
                    }
                    else
                    {
                        Assert.IsNull(next);
                    }
                }
            }

            // Max changes 2

            entry.Changes.RemoveAt(1);
            entry.ValidOffset = new FromToValue <long>(0, long.MaxValue);
            entry.MaxChanges  = new FromToValue <ushort>(2);
            input             = new ManualFuzzingInput(new byte[100]);

            using (var stream = new FuzzingStream(config, input.GetStream()))
            {
                stream.CopyTo(new MemoryStream(), 16);

                Assert.AreEqual(2, stream.Log.Length);
                Assert.AreEqual(0, stream.Log[0].Offset);
                Assert.AreEqual(1, stream.Log[1].Offset);
            }
        }