Пример #1
0
 public TestDirectory(
     string testName,
     BlockSequence blocks,
     Mutation mutation)
 {
     _path = $"testdata/{testName}_{blocks}_{mutation}";
     Directory.CreateDirectory(_path);
 }
Пример #2
0
 public static IEnumerable <object[]> TestCases()
 {
     foreach (var blocks in BlockSequence.All())
     {
         foreach (var mutation in Mutation.All())
         {
             foreach (var options in SignatureOptions())
             {
                 yield return(new object[] { blocks, mutation, options });
             }
         }
     }
 }
Пример #3
0
 public async Task MiddleBlock(BlockSequence blocks, Mutation mutation, SignatureOptions options)
 {
     using var files = new TestDirectory(nameof(MiddleBlock), blocks, mutation);
     await MutationTest.Test(files, blocks, mutation, options, blockToMutate : blocks.Count / 2);
 }
Пример #4
0
 public async Task AllBlocks(BlockSequence blocks, Mutation mutation, SignatureOptions options)
 {
     using var files = new TestDirectory(nameof(AllBlocks), blocks, mutation);
     await MutationTest.Test(files, blocks, mutation, options);
 }
Пример #5
0
        public static async Task Test(
            TestDirectory files,
            BlockSequence blockSequence,
            Mutation mutation,
            SignatureOptions options,
            int?blockToMutate = null)
        {
            var rdiff   = new Rdiff(files);
            var timings = new List <(TestFile, TimeSpan)>();
            var timer   = Stopwatch.StartNew();

            blockSequence.WriteTo(files.Path(TestFile.v1));

            timings.Add((TestFile.v1, timer.Elapsed));
            timer.Restart();

            using (var v1 = files.Read(TestFile.v1))
                using (var sig = files.Write(TestFile.sig))
                {
                    await _rdiff.SignatureAsync(v1, sig, options);
                }

            timings.Add((TestFile.sig, timer.Elapsed));
            timer.Restart();

            rdiff.Signature(TestFile.v1, TestFile.rs_sig, options);

            timings.Add((TestFile.rs_sig, timer.Elapsed));
            await AssertEqual(files, TestFile.rs_sig, TestFile.sig);

            timer.Restart();

            using (var v2 = files.Write(TestFile.v2))
                using (var v1 = files.Read(TestFile.v1))
                {
                    await mutation.WriteTo(
                        blockSequence.Blocks(v1),
                        i => i == (blockToMutate ?? i),
                        v2);
                }

            timings.Add((TestFile.v2, timer.Elapsed));
            timer.Restart();

            using (var sig = files.Read(TestFile.sig))
                using (var v2 = files.Read(TestFile.v2))
                    using (var delta = files.Write(TestFile.delta))
                    {
                        await _rdiff.DeltaAsync(sig, v2, delta);
                    }

            timings.Add((TestFile.delta, timer.Elapsed));
            timer.Restart();

            rdiff.Delta(TestFile.sig, TestFile.v2, TestFile.rs_delta);

            timings.Add((TestFile.rs_delta, timer.Elapsed));
            await AssertEqual(files, TestFile.rs_delta, TestFile.delta);

            timer.Restart();

            using (var delta = files.Read(TestFile.delta))
                using (var v1 = files.Read(TestFile.v1))
                    using (var patched = files.Write(TestFile.patched))
                    {
                        await _rdiff.PatchAsync(v1, delta, patched);
                    }

            timings.Add((TestFile.patched, timer.Elapsed));
            await AssertEqual(files, TestFile.v2, TestFile.patched);

            foreach (var(file, duration) in timings)
            {
                // Console.WriteLine($"{file}: {duration}");
            }
        }