Esempio n. 1
0
        public static void AssertProgressUpdateWasCalledRightNumberOfTimes(this ICorrelater <string> correlater)
        {
            var array1 = new[] { "A", "D", "B", "C" };
            var array2 = new[] { "A", "B", "D", "C" };

            correlater.AssertProgressUpdateWasCalledRightNumberOfTimes(array1, array2, array1.Length + 1);
        }
Esempio n. 2
0
        public static void AsseertCancellationTokenWorks(this ICorrelater <char> correlater)
        {
            var string1 = Utils.GetLongString(10_000);
            var string2 = Utils.GetLongString(10_000);

            correlater.AsseertCancellationTokenWorks(string1, string2);
        }
Esempio n. 3
0
 public IgnoreIdenticalBeginningAndEndCorrelaterWrapper(ICorrelater <T> innerCorrelater)
 {
     this.innerCorrelater              = innerCorrelater;
     innerCorrelater.OnProgressUpdate += (p, t) => OnProgressUpdate?.Invoke(p, t);
     if (innerCorrelater is IContinuousCorrelater <T> continuousCorrelater)
     {
         continuousCorrelater.OnResultUpdate += r => OnResultUpdate?.Invoke(r);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// SplitToChunksCorrelaterWrapper improves the correlation's performance by splitting the collection or string into chunks, and correlates each chunk individually.
        /// </summary>
        /// <param name="chunkSize">Bigger chunks will result in a slower, but more accurate correlation</param>
        /// <param name="maxDistance">If at any point during the correlation we find that the distance will be greater than maxDistance, we'll terminate the correlation and return null</param>
        public SplitToChunksCorrelaterWrapper(ICorrelater <T> innerCorrelater, int chunkSize, long maxDistance) :
            this(innerCorrelater, chunkSize)
        {
            if (maxDistance <= 0)
            {
                throw new ArgumentException($"{nameof(maxDistance)} must be greater than zero", nameof(maxDistance));
            }

            this.maxDistance = maxDistance;
        }
Esempio n. 5
0
        /// <summary>
        /// SplitToChunksCorrelaterWrapper improves the correlation's performance by splitting the collection or string into chunks, and correlates each chunk individually.
        /// </summary>
        /// <param name="chunkSize">Bigger chunks will result in a slower, but more accurate correlation</param>
        public SplitToChunksCorrelaterWrapper(ICorrelater <T> innerCorrelater, int chunkSize)
        {
            if (chunkSize <= 0)
            {
                throw new ArgumentException($"{nameof(chunkSize)} must be greater than zero", nameof(chunkSize));
            }

            this.chunkSize       = chunkSize;
            this.innerCorrelater = innerCorrelater;
            maxEdgeSize          = chunkSize / 2;
        }
Esempio n. 6
0
        public static void AssertProgressUpdateWasCalledRightNumberOfTimes <T>(this ICorrelater <T> correlater, T[] array1, T[] array2, int expectedProgress)
        {
            var progressUpdates = 0;

            correlater.OnProgressUpdate += (progress, outOf) =>
            {
                Assert.AreEqual(expectedProgress, outOf);
                Interlocked.Increment(ref progressUpdates);
                Assert.AreEqual(progressUpdates, progress);
            };
            correlater.Correlate(array1, array2);

            Assert.AreEqual(expectedProgress, progressUpdates);
        }
Esempio n. 7
0
 public static void AssetThrowsNullElementException <T>(this ICorrelater <T> correlater,
                                                        IEnumerable <T> collection1, IEnumerable <T> collection2, string badCollectionName, int nullIndex)
 {
     try
     {
         correlater.Correlate(collection1, collection2);
         Assert.Fail("Exception wasn't thrown");
     }
     catch (NullElementException e)
     {
         Assert.IsTrue(e.Message.Contains(badCollectionName));
         Assert.IsTrue(e.Message.Contains($"index {nullIndex}"));
     }
 }
Esempio n. 8
0
        public static void AsseertCancellationTokenWorks <T>(this ICorrelater <T> correlater, IEnumerable <T> collection1, IEnumerable <T> collection2)
        {
            try
            {
                var cancellationTokenSource = new CancellationTokenSource();
                var task = Task.Run(() => correlater.Correlate(collection1, collection2, cancellationTokenSource.Token));
                cancellationTokenSource.Cancel();
                task.Wait(TimeSpan.FromSeconds(1));
                Assert.Fail("The task doesn't seem to have stopped");
            }
            catch (Exception e) when(e is AggregateException)
            {
                var innerException = e.InnerException;

                while (innerException is AggregateException aggregateException)
                {
                    innerException = aggregateException.InnerException;
                }
                Assert.AreEqual(typeof(OperationCanceledException), innerException.GetType());
            }
        }
 public SplitByPatienceAlgorithmWrapper(ICorrelater <T> innerCorrelater, bool multiThread = true)
 {
     this.innerCorrelater = innerCorrelater;
     this.multiThread     = multiThread;
 }
Esempio n. 10
0
 public static void SetToRetrun <T>(this ICorrelater <T> correlater, Func <IEnumerable <T>, IEnumerable <T> > func1, Func <IEnumerable <T>, IEnumerable <T> > func2, int distance = 0)
 {
     A.CallTo(() => correlater.Correlate(A <IEnumerable <T> > ._, A <IEnumerable <T> > ._, A <CancellationToken> ._))
     .ReturnsLazily((IEnumerable <T> c1, IEnumerable <T> c2, CancellationToken ct) =>
                    new CorrelaterResult <T>(distance, func1(c1).ToArray(), func2(c2).ToArray()));
 }
Esempio n. 11
0
 public static void SetToRetrunInputCollection <T>(this ICorrelater <T> correlater, int distance)
 {
     A.CallTo(() => correlater.Correlate(A <IEnumerable <T> > ._, A <IEnumerable <T> > ._, A <CancellationToken> ._))
     .ReturnsLazily((IEnumerable <T> c1, IEnumerable <T> c2, CancellationToken ct) =>
                    new CorrelaterResult <T>(distance, c1.ToArray(), c2.ToArray()));
 }
Esempio n. 12
0
 public SlowCorrelater(ICorrelater <T> innerCorrelater, int sleepTime)
 {
     this.innerCorrelater              = innerCorrelater;
     innerCorrelater.OnProgressUpdate += (p, t) => OnProgressUpdate?.Invoke(t, p);
     this.sleepTime = sleepTime;
 }
Esempio n. 13
0
 public StringCorrelatorUserControl()
 {
     correlater = new LevenshteinCorrelater <char>(10, 7, 7);
     InitializeComponent();
 }
Esempio n. 14
0
        public static void AssertComparision <T>(this ICorrelater <T> correlater, IEnumerable <T> collection1, IEnumerable <T> collection2, CorrelaterResult <T> expectedResult)
        {
            var result = correlater.Correlate(collection1, collection2);

            AssertResultIsAsExpected(expectedResult, result);
        }