Beispiel #1
0
        public void ComputeNoMatches()
        {
            input.Text.Returns("cozcola");
            input.SubText.Returns("coc");
            input.IsValid.Returns(true);
            prefixCalculator.Pattern.Returns("coc");
            prefixCalculator.Compute().Returns(new int[] { 0, 0, 1 });

            var algo    = new Algorithm(input, prefixCalculator);
            var matches = algo.FindMatches();

            CollectionAssert.IsEmpty(matches);
            Assert.That(matches.Length == 0);
            CollectionAssert.AreEqual(new int[] { }, matches);
        }
Beispiel #2
0
        /// <summary>
        /// Constructor (throws ArgumentException on invalid input)
        /// </summary>
        /// <param name="input">input object</param>
        /// <param name="caseSensitive">flag whether find matches with case sensitive or not (default to case insensitive)</param>
        public Algorithm(IInput input, IOverlapCalculator Table, bool caseSensitive = false)
        {
            try
            {
                if (input == null)
                {
                    throw new ArgumentNullException(Errors.InputWasNull);
                }

                if (!input.IsValid)
                {
                    throw new ArgumentException(Errors.InputWasInvalid);
                }

                if (Table == null)
                {
                    throw new ArgumentNullException(Errors.OvelapCalculatorWasNull);
                }

                this.Text = input.Text;
                this.SubText = input.SubText;
                this.PrefixTable = Table.Compute();
                this.IsCaseSensitive = caseSensitive;
            }
            catch (Exception e)
            {
                Logger.Push("Error received while initializing the KMPAlgorithm class object : " + e.Message);
                throw;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Constructor (throws ArgumentException on invalid input)
        /// </summary>
        /// <param name="input">input object</param>
        /// <param name="caseSensitive">flag whether find matches with case sensitive or not (default to case insensitive)</param>
        public Algorithm(IInput input, IOverlapCalculator Table, bool caseSensitive = false)
        {
            try
            {
                if (input == null)
                {
                    throw new ArgumentNullException(Errors.InputWasNull);
                }

                if (!input.IsValid)
                {
                    throw new ArgumentException(Errors.InputWasInvalid);
                }

                if (Table == null)
                {
                    throw new ArgumentNullException(Errors.OvelapCalculatorWasNull);
                }

                this.Text            = input.Text;
                this.SubText         = input.SubText;
                this.PrefixTable     = Table.Compute();
                this.IsCaseSensitive = caseSensitive;
            }
            catch (Exception e)
            {
                Logger.Push("Error received while initializing the KMPAlgorithm class object : " + e.Message);
                throw;
            }
        }